// // KMBGTemplateItem.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/11/7. // import Cocoa import KMComponentLibrary @objc protocol KMBGTemplateItemDelegate: AnyObject { @objc optional func kmNBGTemplateItemDidEdit(_ view: KMBGTemplateItem) @objc optional func kmNBGTemplateItemDidDelete(_ view: KMBGTemplateItem) } class KMBGTemplateItem: NSCollectionViewItem { @IBOutlet var watermarkItem: ComponentCardWatermark! var backgroundModel: KMBackgroundModel? weak open var delegate: KMBGTemplateItemDelegate? var watermarkProperty: ComponentCardWMProperty = ComponentCardWMProperty(state: .normal, icon: nil, text: "Sample Text", editIcon: NSImage(named: "watermark_edit"), deleteIcon: NSImage(named: "pageEdit_delete")) override func viewDidLoad() { super.viewDidLoad() // Do view setup here. watermarkItem.properties = watermarkProperty watermarkItem.delegate = self } //Setter override var isSelected: Bool { get{ return super.isSelected } set{ super.isSelected = newValue reloadData() } } func reloadData() { watermarkItem.properties.icon = backgroundModel?.modelPreviewImage() watermarkItem.properties.state = isSelected ? .pressed : .normal watermarkItem.properties.text = backgroundModel?.name watermarkItem.reloadData() } } //MARK: - ComponentCardWatermarkDelegate extension KMBGTemplateItem: ComponentCardWatermarkDelegate { func componentSliderDidEdit(_ view: ComponentCardWatermark) { delegate?.kmNBGTemplateItemDidEdit?(self) } func componentSliderDidDelete(_ view: ComponentCardWatermark) { delegate?.kmNBGTemplateItemDidDelete?(self) } }