WelcomeWindowController.m 14 KB

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