WelcomeWindowController.m 16 KB

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