KMSignatureWindowController.m 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. //
  2. // KMSignatureWindowController.m
  3. // PDF Reader Premium
  4. //
  5. // Created by wangshuai on 14/12/3.
  6. // Copyright (c) 2014年 zhangjie. All rights reserved.
  7. //
  8. #import "KMSignatureWindowController.h"
  9. #import "KMDrawView.h"
  10. #import "NSImage+CustomImage.h"
  11. #import "KMPDFSignatureImageView.h"
  12. #import "KMPopUpButton.h"
  13. #import "CPDFListView.h"
  14. #import <PDF_Master-Swift.h>
  15. static NSMutableArray * recentlyFonts;
  16. #pragma mark KMSignatureColorButton
  17. @interface KMSignatureColorButton : NSButton
  18. @property (nonatomic,retain) NSColor *circleColor;
  19. @property (nonatomic,retain) NSImage *drawImage;
  20. @end
  21. @implementation KMSignatureColorButton
  22. -(void)setCircleColor:(NSColor *)circleColor
  23. {
  24. _circleColor = circleColor;
  25. [self setNeedsDisplay:YES];
  26. }
  27. -(id)initWithCoder:(NSCoder *)coder {
  28. if (self == [super initWithCoder:coder]) {
  29. self.wantsLayer = YES;
  30. self.layer.cornerRadius = 12;
  31. self.layer.masksToBounds = YES;
  32. self.layer.borderWidth = 1.5;
  33. }
  34. return self;
  35. }
  36. -(void)drawRect:(NSRect)rect
  37. {
  38. [super drawRect:rect];
  39. if (_circleColor) {
  40. NSBezierPath *path3 = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(3, 3, rect.size.width - 6, rect.size.height - 6)];
  41. [self.circleColor set];
  42. [path3 fill];
  43. } else if (self.drawImage) {
  44. [self.drawImage drawInRect:CGRectMake(3,3,rect.size.width -6,rect.size.height - 6)
  45. fromRect:NSZeroRect
  46. operation:NSCompositeSourceOver
  47. fraction:1.0];
  48. }
  49. }
  50. @end
  51. #pragma mark KMSignatureButton
  52. @interface KMSignatureButton : NSButton
  53. @end
  54. @implementation KMSignatureButton
  55. - (NSMenu*)menuForEvent:(NSEvent *)theEvent
  56. {
  57. NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
  58. NSMenuItem *item = [menu addItemWithTitle:NSLocalizedString(@"Delete", nil) action:@selector(delete) keyEquivalent:@""];
  59. item.target = self;
  60. item = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil keyEquivalent:@""];
  61. NSMenu * tSubMenu = [[NSMenu alloc] init];
  62. NSMenuItem *tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(export:) target:self atIndex:0];
  63. tMenuItem.tag = 0;
  64. tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(export:) target:self atIndex:1];
  65. tMenuItem.tag = 1;
  66. tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(export:) target:self atIndex:2];
  67. tMenuItem.tag = 2;
  68. item.submenu = tSubMenu;
  69. return menu;
  70. }
  71. - (void)delete
  72. {
  73. [[NSNotificationCenter defaultCenter] postNotificationName:@"kKMSignatureDeleteNotification" object:[NSNumber numberWithInteger:self.tag]];
  74. }
  75. - (void)export:(NSMenuItem *)sender
  76. {
  77. NSInteger index = self.tag;
  78. NSInteger type = sender.tag;
  79. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  80. [signatureManager loadAllSignatureList];
  81. KMSignature *signature = signatureManager.signatureList[index];
  82. NSImage *image = signature.pathsImage;
  83. if (type == 0) {
  84. NSData *data = image.TIFFRepresentation;
  85. NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
  86. [imageRep setSize:image.size];
  87. NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:@{}];
  88. NSSavePanel *savePanel = [NSSavePanel savePanel];
  89. savePanel.allowedFileTypes = @[@"png"];
  90. [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
  91. if (result) {
  92. if ([imageData writeToURL:savePanel.URL atomically:YES]) {
  93. [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
  94. inFileViewerRootedAtPath:@""];
  95. }
  96. }
  97. }];
  98. } else if (type == 1) {
  99. NSData *data = image.TIFFRepresentation;
  100. NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
  101. [imageRep setSize:image.size];
  102. NSData *imageData = [imageRep representationUsingType:NSJPEGFileType properties:@{}];
  103. NSSavePanel *savePanel = [NSSavePanel savePanel];
  104. savePanel.allowedFileTypes = @[@"jpg"];
  105. [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
  106. if (result) {
  107. if ([imageData writeToURL:savePanel.URL atomically:YES]) {
  108. [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
  109. inFileViewerRootedAtPath:@""];
  110. }
  111. }
  112. }];
  113. } else {
  114. CPDFDocument *pdf = [[CPDFDocument alloc] init];
  115. // CPDFPage *page = [[CPDFPage alloc] initWithImage:image];
  116. NSString *signatureImagePath =[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"signatureImage.png"];
  117. NSData *data = image.TIFFRepresentation;
  118. [data writeToURL:[NSURL fileURLWithPath:signatureImagePath] atomically:YES];
  119. [pdf insertPage:image.size withImage:signatureImagePath atIndex:0];
  120. NSSavePanel *savePanel = [NSSavePanel savePanel];
  121. savePanel.allowedFileTypes = @[@"pdf"];
  122. [savePanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger result) {
  123. if (result) {
  124. if ([pdf writeToURL:savePanel.URL]) {
  125. [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
  126. inFileViewerRootedAtPath:@""];
  127. }
  128. }
  129. }];
  130. }
  131. }
  132. @end
  133. #pragma mark KMSignatureWindowController
  134. static KMSignatureWindowController *windowController_signature;
  135. @interface KMSignatureWindowController () <KMDrawViewDelegate, KMSelectPopButtonDelegate, KMChangeSignatureTextDelegate>
  136. @property (weak) IBOutlet NSButton *cancelBtton;
  137. @property (weak) IBOutlet NSButton *applyButton;
  138. @property (nonatomic, strong) KMDesignButton *cancelButtonVC;
  139. @property (nonatomic, strong) KMDesignButton *applyButtonVC;
  140. @property (weak) IBOutlet NSButton *clearButton;
  141. @property (strong) IBOutlet NSView *signTypeView;
  142. @property (weak) IBOutlet NSButton *inputButton;
  143. @property (weak) IBOutlet NSButton *drawingButton;
  144. @property (weak) IBOutlet NSButton *pictureButton;
  145. @property (strong) IBOutlet NSView *signTypeBackView;
  146. @property (weak) IBOutlet NSTextField *trackpadLabel;
  147. @property (weak) IBOutlet NSBox *contentBox;
  148. @property (weak) IBOutlet NSTextField *titleLabel;
  149. //keyboard
  150. @property (strong) IBOutlet NSView *inputView;
  151. @property (weak) IBOutlet KMPDFSignatureTextView *keyboardView;
  152. @property (weak) IBOutlet NSPopUpButton *fontBox;
  153. @property (strong) IBOutlet NSButton *keyboardColorBtn1;
  154. @property (strong) IBOutlet NSButton *keyboardColorBtn2;
  155. @property (strong) IBOutlet NSButton *keyboardColorBtn3;
  156. @property (strong) IBOutlet NSButton *keyboardColorBtn4;
  157. @property (strong) IBOutlet NSView *keyboardColorSelView;
  158. @property (weak) IBOutlet KMSignatureColorButton *textColorButton;
  159. @property (nonatomic, strong) KMDesignSelect *fontVC;
  160. @property (nonatomic, strong) NSArray *fontValues;
  161. @property (nonatomic, copy) NSString *fontDefaultValue;
  162. //Draw
  163. @property (strong) IBOutlet NSView *drawingView;
  164. @property (weak) IBOutlet KMDrawView *drawView;
  165. @property (weak) IBOutlet NSButton *trackpadButton;
  166. @property (nonatomic, strong) KMDesignButton *trackpadButtonVC;
  167. @property (strong) IBOutlet NSPopUpButton *drawSizeBox;
  168. @property (strong) IBOutlet NSView *colorBGView;
  169. @property (strong) IBOutlet NSView *drawColorSelView;
  170. @property (strong) IBOutlet NSButton *drawColorBtn1;
  171. @property (strong) IBOutlet NSButton *drawColorBtn2;
  172. @property (strong) IBOutlet NSButton *drawColorBtn3;
  173. @property (strong) IBOutlet NSButton *drawColorBtn4;
  174. @property (nonatomic, strong) KMDesignSelect *drawSizeVC;
  175. @property (nonatomic, strong) NSArray *drawSizeValues;
  176. @property (nonatomic, copy) NSString *drawSizeDefaultValue;
  177. @property (weak) IBOutlet NSView *drawTipView;
  178. @property (weak) IBOutlet NSTextField *drawTipLabel;
  179. //Picture
  180. @property (strong) IBOutlet NSView *pictureView;
  181. @property (weak) IBOutlet KMPDFSignatureImageView *pictureBackView;
  182. @property (strong) IBOutlet NSButton *pictureClearBackBtn;
  183. @property (nonatomic, strong) KMDesignButton *pictureClearBackBtnVC;
  184. @property (weak) IBOutlet KMCoverButton *pictureHelpButton;
  185. @property (nonatomic,strong) KMSignature *selectedSignature;
  186. @property (nonatomic,strong) NSMenuItem *selectItem;
  187. @property (nonatomic,assign) KMPDFSignatureType type;
  188. @property (nonatomic,copy) void (^handler)(KMSignature*);
  189. @property (nonatomic, strong) NSPopover *popover;
  190. @end
  191. @implementation KMSignatureWindowController
  192. - (id)init
  193. {
  194. if (self = [super initWithWindowNibName:@"KMSignatureWindowController"]) {
  195. NSMutableArray *fonts = [NSMutableArray array];
  196. for (NSDictionary *dic in [CPDFAnnotationModel supportFonts]) {
  197. [fonts addObject:dic.allKeys.firstObject];
  198. }
  199. self.fontValues = fonts.copy;
  200. self.fontDefaultValue = @"Helvetica";
  201. self.drawSizeValues = @[@"1.0",@"2.0",@"4.0",@"6.0",@"8.0"];
  202. self.drawSizeDefaultValue = @"2.0";
  203. }
  204. return self;
  205. }
  206. - (void)dealloc
  207. {
  208. _drawView.delegate = nil;
  209. _keyboardView.delegate = nil;
  210. [[NSNotificationCenter defaultCenter] removeObserver:self];
  211. [[NSColorPanel sharedColorPanel] setTarget:nil];
  212. [[NSColorPanel sharedColorPanel] setAction:nil];
  213. }
  214. #pragma mark - View Methods
  215. - (void)windowDidLoad {
  216. [super windowDidLoad];
  217. __weak typeof (self) weakSelf = self;
  218. self.type = KMPDFSignatureTypeText;
  219. // self.textColorButton.drawImage = self.mouseColorButton.drawImage = [NSImage imageNamed:@"view_color"];
  220. self.cancelBtton.title = @"";
  221. self.cancelButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
  222. [self.cancelBtton addSubview:self.cancelButtonVC.view];
  223. self.cancelButtonVC.view.frame = self.cancelBtton.bounds;
  224. self.cancelButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  225. self.cancelButtonVC.stringValue = NSLocalizedString(@"Cancel", nil);
  226. self.cancelButtonVC.target = self;
  227. self.cancelButtonVC.action = @selector(dismissSheet:);
  228. [self.cancelButtonVC buttonWithType:TokenButtonTypeSec_Icon size:TokenButtonSizeM height:nil];
  229. [self.clearButton setTarget:self];
  230. [self.clearButton setAction:@selector(clearButton_Click:)];
  231. self.clearButton.hidden = YES;
  232. self.applyButton.title = @"";
  233. self.applyButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
  234. [self.applyButton addSubview:self.applyButtonVC.view];
  235. self.applyButtonVC.view.frame = self.applyButton.bounds;
  236. self.applyButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  237. self.applyButtonVC.stringValue = NSLocalizedString(@"Save", nil);
  238. self.applyButtonVC.target = self;
  239. self.applyButtonVC.action = @selector(applyButton_Click:);
  240. [self.applyButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeM height:nil];
  241. self.applyButtonVC.enabled = NO;
  242. self.contentBox.wantsLayer = YES;
  243. self.contentBox.layer.backgroundColor = [NSColor clearColor].CGColor;
  244. self.contentBox.borderType = NSNoBorder;
  245. self.inputButton.bordered = self.drawingButton.bordered = self.pictureButton.bordered = NO;
  246. //Keyboard
  247. self.inputView.wantsLayer = YES;
  248. self.inputView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  249. self.keyboardView.wantsLayer = YES;
  250. self.keyboardView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
  251. self.keyboardView.changeSignatureTextCallback = ^(BOOL isTure) {
  252. if (isTure) {
  253. weakSelf.clearButton.hidden = NO;
  254. weakSelf.clearButton.title = NSLocalizedString(@"Clear", nil);
  255. } else {
  256. weakSelf.clearButton.hidden = YES;
  257. }
  258. };
  259. self.keyboardColorBtn1.wantsLayer = self.keyboardColorBtn2.wantsLayer = self.keyboardColorBtn3.wantsLayer = self.keyboardColorBtn4.wantsLayer = YES;
  260. self.keyboardColorBtn1.layer.backgroundColor = [NSColor colorWithRed:37/255.0f green:38/255.0f blue:41/255.0f alpha:1.0f].CGColor;
  261. self.keyboardColorBtn2.layer.backgroundColor = [NSColor colorWithRed:252/255.0f green:31/255.0f blue:31/255.0f alpha:1.0f].CGColor;
  262. self.keyboardColorBtn3.layer.backgroundColor = [NSColor colorWithRed:39/255.0f green:60/255.0f blue:98/255.0f alpha:1.0f].CGColor;
  263. self.keyboardColorBtn4.layer.backgroundColor = [NSColor colorWithRed:148/255.0f green:152/255.0f blue:156/255.0f alpha:1.0f].CGColor;
  264. self.keyboardColorBtn1.layer.cornerRadius = self.keyboardColorBtn2.layer.cornerRadius = self.keyboardColorBtn3.layer.cornerRadius = self.keyboardColorBtn4.layer.cornerRadius = 10.;
  265. self.keyboardColorBtn1.layer.masksToBounds = self.keyboardColorBtn2.layer.masksToBounds = self.keyboardColorBtn3.layer.masksToBounds = self.keyboardColorBtn4.layer.masksToBounds = YES;
  266. self.keyboardColorSelView.wantsLayer = YES;
  267. self.keyboardColorSelView.layer.backgroundColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:0.6].CGColor;
  268. self.keyboardColorSelView.layer.borderWidth = 1.;
  269. self.keyboardColorSelView.layer.borderColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:1.0f].CGColor;
  270. self.keyboardColorSelView.layer.cornerRadius = 4.;
  271. self.keyboardColorSelView.layer.masksToBounds = YES;
  272. [self colorTextButtonAction:self.keyboardColorBtn1];
  273. //Draw
  274. self.drawView.delegate = self;
  275. self.drawView.wantsLayer = YES;
  276. self.drawView.strokeRadius = [self.drawSizeDefaultValue floatValue];
  277. self.drawView.layer.cornerRadius = 4.;
  278. self.drawView.layer.masksToBounds = YES;
  279. self.drawView.layer.borderWidth = 1.;
  280. self.drawView.layer.borderColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
  281. self.drawView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
  282. self.drawColorBtn1.wantsLayer = self.drawColorBtn2.wantsLayer = self.drawColorBtn3.wantsLayer = self.drawColorBtn4.wantsLayer = YES;
  283. self.drawColorBtn1.layer.backgroundColor = [NSColor colorWithRed:37/255.0f green:38/255.0f blue:41/255.0f alpha:1.0f].CGColor;
  284. self.drawColorBtn2.layer.backgroundColor = [NSColor colorWithRed:252/255.0f green:31/255.0f blue:31/255.0f alpha:1.0f].CGColor;
  285. self.drawColorBtn3.layer.backgroundColor = [NSColor colorWithRed:39/255.0f green:60/255.0f blue:98/255.0f alpha:1.0f].CGColor;
  286. self.drawColorBtn4.layer.backgroundColor = [NSColor colorWithRed:148/255.0f green:152/255.0f blue:156/255.0f alpha:1.0f].CGColor;
  287. self.drawColorBtn1.layer.cornerRadius = self.drawColorBtn2.layer.cornerRadius = self.drawColorBtn3.layer.cornerRadius = self.drawColorBtn4.layer.cornerRadius = 10.;
  288. self.drawColorBtn1.layer.masksToBounds = self.drawColorBtn2.layer.masksToBounds = self.drawColorBtn3.layer.masksToBounds = self.drawColorBtn4.layer.masksToBounds = YES;
  289. self.drawColorSelView.wantsLayer = YES;
  290. self.drawColorSelView.layer.backgroundColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:0.6].CGColor;
  291. self.drawColorSelView.layer.borderWidth = 1.;
  292. self.drawColorSelView.layer.borderColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:1.0f].CGColor;
  293. self.drawColorSelView.layer.cornerRadius = 4.;
  294. self.drawColorSelView.layer.masksToBounds = YES;
  295. [self drawColorBtnClicked:self.drawColorBtn1];
  296. for (NSString *pxSize in @[@"0.5",@"1.0",@"1.5",@"2.0",@"2.5",@"3.0"]) {
  297. NSDictionary *attrited = @{NSFontAttributeName:[NSFont systemFontOfSize:14]};
  298. NSAttributedString *string = [[NSAttributedString alloc] initWithString:pxSize attributes:attrited];
  299. NSMenuItem *item = [[NSMenuItem alloc] init];
  300. item.attributedTitle = string;
  301. [self.drawSizeBox.menu addItem:item];
  302. }
  303. [self.drawSizeBox selectItem:[self.drawSizeBox itemAtIndex:1]];
  304. [self.drawSizeBox setTitle:@"1.0 pt"];
  305. //Picture
  306. self.pictureView.wantsLayer = YES;
  307. self.pictureView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  308. self.pictureBackView.wantsLayer = YES;
  309. self.pictureBackView.layer.cornerRadius = 4.;
  310. self.pictureBackView.layer.masksToBounds = YES;
  311. self.pictureBackView.layer.borderWidth = 1.;
  312. self.pictureBackView.layer.borderColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
  313. self.pictureBackView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
  314. self.pictureBackView.changeSignatureImageCallback = ^(BOOL isTure) {
  315. if (isTure) {
  316. weakSelf.applyButtonVC.enabled = YES;
  317. } else {
  318. weakSelf.applyButtonVC.enabled = NO;
  319. }
  320. if (weakSelf.pictureBackView.signatureImage) {
  321. weakSelf.clearButton.hidden = NO;
  322. weakSelf.clearButton.title = NSLocalizedString(@"Reselect", nil);
  323. } else {
  324. weakSelf.clearButton.hidden = YES;
  325. }
  326. };
  327. [self.trackpadLabel setHidden:YES];
  328. self.drawTipView.hidden = YES;
  329. self.keyboardView.delegate = self;
  330. self.drawView.changeDrawCallback = ^(BOOL isTure) {
  331. if (isTure) {
  332. weakSelf.applyButtonVC.enabled = YES;
  333. } else {
  334. weakSelf.applyButtonVC.enabled = NO;
  335. }
  336. };
  337. self.drawView.touchEndCallback = ^(BOOL isClear) {
  338. if (isClear) {
  339. weakSelf.clearButton.hidden = YES;
  340. } else {
  341. weakSelf.clearButton.hidden = NO;
  342. weakSelf.clearButton.title = NSLocalizedString(@"Clear", nil);
  343. }
  344. };
  345. [self inputButton_Click:nil];
  346. self.pictureHelpButton.image = [NSImage imageNamed:@"KMImageNameHelpNormal"];
  347. self.pictureHelpButton.toolTip = @"Remove white background from images";
  348. self.pictureHelpButton.action = @selector(showHelpTip:);
  349. self.pictureHelpButton.coverAction = ^(KMCoverButton * _Nonnull button, KMCoverAction action) {
  350. if (action == KMCoverActionEnter) {
  351. button.image = [NSImage imageNamed:@"KMImageNameHelpHover"];
  352. // [weakSelf showHelpTip:button];
  353. } else if (action == KMCoverActionExit) {
  354. button.image = [NSImage imageNamed:@"KMImageNameHelpNormal"];
  355. // [weakSelf dismissHelpTip];
  356. }
  357. };
  358. [self localizedString];
  359. [self setupUI];
  360. }
  361. - (void)setupUI {
  362. NSString *fontName = @"SFProText-Regular";
  363. self.titleLabel.font = [NSFont fontWithName:@"SFProText-Semibold" size:16];
  364. self.titleLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
  365. self.signTypeView.wantsLayer = YES;
  366. self.signTypeView.layer.backgroundColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
  367. self.signTypeView.layer.cornerRadius = 4.;
  368. self.signTypeView.layer.masksToBounds = YES;
  369. self.signTypeBackView.wantsLayer = YES;
  370. self.signTypeBackView.layer.cornerRadius = 2.;
  371. self.signTypeBackView.layer.masksToBounds = YES;
  372. self.signTypeBackView.layer.backgroundColor = [NSColor whiteColor].CGColor;
  373. for (NSButton *button in @[self.inputButton, self.drawingButton, self.pictureButton]) {
  374. [button setTitleColorWithColor:[NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f] font:nil];
  375. button.font = [NSFont fontWithName:fontName size:12];
  376. }
  377. // Input
  378. self.fontVC = [[KMDesignSelect alloc] initWithType:SelectTypeCombox];
  379. [self.fontBox.superview addSubview:self.fontVC.view];
  380. [self.fontVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  381. make.left.equalTo(self.fontBox);
  382. make.centerY.equalTo(self.fontBox);
  383. make.size.mas_equalTo(NSMakeSize(200, 32));
  384. }];
  385. self.fontBox.hidden = YES;
  386. [self.fontVC addItemsWithObjectValues:self.fontValues];
  387. self.fontVC.stringValue = self.fontDefaultValue;
  388. self.fontVC.delete = self;
  389. // Drawing
  390. self.drawSizeVC = [[KMDesignSelect alloc] initWithType:SelectTypeCombox];
  391. [self.drawSizeBox.superview addSubview:self.drawSizeVC.view];
  392. [self.drawSizeVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  393. make.left.equalTo(self.drawSizeBox);
  394. make.centerY.equalTo(self.drawSizeBox);
  395. make.size.mas_equalTo(NSMakeSize(85, 32));
  396. }];
  397. self.drawSizeBox.hidden = YES;
  398. self.drawSizeVC.delete = self;
  399. NSMutableArray *drawSizes = [NSMutableArray array];
  400. for (NSString *value in self.drawSizeValues) {
  401. [drawSizes addObject:[NSString stringWithFormat:@"%@ pt", value]];
  402. }
  403. [self.drawSizeVC addItemsWithObjectValues:drawSizes.copy];
  404. self.drawSizeVC.stringValue = [NSString stringWithFormat:@"%@ pt", self.drawSizeDefaultValue];
  405. self.trackpadButton.title = NSLocalizedString(@"Trackpad", nil);
  406. self.trackpadButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeCheckBox];
  407. [self.trackpadButton.superview addSubview:self.trackpadButtonVC.view];
  408. self.trackpadButtonVC.stringValue = NSLocalizedString(@"Trackpad", nil);
  409. self.trackpadButtonVC.state = KMDesignTokenStateNorm;
  410. [self.trackpadButtonVC checkbox_radioWithImageHeight:[[NSLayoutConstraint alloc] init]];
  411. self.trackpadButtonVC.target = self;
  412. self.trackpadButtonVC.action = @selector(trackpadButton_Click:);
  413. [self.trackpadButtonVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  414. make.left.equalTo(self.trackpadButton);
  415. make.centerY.equalTo(self.drawSizeVC.view);
  416. make.width.mas_equalTo(120);
  417. make.height.mas_equalTo(22);
  418. }];
  419. self.trackpadButton.hidden = YES;
  420. self.drawTipView.wantsLayer = YES;
  421. self.drawTipView.layer.backgroundColor = [NSColor colorWithRed:189/255.f green:223/255.f blue:253/255.f alpha:1.f].CGColor;
  422. self.drawTipLabel.stringValue = NSLocalizedString(@"Press any key to disable the touchpad", nil);
  423. self.drawTipLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
  424. self.drawTipLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
  425. // Picture
  426. self.pictureBackView.emptyTipLbl.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1];
  427. self.pictureBackView.emptyTipLbl.font = [NSFont fontWithName:fontName size:14];
  428. self.pictureClearBackBtn.title = NSLocalizedString(@"Clear background", nil);
  429. self.pictureClearBackBtnVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeCheckBox];
  430. [self.pictureClearBackBtn.superview addSubview:self.pictureClearBackBtnVC.view];
  431. self.pictureClearBackBtnVC.stringValue = NSLocalizedString(@"Clear background", nil);
  432. self.pictureClearBackBtnVC.state = KMDesignTokenStateNorm;
  433. [self.pictureClearBackBtnVC checkbox_radioWithImageHeight:[[NSLayoutConstraint alloc] init]];
  434. self.pictureClearBackBtnVC.target = self;
  435. self.pictureClearBackBtnVC.action = @selector(pictureClearBackBtnAction:);
  436. self.pictureClearBackBtn.hidden = YES;
  437. [self.pictureClearBackBtnVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  438. make.edges.equalTo(self.pictureClearBackBtn);
  439. }];
  440. }
  441. - (void)setType:(KMPDFSignatureType)type {
  442. _type = type;
  443. CGRect rect = self.signTypeBackView.frame;
  444. if (_type == KMPDFSignatureTypeText) {
  445. rect.origin.x = 1;
  446. } else if (_type == KMPDFSignatureTypeInk) {
  447. rect.origin.x = 2 + 75;
  448. } else if (_type == KMPDFSignatureTypeImage) {
  449. rect.origin.x = 2 + 75*2;
  450. }
  451. rect.origin.y = (CGRectGetHeight(self.signTypeBackView.superview.frame) - CGRectGetHeight(self.signTypeBackView.frame))/2.;
  452. self.signTypeBackView.frame = rect;
  453. self.clearButton.hidden = YES;
  454. if (_type == KMPDFSignatureTypeText) {
  455. } else if (_type == KMPDFSignatureTypeInk) {
  456. } else if (_type == KMPDFSignatureTypeImage) {
  457. if (self.pictureBackView.signatureImage) {
  458. self.clearButton.title = NSLocalizedString(@"Reselect", nil);
  459. self.clearButton.hidden = NO;
  460. }
  461. }
  462. }
  463. #pragma mark - mouse
  464. - (void)mouseDown:(NSEvent *)event {
  465. [self dismissHelpTip];
  466. }
  467. #pragma mark - Private Methods
  468. -(void)localizedString
  469. {
  470. self.titleLabel.stringValue = NSLocalizedString(@"Create Signature", "");
  471. [self.trackpadButton setTitle:NSLocalizedString(@"Trackpad", nil)];
  472. [self.clearButton setTitle:NSLocalizedString(@"Clear", nil)];
  473. [self.trackpadLabel setStringValue:NSLocalizedString(@"Press \"esc\" to disable the Trackpad.", nil)];
  474. NSArray *seletorFonts = @[@"Mistral", @"Bradley Hand", @"Brush Script MT", @"SignPainter", @"Edwardian Script ITC", @"American Typewriter",@"Baoli SC",@"Snell Roundhand", @"Apple Chancery", @"Monotype Corsiva"];
  475. NSArray *fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  476. for (NSString *fontName in fonts) {
  477. NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:fontName size:12.0]};
  478. NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
  479. NSMenuItem *item = [[NSMenuItem alloc] init];
  480. item.attributedTitle = string;
  481. [self.fontBox.menu addItem:item];
  482. }
  483. NSString * fontName = nil;
  484. if (!recentlyFonts) {
  485. recentlyFonts = [[NSMutableArray alloc] init];
  486. }
  487. if (recentlyFonts.count < 1) {
  488. for (NSString *name in seletorFonts) {
  489. if ([fonts containsObject:name]) {
  490. fontName = name;
  491. break;
  492. }
  493. }
  494. if (fontName) {
  495. [recentlyFonts addObject:fontName];
  496. }
  497. } else {
  498. fontName = recentlyFonts.firstObject;
  499. }
  500. // if ([fonts containsObject:fontName]) {
  501. // self.keyboardView.fontName = fontName;
  502. // [self.fontBox setTitle:fontName];
  503. // } else {
  504. // self.keyboardView.fontName = fonts.firstObject;
  505. // [self.fontBox setTitle:fonts.firstObject];
  506. // }
  507. self.keyboardView.fontName = self.fontDefaultValue;
  508. for (NSInteger i = 0; i<recentlyFonts.count; i++) {
  509. NSString *fontName = recentlyFonts[i];
  510. NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:fontName size:12.0]};
  511. NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
  512. NSMenuItem *item = [[NSMenuItem alloc] init];
  513. item.attributedTitle = string;
  514. [self.fontBox.menu insertItem:item atIndex:1 + i];
  515. }
  516. NSMenuItem *sep = [NSMenuItem separatorItem];
  517. [self.fontBox.menu insertItem:sep atIndex:(recentlyFonts.count)+1];
  518. self.selectItem = [self.fontBox.menu itemAtIndex:1];
  519. self.selectItem.state = NSControlStateValueOn;
  520. [self.inputButton setTitle:NSLocalizedString(@"Keyboard", nil)];
  521. [self.drawingButton setTitle:NSLocalizedString(@"Trackpad", nil)];
  522. [self.pictureButton setTitle:NSLocalizedString(@"Image", nil)];
  523. }
  524. - (void)showHelpTip:(NSButton *)sender {
  525. if (self.popover) {
  526. [self dismissHelpTip];
  527. return;
  528. }
  529. NSPopover *pop = [[NSPopover alloc] init];
  530. self.popover = pop;
  531. KMSignatureHelpViewController *controller = [[KMSignatureHelpViewController alloc] init];
  532. pop.contentViewController = controller;
  533. controller.tipString = NSLocalizedString(@"Remove white background from images", nil);
  534. [pop setValue:@YES forKey:@"shouldHideAnchor"];
  535. [pop showRelativeToRect:NSMakeRect(0, -8, NSWidth(sender.bounds), NSHeight(sender.bounds)) ofView:sender preferredEdge:NSRectEdgeMaxY];
  536. }
  537. - (void)dismissHelpTip {
  538. [self.popover close];
  539. self.popover = nil;
  540. }
  541. #pragma mark Button Mehtods
  542. - (IBAction)inputButton_Click:(id)sender {
  543. self.contentBox.contentView = self.inputView;
  544. self.type = KMPDFSignatureTypeText;
  545. }
  546. - (IBAction)drawingButton_Click:(id)sender {
  547. self.contentBox.contentView = self.drawingView;
  548. self.type = KMPDFSignatureTypeInk;
  549. }
  550. - (IBAction)pictureButton_Click:(id)sender {
  551. self.contentBox.contentView = self.pictureView;
  552. self.type = KMPDFSignatureTypeImage;
  553. }
  554. - (void)clearButton_Click:(id)sender
  555. {
  556. if (KMPDFSignatureTypeImage == self.type) {
  557. [self.pictureBackView reSelectImage];
  558. } else if (KMPDFSignatureTypeInk == self.type) {
  559. [self.drawView clearImage];
  560. }else if (KMPDFSignatureTypeText == self.type) {
  561. [self.keyboardView clearImage];
  562. }
  563. self.applyButtonVC.enabled = NO;
  564. }
  565. - (void)applyButton_Click:(id)sender
  566. {
  567. KMSignature *signature = [[KMSignature alloc] init];
  568. if (KMPDFSignatureTypeText == self.type) {
  569. NSImage *image = [self.keyboardView signatureImage];
  570. if (!image) {
  571. NSAlert *alert = [[NSAlert alloc] init];
  572. [alert setAlertStyle:NSAlertStyleCritical];
  573. [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
  574. [alert runModal];
  575. return;
  576. }
  577. signature.pathsImage = image;
  578. signature.signatureType = KMPDFSignatureTypeText;
  579. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  580. [signatureManager loadAllSignatureList];
  581. [signatureManager addSignature:signature];
  582. [signatureManager saveSingaturesToFile];
  583. } else if(KMPDFSignatureTypeImage == self.type) {
  584. NSImage *image = [self.pictureBackView signatureImage];
  585. if (!image) {
  586. NSAlert *alert = [[NSAlert alloc] init];
  587. [alert setAlertStyle:NSAlertStyleCritical];
  588. [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
  589. [alert runModal];
  590. return;
  591. }
  592. signature.pathsImage = image;
  593. signature.signatureType = KMPDFSignatureTypeImage;
  594. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  595. [signatureManager loadAllSignatureList];
  596. [signatureManager addSignature:signature];
  597. [signatureManager saveSingaturesToFile];
  598. } else {
  599. NSImage *image = [self.drawView signatureImage];
  600. if (!image) {
  601. NSAlert *alert = [[NSAlert alloc] init];
  602. [alert setAlertStyle:NSAlertStyleCritical];
  603. [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
  604. [alert runModal];
  605. return;
  606. }
  607. [signature addPath:self.drawView.drawBezierPath];
  608. signature.signatureType = KMPDFSignatureTypeInk;
  609. signature.signatureColor = self.drawView.drawColor;
  610. signature.pathsImage = image;
  611. KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
  612. [signatureManager loadAllSignatureList];
  613. [signatureManager addSignature:signature];
  614. [signatureManager saveSingaturesToFile];
  615. }
  616. self.selectedSignature = signature;
  617. [self dismissSheet:nil];
  618. }
  619. - (IBAction)trackpadButton_Click:(id)sender
  620. {
  621. if (self.trackpadButtonVC.state == KMDesignTokenStateChecked) {
  622. self.trackpadButtonVC.state = KMDesignTokenStateNorm;
  623. self.trackpadLabel.hidden = YES;
  624. self.drawTipView.hidden = YES;
  625. self.drawView.isAcceptsTouch = NO;
  626. } else {
  627. self.trackpadButtonVC.state = KMDesignTokenStateChecked;
  628. self.trackpadLabel.hidden = YES;
  629. self.drawTipView.hidden = NO;
  630. self.drawView.isAcceptsTouch = YES;
  631. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  632. self.drawTipView.hidden = YES;
  633. });
  634. }
  635. }
  636. - (IBAction)boxItemClicked_Font:(id)sender
  637. {
  638. NSString * name = self.fontBox.selectedItem.title;
  639. self.fontBox.title = name;
  640. self.keyboardView.fontName = name;
  641. if ([recentlyFonts containsObject:name]) {
  642. NSInteger index = [recentlyFonts indexOfObject:name];
  643. [recentlyFonts removeObject:name];
  644. [self.fontBox.menu removeItemAtIndex:index +1];
  645. }
  646. if (recentlyFonts.count >0) {
  647. [recentlyFonts insertObject:name atIndex:0];
  648. } else {
  649. [recentlyFonts addObject:name];
  650. }
  651. if (recentlyFonts.count >5) {
  652. [recentlyFonts removeLastObject];
  653. [self.fontBox.menu removeItemAtIndex:recentlyFonts.count];
  654. }
  655. NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:name size:12.0]};
  656. NSAttributedString *string = [[NSAttributedString alloc] initWithString:name attributes:attrited];
  657. NSMenuItem *item = [[NSMenuItem alloc] init];
  658. item.attributedTitle = string;
  659. [self.fontBox.menu insertItem:item atIndex:1];
  660. self.selectItem.state = NSControlStateValueOff;
  661. self.selectItem = [self.fontBox.menu itemAtIndex:1];
  662. self.selectItem.state = NSControlStateValueOn;
  663. }
  664. - (IBAction)colorTextButtonAction:(id)sender {
  665. if ([sender isEqual:self.keyboardColorBtn1] ||
  666. [sender isEqual:self.keyboardColorBtn2] ||
  667. [sender isEqual:self.keyboardColorBtn3] ||
  668. [sender isEqual:self.keyboardColorBtn4]) {
  669. self.keyboardView.keyboardColor = [NSColor colorWithCGColor:((NSButton *)sender).layer.backgroundColor];
  670. CGRect rect = self.keyboardView.frame;
  671. rect.origin.y = CGRectGetMidY(((NSButton *)sender).frame)-16;
  672. rect.origin.x = CGRectGetMidX(((NSButton *)sender).frame)-16;
  673. rect.size.width = rect.size.height = 32;
  674. self.keyboardColorSelView.frame = rect;
  675. } else {
  676. [[NSColorPanel sharedColorPanel] setTarget:self];
  677. [[NSColorPanel sharedColorPanel] setAction:@selector(keyboardColorPanelColorDidChange:)];
  678. [[NSColorPanel sharedColorPanel] orderFront:nil];
  679. }
  680. }
  681. - (IBAction)drawColorBtnClicked:(NSButton *)sender {
  682. if ([sender isEqual:self.drawColorBtn1] ||
  683. [sender isEqual:self.drawColorBtn2] ||
  684. [sender isEqual:self.drawColorBtn3] ||
  685. [sender isEqual:self.drawColorBtn4]) {
  686. self.drawView.drawColor = [NSColor colorWithCGColor:((NSButton *)sender).layer.backgroundColor];
  687. CGRect rect = self.drawColorSelView.frame;
  688. rect.origin.y = CGRectGetMidY(((NSButton *)sender).frame)-16;
  689. rect.origin.x = CGRectGetMidX(((NSButton *)sender).frame)-16;
  690. rect.size.width = rect.size.height = 32;
  691. self.drawColorSelView.frame = rect;
  692. }
  693. }
  694. - (IBAction)drawSizeBtnClicked:(NSPopUpButton *)sender {
  695. NSString * name = self.drawSizeBox.selectedItem.title;
  696. self.drawSizeBox.title = name;
  697. self.drawView.strokeRadius = [[@[@"0.5",@"1.0",@"1.5",@"2.0",@"2.5",@"3.0"] objectAtIndex:(self.drawSizeBox.indexOfSelectedItem -1)] floatValue];
  698. }
  699. //Picture
  700. - (IBAction)pictureClearBackBtnAction:(NSButton *)sender {
  701. BOOL clearBack = YES;
  702. if (self.pictureClearBackBtnVC.state == KMDesignTokenStateChecked) {
  703. self.pictureClearBackBtnVC.state = KMDesignTokenStateNorm;
  704. clearBack = NO;
  705. } else {
  706. self.pictureClearBackBtnVC.state = KMDesignTokenStateChecked;
  707. clearBack = YES;
  708. }
  709. self.pictureBackView.clearBackground = clearBack;
  710. }
  711. - (void)keyboardColorPanelColorDidChange:(id)sender
  712. {
  713. self.textColorButton.layer.borderColor= [NSColor clearColor].CGColor;
  714. CGFloat red,green,blue,alpha;
  715. NSColor *color = [NSColorPanel sharedColorPanel].color ? : [NSColor clearColor];
  716. [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
  717. self.keyboardView.keyboardColor = color;
  718. self.textColorButton.layer.borderColor = [NSColor colorWithRed:33.0/255.0 green:124.0/255.0 blue:234.0/255.0 alpha:1.0].CGColor;
  719. }
  720. #pragma mark KMDrawViewDelegate Methods
  721. - (void)drawViewDidFinishTouchMode:(KMDrawView *)view
  722. {
  723. self.trackpadButtonVC.state = KMDesignTokenStateNorm;
  724. [self.trackpadLabel setHidden:YES];
  725. // [NSAnimationContext beginGrouping];
  726. // [NSAnimationContext currentContext].duration = 1.5;
  727. // [NSAnimationContext currentContext].timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  728. // self.scrollView.animator.frame = originFrame;
  729. self.drawTipView.animator.hidden = YES;
  730. // [NSAnimationContext endGrouping];
  731. }
  732. #pragma mark KMChangeSignatureTextDelegate Methods
  733. - (void)changeSignatureText:(BOOL)isTure {
  734. self.applyButtonVC.enabled = isTure;
  735. }
  736. #pragma mark Show Methods
  737. - (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
  738. {
  739. if (contextInfo != NULL && self.handler) {
  740. self.handler(self.selectedSignature);
  741. }
  742. }
  743. - (void)beginSheetModalForWindow:(NSWindow *)window completionHandler:(void (^)(KMSignature *signature))handler;
  744. {
  745. windowController_signature = self;
  746. [NSApp beginSheet:[self window]
  747. modalForWindow:window
  748. modalDelegate:self
  749. didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
  750. contextInfo:(__bridge void * _Null_unspecified)(handler ? handler : NULL)];
  751. self.handler = handler;
  752. }
  753. - (void)dismissSheet:(id)sender {
  754. windowController_signature = nil;
  755. if (sender) {
  756. [NSApp endSheet:[self window] returnCode:0];
  757. } else {
  758. [NSApp endSheet:[self window] returnCode:1];
  759. }
  760. [[self window] orderOut:self];
  761. }
  762. #pragma mark -
  763. #pragma mark - KMSelectPopButtonDelegate
  764. - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
  765. if ([obj isEqual:self.fontVC]) {
  766. NSInteger index = self.fontVC.indexOfSelectedItem;
  767. if (index < 0) {
  768. index = 0;
  769. }
  770. self.keyboardView.fontName = self.fontVC.items[index];
  771. } else if ([obj isEqual:self.drawSizeVC]) {
  772. NSInteger index = self.drawSizeVC.indexOfSelectedItem;
  773. if (index < 0) {
  774. index = 0;
  775. }
  776. self.drawView.strokeRadius = [self.drawSizeValues[index] floatValue];
  777. }
  778. }
  779. #pragma mark NSTabViewDelegate Methods
  780. - (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(nullable NSTabViewItem *)tabViewItem
  781. {
  782. return YES;
  783. }
  784. - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
  785. {
  786. BOOL isImage = NO;
  787. if ([tabView indexOfTabViewItem:tabViewItem] == 0) {
  788. self.type = KMPDFSignatureTypeText;
  789. if ([self.keyboardView signatureImage]) {
  790. isImage = YES;
  791. }
  792. } else if ([tabView indexOfTabViewItem:tabViewItem] == 1) {
  793. self.type = KMPDFSignatureTypeInk;
  794. if ([self.drawView signatureImage]) {
  795. isImage = YES;
  796. }
  797. } else if ([tabView indexOfTabViewItem:tabViewItem] == 2) {
  798. self.type = KMPDFSignatureTypeImage;
  799. if ([self.pictureBackView signatureImage]) {
  800. isImage = YES;
  801. }
  802. }
  803. if (isImage) {
  804. self.applyButtonVC.enabled = YES;
  805. } else {
  806. self.applyButtonVC.enabled = NO;
  807. }
  808. }
  809. @end