KMHomeQuickToolsWindowCollectionViewItem.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // KMHomeQuickToolsWindowCollectionViewItem.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/10/31.
  6. //
  7. import Cocoa
  8. class KMHomeQuickToolsWindowCollectionViewItem: NSCollectionViewItem {
  9. @IBOutlet weak var iconImageView: NSImageView!
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var box: KMBox!
  12. var model: KMQucikToolsModel? {
  13. didSet {
  14. self.reloadData()
  15. }
  16. }
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. // Do view setup here.
  20. self.setup()
  21. }
  22. func setup() {
  23. self.box.fillColor = NSColor.clear
  24. self.titleLabel.textColor = KMAppearance.Layout.h2Color()
  25. self.box.moveCallback = { [unowned self] mouseEntered, mouseBox in
  26. if mouseEntered {
  27. box.fillColor = KMAppearance.Interactive.a0Color()
  28. titleLabel.textColor = KMAppearance.Layout.w0Color()
  29. iconImageView.image = model?.iconImage(true)
  30. } else {
  31. box.fillColor = NSColor.clear
  32. titleLabel.textColor = KMAppearance.Layout.h2Color()
  33. iconImageView.image = model?.iconImage(false)
  34. }
  35. }
  36. }
  37. func reloadData() {
  38. guard let model = model else { return }
  39. titleLabel.stringValue = model.titleString()
  40. iconImageView.image = model.iconImage()
  41. }
  42. }