123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // KMSigntureViewItem.m
- // PDF Master
- //
- // Created by Niehaoyu on 2023/2/25.
- //
- #import "KMSigntureViewItem.h"
- #import "NSMenu+Category.h"
- #if VERSION_DMG
- #import <PDF_Master-Swift.h>
- #else
- #import <PDF_Master-Swift.h>
- #endif
- @interface KMSigntureViewItem ()
- @property (strong) IBOutlet NSView *contendView;
- @property (nonatomic, copy) NSTrackingArea *trackingArea;
- @end
- @implementation KMSigntureViewItem
- - (void)dealloc {
-
- if (self.trackingArea) {
- [self.view removeTrackingArea:self.trackingArea];
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do view setup here.
-
- self.contendView.wantsLayer = YES;
- self.contendView.layer.cornerRadius = 8.0;
- self.contendView.layer.masksToBounds = YES;
- self.contendView.layer.borderWidth = 1.;
- self.contendView.layer.borderColor = [NSColor clearColor].CGColor;
-
- self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.view.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways |NSTrackingMouseMoved owner:self userInfo:nil];
- [self.view addTrackingArea:self.trackingArea];
-
- self.deleteIconBtn.hidden = YES;
-
- [self tableViewMenu];
- }
- - (void)tableViewMenu {
- NSMenu *menu = [[NSMenu alloc] init];
- NSMenuItem *item = [menu addItemWithTitle:NSLocalizedString(@"Export stamp", nil) action:nil target:self];
- NSMenu *tSubMenu = [[NSMenu alloc] init];
- NSMenuItem *tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(exportCustomizeStamp:) target:self atIndex:0];
- tMenuItem.tag = 0;
- // tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(exportCustomizeStamp:) target:self atIndex:1];
- // tMenuItem.tag = 1;
- tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(exportCustomizeStamp:) target:self atIndex:1];
- tMenuItem.tag = 2;
- item.submenu = tSubMenu;
- [menu addItem:[NSMenuItem separatorItem]];
- [menu addItemWithTitle:NSLocalizedString(@"Delete stamp", nil) action:@selector(deleteCustomizeStamp) target:self];
- [menu addItemWithTitle:NSLocalizedString(@"Delete All stamp", nil) action:@selector(deleteAllCustomizeStamp) target:self];
- self.view.menu = menu;
- }
- #pragma mark - set
- - (void)setIsSelect:(BOOL)isSelect {
- _isSelect = isSelect;
-
- if(_isSelect) {
- self.contendView.layer.borderColor = [NSColor km_initWithHex: @"#CED0D4" alpha: 0.6].CGColor;
- self.contendView.layer.backgroundColor = [NSColor km_initWithHex: @"#CED0D4" alpha: 1].CGColor;
- } else {
- self.contendView.layer.borderColor = [NSColor clearColor].CGColor;
- self.contendView.layer.backgroundColor = [NSColor clearColor].CGColor;
- }
-
- }
- #pragma mark - mouse
- - (void)mouseEntered:(NSEvent *)event {
- [super mouseEntered:event];
-
- if (_isSelect) {
-
- } else {
- self.contendView.layer.borderColor = [NSColor km_initWithHex: @"#EDEEF0" alpha: 1].CGColor;
- self.contendView.layer.backgroundColor = [NSColor km_initWithHex: @"#EDEEF0" alpha: 1].CGColor;
- }
- }
- - (void)mouseExited:(NSEvent *)event {
- [super mouseExited:event];
-
- // self.deleteIconBtn.hidden = YES;
- if (_isSelect) {
-
- } else {
- self.contendView.layer.borderColor = [NSColor clearColor].CGColor;
- self.contendView.layer.backgroundColor = [NSColor clearColor].CGColor;
- }
- }
- - (void)exportCustomizeStamp:(NSMenuItem *)sender {
- if (self.delegate && [self.delegate respondsToSelector:@selector(kmSigntureViewItem:didClickMenuWithItem:)]) {
- [self.delegate kmSigntureViewItem:self didClickMenuWithItem:sender];
- }
- }
- - (void)deleteCustomizeStamp {
- if (self.delegate && [self.delegate respondsToSelector:@selector(kmSigntureViewItemDidClickDeleteMenuItem:)]) {
- [self.delegate kmSigntureViewItemDidClickDeleteMenuItem:self];
- }
- }
- - (void)deleteAllCustomizeStamp {
- if (self.delegate && [self.delegate respondsToSelector:@selector(kmSigntureViewItemDidClickAllDeleteMenuItem:)]) {
- [self.delegate kmSigntureViewItemDidClickAllDeleteMenuItem:self];
- }
- }
- @end
|