KMSigntureViewItem.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // KMSigntureViewItem.m
  3. // PDF Master
  4. //
  5. // Created by Niehaoyu on 2023/2/25.
  6. //
  7. #import "KMSigntureViewItem.h"
  8. #import "NSMenu+Category.h"
  9. #if VERSION_DMG
  10. #import <PDF_Master-Swift.h>
  11. #else
  12. #import <PDF_Master-Swift.h>
  13. #endif
  14. @interface KMSigntureViewItem ()
  15. @property (strong) IBOutlet NSView *contendView;
  16. @property (nonatomic, copy) NSTrackingArea *trackingArea;
  17. @end
  18. @implementation KMSigntureViewItem
  19. - (void)dealloc {
  20. if (self.trackingArea) {
  21. [self.view removeTrackingArea:self.trackingArea];
  22. }
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do view setup here.
  27. self.contendView.wantsLayer = YES;
  28. self.contendView.layer.cornerRadius = 8.0;
  29. self.contendView.layer.masksToBounds = YES;
  30. self.contendView.layer.borderWidth = 1.;
  31. self.contendView.layer.borderColor = [NSColor clearColor].CGColor;
  32. self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.view.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways |NSTrackingMouseMoved owner:self userInfo:nil];
  33. [self.view addTrackingArea:self.trackingArea];
  34. self.deleteIconBtn.hidden = YES;
  35. [self tableViewMenu];
  36. }
  37. - (void)tableViewMenu {
  38. NSMenu *menu = [[NSMenu alloc] init];
  39. NSMenuItem *item = [menu addItemWithTitle:NSLocalizedString(@"Export stamp", nil) action:nil target:self];
  40. NSMenu *tSubMenu = [[NSMenu alloc] init];
  41. NSMenuItem *tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(exportCustomizeStamp:) target:self atIndex:0];
  42. tMenuItem.tag = 0;
  43. // tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(exportCustomizeStamp:) target:self atIndex:1];
  44. // tMenuItem.tag = 1;
  45. tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(exportCustomizeStamp:) target:self atIndex:1];
  46. tMenuItem.tag = 2;
  47. item.submenu = tSubMenu;
  48. [menu addItem:[NSMenuItem separatorItem]];
  49. [menu addItemWithTitle:NSLocalizedString(@"Delete stamp", nil) action:@selector(deleteCustomizeStamp) target:self];
  50. [menu addItemWithTitle:NSLocalizedString(@"Delete All stamp", nil) action:@selector(deleteAllCustomizeStamp) target:self];
  51. self.view.menu = menu;
  52. }
  53. #pragma mark - set
  54. - (void)setIsSelect:(BOOL)isSelect {
  55. _isSelect = isSelect;
  56. if(_isSelect) {
  57. self.contendView.layer.borderColor = [NSColor km_initWithHex: @"#CED0D4" alpha: 0.6].CGColor;
  58. self.contendView.layer.backgroundColor = [NSColor km_initWithHex: @"#CED0D4" alpha: 1].CGColor;
  59. } else {
  60. self.contendView.layer.borderColor = [NSColor clearColor].CGColor;
  61. self.contendView.layer.backgroundColor = [NSColor clearColor].CGColor;
  62. }
  63. }
  64. #pragma mark - mouse
  65. - (void)mouseEntered:(NSEvent *)event {
  66. [super mouseEntered:event];
  67. if (_isSelect) {
  68. } else {
  69. self.contendView.layer.borderColor = [NSColor km_initWithHex: @"#EDEEF0" alpha: 1].CGColor;
  70. self.contendView.layer.backgroundColor = [NSColor km_initWithHex: @"#EDEEF0" alpha: 1].CGColor;
  71. }
  72. }
  73. - (void)mouseExited:(NSEvent *)event {
  74. [super mouseExited:event];
  75. // self.deleteIconBtn.hidden = YES;
  76. if (_isSelect) {
  77. } else {
  78. self.contendView.layer.borderColor = [NSColor clearColor].CGColor;
  79. self.contendView.layer.backgroundColor = [NSColor clearColor].CGColor;
  80. }
  81. }
  82. - (void)exportCustomizeStamp:(NSMenuItem *)sender {
  83. if (self.delegate && [self.delegate respondsToSelector:@selector(kmSigntureViewItem:didClickMenuWithItem:)]) {
  84. [self.delegate kmSigntureViewItem:self didClickMenuWithItem:sender];
  85. }
  86. }
  87. - (void)deleteCustomizeStamp {
  88. if (self.delegate && [self.delegate respondsToSelector:@selector(kmSigntureViewItemDidClickDeleteMenuItem:)]) {
  89. [self.delegate kmSigntureViewItemDidClickDeleteMenuItem:self];
  90. }
  91. }
  92. - (void)deleteAllCustomizeStamp {
  93. if (self.delegate && [self.delegate respondsToSelector:@selector(kmSigntureViewItemDidClickAllDeleteMenuItem:)]) {
  94. [self.delegate kmSigntureViewItemDidClickAllDeleteMenuItem:self];
  95. }
  96. }
  97. @end