KMNThumbnailCollectionViewItem.swift 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // KMNThumbnailCollectionViewItem.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/10/21.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNThumbnailCollectionViewItem: NSCollectionViewItem {
  10. @IBOutlet var cardFileView: ComponentCardFile!
  11. var doubleClickBack: (() -> Void)?
  12. public var thumbnailMode: KMNThumbnail = KMNThumbnail.init() {
  13. didSet {
  14. cardFileView.properties = ComponentCardFileProperty(folder: false,
  15. state: .normal,
  16. icon: NSImage.init(named: "KMNImageNameThumbnailPlaceImage"),
  17. text: String(format: "%d", thumbnailMode.pageIndex),
  18. subText: String(format: "%.0f x %.0f", thumbnailMode.pageSize.width, thumbnailMode.pageSize.height),
  19. markIcon:NSImage.init(named: "KMNImageNameThumbnailBookMark"))
  20. cardFileView.properties.propertyInfo.infoLabelHeight = 16.0
  21. let maxThumCellWidth = self.view.frame.size.width - 32.0
  22. var maxThumCellHeight = self.view.frame.size.height
  23. maxThumCellHeight -= cardFileView.properties.propertyInfo.infoLabelHeight
  24. maxThumCellHeight -= cardFileView.properties.propertyInfo.subLabelHeight
  25. maxThumCellHeight -= (cardFileView.properties.propertyInfo.topIconOffset + cardFileView.properties.propertyInfo.bottomOffset + cardFileView.properties.propertyInfo.topLabelOffset) //间隔
  26. let orgPageHeight = thumbnailMode.pageSize.height
  27. let orgPagewidth = thumbnailMode.pageSize.width
  28. let minimumValue = min(maxThumCellHeight/orgPageHeight, maxThumCellWidth/orgPagewidth)
  29. let relCellHeight = thumbnailMode.pageSize.height * minimumValue
  30. let relCellWidth = thumbnailMode.pageSize.width * minimumValue
  31. cardFileView.properties.isShowMarkIcon = thumbnailMode.isHoveBookMark
  32. thumbnailMode.generateThumImage { image in
  33. self.cardFileView.properties.propertyInfo.iconImageWidth = relCellWidth
  34. self.cardFileView.properties.propertyInfo.iconImageHeight = relCellHeight
  35. if(image != nil) {
  36. self.cardFileView.properties.icon = image
  37. }
  38. self.cardFileView.reloadData()
  39. }
  40. }
  41. }
  42. override var isSelected: Bool{
  43. didSet {
  44. cardFileView.properties.state = isSelected ? .pressed : .normal
  45. cardFileView.reloadData()
  46. }
  47. }
  48. public var isShowFileSize :Bool = false {
  49. didSet {
  50. cardFileView.properties.isShowSubText = isShowFileSize
  51. cardFileView.reloadData()
  52. }
  53. }
  54. override func viewDidLoad() {
  55. super.viewDidLoad()
  56. }
  57. override func mouseDown(with event: NSEvent) {
  58. super.mouseDown(with: event)
  59. if (event.clickCount > 1) {
  60. doubleClickBack?()
  61. }
  62. }
  63. }