WelcomeWindowController.m 19 KB

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