|
@@ -1,976 +0,0 @@
|
|
|
-//
|
|
|
-// KMSignatureWindowController.m
|
|
|
-// PDF Reader Premium
|
|
|
-//
|
|
|
-// Created by wangshuai on 14/12/3.
|
|
|
-// Copyright (c) 2014年 zhangjie. All rights reserved.
|
|
|
-//
|
|
|
-
|
|
|
-#import "KMSignatureWindowController.h"
|
|
|
-#import "CPDFListView.h"
|
|
|
-#import <PDF_Master-Swift.h>
|
|
|
-
|
|
|
-static NSMutableArray * recentlyFonts;
|
|
|
-
|
|
|
-#pragma mark KMSignatureColorButton
|
|
|
-@interface KMSignatureColorButton : NSButton
|
|
|
-
|
|
|
-@property (nonatomic,retain) NSColor *circleColor;
|
|
|
-@property (nonatomic,retain) NSImage *drawImage;
|
|
|
-@end
|
|
|
-
|
|
|
-@implementation KMSignatureColorButton
|
|
|
-
|
|
|
--(void)setCircleColor:(NSColor *)circleColor
|
|
|
-{
|
|
|
- _circleColor = circleColor;
|
|
|
- [self setNeedsDisplay:YES];
|
|
|
-}
|
|
|
-
|
|
|
--(id)initWithCoder:(NSCoder *)coder {
|
|
|
- if (self == [super initWithCoder:coder]) {
|
|
|
- self.wantsLayer = YES;
|
|
|
- self.layer.cornerRadius = 12;
|
|
|
- self.layer.masksToBounds = YES;
|
|
|
- self.layer.borderWidth = 1.5;
|
|
|
- }
|
|
|
- return self;
|
|
|
-}
|
|
|
-
|
|
|
--(void)drawRect:(NSRect)rect
|
|
|
-{
|
|
|
- [super drawRect:rect];
|
|
|
- if (_circleColor) {
|
|
|
- NSBezierPath *path3 = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(3, 3, rect.size.width - 6, rect.size.height - 6)];
|
|
|
- [self.circleColor set];
|
|
|
- [path3 fill];
|
|
|
- } else if (self.drawImage) {
|
|
|
- [self.drawImage drawInRect:CGRectMake(3,3,rect.size.width -6,rect.size.height - 6)
|
|
|
- fromRect:NSZeroRect
|
|
|
- operation:NSCompositeSourceOver
|
|
|
- fraction:1.0];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@end
|
|
|
-
|
|
|
-
|
|
|
-#pragma mark KMSignatureButton
|
|
|
-@interface KMSignatureButton : NSButton
|
|
|
-
|
|
|
-@end
|
|
|
-
|
|
|
-@implementation KMSignatureButton
|
|
|
-
|
|
|
-- (NSMenu*)menuForEvent:(NSEvent *)theEvent
|
|
|
-{
|
|
|
- NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
|
|
|
- NSMenuItem *item = [menu addItemWithTitle:NSLocalizedString(@"Delete", nil) action:@selector(delete) keyEquivalent:@""];
|
|
|
- item.target = self;
|
|
|
-
|
|
|
- item = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil keyEquivalent:@""];
|
|
|
-
|
|
|
- NSMenu * tSubMenu = [[NSMenu alloc] init];
|
|
|
-
|
|
|
- NSMenuItem *tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(export:) target:self atIndex:0];
|
|
|
- tMenuItem.tag = 0;
|
|
|
-
|
|
|
- tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(export:) target:self atIndex:1];
|
|
|
- tMenuItem.tag = 1;
|
|
|
-
|
|
|
- tMenuItem = [tSubMenu insertItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(export:) target:self atIndex:2];
|
|
|
- tMenuItem.tag = 2;
|
|
|
-
|
|
|
- item.submenu = tSubMenu;
|
|
|
-
|
|
|
- return menu;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)delete
|
|
|
-{
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kKMSignatureDeleteNotification" object:[NSNumber numberWithInteger:self.tag]];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)export:(NSMenuItem *)sender
|
|
|
-{
|
|
|
- NSInteger index = self.tag;
|
|
|
- NSInteger type = sender.tag;
|
|
|
-
|
|
|
- KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
|
|
|
- [signatureManager loadAllSignatureList];
|
|
|
- KMSignature *signature = signatureManager.signatureList[index];
|
|
|
- NSImage *image = signature.pathsImage;
|
|
|
-
|
|
|
- if (type == 0) {
|
|
|
- NSData *data = image.TIFFRepresentation;
|
|
|
- NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
|
|
|
- [imageRep setSize:image.size];
|
|
|
- NSData *imageData = [imageRep representationUsingType:NSPNGFileType properties:@{}];
|
|
|
-
|
|
|
- NSSavePanel *savePanel = [NSSavePanel savePanel];
|
|
|
- savePanel.allowedFileTypes = @[@"png"];
|
|
|
- [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
|
|
- if (result) {
|
|
|
- if ([imageData writeToURL:savePanel.URL atomically:YES]) {
|
|
|
- [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
|
|
|
- inFileViewerRootedAtPath:@""];
|
|
|
- }
|
|
|
- }
|
|
|
- }];
|
|
|
- } else if (type == 1) {
|
|
|
- NSData *data = image.TIFFRepresentation;
|
|
|
- NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:data];
|
|
|
- [imageRep setSize:image.size];
|
|
|
- NSData *imageData = [imageRep representationUsingType:NSJPEGFileType properties:@{}];
|
|
|
-
|
|
|
- NSSavePanel *savePanel = [NSSavePanel savePanel];
|
|
|
- savePanel.allowedFileTypes = @[@"jpg"];
|
|
|
- [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
|
|
- if (result) {
|
|
|
- if ([imageData writeToURL:savePanel.URL atomically:YES]) {
|
|
|
- [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
|
|
|
- inFileViewerRootedAtPath:@""];
|
|
|
- }
|
|
|
- }
|
|
|
- }];
|
|
|
- } else {
|
|
|
- CPDFDocument *pdf = [[CPDFDocument alloc] init];
|
|
|
-// CPDFPage *page = [[CPDFPage alloc] initWithImage:image];
|
|
|
-
|
|
|
- NSString *signatureImagePath =[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"signatureImage.png"];
|
|
|
- NSData *data = image.TIFFRepresentation;
|
|
|
- [data writeToURL:[NSURL fileURLWithPath:signatureImagePath] atomically:YES];
|
|
|
- [pdf insertPage:image.size withImage:signatureImagePath atIndex:0];
|
|
|
-
|
|
|
- NSSavePanel *savePanel = [NSSavePanel savePanel];
|
|
|
- savePanel.allowedFileTypes = @[@"pdf"];
|
|
|
- [savePanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger result) {
|
|
|
- if (result) {
|
|
|
- if ([pdf writeToURL:savePanel.URL]) {
|
|
|
- [[NSWorkspace sharedWorkspace] selectFile:savePanel.URL.path
|
|
|
- inFileViewerRootedAtPath:@""];
|
|
|
- }
|
|
|
- }
|
|
|
- }];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@end
|
|
|
-
|
|
|
-#pragma mark KMSignatureWindowController
|
|
|
-
|
|
|
-static KMSignatureWindowController *windowController_signature;
|
|
|
-
|
|
|
-@interface KMSignatureWindowController () <KMDrawViewDelegate, KMSelectPopButtonDelegate, KMChangeSignatureTextDelegate>
|
|
|
-
|
|
|
-@property (weak) IBOutlet NSButton *cancelBtton;
|
|
|
-@property (weak) IBOutlet NSButton *applyButton;
|
|
|
-
|
|
|
-@property (nonatomic, strong) KMDesignButton *cancelButtonVC;
|
|
|
-@property (nonatomic, strong) KMDesignButton *applyButtonVC;
|
|
|
-
|
|
|
-@property (weak) IBOutlet NSButton *clearButton;
|
|
|
-
|
|
|
-@property (strong) IBOutlet NSView *signTypeView;
|
|
|
-@property (weak) IBOutlet NSButton *inputButton;
|
|
|
-@property (weak) IBOutlet NSButton *drawingButton;
|
|
|
-@property (weak) IBOutlet NSButton *pictureButton;
|
|
|
-@property (strong) IBOutlet NSView *signTypeBackView;
|
|
|
-
|
|
|
-@property (weak) IBOutlet NSTextField *trackpadLabel;
|
|
|
-
|
|
|
-@property (weak) IBOutlet NSBox *contentBox;
|
|
|
-
|
|
|
-@property (weak) IBOutlet NSTextField *titleLabel;
|
|
|
-
|
|
|
-//keyboard
|
|
|
-@property (strong) IBOutlet NSView *inputView;
|
|
|
-@property (weak) IBOutlet KMPDFSignatureTextView *keyboardView;
|
|
|
-@property (weak) IBOutlet NSPopUpButton *fontBox;
|
|
|
-@property (strong) IBOutlet NSButton *keyboardColorBtn1;
|
|
|
-@property (strong) IBOutlet NSButton *keyboardColorBtn2;
|
|
|
-@property (strong) IBOutlet NSButton *keyboardColorBtn3;
|
|
|
-@property (strong) IBOutlet NSButton *keyboardColorBtn4;
|
|
|
-@property (strong) IBOutlet NSView *keyboardColorSelView;
|
|
|
-@property (weak) IBOutlet KMSignatureColorButton *textColorButton;
|
|
|
-
|
|
|
-@property (nonatomic, strong) KMDesignSelect *fontVC;
|
|
|
-@property (nonatomic, strong) NSArray *fontValues;
|
|
|
-@property (nonatomic, copy) NSString *fontDefaultValue;
|
|
|
-
|
|
|
-//Draw
|
|
|
-@property (strong) IBOutlet NSView *drawingView;
|
|
|
-@property (weak) IBOutlet KMDrawView *drawView;
|
|
|
-@property (weak) IBOutlet NSButton *trackpadButton;
|
|
|
-@property (nonatomic, strong) KMDesignButton *trackpadButtonVC;
|
|
|
-
|
|
|
-@property (strong) IBOutlet NSPopUpButton *drawSizeBox;
|
|
|
-@property (strong) IBOutlet NSView *colorBGView;
|
|
|
-@property (strong) IBOutlet NSView *drawColorSelView;
|
|
|
-@property (strong) IBOutlet NSButton *drawColorBtn1;
|
|
|
-@property (strong) IBOutlet NSButton *drawColorBtn2;
|
|
|
-@property (strong) IBOutlet NSButton *drawColorBtn3;
|
|
|
-@property (strong) IBOutlet NSButton *drawColorBtn4;
|
|
|
-
|
|
|
-@property (nonatomic, strong) KMDesignSelect *drawSizeVC;
|
|
|
-@property (nonatomic, strong) NSArray *drawSizeValues;
|
|
|
-@property (nonatomic, copy) NSString *drawSizeDefaultValue;
|
|
|
-
|
|
|
-@property (weak) IBOutlet NSView *drawTipView;
|
|
|
-@property (weak) IBOutlet NSTextField *drawTipLabel;
|
|
|
-
|
|
|
-
|
|
|
-//Picture
|
|
|
-@property (strong) IBOutlet NSView *pictureView;
|
|
|
-@property (weak) IBOutlet KMPDFSignatureImageView *pictureBackView;
|
|
|
-@property (strong) IBOutlet NSButton *pictureClearBackBtn;
|
|
|
-
|
|
|
-@property (nonatomic, strong) KMDesignButton *pictureClearBackBtnVC;
|
|
|
-@property (weak) IBOutlet KMCoverButton *pictureHelpButton;
|
|
|
-
|
|
|
-@property (nonatomic,strong) KMSignature *selectedSignature;
|
|
|
-@property (nonatomic,strong) NSMenuItem *selectItem;
|
|
|
-@property (nonatomic,assign) KMPDFSignatureType type;
|
|
|
-@property (nonatomic,copy) void (^handler)(KMSignature*);
|
|
|
-
|
|
|
-@property (nonatomic, strong) NSPopover *popover;
|
|
|
-
|
|
|
-@end
|
|
|
-
|
|
|
-@implementation KMSignatureWindowController
|
|
|
-
|
|
|
-- (id)init
|
|
|
-{
|
|
|
- if (self = [super initWithWindowNibName:@"KMSignatureWindowController"]) {
|
|
|
- NSMutableArray *fonts = [NSMutableArray array];
|
|
|
- for (NSDictionary *dic in [CPDFAnnotationModel supportFonts]) {
|
|
|
- [fonts addObject:dic.allKeys.firstObject];
|
|
|
- }
|
|
|
- self.fontValues = fonts.copy;
|
|
|
- self.fontDefaultValue = @"Helvetica";
|
|
|
-
|
|
|
- self.drawSizeValues = @[@"1.0",@"2.0",@"4.0",@"6.0",@"8.0"];
|
|
|
- self.drawSizeDefaultValue = @"2.0";
|
|
|
- }
|
|
|
- return self;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)dealloc
|
|
|
-{
|
|
|
- _drawView.delegate = nil;
|
|
|
- _keyboardView.delegate = nil;
|
|
|
- [[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
- [[NSColorPanel sharedColorPanel] setTarget:nil];
|
|
|
- [[NSColorPanel sharedColorPanel] setAction:nil];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark - View Methods
|
|
|
-
|
|
|
-- (void)windowDidLoad {
|
|
|
- [super windowDidLoad];
|
|
|
-
|
|
|
- __weak typeof (self) weakSelf = self;
|
|
|
-
|
|
|
- self.type = KMPDFSignatureTypeText;
|
|
|
-
|
|
|
-// self.textColorButton.drawImage = self.mouseColorButton.drawImage = [NSImage imageNamed:@"view_color"];
|
|
|
- self.cancelBtton.title = @"";
|
|
|
- self.cancelButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
|
|
|
- [self.cancelBtton addSubview:self.cancelButtonVC.view];
|
|
|
- self.cancelButtonVC.view.frame = self.cancelBtton.bounds;
|
|
|
- self.cancelButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
|
- self.cancelButtonVC.stringValue = NSLocalizedString(@"Cancel", nil);
|
|
|
- self.cancelButtonVC.target = self;
|
|
|
- self.cancelButtonVC.action = @selector(dismissSheet:);
|
|
|
- [self.cancelButtonVC buttonWithType:TokenButtonTypeSec_Icon size:TokenButtonSizeM height:nil];
|
|
|
-
|
|
|
- [self.clearButton setTarget:self];
|
|
|
- [self.clearButton setAction:@selector(clearButton_Click:)];
|
|
|
- self.clearButton.hidden = YES;
|
|
|
-
|
|
|
- self.applyButton.title = @"";
|
|
|
- self.applyButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
|
|
|
- [self.applyButton addSubview:self.applyButtonVC.view];
|
|
|
- self.applyButtonVC.view.frame = self.applyButton.bounds;
|
|
|
- self.applyButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
|
- self.applyButtonVC.stringValue = NSLocalizedString(@"Save", nil);
|
|
|
- self.applyButtonVC.target = self;
|
|
|
- self.applyButtonVC.action = @selector(applyButton_Click:);
|
|
|
- [self.applyButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeM height:nil];
|
|
|
- self.applyButtonVC.enabled = NO;
|
|
|
-
|
|
|
-
|
|
|
- self.contentBox.wantsLayer = YES;
|
|
|
- self.contentBox.layer.backgroundColor = [NSColor clearColor].CGColor;
|
|
|
- self.contentBox.borderType = NSNoBorder;
|
|
|
-
|
|
|
- self.inputButton.bordered = self.drawingButton.bordered = self.pictureButton.bordered = NO;
|
|
|
-
|
|
|
- //Keyboard
|
|
|
- self.inputView.wantsLayer = YES;
|
|
|
- self.inputView.layer.backgroundColor = [NSColor whiteColor].CGColor;
|
|
|
-
|
|
|
- self.keyboardView.wantsLayer = YES;
|
|
|
- self.keyboardView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
|
|
|
- self.keyboardView.changeSignatureTextCallback = ^(BOOL isTure) {
|
|
|
- if (isTure) {
|
|
|
- weakSelf.clearButton.hidden = NO;
|
|
|
- weakSelf.clearButton.title = NSLocalizedString(@"Clear", nil);
|
|
|
- } else {
|
|
|
- weakSelf.clearButton.hidden = YES;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- self.keyboardColorBtn1.wantsLayer = self.keyboardColorBtn2.wantsLayer = self.keyboardColorBtn3.wantsLayer = self.keyboardColorBtn4.wantsLayer = YES;
|
|
|
- self.keyboardColorBtn1.layer.backgroundColor = [NSColor colorWithRed:37/255.0f green:38/255.0f blue:41/255.0f alpha:1.0f].CGColor;
|
|
|
- self.keyboardColorBtn2.layer.backgroundColor = [NSColor colorWithRed:252/255.0f green:31/255.0f blue:31/255.0f alpha:1.0f].CGColor;
|
|
|
- self.keyboardColorBtn3.layer.backgroundColor = [NSColor colorWithRed:39/255.0f green:60/255.0f blue:98/255.0f alpha:1.0f].CGColor;
|
|
|
- self.keyboardColorBtn4.layer.backgroundColor = [NSColor colorWithRed:148/255.0f green:152/255.0f blue:156/255.0f alpha:1.0f].CGColor;
|
|
|
- self.keyboardColorBtn1.layer.cornerRadius = self.keyboardColorBtn2.layer.cornerRadius = self.keyboardColorBtn3.layer.cornerRadius = self.keyboardColorBtn4.layer.cornerRadius = 10.;
|
|
|
- self.keyboardColorBtn1.layer.masksToBounds = self.keyboardColorBtn2.layer.masksToBounds = self.keyboardColorBtn3.layer.masksToBounds = self.keyboardColorBtn4.layer.masksToBounds = YES;
|
|
|
- self.keyboardColorSelView.wantsLayer = YES;
|
|
|
- self.keyboardColorSelView.layer.backgroundColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:0.6].CGColor;
|
|
|
- self.keyboardColorSelView.layer.borderWidth = 1.;
|
|
|
- self.keyboardColorSelView.layer.borderColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:1.0f].CGColor;
|
|
|
- self.keyboardColorSelView.layer.cornerRadius = 4.;
|
|
|
- self.keyboardColorSelView.layer.masksToBounds = YES;
|
|
|
-
|
|
|
- [self colorTextButtonAction:self.keyboardColorBtn1];
|
|
|
-
|
|
|
- //Draw
|
|
|
- self.drawView.delegate = self;
|
|
|
- self.drawView.wantsLayer = YES;
|
|
|
- self.drawView.strokeRadius = [self.drawSizeDefaultValue floatValue];
|
|
|
- self.drawView.layer.cornerRadius = 4.;
|
|
|
- self.drawView.layer.masksToBounds = YES;
|
|
|
- self.drawView.layer.borderWidth = 1.;
|
|
|
- self.drawView.layer.borderColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
|
|
|
- self.drawView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
|
|
|
-
|
|
|
- self.drawColorBtn1.wantsLayer = self.drawColorBtn2.wantsLayer = self.drawColorBtn3.wantsLayer = self.drawColorBtn4.wantsLayer = YES;
|
|
|
- self.drawColorBtn1.layer.backgroundColor = [NSColor colorWithRed:37/255.0f green:38/255.0f blue:41/255.0f alpha:1.0f].CGColor;
|
|
|
- self.drawColorBtn2.layer.backgroundColor = [NSColor colorWithRed:252/255.0f green:31/255.0f blue:31/255.0f alpha:1.0f].CGColor;
|
|
|
- self.drawColorBtn3.layer.backgroundColor = [NSColor colorWithRed:39/255.0f green:60/255.0f blue:98/255.0f alpha:1.0f].CGColor;
|
|
|
- self.drawColorBtn4.layer.backgroundColor = [NSColor colorWithRed:148/255.0f green:152/255.0f blue:156/255.0f alpha:1.0f].CGColor;
|
|
|
-
|
|
|
- self.drawColorBtn1.layer.cornerRadius = self.drawColorBtn2.layer.cornerRadius = self.drawColorBtn3.layer.cornerRadius = self.drawColorBtn4.layer.cornerRadius = 10.;
|
|
|
- self.drawColorBtn1.layer.masksToBounds = self.drawColorBtn2.layer.masksToBounds = self.drawColorBtn3.layer.masksToBounds = self.drawColorBtn4.layer.masksToBounds = YES;
|
|
|
- self.drawColorSelView.wantsLayer = YES;
|
|
|
- self.drawColorSelView.layer.backgroundColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:0.6].CGColor;
|
|
|
- self.drawColorSelView.layer.borderWidth = 1.;
|
|
|
- self.drawColorSelView.layer.borderColor = [NSColor colorWithRed:206/255.0f green:208/255.0f blue:212/255.0f alpha:1.0f].CGColor;
|
|
|
- self.drawColorSelView.layer.cornerRadius = 4.;
|
|
|
- self.drawColorSelView.layer.masksToBounds = YES;
|
|
|
-
|
|
|
- [self drawColorBtnClicked:self.drawColorBtn1];
|
|
|
-
|
|
|
- for (NSString *pxSize in @[@"0.5",@"1.0",@"1.5",@"2.0",@"2.5",@"3.0"]) {
|
|
|
- NSDictionary *attrited = @{NSFontAttributeName:[NSFont systemFontOfSize:14]};
|
|
|
- NSAttributedString *string = [[NSAttributedString alloc] initWithString:pxSize attributes:attrited];
|
|
|
- NSMenuItem *item = [[NSMenuItem alloc] init];
|
|
|
- item.attributedTitle = string;
|
|
|
- [self.drawSizeBox.menu addItem:item];
|
|
|
- }
|
|
|
- [self.drawSizeBox selectItem:[self.drawSizeBox itemAtIndex:1]];
|
|
|
- [self.drawSizeBox setTitle:@"1.0 pt"];
|
|
|
-
|
|
|
- //Picture
|
|
|
- self.pictureView.wantsLayer = YES;
|
|
|
- self.pictureView.layer.backgroundColor = [NSColor whiteColor].CGColor;
|
|
|
-
|
|
|
- self.pictureBackView.wantsLayer = YES;
|
|
|
- self.pictureBackView.layer.cornerRadius = 4.;
|
|
|
- self.pictureBackView.layer.masksToBounds = YES;
|
|
|
- self.pictureBackView.layer.borderWidth = 1.;
|
|
|
- self.pictureBackView.layer.borderColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
|
|
|
- self.pictureBackView.layer.backgroundColor = [NSColor colorWithRed:247/255. green:248/255. blue:250/255. alpha:1.].CGColor;
|
|
|
- self.pictureBackView.changeSignatureImageCallback = ^(BOOL isTure) {
|
|
|
- if (isTure) {
|
|
|
- weakSelf.applyButtonVC.enabled = YES;
|
|
|
- } else {
|
|
|
- weakSelf.applyButtonVC.enabled = NO;
|
|
|
- }
|
|
|
- if (weakSelf.pictureBackView.signatureImage) {
|
|
|
- weakSelf.clearButton.hidden = NO;
|
|
|
- weakSelf.clearButton.title = NSLocalizedString(@"Reselect", nil);
|
|
|
- } else {
|
|
|
- weakSelf.clearButton.hidden = YES;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- [self.trackpadLabel setHidden:YES];
|
|
|
- self.drawTipView.hidden = YES;
|
|
|
-
|
|
|
- self.keyboardView.delegate = self;
|
|
|
- self.drawView.changeDrawCallback = ^(BOOL isTure) {
|
|
|
- if (isTure) {
|
|
|
- weakSelf.applyButtonVC.enabled = YES;
|
|
|
- } else {
|
|
|
- weakSelf.applyButtonVC.enabled = NO;
|
|
|
- }
|
|
|
- };
|
|
|
- self.drawView.touchEndCallback = ^(BOOL isClear) {
|
|
|
- if (isClear) {
|
|
|
- weakSelf.clearButton.hidden = YES;
|
|
|
- } else {
|
|
|
- weakSelf.clearButton.hidden = NO;
|
|
|
- weakSelf.clearButton.title = NSLocalizedString(@"Clear", nil);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- [self inputButton_Click:nil];
|
|
|
-
|
|
|
- self.pictureHelpButton.image = [NSImage imageNamed:@"KMImageNameHelpNormal"];
|
|
|
- self.pictureHelpButton.toolTip = @"Remove white background from images";
|
|
|
- self.pictureHelpButton.action = @selector(showHelpTip:);
|
|
|
- self.pictureHelpButton.coverAction = ^(KMCoverButton * _Nonnull button, KMCoverAction action) {
|
|
|
- if (action == KMCoverActionEnter) {
|
|
|
- button.image = [NSImage imageNamed:@"KMImageNameHelpHover"];
|
|
|
-// [weakSelf showHelpTip:button];
|
|
|
- } else if (action == KMCoverActionExit) {
|
|
|
- button.image = [NSImage imageNamed:@"KMImageNameHelpNormal"];
|
|
|
-// [weakSelf dismissHelpTip];
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- [self localizedString];
|
|
|
- [self setupUI];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)setupUI {
|
|
|
- NSString *fontName = @"SFProText-Regular";
|
|
|
-
|
|
|
- self.titleLabel.font = [NSFont fontWithName:@"SFProText-Semibold" size:16];
|
|
|
- self.titleLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
|
|
|
-
|
|
|
- self.signTypeView.wantsLayer = YES;
|
|
|
- self.signTypeView.layer.backgroundColor = [NSColor colorWithRed:223/255. green:225/255. blue:229/255. alpha:1.].CGColor;
|
|
|
- self.signTypeView.layer.cornerRadius = 4.;
|
|
|
- self.signTypeView.layer.masksToBounds = YES;
|
|
|
- self.signTypeBackView.wantsLayer = YES;
|
|
|
- self.signTypeBackView.layer.cornerRadius = 2.;
|
|
|
- self.signTypeBackView.layer.masksToBounds = YES;
|
|
|
- self.signTypeBackView.layer.backgroundColor = [NSColor whiteColor].CGColor;
|
|
|
-
|
|
|
- for (NSButton *button in @[self.inputButton, self.drawingButton, self.pictureButton]) {
|
|
|
- [button setTitleColorWithColor:[NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f] font:nil];
|
|
|
- button.font = [NSFont fontWithName:fontName size:12];
|
|
|
- }
|
|
|
-
|
|
|
- // Input
|
|
|
- self.fontVC = [[KMDesignSelect alloc] initWithType:SelectTypeCombox];
|
|
|
- [self.fontBox.superview addSubview:self.fontVC.view];
|
|
|
- [self.fontVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.left.equalTo(self.fontBox);
|
|
|
- make.centerY.equalTo(self.fontBox);
|
|
|
- make.size.mas_equalTo(NSMakeSize(200, 32));
|
|
|
- }];
|
|
|
- self.fontBox.hidden = YES;
|
|
|
-
|
|
|
- [self.fontVC addItemsWithObjectValues:self.fontValues];
|
|
|
- self.fontVC.stringValue = self.fontDefaultValue;
|
|
|
- self.fontVC.delete = self;
|
|
|
-
|
|
|
- // Drawing
|
|
|
- self.drawSizeVC = [[KMDesignSelect alloc] initWithType:SelectTypeCombox];
|
|
|
- [self.drawSizeBox.superview addSubview:self.drawSizeVC.view];
|
|
|
- [self.drawSizeVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.left.equalTo(self.drawSizeBox);
|
|
|
- make.centerY.equalTo(self.drawSizeBox);
|
|
|
- make.size.mas_equalTo(NSMakeSize(85, 32));
|
|
|
- }];
|
|
|
- self.drawSizeBox.hidden = YES;
|
|
|
- self.drawSizeVC.delete = self;
|
|
|
- NSMutableArray *drawSizes = [NSMutableArray array];
|
|
|
- for (NSString *value in self.drawSizeValues) {
|
|
|
- [drawSizes addObject:[NSString stringWithFormat:@"%@ pt", value]];
|
|
|
- }
|
|
|
- [self.drawSizeVC addItemsWithObjectValues:drawSizes.copy];
|
|
|
- self.drawSizeVC.stringValue = [NSString stringWithFormat:@"%@ pt", self.drawSizeDefaultValue];
|
|
|
-
|
|
|
- self.trackpadButton.title = NSLocalizedString(@"Trackpad", nil);
|
|
|
- self.trackpadButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeCheckBox];
|
|
|
- [self.trackpadButton.superview addSubview:self.trackpadButtonVC.view];
|
|
|
- self.trackpadButtonVC.stringValue = NSLocalizedString(@"Trackpad", nil);
|
|
|
- self.trackpadButtonVC.state = KMDesignTokenStateNorm;
|
|
|
- [self.trackpadButtonVC checkbox_radioWithImageHeight:[[NSLayoutConstraint alloc] init]];
|
|
|
- self.trackpadButtonVC.target = self;
|
|
|
- self.trackpadButtonVC.action = @selector(trackpadButton_Click:);
|
|
|
-
|
|
|
- [self.trackpadButtonVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.left.equalTo(self.trackpadButton);
|
|
|
- make.centerY.equalTo(self.drawSizeVC.view);
|
|
|
- make.width.mas_equalTo(120);
|
|
|
- make.height.mas_equalTo(22);
|
|
|
- }];
|
|
|
- self.trackpadButton.hidden = YES;
|
|
|
-
|
|
|
- self.drawTipView.wantsLayer = YES;
|
|
|
- self.drawTipView.layer.backgroundColor = [NSColor colorWithRed:189/255.f green:223/255.f blue:253/255.f alpha:1.f].CGColor;
|
|
|
- self.drawTipLabel.stringValue = NSLocalizedString(@"Press any key to disable the touchpad", nil);
|
|
|
- self.drawTipLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
|
|
|
- self.drawTipLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
|
|
|
-
|
|
|
- // Picture
|
|
|
- self.pictureBackView.emptyTipLbl.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1];
|
|
|
- self.pictureBackView.emptyTipLbl.font = [NSFont fontWithName:fontName size:14];
|
|
|
-
|
|
|
- self.pictureClearBackBtn.title = NSLocalizedString(@"Clear background", nil);
|
|
|
- self.pictureClearBackBtnVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeCheckBox];
|
|
|
- [self.pictureClearBackBtn.superview addSubview:self.pictureClearBackBtnVC.view];
|
|
|
- self.pictureClearBackBtnVC.stringValue = NSLocalizedString(@"Clear background", nil);
|
|
|
- self.pictureClearBackBtnVC.state = KMDesignTokenStateNorm;
|
|
|
- [self.pictureClearBackBtnVC checkbox_radioWithImageHeight:[[NSLayoutConstraint alloc] init]];
|
|
|
- self.pictureClearBackBtnVC.target = self;
|
|
|
- self.pictureClearBackBtnVC.action = @selector(pictureClearBackBtnAction:);
|
|
|
-
|
|
|
- self.pictureClearBackBtn.hidden = YES;
|
|
|
- [self.pictureClearBackBtnVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.edges.equalTo(self.pictureClearBackBtn);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)setType:(KMPDFSignatureType)type {
|
|
|
- _type = type;
|
|
|
-
|
|
|
- CGRect rect = self.signTypeBackView.frame;
|
|
|
- if (_type == KMPDFSignatureTypeText) {
|
|
|
- rect.origin.x = 1;
|
|
|
- } else if (_type == KMPDFSignatureTypeInk) {
|
|
|
- rect.origin.x = 2 + 75;
|
|
|
- } else if (_type == KMPDFSignatureTypeImage) {
|
|
|
- rect.origin.x = 2 + 75*2;
|
|
|
- }
|
|
|
- rect.origin.y = (CGRectGetHeight(self.signTypeBackView.superview.frame) - CGRectGetHeight(self.signTypeBackView.frame))/2.;
|
|
|
- self.signTypeBackView.frame = rect;
|
|
|
-
|
|
|
- self.clearButton.hidden = YES;
|
|
|
- if (_type == KMPDFSignatureTypeText) {
|
|
|
-
|
|
|
- } else if (_type == KMPDFSignatureTypeInk) {
|
|
|
-
|
|
|
- } else if (_type == KMPDFSignatureTypeImage) {
|
|
|
- if (self.pictureBackView.signatureImage) {
|
|
|
- self.clearButton.title = NSLocalizedString(@"Reselect", nil);
|
|
|
- self.clearButton.hidden = NO;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark - mouse
|
|
|
-- (void)mouseDown:(NSEvent *)event {
|
|
|
- [self dismissHelpTip];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark - Private Methods
|
|
|
-
|
|
|
--(void)localizedString
|
|
|
-{
|
|
|
-
|
|
|
- self.titleLabel.stringValue = NSLocalizedString(@"Create Signature", "");
|
|
|
-
|
|
|
- [self.trackpadButton setTitle:NSLocalizedString(@"Trackpad", nil)];
|
|
|
- [self.clearButton setTitle:NSLocalizedString(@"Clear", nil)];
|
|
|
- [self.trackpadLabel setStringValue:NSLocalizedString(@"Press \"esc\" to disable the Trackpad.", nil)];
|
|
|
-
|
|
|
- NSArray *seletorFonts = @[@"Mistral", @"Bradley Hand", @"Brush Script MT", @"SignPainter", @"Edwardian Script ITC", @"American Typewriter",@"Baoli SC",@"Snell Roundhand", @"Apple Chancery", @"Monotype Corsiva"];
|
|
|
-
|
|
|
- NSArray *fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
|
|
|
- for (NSString *fontName in fonts) {
|
|
|
- NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:fontName size:12.0]};
|
|
|
- NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
|
|
|
- NSMenuItem *item = [[NSMenuItem alloc] init];
|
|
|
- item.attributedTitle = string;
|
|
|
- [self.fontBox.menu addItem:item];
|
|
|
- }
|
|
|
-
|
|
|
- NSString * fontName = nil;
|
|
|
-
|
|
|
- if (!recentlyFonts) {
|
|
|
- recentlyFonts = [[NSMutableArray alloc] init];
|
|
|
- }
|
|
|
- if (recentlyFonts.count < 1) {
|
|
|
- for (NSString *name in seletorFonts) {
|
|
|
- if ([fonts containsObject:name]) {
|
|
|
- fontName = name;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (fontName) {
|
|
|
- [recentlyFonts addObject:fontName];
|
|
|
- }
|
|
|
- } else {
|
|
|
- fontName = recentlyFonts.firstObject;
|
|
|
- }
|
|
|
-
|
|
|
-// if ([fonts containsObject:fontName]) {
|
|
|
-// self.keyboardView.fontName = fontName;
|
|
|
-// [self.fontBox setTitle:fontName];
|
|
|
-// } else {
|
|
|
-// self.keyboardView.fontName = fonts.firstObject;
|
|
|
-// [self.fontBox setTitle:fonts.firstObject];
|
|
|
-// }
|
|
|
- self.keyboardView.fontName = self.fontDefaultValue;
|
|
|
-
|
|
|
- for (NSInteger i = 0; i<recentlyFonts.count; i++) {
|
|
|
- NSString *fontName = recentlyFonts[i];
|
|
|
- NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:fontName size:12.0]};
|
|
|
- NSAttributedString *string = [[NSAttributedString alloc] initWithString:fontName attributes:attrited];
|
|
|
- NSMenuItem *item = [[NSMenuItem alloc] init];
|
|
|
- item.attributedTitle = string;
|
|
|
- [self.fontBox.menu insertItem:item atIndex:1 + i];
|
|
|
- }
|
|
|
- NSMenuItem *sep = [NSMenuItem separatorItem];
|
|
|
- [self.fontBox.menu insertItem:sep atIndex:(recentlyFonts.count)+1];
|
|
|
-
|
|
|
- self.selectItem = [self.fontBox.menu itemAtIndex:1];
|
|
|
- self.selectItem.state = NSControlStateValueOn;
|
|
|
- [self.inputButton setTitle:NSLocalizedString(@"Keyboard", nil)];
|
|
|
- [self.drawingButton setTitle:NSLocalizedString(@"Trackpad", nil)];
|
|
|
- [self.pictureButton setTitle:NSLocalizedString(@"Image", nil)];
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-- (void)showHelpTip:(NSButton *)sender {
|
|
|
- if (self.popover) {
|
|
|
- [self dismissHelpTip];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- NSPopover *pop = [[NSPopover alloc] init];
|
|
|
- self.popover = pop;
|
|
|
- KMSignatureHelpViewController *controller = [[KMSignatureHelpViewController alloc] init];
|
|
|
- pop.contentViewController = controller;
|
|
|
- controller.tipString = NSLocalizedString(@"Remove white background from images", nil);
|
|
|
- [pop setValue:@YES forKey:@"shouldHideAnchor"];
|
|
|
-
|
|
|
- [pop showRelativeToRect:NSMakeRect(0, -8, NSWidth(sender.bounds), NSHeight(sender.bounds)) ofView:sender preferredEdge:NSRectEdgeMaxY];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)dismissHelpTip {
|
|
|
- [self.popover close];
|
|
|
- self.popover = nil;
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark Button Mehtods
|
|
|
-
|
|
|
-- (IBAction)inputButton_Click:(id)sender {
|
|
|
- self.contentBox.contentView = self.inputView;
|
|
|
- self.type = KMPDFSignatureTypeText;
|
|
|
-}
|
|
|
-- (IBAction)drawingButton_Click:(id)sender {
|
|
|
- self.contentBox.contentView = self.drawingView;
|
|
|
- self.type = KMPDFSignatureTypeInk;
|
|
|
-}
|
|
|
-
|
|
|
-- (IBAction)pictureButton_Click:(id)sender {
|
|
|
- self.contentBox.contentView = self.pictureView;
|
|
|
- self.type = KMPDFSignatureTypeImage;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)clearButton_Click:(id)sender
|
|
|
-{
|
|
|
- if (KMPDFSignatureTypeImage == self.type) {
|
|
|
- [self.pictureBackView reSelectImage];
|
|
|
- } else if (KMPDFSignatureTypeInk == self.type) {
|
|
|
- [self.drawView clearImage];
|
|
|
- }else if (KMPDFSignatureTypeText == self.type) {
|
|
|
- [self.keyboardView clearImage];
|
|
|
- }
|
|
|
-
|
|
|
- self.applyButtonVC.enabled = NO;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)applyButton_Click:(id)sender
|
|
|
-{
|
|
|
- KMSignature *signature = [[KMSignature alloc] init];
|
|
|
-
|
|
|
- if (KMPDFSignatureTypeText == self.type) {
|
|
|
- NSImage *image = [self.keyboardView signatureImage];
|
|
|
-
|
|
|
- if (!image) {
|
|
|
- NSAlert *alert = [[NSAlert alloc] init];
|
|
|
- [alert setAlertStyle:NSAlertStyleCritical];
|
|
|
- [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
|
|
|
- [alert runModal];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- signature.pathsImage = image;
|
|
|
- signature.signatureType = KMPDFSignatureTypeText;
|
|
|
- KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
|
|
|
- [signatureManager loadAllSignatureList];
|
|
|
- [signatureManager addSignature:signature];
|
|
|
- [signatureManager saveSingaturesToFile];
|
|
|
- } else if(KMPDFSignatureTypeImage == self.type) {
|
|
|
- NSImage *image = [self.pictureBackView signatureImage];
|
|
|
-
|
|
|
- if (!image) {
|
|
|
- NSAlert *alert = [[NSAlert alloc] init];
|
|
|
- [alert setAlertStyle:NSAlertStyleCritical];
|
|
|
- [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
|
|
|
- [alert runModal];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- signature.pathsImage = image;
|
|
|
- signature.signatureType = KMPDFSignatureTypeImage;
|
|
|
-
|
|
|
- KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
|
|
|
- [signatureManager loadAllSignatureList];
|
|
|
- [signatureManager addSignature:signature];
|
|
|
- [signatureManager saveSingaturesToFile];
|
|
|
-
|
|
|
- } else {
|
|
|
- NSImage *image = [self.drawView signatureImage];
|
|
|
-
|
|
|
- if (!image) {
|
|
|
- NSAlert *alert = [[NSAlert alloc] init];
|
|
|
- [alert setAlertStyle:NSAlertStyleCritical];
|
|
|
- [alert setMessageText:NSLocalizedString(@"Unable to add new signatures. Please try again.",nil)];
|
|
|
- [alert runModal];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- [signature addPath:self.drawView.drawBezierPath];
|
|
|
- signature.signatureType = KMPDFSignatureTypeInk;
|
|
|
- signature.signatureColor = self.drawView.drawColor;
|
|
|
- signature.pathsImage = image;
|
|
|
- KMSignatureManager *signatureManager = [[KMSignatureManager alloc] init];
|
|
|
- [signatureManager loadAllSignatureList];
|
|
|
- [signatureManager addSignature:signature];
|
|
|
- [signatureManager saveSingaturesToFile];
|
|
|
- }
|
|
|
- self.selectedSignature = signature;
|
|
|
- [self dismissSheet:nil];
|
|
|
-}
|
|
|
-
|
|
|
-- (IBAction)trackpadButton_Click:(id)sender
|
|
|
-{
|
|
|
- if (self.trackpadButtonVC.state == KMDesignTokenStateChecked) {
|
|
|
- self.trackpadButtonVC.state = KMDesignTokenStateNorm;
|
|
|
- self.trackpadLabel.hidden = YES;
|
|
|
- self.drawTipView.hidden = YES;
|
|
|
- self.drawView.isAcceptsTouch = NO;
|
|
|
- } else {
|
|
|
- self.trackpadButtonVC.state = KMDesignTokenStateChecked;
|
|
|
- self.trackpadLabel.hidden = YES;
|
|
|
- self.drawTipView.hidden = NO;
|
|
|
- self.drawView.isAcceptsTouch = YES;
|
|
|
-
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
- self.drawTipView.hidden = YES;
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (IBAction)boxItemClicked_Font:(id)sender
|
|
|
-{
|
|
|
- NSString * name = self.fontBox.selectedItem.title;
|
|
|
- self.fontBox.title = name;
|
|
|
- self.keyboardView.fontName = name;
|
|
|
-
|
|
|
- if ([recentlyFonts containsObject:name]) {
|
|
|
- NSInteger index = [recentlyFonts indexOfObject:name];
|
|
|
- [recentlyFonts removeObject:name];
|
|
|
- [self.fontBox.menu removeItemAtIndex:index +1];
|
|
|
-
|
|
|
- }
|
|
|
- if (recentlyFonts.count >0) {
|
|
|
- [recentlyFonts insertObject:name atIndex:0];
|
|
|
- } else {
|
|
|
- [recentlyFonts addObject:name];
|
|
|
- }
|
|
|
-
|
|
|
- if (recentlyFonts.count >5) {
|
|
|
- [recentlyFonts removeLastObject];
|
|
|
- [self.fontBox.menu removeItemAtIndex:recentlyFonts.count];
|
|
|
- }
|
|
|
-
|
|
|
- NSDictionary *attrited = @{NSFontAttributeName:[NSFont fontWithName:name size:12.0]};
|
|
|
- NSAttributedString *string = [[NSAttributedString alloc] initWithString:name attributes:attrited];
|
|
|
- NSMenuItem *item = [[NSMenuItem alloc] init];
|
|
|
- item.attributedTitle = string;
|
|
|
- [self.fontBox.menu insertItem:item atIndex:1];
|
|
|
-
|
|
|
- self.selectItem.state = NSControlStateValueOff;
|
|
|
- self.selectItem = [self.fontBox.menu itemAtIndex:1];
|
|
|
- self.selectItem.state = NSControlStateValueOn;
|
|
|
-}
|
|
|
-
|
|
|
-- (IBAction)colorTextButtonAction:(id)sender {
|
|
|
- if ([sender isEqual:self.keyboardColorBtn1] ||
|
|
|
- [sender isEqual:self.keyboardColorBtn2] ||
|
|
|
- [sender isEqual:self.keyboardColorBtn3] ||
|
|
|
- [sender isEqual:self.keyboardColorBtn4]) {
|
|
|
-
|
|
|
- self.keyboardView.keyboardColor = [NSColor colorWithCGColor:((NSButton *)sender).layer.backgroundColor];
|
|
|
-
|
|
|
- CGRect rect = self.keyboardView.frame;
|
|
|
- rect.origin.y = CGRectGetMidY(((NSButton *)sender).frame)-16;
|
|
|
- rect.origin.x = CGRectGetMidX(((NSButton *)sender).frame)-16;
|
|
|
- rect.size.width = rect.size.height = 32;
|
|
|
- self.keyboardColorSelView.frame = rect;
|
|
|
-
|
|
|
- } else {
|
|
|
- [[NSColorPanel sharedColorPanel] setTarget:self];
|
|
|
- [[NSColorPanel sharedColorPanel] setAction:@selector(keyboardColorPanelColorDidChange:)];
|
|
|
- [[NSColorPanel sharedColorPanel] orderFront:nil];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (IBAction)drawColorBtnClicked:(NSButton *)sender {
|
|
|
- if ([sender isEqual:self.drawColorBtn1] ||
|
|
|
- [sender isEqual:self.drawColorBtn2] ||
|
|
|
- [sender isEqual:self.drawColorBtn3] ||
|
|
|
- [sender isEqual:self.drawColorBtn4]) {
|
|
|
-
|
|
|
- self.drawView.drawColor = [NSColor colorWithCGColor:((NSButton *)sender).layer.backgroundColor];
|
|
|
-
|
|
|
- CGRect rect = self.drawColorSelView.frame;
|
|
|
- rect.origin.y = CGRectGetMidY(((NSButton *)sender).frame)-16;
|
|
|
- rect.origin.x = CGRectGetMidX(((NSButton *)sender).frame)-16;
|
|
|
- rect.size.width = rect.size.height = 32;
|
|
|
- self.drawColorSelView.frame = rect;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (IBAction)drawSizeBtnClicked:(NSPopUpButton *)sender {
|
|
|
- NSString * name = self.drawSizeBox.selectedItem.title;
|
|
|
- self.drawSizeBox.title = name;
|
|
|
-
|
|
|
- self.drawView.strokeRadius = [[@[@"0.5",@"1.0",@"1.5",@"2.0",@"2.5",@"3.0"] objectAtIndex:(self.drawSizeBox.indexOfSelectedItem -1)] floatValue];
|
|
|
-}
|
|
|
-
|
|
|
-//Picture
|
|
|
-
|
|
|
-- (IBAction)pictureClearBackBtnAction:(NSButton *)sender {
|
|
|
- BOOL clearBack = YES;
|
|
|
- if (self.pictureClearBackBtnVC.state == KMDesignTokenStateChecked) {
|
|
|
- self.pictureClearBackBtnVC.state = KMDesignTokenStateNorm;
|
|
|
- clearBack = NO;
|
|
|
- } else {
|
|
|
- self.pictureClearBackBtnVC.state = KMDesignTokenStateChecked;
|
|
|
- clearBack = YES;
|
|
|
- }
|
|
|
- self.pictureBackView.clearBackground = clearBack;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)keyboardColorPanelColorDidChange:(id)sender
|
|
|
-{
|
|
|
- self.textColorButton.layer.borderColor= [NSColor clearColor].CGColor;
|
|
|
-
|
|
|
- CGFloat red,green,blue,alpha;
|
|
|
- NSColor *color = [NSColorPanel sharedColorPanel].color ? : [NSColor clearColor];
|
|
|
- [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
|
|
|
- self.keyboardView.keyboardColor = color;
|
|
|
- self.textColorButton.layer.borderColor = [NSColor colorWithRed:33.0/255.0 green:124.0/255.0 blue:234.0/255.0 alpha:1.0].CGColor;
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark KMDrawViewDelegate Methods
|
|
|
-
|
|
|
-- (void)drawViewDidFinishTouchMode:(KMDrawView *)view
|
|
|
-{
|
|
|
- self.trackpadButtonVC.state = KMDesignTokenStateNorm;
|
|
|
- [self.trackpadLabel setHidden:YES];
|
|
|
-
|
|
|
-// [NSAnimationContext beginGrouping];
|
|
|
-// [NSAnimationContext currentContext].duration = 1.5;
|
|
|
-// [NSAnimationContext currentContext].timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
|
|
|
-// self.scrollView.animator.frame = originFrame;
|
|
|
- self.drawTipView.animator.hidden = YES;
|
|
|
-// [NSAnimationContext endGrouping];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark KMChangeSignatureTextDelegate Methods
|
|
|
-
|
|
|
-- (void)changeSignatureText:(BOOL)isTure {
|
|
|
- self.applyButtonVC.enabled = isTure;
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark Show Methods
|
|
|
-- (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
|
|
|
-{
|
|
|
- if (contextInfo != NULL && self.handler) {
|
|
|
- self.handler(self.selectedSignature);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (void)beginSheetModalForWindow:(NSWindow *)window completionHandler:(void (^)(KMSignature *signature))handler;
|
|
|
-{
|
|
|
- windowController_signature = self;
|
|
|
-
|
|
|
- [NSApp beginSheet:[self window]
|
|
|
- modalForWindow:window
|
|
|
- modalDelegate:self
|
|
|
- didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
|
|
- contextInfo:(__bridge void * _Null_unspecified)(handler ? handler : NULL)];
|
|
|
- self.handler = handler;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)dismissSheet:(id)sender {
|
|
|
- windowController_signature = nil;
|
|
|
-
|
|
|
- if (sender) {
|
|
|
- [NSApp endSheet:[self window] returnCode:0];
|
|
|
- } else {
|
|
|
- [NSApp endSheet:[self window] returnCode:1];
|
|
|
- }
|
|
|
- [[self window] orderOut:self];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark -
|
|
|
-#pragma mark - KMSelectPopButtonDelegate
|
|
|
-
|
|
|
-- (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
|
|
|
- if ([obj isEqual:self.fontVC]) {
|
|
|
- NSInteger index = self.fontVC.indexOfSelectedItem;
|
|
|
- if (index < 0) {
|
|
|
- index = 0;
|
|
|
- }
|
|
|
-
|
|
|
- self.keyboardView.fontName = self.fontVC.items[index];
|
|
|
- } else if ([obj isEqual:self.drawSizeVC]) {
|
|
|
- NSInteger index = self.drawSizeVC.indexOfSelectedItem;
|
|
|
- if (index < 0) {
|
|
|
- index = 0;
|
|
|
- }
|
|
|
- self.drawView.strokeRadius = [self.drawSizeValues[index] floatValue];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark NSTabViewDelegate Methods
|
|
|
-
|
|
|
-- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(nullable NSTabViewItem *)tabViewItem
|
|
|
-{
|
|
|
- return YES;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
|
|
|
-{
|
|
|
- BOOL isImage = NO;
|
|
|
- if ([tabView indexOfTabViewItem:tabViewItem] == 0) {
|
|
|
- self.type = KMPDFSignatureTypeText;
|
|
|
- if ([self.keyboardView signatureImage]) {
|
|
|
- isImage = YES;
|
|
|
- }
|
|
|
- } else if ([tabView indexOfTabViewItem:tabViewItem] == 1) {
|
|
|
- self.type = KMPDFSignatureTypeInk;
|
|
|
- if ([self.drawView signatureImage]) {
|
|
|
- isImage = YES;
|
|
|
- }
|
|
|
- } else if ([tabView indexOfTabViewItem:tabViewItem] == 2) {
|
|
|
- self.type = KMPDFSignatureTypeImage;
|
|
|
- if ([self.pictureBackView signatureImage]) {
|
|
|
- isImage = YES;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (isImage) {
|
|
|
- self.applyButtonVC.enabled = YES;
|
|
|
- } else {
|
|
|
- self.applyButtonVC.enabled = NO;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@end
|