WelcomeWindowController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. //
  2. // WelcomeWindowController.m
  3. // PDF Reader
  4. //
  5. // Created by wangshuai on 13-12-11.
  6. // Copyright (c) 2013年 zhangjie. All rights reserved.
  7. //
  8. #import "WelcomeWindowController.h"
  9. #import "WaitingView.h"
  10. #import <PDF_Master-Swift.h>
  11. #import "TCPageIndicator.h"
  12. #import "NSButton+TitleColor.h"
  13. static WelcomeWindowController *windowController = nil;
  14. static NSString * const kKMWelcomeHasShowKey = @"WelcomeHasShowKey";
  15. static NSString * const kKMWelcomeRemindMeLaterKey = @"WelcomeRemindMeLaterKey";
  16. @interface WelcomeWindowController ()
  17. @property (nonatomic,assign) IBOutlet NSScrollView *scrollView;
  18. @property (nonatomic,assign) IBOutlet NSView *content1View;
  19. @property (nonatomic,assign) IBOutlet NSView *content2View;
  20. @property (nonatomic,assign) IBOutlet NSView *content3View;
  21. @property (nonatomic,assign) IBOutlet NSView *content4View;
  22. @property (strong) IBOutlet NSView *content5View;
  23. @property (nonatomic,assign) IBOutlet NSTextField *title1Label;
  24. @property (nonatomic,assign) IBOutlet NSTextField *subtitle1Label;
  25. @property (nonatomic,assign) IBOutlet NSTextField *title2Label;
  26. @property (nonatomic,assign) IBOutlet NSTextField *subtitle2Label;
  27. @property (nonatomic,assign) IBOutlet NSTextField *title3Label;
  28. @property (nonatomic,assign) IBOutlet NSTextField *subtitle3Label;
  29. @property (nonatomic,assign) IBOutlet NSTextField *title4Label;
  30. @property (nonatomic,assign) IBOutlet NSTextField *subtitle4Label;
  31. @property (weak) IBOutlet NSTextField *title5Label;
  32. @property (weak) IBOutlet NSTextField *subtitle5Label;
  33. @property (weak) IBOutlet NSBox *preBox;
  34. @property (weak) IBOutlet NSBox *nextBox;
  35. @property (nonatomic, strong) KMDesignButton *preButtonVC;
  36. @property (nonatomic, strong) KMDesignButton *nextButtonVC;
  37. @property (weak) IBOutlet NSBox *next1Box;
  38. @property (weak) IBOutlet NSBox *remindMeLaterBox;
  39. @property (weak) IBOutlet NSBox *next2Box;
  40. @property (weak) IBOutlet NSBox *next3Box;
  41. @property (weak) IBOutlet NSBox *next4Box;
  42. @property (weak) IBOutlet NSBox *signUpBox;
  43. @property (nonatomic, strong) KMDesignButton *next1ButtonVC;
  44. @property (nonatomic, strong) KMDesignButton *remindMeLaterButtonVC;
  45. @property (nonatomic, strong) KMDesignButton *next2ButtonVC;
  46. @property (nonatomic, strong) KMDesignButton *next3ButtonVC;
  47. @property (nonatomic, strong) KMDesignButton *next4ButtonVC;
  48. @property (nonatomic, strong) KMDesignButton *signUpButtonVC;
  49. @property (weak) IBOutlet TCPageIndicator *pageIndicator1;
  50. @property (weak) IBOutlet TCPageIndicator *pageIndicator2;
  51. @property (weak) IBOutlet TCPageIndicator *pageIndicator3;
  52. @property (weak) IBOutlet TCPageIndicator *pageIndicator4;
  53. @property (weak) IBOutlet TCPageIndicator *pageIndicator5;
  54. @property (nonatomic,retain) NSArray *contentViews;
  55. @property (nonatomic,assign) NSInteger currentIndex;
  56. @property (weak) IBOutlet NSButton *closeButton;
  57. @property (weak) IBOutlet KMBox *closeBox;
  58. @end
  59. @implementation WelcomeWindowController
  60. - (void)dealloc {
  61. #if DEBUG
  62. NSLog(@"%s", __func__);
  63. #endif
  64. }
  65. + (void)load {
  66. // 处理再次提醒
  67. if ([[NSUserDefaults standardUserDefaults] boolForKey:kKMWelcomeRemindMeLaterKey]) {
  68. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kKMWelcomeRemindMeLaterKey];
  69. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kKMWelcomeHasShowKey];
  70. [[NSUserDefaults standardUserDefaults] synchronize];
  71. }
  72. }
  73. + (BOOL)welcomeHasShow {
  74. return [[NSUserDefaults standardUserDefaults] boolForKey:kKMWelcomeHasShowKey];
  75. }
  76. #pragma mark Init Methods
  77. - (id)init {
  78. if (self = [super initWithWindowNibName:@"WelcomeWindowController"]) {
  79. windowController = self;
  80. }
  81. return self;
  82. }
  83. - (void)awakeFromNib {
  84. [super awakeFromNib];
  85. NSClipView *clipView = self.scrollView.contentView;
  86. self.contentViews = @[self.content1View,self.content2View,self.content3View,self.content4View,self.content5View];
  87. for (int i=0; i<self.contentViews.count; i++) {
  88. NSView *view = self.contentViews[i];
  89. view.frame = CGRectMake(i*clipView.bounds.size.width, 0,
  90. clipView.bounds.size.width,
  91. clipView.bounds.size.height);
  92. [self.scrollView.documentView addSubview:view];
  93. }
  94. self.scrollView.documentView.frame = CGRectMake(0, 0, clipView.bounds.size.width*self.contentViews.count, clipView.bounds.size.height);
  95. }
  96. - (void)windowDidLoad {
  97. [super windowDidLoad];
  98. [self localizedString];
  99. [self initSubViews];
  100. [self setupUI];
  101. [self reloadData];
  102. // 设置【显示】标识
  103. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kKMWelcomeHasShowKey];
  104. [[NSUserDefaults standardUserDefaults] synchronize];
  105. }
  106. - (void)localizedString {
  107. self.title1Label.stringValue = NSLocalizedString(@"The Brand New PDF Master", nil);
  108. self.subtitle1Label.stringValue = NSLocalizedString(@"PDF Master Beta Invites You to Enjoy All Advanced Features! View, Annotate, Fill and Convert PDFs with PDF Master to boost your productivity.", nil);
  109. self.title2Label.stringValue = NSLocalizedString(@"Comment PDFs with Rich Annotation Tools", nil);
  110. self.subtitle2Label.stringValue = NSLocalizedString(@"Add highlights, freehand, text, stamps, links, shapes, and notes to your documents. Easily mark up your PDFs anytime!", nil);
  111. self.title3Label.stringValue = NSLocalizedString(@"Convert PDF to Office Fast and Easily", nil);
  112. self.subtitle3Label.stringValue = NSLocalizedString(@"Convert PDF to editable Word, Excel, PPT, Text and image with all your fonts and formatting preserved.", nil);
  113. self.title4Label.stringValue = NSLocalizedString(@"Fill out Form & Sign Documents", nil);
  114. self.subtitle4Label.stringValue = NSLocalizedString(@"Fill out forms effortlessly and add text, image or handwritten signatures to PDFs.", nil);
  115. self.title5Label.stringValue = NSLocalizedString(@"Sign up to Unlock Premium Features", nil);
  116. self.subtitle5Label.stringValue = NSLocalizedString(@"All advanced features in PDF Master can be used after registration, including converting PDFs without limitation.", nil);
  117. }
  118. - (void)initSubViews {
  119. self.preBox.borderType = NSNoBorder;
  120. self.preButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeImage];
  121. [self.preBox.contentView addSubview:self.preButtonVC.view];
  122. self.preButtonVC.view.frame = self.preBox.contentView.bounds;
  123. self.preButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  124. self.preButtonVC.image = [NSImage imageNamed:@"KMImageNameLeftButtonImage"];
  125. [self.preButtonVC pagination];
  126. self.preButtonVC.target = self;
  127. self.preButtonVC.action = @selector(previousButtonAction:);
  128. self.nextBox.borderType = NSNoBorder;
  129. self.nextButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeImage];
  130. [self.nextBox.contentView addSubview:self.nextButtonVC.view];
  131. self.nextButtonVC.view.frame = self.nextBox.contentView.bounds;
  132. self.nextButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  133. self.nextButtonVC.image = [NSImage imageNamed:@"KMImageNameRightButtonImage"];
  134. [self.nextButtonVC pagination];
  135. self.nextButtonVC.target = self;
  136. self.nextButtonVC.action = @selector(nextButtonAction:);
  137. for (NSBox *box in @[self.next1Box, self.next2Box, self.next3Box, self.next4Box]) {
  138. box.borderType = NSNoBorder;
  139. KMDesignButton *nextButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
  140. [box.contentView addSubview:nextButtonVC.view];
  141. nextButtonVC.view.frame = box.contentView.bounds;
  142. nextButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  143. nextButtonVC.stringValue = NSLocalizedString(@"Next", nil);
  144. nextButtonVC.target = self;
  145. nextButtonVC.action = @selector(nextButtonAction:);
  146. [nextButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeL height:[[NSLayoutConstraint alloc] init]];
  147. if ([box isEqual:self.next1Box]) {
  148. self.next1ButtonVC = nextButtonVC;
  149. } else if ([box isEqual:self.next2Box]) {
  150. self.next2ButtonVC = nextButtonVC;
  151. } else if ([box isEqual:self.next3Box]) {
  152. self.next3ButtonVC = nextButtonVC;
  153. } else if ([box isEqual:self.next4Box]) {
  154. self.next4ButtonVC = nextButtonVC;
  155. }
  156. }
  157. self.remindMeLaterBox.borderType = NSNoBorder;
  158. self.remindMeLaterButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
  159. [self.remindMeLaterBox.contentView addSubview:self.remindMeLaterButtonVC.view];
  160. self.remindMeLaterButtonVC.view.frame = self.remindMeLaterBox.contentView.bounds;
  161. self.remindMeLaterButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  162. self.remindMeLaterButtonVC.stringValue = NSLocalizedString(@"Remind Me Later", nil);
  163. self.remindMeLaterButtonVC.target = self;
  164. self.remindMeLaterButtonVC.action = @selector(remindMeLaterButtonAction:);
  165. // TokenButtonTypeLink
  166. [self.remindMeLaterButtonVC buttonWithType:TokenButtonTypeText size:TokenButtonSizeM height:[[NSLayoutConstraint alloc] init]];
  167. self.signUpBox.borderType = NSNoBorder;
  168. self.signUpButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
  169. [self.signUpBox.contentView addSubview:self.signUpButtonVC.view];
  170. self.signUpButtonVC.view.frame = self.signUpBox.contentView.bounds;
  171. self.signUpButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
  172. self.signUpButtonVC.stringValue = NSLocalizedString(@"Sign up", nil);
  173. self.signUpButtonVC.target = self;
  174. self.signUpButtonVC.action = @selector(signUpButtonAction:);
  175. [self.signUpButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeL height:[[NSLayoutConstraint alloc] init]];
  176. for (TCPageIndicator *pageindicator in @[self.pageIndicator1, self.pageIndicator2, self.pageIndicator3,
  177. self.pageIndicator4, self.pageIndicator5]) {
  178. pageindicator.numberOfPages = 5;
  179. pageindicator.selectedColor = [NSColor colorWithRed:39/255.f green:60/255.f blue:98/255.f alpha:1.f];
  180. pageindicator.normalColor = [NSColor colorWithRed:0/255.f green:0/255.f blue:0/255.f alpha:0.2];
  181. pageindicator.pageIndicatorSize = NSMakeSize(6, 6);
  182. pageindicator.enabled = NO;
  183. if ([pageindicator isEqual:self.pageIndicator1]) {
  184. pageindicator.currentPage = 0;
  185. } else if ([pageindicator isEqual:self.pageIndicator2]) {
  186. pageindicator.currentPage = 1;
  187. } else if ([pageindicator isEqual:self.pageIndicator3]) {
  188. pageindicator.currentPage = 2;
  189. } else if ([pageindicator isEqual:self.pageIndicator4]) {
  190. pageindicator.currentPage = 3;
  191. } else if ([pageindicator isEqual:self.pageIndicator5]) {
  192. pageindicator.currentPage = 4;
  193. }
  194. }
  195. __weak typeof(self)weakSelf = self;
  196. self.closeBox.moveCallback = ^(BOOL mouseEntered, KMBox *mouseBox) {
  197. if (mouseEntered) {
  198. weakSelf.closeButton.image = [NSImage imageNamed:@"control_btn_icon_close_hov"];
  199. } else {
  200. weakSelf.closeButton.image = [NSImage imageNamed:@"control_btn_icon_close"];
  201. }
  202. };
  203. }
  204. - (void)setupUI {
  205. for (NSTextField *titleLabel in @[self.title1Label, self.title2Label, self.title3Label,
  206. self.title4Label, self.title5Label]) {
  207. titleLabel.font = [NSFont fontWithName:@"SFProText-Semibold" size:20];
  208. titleLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
  209. }
  210. NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
  211. ps.lineSpacing = 6;
  212. ps.alignment = NSTextAlignmentCenter;
  213. for (NSTextField *subtitleLabel in @[self.subtitle1Label, self.subtitle2Label, self.subtitle3Label,
  214. self.subtitle4Label, self.subtitle5Label]) {
  215. subtitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:subtitleLabel.stringValue attributes:@{
  216. NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:14],
  217. NSForegroundColorAttributeName : [NSColor colorWithRed:97/255.f green:100/255.f blue:105/255.f alpha:1.f],
  218. NSParagraphStyleAttributeName : ps
  219. }];
  220. }
  221. }
  222. - (void)close {
  223. windowController = nil;
  224. [super close];
  225. }
  226. #pragma mark Private Methods
  227. - (void)reloadData {
  228. self.preBox.hidden = NO;
  229. self.nextBox.hidden = NO;
  230. if (self.currentIndex == 0) {
  231. self.preBox.hidden = YES;
  232. } else if (self.currentIndex == 1) {
  233. } else if (self.currentIndex == 2) {
  234. } else if (self.currentIndex == 3) {
  235. } else if (self.currentIndex == 4){
  236. self.nextBox.hidden = YES;
  237. }
  238. }
  239. - (void)addWaingView:(NSView *)view {
  240. [self removeWaitingView:view];
  241. WaitingView *wView = [[WaitingView alloc] initWithFrame:view.bounds];
  242. [wView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
  243. [view addSubview:wView];
  244. [wView startAnimation];
  245. }
  246. - (void)removeWaitingView:(NSView *)view {
  247. for (id v in view.subviews) {
  248. if ([[v class] isSubclassOfClass:[WaitingView class]]) {
  249. [v removeFromSuperview];
  250. break;
  251. }
  252. }
  253. }
  254. #pragma mark Button Actions
  255. - (IBAction)previousButtonAction:(id)sender {
  256. if (self.currentIndex <= 0) {
  257. return;
  258. }
  259. self.currentIndex--;
  260. [NSAnimationContext beginGrouping];
  261. NSClipView *clipView = [self.scrollView contentView];
  262. NSPoint newOrigin = [clipView bounds].origin;
  263. newOrigin.x = clipView.bounds.size.width*self.currentIndex;
  264. [[clipView animator] setBoundsOrigin:newOrigin];
  265. [NSAnimationContext endGrouping];
  266. [self reloadData];
  267. }
  268. - (IBAction)nextButtonAction:(id)sender {
  269. if (self.currentIndex >= self.contentViews.count-1) {
  270. return;
  271. }
  272. self.currentIndex++;
  273. [NSAnimationContext beginGrouping];
  274. NSClipView *clipView = [self.scrollView contentView];
  275. NSPoint newOrigin = [clipView bounds].origin;
  276. newOrigin.x = clipView.bounds.size.width*self.currentIndex;
  277. [[clipView animator] setBoundsOrigin:newOrigin];
  278. [NSAnimationContext endGrouping];
  279. [self reloadData];
  280. }
  281. - (IBAction)closeAction:(id)sender {
  282. if (self.itemClick) {
  283. self.itemClick(1, self);
  284. }
  285. [self close];
  286. }
  287. - (void)signUpButtonAction:(NSButton *)sender {
  288. if (self.itemClick) {
  289. self.itemClick(3, self);
  290. }
  291. [self close];
  292. }
  293. - (void)remindMeLaterButtonAction:(NSButton *)sender {
  294. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kKMWelcomeRemindMeLaterKey];
  295. [[NSUserDefaults standardUserDefaults] synchronize];
  296. if (self.itemClick) {
  297. self.itemClick(2, self);
  298. }
  299. [self close];
  300. }
  301. @end