WelcomeWindowController.m 16 KB

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