123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // KMSigntureViewItem.swift
- // PDF Master
- //
- // Created by lizhe on 2023/10/9.
- //
- import Cocoa
- @objcMembers class KMSigntureViewItem: NSCollectionViewItem {
- @IBOutlet var contendView: NSView!
- @IBOutlet var iconImg: NSImageView!
- @IBOutlet var deleteIconBtn: NSButton!
- weak var delegate: KMSigntureViewItemDelegate?
-
- var trackingArea: NSTrackingArea?
- var itemIndex: Int = 0
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.contendView.wantsLayer = true
- self.contendView.layer?.cornerRadius = 8.0
- self.contendView.layer?.masksToBounds = true
- self.contendView.layer?.borderWidth = 1.0
- self.contendView.layer?.borderColor = NSColor.clear.cgColor
- self.trackingArea = NSTrackingArea(rect: self.view.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeAlways, .mouseMoved], owner: self, userInfo: nil)
- self.view.addTrackingArea(self.trackingArea!)
- self.deleteIconBtn.isHidden = true
- tableViewMenu()
- }
- func tableViewMenu() {
- let menu = NSMenu()
- let item = menu.addItem(withTitle: NSLocalizedString("Export stamp", comment: ""), action: nil, keyEquivalent: "")
- let tSubMenu = NSMenu()
- var tMenuItem = tSubMenu.insertItem(withTitle: NSLocalizedString("PNG", comment: ""), action: #selector(exportCustomizeStamp(_:)), keyEquivalent: "", at: 0)
- tMenuItem.tag = 0
- // tMenuItem = tSubMenu.insertItem(withTitle: NSLocalizedString("JPG", comment: ""), action: #selector(exportCustomizeStamp(_:)), keyEquivalent: "", at: 1)
- // tMenuItem.tag = 1
- tMenuItem = tSubMenu.insertItem(withTitle: NSLocalizedString("PDF", comment: ""), action: #selector(exportCustomizeStamp(_:)), keyEquivalent: "", at: 1)
- tMenuItem.tag = 2
- item.submenu = tSubMenu
- menu.addItem(NSMenuItem.separator())
- menu.addItem(withTitle: NSLocalizedString("Delete stamp", comment: ""), action: #selector(deleteCustomizeStamp), keyEquivalent: "")
- menu.addItem(withTitle: NSLocalizedString("Delete All stamp", comment: ""), action: #selector(deleteAllCustomizeStamp), keyEquivalent: "")
- self.view.menu = menu
- }
- var isSelect: Bool = false {
- didSet {
- if isSelect {
- self.contendView.layer?.borderColor = NSColor(red: 206/255, green: 208/255, blue: 212/255, alpha: 0.6).cgColor
- self.contendView.layer?.backgroundColor = NSColor(red: 206/255, green: 208/255, blue: 212/255, alpha: 1).cgColor
- } else {
- self.contendView.layer?.borderColor = NSColor.clear.cgColor
- self.contendView.layer?.backgroundColor = NSColor.clear.cgColor
- }
- }
- }
- override func mouseEntered(with event: NSEvent) {
- super.mouseEntered(with: event)
- if isSelect {
- } else {
- self.contendView.layer?.borderColor = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1).cgColor
- self.contendView.layer?.backgroundColor = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1).cgColor
- }
- }
- override func mouseExited(with event: NSEvent) {
- super.mouseExited(with: event)
- if isSelect {
- } else {
- self.contendView.layer?.borderColor = NSColor.clear.cgColor
- self.contendView.layer?.backgroundColor = NSColor.clear.cgColor
- }
- }
- @objc func exportCustomizeStamp(_ sender: NSMenuItem) {
- if let delegate = self.delegate {
- delegate.kmSigntureViewItem(self, didClickMenuWithItem: sender)
- }
- }
- @objc func deleteCustomizeStamp() {
- if let delegate = self.delegate {
- delegate.kmSigntureViewItemDidClickDeleteMenuItem(self)
- }
- }
- @objc func deleteAllCustomizeStamp() {
- if let delegate = self.delegate {
- delegate.kmSigntureViewItemDidClickAllDeleteMenuItem(self)
- }
- }
- }
- @objc protocol KMSigntureViewItemDelegate: NSObjectProtocol {
- func kmSigntureViewItem(_ item: KMSigntureViewItem, didClickMenuWithItem menuItem: NSMenuItem)
- func kmSigntureViewItemDidClickDeleteMenuItem(_ item: KMSigntureViewItem)
- func kmSigntureViewItemDidClickAllDeleteMenuItem(_ item: KMSigntureViewItem)
- }
|