123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //
- // 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)
- }
- }
|