// // KMNThumbnailCollectionViewItem.swift // PDF Reader Pro // // Created by 丁林圭 on 2024/10/21. // import Cocoa import KMComponentLibrary class KMNThumbnailCollectionViewItem: NSCollectionViewItem { @IBOutlet var cardFileView: ComponentCardFile! var doubleClickBack: (() -> Void)? public var thumbnailMode: KMNThumbnail = KMNThumbnail.init() { didSet { var orgPageHeight = thumbnailMode.pageSize.height var orgPagewidth = thumbnailMode.pageSize.width if (thumbnailMode.thumbnaiPage?.rotation ?? 0) % 180 != 0 { orgPageHeight = thumbnailMode.pageSize.width orgPagewidth = thumbnailMode.pageSize.height } cardFileView.properties = ComponentCardFileProperty(folder: false, state: .normal, icon: NSImage.init(named: "KMNImageNameThumbnailPlaceImage"), text: String(format: "%d", (thumbnailMode.pageIndex+1)), subText: String(format: "%.0f x %.0fmm", (thumbnailMode.pageSize.width / 595 * 210), (thumbnailMode.pageSize.height / 842 * 297)), markIcon:NSImage.init(named: "KMNImageNameThumbnailBookMark")) cardFileView.properties.isShowSubText = isShowFileSize cardFileView.properties.propertyInfo.infoLabelHeight = infoThumTitleHeight cardFileView.properties.isShowMarkIcon = thumbnailMode.isHoveBookMark cardFileView.reloadData() let maxThumCellWidth = self.view.frame.size.width - infoThumTitleBottom * 2 var maxThumCellHeight = self.view.frame.size.height maxThumCellHeight -= cardFileView.properties.propertyInfo.infoLabelHeight maxThumCellHeight -= cardFileView.properties.propertyInfo.subLabelHeight maxThumCellHeight -= (cardFileView.properties.propertyInfo.topIconOffset + cardFileView.properties.propertyInfo.bottomOffset + cardFileView.properties.propertyInfo.topLabelOffset) //间隔 let minimumValue = min(maxThumCellHeight/orgPageHeight, maxThumCellWidth/orgPagewidth) let relCellHeight = orgPageHeight * minimumValue let relCellWidth = orgPagewidth * minimumValue thumbnailMode.generateThumImage { image in self.cardFileView.properties.propertyInfo.iconImageWidth = relCellWidth self.cardFileView.properties.propertyInfo.iconImageHeight = relCellHeight if(image != nil) { self.cardFileView.properties.icon = image } self.cardFileView.reloadData() } } } override var isSelected: Bool{ didSet { cardFileView.properties.state = isSelected ? .pressed : .normal cardFileView.reloadData() } } public var isShowFileSize :Bool = false override func viewDidLoad() { super.viewDidLoad() } override func mouseDown(with event: NSEvent) { super.mouseDown(with: event) if (event.clickCount > 1) { doubleClickBack?() } } }