123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // KMThumbnailTableviewCell.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/11/16.
- //
- import Cocoa
- class KMThumbnailTableviewCell: NSTableCellView {
- @IBOutlet var thumBox: KMBox!
- @IBOutlet var thumImage: NSImageView!
- @IBOutlet var pageNumLabel: NSTextField!
- @IBOutlet var sizeLabel: NSTextField!
- @IBOutlet var labelView: NSView!
- @IBOutlet var sizeTopConstant: NSLayoutConstraint!
- @IBOutlet var imageAspectRatioLayout: NSLayoutConstraint!
-
- var bkIcon: NSImageView = NSImageView()
-
- lazy var pageView = KMPDFThumbnialPageView()
- lazy var pageBox = NSView()
-
- var isSelectCell = false {
- didSet {
- if (self.isSelectCell) {
- self.thumImage.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- self.thumImage.layer?.borderWidth = 1.0
- self.pageBox.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- self.pageBox.layer?.borderWidth = 1.0
- self.labelView.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.pageNumLabel.textColor = KMAppearance.Layout.w0Color()
- self.sizeLabel.textColor = KMAppearance.Layout.w0Color()
- } else {
- self.thumImage.layer?.borderColor = KMAppearance.Layout.h2Color().cgColor
- self.thumImage.layer?.borderWidth = 1.0
- self.pageBox.layer?.borderColor = KMAppearance.Layout.h2Color().cgColor
- self.pageBox.layer?.borderWidth = 1.0
- self.labelView.layer?.backgroundColor = .clear
- self.pageNumLabel.textColor = KMAppearance.Layout.h0Color()
- self.sizeLabel.textColor = KMAppearance.Layout.h0Color()
- }
- }
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.wantsLayer = true
- self.layer?.backgroundColor = .clear
- self.layer?.cornerRadius = 0.0
-
- self.thumImage.wantsLayer = true
- self.labelView.wantsLayer = true
-
- self.addSubview(self.pageBox)
- self.pageBox.wantsLayer = true
- self.addSubview(self.pageView)
- self.thumImage.isHidden = true
-
- self.addSubview(self.bkIcon)
- self.bkIcon.wantsLayer = true
- // self.bkIcon.layer?.backgroundColor = .black
- self.bkIcon.image = NSImage(named: "KMImageNameBookmarkIcon")
- }
-
- override func layout() {
- super.layout()
-
- let width = NSWidth(self.bounds)
- let height = NSHeight(self.bounds)
-
- let border: CGFloat = 10
- var bounds = self.pageView.page?.bounds ?? .zero
- let rotate = self.pageView.page?.rotation ?? 0 % 360
- if (bounds.size.equalTo(.zero)) {
- return
- }
-
- if rotate == 90 || rotate == 270 {
- let tmp = bounds.size.width
- bounds.size.width = bounds.size.height
- bounds.size.height = tmp
- }
- var pageSelectionSize = CGSize(width: NSWidth(self.bounds)-30, height: NSHeight(self.bounds)-40)
- var size = NSMakeSize(pageSelectionSize.width - 2 * border, pageSelectionSize.height - 2 * border)
- // let minScale = min(size.width/bounds.size.width, size.height/bounds.size.height)
- let minScale = size.height/bounds.size.height
- size.width = bounds.size.width * minScale
- size.height = bounds.size.height * minScale
-
- if rotate == 90 || rotate == 270 {
- let max = max(size.height, size.width)
- // let ws = size.width / max
- let hs = size.height / max
-
- let tmp = size.width
- // size.width = size.height * hs
- // size.height = tmp
- }
-
- let pageViewX = (pageSelectionSize.width-size.width) * 0.5 + 15
- let pageViewY = (pageSelectionSize.height-size.height) * 0.5 + 20 + 20
- self.pageView.frame = NSMakeRect(pageViewX, pageViewY, size.width, size.height)
- self.pageBox.frame = NSInsetRect(self.pageView.frame, -5, -5)
-
- let bkWH: CGFloat = 20
- let bkX = NSMaxX(self.pageView.frame)-bkWH
- let bkY = NSMaxY(self.pageView.frame)-bkWH
- self.bkIcon.frame = NSMakeRect(bkX, bkY, bkWH, bkWH)
- }
- }
|