123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- //
- // KMWatermarkCollectionViewItem.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/11/3.
- //
- import Cocoa
- class KMWatermarkCollectionViewItem: NSCollectionViewItem {
- var waterMarkOprateCallback: ((KMWatermarkOperateType, KMWatermarkModel?) -> Void)?
- var backgroundOperateCallback: ((KMBackgroundOperateType, KMBackgroundModel?) -> Void)?
-
- @IBOutlet var topBaseView: NSView!
- @IBOutlet var optionView: NSView!
- @IBOutlet var editButton: KMCoverButton!
- @IBOutlet var deleteButton: KMCoverButton!
- @IBOutlet var watermarkNameLabel: NSTextField!
- @IBOutlet var watermarkImageView: NSImageView!
- @IBOutlet var labelContainerView: NSView!
- private var _waterMark: KMWatermarkModel?
- private var _background: KMBackgroundModel?
-
- deinit {
- KMPrint("KMWatermarkCollectionViewItem deinit.")
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- self._configuUI()
- self._addTrackingArea()
- }
-
- override var isSelected: Bool {
- didSet {
- if (self.isSelected) {
- self.imageView?.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- self.labelContainerView.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.watermarkNameLabel.textColor = KMAppearance.Layout.w0Color()
- self.topBaseView.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- } else {
- self.imageView?.layer?.borderColor = KMAppearance.Layout.h2Color().cgColor
- self.labelContainerView.layer?.backgroundColor = .clear
- self.watermarkNameLabel.textColor = KMAppearance.Layout.h0Color()
- self.topBaseView.layer?.borderColor = KMAppearance.Layout.h2Color().cgColor
- }
- }
- }
-
- func updateInterface(_ waterMark: KMWatermarkModel) {
- self._waterMark = waterMark;
- if waterMark.isFront {
- self.watermarkImageView.image = NSImage(named: "KMImageNameUXIconVipWatermarkImg")
- self.imageView!.image = KMWatermarkModel.drawImageAtpageRect(rect: self.watermarkImageView.bounds, data: waterMark) // KMWatermarkManager.drawImageAtpageRect:self.watermarkImageView.bounds watermarkDatas:waterMark];
- } else {
- self.imageView?.image = NSImage(named: "KMImageNameUXIconVipWatermarkImg")
- self.watermarkImageView.image = KMWatermarkModel.drawImageAtpageRect(rect: self.watermarkImageView.bounds, data: waterMark)//[KMPDFWatermarkObject drawImageAtpageRect:self.watermarkImageView.bounds watermarkDatas:waterMark];
- }
- self.watermarkNameLabel.stringValue = waterMark.watermarkID
- }
-
- func updateBackgroundInterface(_ background: KMBackgroundModel) {
- self._background = background
- if (background.type == .color) {
- self.watermarkImageView.image = nil
- self.imageView?.image = nil
- self.watermarkImageView.wantsLayer = true
- self.watermarkImageView.layer?.backgroundColor = background.color?.cgColor
- } else {
- self.watermarkImageView.image = background.image
- self.watermarkImageView.layer?.backgroundColor = NSColor.clear.cgColor
- }
- self.watermarkNameLabel.stringValue = background.backgroundID
- }
-
- //编辑水印
- @IBAction @objc func buttonClicked_EditWatermark(_ sender: AnyObject?) {
- if (self.waterMarkOprateCallback != nil) {
- self.waterMarkOprateCallback!(.Edit, self._waterMark)
- }
- if (self.backgroundOperateCallback != nil) {
- self.backgroundOperateCallback!(.Edit, self._background)
- }
- }
-
- //删除水印
- @IBAction @objc func buttonClicked_DeleteWatermark(_ sender: AnyObject?) {
- if (self.waterMarkOprateCallback != nil) {
- self.waterMarkOprateCallback!(.Delete, self._waterMark)
- }
-
- if (self.backgroundOperateCallback != nil) {
- self.backgroundOperateCallback!(.Delete, self._background)
- }
- }
-
- override func mouseEntered(with event: NSEvent) {
- if let data = self.view.window?.isKeyWindow, data {
- self.optionView.isHidden = false
- self.topBaseView.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- }
- }
-
- override func mouseExited(with event: NSEvent) {
- if let data = self.view.window?.isKeyWindow, data {
- self.optionView.isHidden = true
- if(self.isSelected) {
- self.topBaseView.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- } else {
- self.topBaseView.layer?.borderColor = KMAppearance.Layout.h2Color().cgColor
- }
- }
- }
- }
- // MARK: - Private Methods
- extension KMWatermarkCollectionViewItem {
- private func _configuUI() {
- self.imageView?.wantsLayer = true
- self.imageView?.layer?.borderWidth = 1.0
-
- self.topBaseView.wantsLayer = true
- self.topBaseView.layer?.borderWidth = 1.0
- self.topBaseView.layer?.borderColor = KMAppearance.Layout.h2Color().cgColor
-
- self.optionView.wantsLayer = true
- // self.optionView.layer.backgroundColor = [KMAppearance KMColor_Layout_L_1].CGColor;
- self.optionView.isHidden = true
-
- self.labelContainerView.wantsLayer = true
- self.labelContainerView.layer?.cornerRadius = 1.0
- self.imageView?.layer?.borderColor = KMAppearance.Layout.h2Color().cgColor
-
- self.editButton.coverAction = { [unowned self] cbutton, cation in
- if (cation == .enter) {
- self.editButton.image = NSImage(named: KMImageNameUXIconBtnEditHov)
- } else {
- self.editButton.image = NSImage(named: KMImageNameUXIconBtnEditNor)
- }
- }
- self.deleteButton.coverAction = { [unowned self] cbutton, cation in
- if (cation == .enter) {
- self.deleteButton.image = NSImage(named: KMImageNameUXIconBtnCloseHov)
- } else {
- self.deleteButton.image = NSImage(named: KMImageNameUXIconBtnCloseNor)
- }
- };
- }
-
- private func _addTrackingArea() {
- let trackingArea = NSTrackingArea(rect: self.view.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeAlways, .mouseMoved], owner: self)
- self.view.addTrackingArea(trackingArea)
- }
- }
|