123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- //
- // WelcomeWindowController.m
- // PDF Reader
- //
- // Created by wangshuai on 13-12-11.
- // Copyright (c) 2013年 zhangjie. All rights reserved.
- //
- #import "WelcomeWindowController.h"
- #import "WaitingView.h"
- #if VERSION_DMG
- #import <PDF_Master-Swift.h>
- #else
- #import <PDF_Master-Swift.h>
- #endif
- #import "TCPageIndicator.h"
- #import "NSButton+TitleColor.h"
- static WelcomeWindowController *windowController = nil;
- static NSString * const kKMWelcomeHasShowKey = @"WelcomeHasShowKey";
- static NSString * const kKMWelcomeRemindMeLaterKey = @"WelcomeRemindMeLaterKey";
- @interface WelcomeWindowController ()
- @property (nonatomic,assign) IBOutlet NSScrollView *scrollView;
- @property (nonatomic,assign) IBOutlet NSView *content1View;
- @property (nonatomic,assign) IBOutlet NSView *content2View;
- @property (nonatomic,assign) IBOutlet NSView *content3View;
- @property (nonatomic,assign) IBOutlet NSView *content4View;
- @property (strong) IBOutlet NSView *content5View;
- @property (nonatomic,assign) IBOutlet NSTextField *title1Label;
- @property (nonatomic,assign) IBOutlet NSTextField *subtitle1Label;
- @property (nonatomic,assign) IBOutlet NSTextField *title2Label;
- @property (nonatomic,assign) IBOutlet NSTextField *subtitle2Label;
- @property (nonatomic,assign) IBOutlet NSTextField *title3Label;
- @property (nonatomic,assign) IBOutlet NSTextField *subtitle3Label;
- @property (nonatomic,assign) IBOutlet NSTextField *title4Label;
- @property (nonatomic,assign) IBOutlet NSTextField *subtitle4Label;
- @property (weak) IBOutlet NSTextField *title5Label;
- @property (weak) IBOutlet NSTextField *subtitle5Label;
- @property (weak) IBOutlet NSBox *preBox;
- @property (weak) IBOutlet NSBox *nextBox;
- @property (nonatomic, strong) KMDesignButton *preButtonVC;
- @property (nonatomic, strong) KMDesignButton *nextButtonVC;
- @property (weak) IBOutlet NSBox *next1Box;
- @property (weak) IBOutlet NSBox *remindMeLaterBox;
- @property (weak) IBOutlet NSBox *next2Box;
- @property (weak) IBOutlet NSBox *next3Box;
- @property (weak) IBOutlet NSBox *next4Box;
- @property (weak) IBOutlet NSBox *signUpBox;
- @property (nonatomic, strong) KMDesignButton *next1ButtonVC;
- @property (nonatomic, strong) KMDesignButton *remindMeLaterButtonVC;
- @property (nonatomic, strong) KMDesignButton *next2ButtonVC;
- @property (nonatomic, strong) KMDesignButton *next3ButtonVC;
- @property (nonatomic, strong) KMDesignButton *next4ButtonVC;
- @property (nonatomic, strong) KMDesignButton *signUpButtonVC;
- @property (weak) IBOutlet TCPageIndicator *pageIndicator1;
- @property (weak) IBOutlet TCPageIndicator *pageIndicator2;
- @property (weak) IBOutlet TCPageIndicator *pageIndicator3;
- @property (weak) IBOutlet TCPageIndicator *pageIndicator4;
- @property (weak) IBOutlet TCPageIndicator *pageIndicator5;
- @property (nonatomic,retain) NSArray *contentViews;
- @property (nonatomic,assign) NSInteger currentIndex;
- @property (weak) IBOutlet NSButton *closeButton;
- @property (weak) IBOutlet KMBox *closeBox;
- @end
- @implementation WelcomeWindowController
- - (void)dealloc {
- #if DEBUG
- NSLog(@"%s", __func__);
- #endif
- }
- + (void)load {
- // 处理再次提醒
- if ([[NSUserDefaults standardUserDefaults] boolForKey:kKMWelcomeRemindMeLaterKey]) {
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kKMWelcomeRemindMeLaterKey];
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kKMWelcomeHasShowKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- }
- + (BOOL)welcomeHasShow {
- return [[NSUserDefaults standardUserDefaults] boolForKey:kKMWelcomeHasShowKey];
- }
- #pragma mark Init Methods
- - (id)init {
- if (self = [super initWithWindowNibName:@"WelcomeWindowController"]) {
- windowController = self;
- }
- return self;
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
-
- NSClipView *clipView = self.scrollView.contentView;
- // ,self.content4View
- self.contentViews = @[self.content1View,self.content2View,self.content5View];
- for (int i=0; i<self.contentViews.count; i++) {
- NSView *view = self.contentViews[i];
- view.frame = CGRectMake(i*clipView.bounds.size.width, 0,
- clipView.bounds.size.width,
- clipView.bounds.size.height);
- [self.scrollView.documentView addSubview:view];
- }
- self.scrollView.documentView.frame = CGRectMake(0, 0, clipView.bounds.size.width*self.contentViews.count, clipView.bounds.size.height);
- }
- - (void)windowDidLoad {
- [super windowDidLoad];
-
- [self localizedString];
- [self initSubViews];
- [self setupUI];
- [self reloadData];
-
- // 设置【显示】标识
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kKMWelcomeHasShowKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- - (void)localizedString {
- self.title1Label.stringValue = NSLocalizedString(@"The Brand New PDF Master", nil);
- 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);
-
- self.title2Label.stringValue = NSLocalizedString(@"Process PDF Document wit AI Robot", nil);
- 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);
-
- // self.title3Label.stringValue = NSLocalizedString(@"Convert PDF to Office Fast and Easily", nil);
- // self.subtitle3Label.stringValue = NSLocalizedString(@"Convert PDF to editable Word, Excel, PPT, Text and image with all your fonts and formatting preserved.", nil);
- //
- // self.title4Label.stringValue = NSLocalizedString(@"Fill out Form & Sign Documents", nil);
- // self.subtitle4Label.stringValue = NSLocalizedString(@"Fill out forms effortlessly and add text, image or handwritten signatures to PDFs.", nil);
-
- self.title5Label.stringValue = NSLocalizedString(@"Sign up to Unlock Premium Features", nil);
- self.subtitle5Label.stringValue = NSLocalizedString(@"All advanced features in PDF Master can be used after registration.", nil);
- }
- - (void)initSubViews {
- self.preBox.borderType = NSNoBorder;
- self.preButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeImage];
- [self.preBox.contentView addSubview:self.preButtonVC.view];
- self.preButtonVC.view.frame = self.preBox.contentView.bounds;
- self.preButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
- self.preButtonVC.image = [NSImage imageNamed:@"KMImageNameLeftButtonImage"];
- [self.preButtonVC pagination];
- self.preButtonVC.target = self;
- self.preButtonVC.action = @selector(previousButtonAction:);
-
- self.nextBox.borderType = NSNoBorder;
- self.nextButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeImage];
- [self.nextBox.contentView addSubview:self.nextButtonVC.view];
- self.nextButtonVC.view.frame = self.nextBox.contentView.bounds;
- self.nextButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
- self.nextButtonVC.image = [NSImage imageNamed:@"KMImageNameRightButtonImage"];
- [self.nextButtonVC pagination];
- self.nextButtonVC.target = self;
- self.nextButtonVC.action = @selector(nextButtonAction:);
-
- for (NSBox *box in @[self.next1Box, self.next2Box, self.next3Box, self.next4Box]) {
- box.borderType = NSNoBorder;
- KMDesignButton *nextButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
- [box.contentView addSubview:nextButtonVC.view];
- nextButtonVC.view.frame = box.contentView.bounds;
- nextButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
- nextButtonVC.stringValue = NSLocalizedString(@"Next", nil);
- nextButtonVC.target = self;
- nextButtonVC.action = @selector(nextButtonAction:);
- [nextButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeL height:[[NSLayoutConstraint alloc] init]];
-
- if ([box isEqual:self.next1Box]) {
- self.next1ButtonVC = nextButtonVC;
- } else if ([box isEqual:self.next2Box]) {
- self.next2ButtonVC = nextButtonVC;
- } else if ([box isEqual:self.next3Box]) {
- self.next3ButtonVC = nextButtonVC;
- } else if ([box isEqual:self.next4Box]) {
- self.next4ButtonVC = nextButtonVC;
- }
- }
-
- self.remindMeLaterBox.borderType = NSNoBorder;
- self.remindMeLaterButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
- [self.remindMeLaterBox.contentView addSubview:self.remindMeLaterButtonVC.view];
- self.remindMeLaterButtonVC.view.frame = self.remindMeLaterBox.contentView.bounds;
- self.remindMeLaterButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
- self.remindMeLaterButtonVC.stringValue = NSLocalizedString(@"Remind Me Later", nil);
- self.remindMeLaterButtonVC.target = self;
- self.remindMeLaterButtonVC.action = @selector(remindMeLaterButtonAction:);
- // TokenButtonTypeLink
- [self.remindMeLaterButtonVC buttonWithType:TokenButtonTypeText size:TokenButtonSizeM height:[[NSLayoutConstraint alloc] init]];
-
- self.signUpBox.borderType = NSNoBorder;
- self.signUpButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
- [self.signUpBox.contentView addSubview:self.signUpButtonVC.view];
- self.signUpButtonVC.view.frame = self.signUpBox.contentView.bounds;
- self.signUpButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
- if (KMLightMemberManager.manager.isLogin) { // let’s start
- self.signUpButtonVC.stringValue = NSLocalizedString(@"Let's Start", nil);
- } else {
- self.signUpButtonVC.stringValue = NSLocalizedString(@"Sign up", nil);
- }
-
- self.signUpButtonVC.target = self;
- self.signUpButtonVC.action = @selector(signUpButtonAction:);
- [self.signUpButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeL height:[[NSLayoutConstraint alloc] init]];
-
- // , self.pageIndicator5
- for (TCPageIndicator *pageindicator in @[self.pageIndicator1, self.pageIndicator2, self.pageIndicator5]) {
- pageindicator.numberOfPages = 3;
- pageindicator.selectedColor = [NSColor colorWithRed:39/255.f green:60/255.f blue:98/255.f alpha:1.f];
- pageindicator.normalColor = [NSColor colorWithRed:0/255.f green:0/255.f blue:0/255.f alpha:0.2];
- pageindicator.pageIndicatorSize = NSMakeSize(6, 6);
- pageindicator.enabled = NO;
-
- if ([pageindicator isEqual:self.pageIndicator1]) {
- pageindicator.currentPage = 0;
- } else if ([pageindicator isEqual:self.pageIndicator2]) {
- pageindicator.currentPage = 1;
- } else if ([pageindicator isEqual:self.pageIndicator3]) {
- pageindicator.currentPage = 2;
- } else if ([pageindicator isEqual:self.pageIndicator4]) {
- pageindicator.currentPage = 3;
- } else if ([pageindicator isEqual:self.pageIndicator5]) {
- pageindicator.currentPage = 2;
- }
- }
-
- __weak typeof(self)weakSelf = self;
- self.closeBox.moveCallback = ^(BOOL mouseEntered, KMBox *mouseBox) {
- if (mouseEntered) {
- weakSelf.closeButton.image = [NSImage imageNamed:@"control_btn_icon_close_hov"];
- } else {
- weakSelf.closeButton.image = [NSImage imageNamed:@"control_btn_icon_close"];
- }
- };
- }
- - (void)setupUI {
- for (NSTextField *titleLabel in @[self.title1Label, self.title2Label, self.title3Label,
- self.title4Label, self.title5Label]) {
- titleLabel.font = [NSFont fontWithName:@"SFProText-Semibold" size:20];
- titleLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
- }
-
- NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
- ps.lineSpacing = 6;
- ps.alignment = NSTextAlignmentCenter;
- for (NSTextField *subtitleLabel in @[self.subtitle1Label, self.subtitle2Label, self.subtitle3Label,
- self.subtitle4Label, self.subtitle5Label]) {
- if ([subtitleLabel isEqual:self.subtitle1Label]) {
- NSMutableParagraphStyle *ps_ = [[NSMutableParagraphStyle alloc] init];
- // ps_.lineSpacing = 6;
- ps_.alignment = NSTextAlignmentCenter;
- subtitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:subtitleLabel.stringValue attributes:@{
- NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:14],
- NSForegroundColorAttributeName : [NSColor colorWithRed:97/255.f green:100/255.f blue:105/255.f alpha:1.f],
- NSParagraphStyleAttributeName : ps_
- }];
- } else {
- subtitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:subtitleLabel.stringValue attributes:@{
- NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:14],
- NSForegroundColorAttributeName : [NSColor colorWithRed:97/255.f green:100/255.f blue:105/255.f alpha:1.f],
- NSParagraphStyleAttributeName : ps
- }];
- }
- }
- }
- - (void)close {
- windowController = nil;
-
- [super close];
- }
- #pragma mark Private Methods
- - (void)reloadData {
- self.preBox.hidden = NO;
- self.nextBox.hidden = NO;
-
- if (self.currentIndex == 0) {
- self.preBox.hidden = YES;
- } else if (self.currentIndex == 1) {
- } else if (self.currentIndex == 2) {
- self.nextBox.hidden = YES;
- } else if (self.currentIndex == 3) {
- } else if (self.currentIndex == 4){
- self.nextBox.hidden = YES;
- }
- }
- - (void)addWaingView:(NSView *)view {
- [self removeWaitingView:view];
- WaitingView *wView = [[WaitingView alloc] initWithFrame:view.bounds];
- [wView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
- [view addSubview:wView];
- [wView startAnimation];
- }
- - (void)removeWaitingView:(NSView *)view {
- for (id v in view.subviews) {
- if ([[v class] isSubclassOfClass:[WaitingView class]]) {
- [v removeFromSuperview];
- break;
- }
- }
- }
- #pragma mark Button Actions
- - (IBAction)previousButtonAction:(id)sender {
- if (self.currentIndex <= 0) {
- return;
- }
- self.currentIndex--;
- [NSAnimationContext beginGrouping];
- NSClipView *clipView = [self.scrollView contentView];
- NSPoint newOrigin = [clipView bounds].origin;
- newOrigin.x = clipView.bounds.size.width*self.currentIndex;
- [[clipView animator] setBoundsOrigin:newOrigin];
- [NSAnimationContext endGrouping];
-
- [self reloadData];
- }
- - (IBAction)nextButtonAction:(id)sender {
- if (self.currentIndex >= self.contentViews.count-1) {
- return;
- }
- self.currentIndex++;
- [NSAnimationContext beginGrouping];
- NSClipView *clipView = [self.scrollView contentView];
- NSPoint newOrigin = [clipView bounds].origin;
- newOrigin.x = clipView.bounds.size.width*self.currentIndex;
- [[clipView animator] setBoundsOrigin:newOrigin];
- [NSAnimationContext endGrouping];
-
- [self reloadData];
- }
- - (IBAction)closeAction:(id)sender {
- if (self.itemClick) {
- self.itemClick(1, self);
- }
- [self close];
- }
- - (void)signUpButtonAction:(NSButton *)sender {
- if (KMLightMemberManager.manager.isLogin) {
- [self closeAction:sender];
- } else {
- if (self.itemClick) {
- self.itemClick(3, self);
- }
- [self close];
- }
- }
- - (void)remindMeLaterButtonAction:(NSButton *)sender {
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kKMWelcomeRemindMeLaterKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
-
- if (self.itemClick) {
- self.itemClick(2, self);
- }
- [self close];
- }
- @end
|