123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // KMOpenFileFunctionView.swift
- // PDF Reader Pro Edition
- //
- // Created by Niehaoyu on 2023/12/11.
- //
- import Cocoa
- class KMOpenFileFunctionView: NSView, NibLoadable {
-
- @IBOutlet weak var contendView: NSView!
- @IBOutlet weak var shadowView: NSView!
-
- @IBOutlet weak var bigCircleView: NSView!
- @IBOutlet weak var smallCircleView: NSView!
- @IBOutlet weak var circleLeftConst: NSLayoutConstraint!
- @IBOutlet weak var circleTopConst: NSLayoutConstraint!
-
- @IBOutlet weak var tipInfoView: NSView!
- @IBOutlet weak var tipImage: NSImageView!
- @IBOutlet weak var ntipView: NSView!
- @IBOutlet weak var ntipLabel: NSTextField!
- @IBOutlet weak var tipTitleLabel: NSTextField!
- @IBOutlet weak var tipSubTitleLabel: NSTextField!
-
- @IBOutlet weak var getItBox: KMBox!
- @IBOutlet weak var getItLabel: NSTextField!
- @IBOutlet weak var getItButton: KMButton!
-
- @objc var _type: KMGuideInfoType = .none
- @objc var _circleRect: CGRect = .zero
-
- var clickHandle: ((_ view: KMOpenFileFunctionView, _ actionType: KMGuideActionType)->Void)?
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- deinit {
- DistributedNotificationCenter.default.removeObserver(self)
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.bigCircleView.wantsLayer = true
- self.bigCircleView.layer?.cornerRadius = CGRectGetWidth(self.bigCircleView.frame)/2
- self.bigCircleView.layer?.borderWidth = 3
-
- self.smallCircleView.wantsLayer = true
- self.smallCircleView.layer?.cornerRadius = CGRectGetWidth(self.smallCircleView.frame)/2
- self.smallCircleView.layer?.borderWidth = 3
-
- self.tipInfoView.wantsLayer = true
- self.tipInfoView.layer?.borderWidth = 2
- self.tipInfoView.layer?.cornerRadius = 8
- self.tipInfoView.layer?.masksToBounds = true
-
- self.ntipView.wantsLayer = true
- self.ntipView.layer?.cornerRadius = 10
- self.ntipView.layer?.masksToBounds = true
-
- self.getItBox.wantsLayer = true
- self.getItBox.fillColor = NSColor.clear
- self.getItBox.cornerRadius = 4
- self.getItButton.mouseMoveCallback = { [weak self] mouseEntered in
- if KMAppearance.isDarkMode() {
- if mouseEntered {
- self?.getItBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
- } else {
- self?.getItBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
- }
- } else {
- if mouseEntered {
- self?.getItBox.fillColor = NSColor(red: 56/255, green: 100/255, blue: 176/255, alpha: 1)
- } else {
- self?.getItBox.fillColor = KMAppearance.KMColor_Interactive_A0()
- }
- }
- }
-
- self.ntipLabel.stringValue = NSLocalizedString("New", comment: "")
-
- self.shadowView.wantsLayer = true
- self.shadowView.layer?.borderWidth = 0
- self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
- self.shadowView.layer?.shadowOpacity = 0.1
- self.shadowView.layer?.shadowRadius = 3.0
-
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
- self.updateViewColor()
- }
-
- @objc func updateViewColor() {
-
- if self.type == .digitalSignGuide {
- self.circleTopConst.constant = 20
- self.circleLeftConst.constant = CGRectGetMinX(self.circleRect) - CGRectGetWidth(self.bigCircleView.frame)/2 + CGRectGetWidth(self.circleRect)/2
- self.tipImage.image = NSImage(named: "guideDigitalSign")
- self.tipTitleLabel.stringValue = NSLocalizedString("Digital Signature", comment: "")
- self.tipSubTitleLabel.stringValue = NSLocalizedString("Digital signature provides proof of the signer's identity and intent, ensuring a high level of security and authenticity, making you more productive to sign digital documents.", comment: "")
- self.getItLabel.stringValue = NSLocalizedString("Got it", comment: "")
-
- } else if self.type == .pdfCompareGuide {
- if self.window != nil {
- self.circleTopConst.constant = (self.window?.frame.size.height)! - self.circleRect.origin.y - CGRectGetHeight(self.bigCircleView.frame) + 50
- }
- self.circleLeftConst.constant = CGRectGetMinX(KMGuideInfoWindowController.currentWC().compareItemRect) - CGRectGetWidth(self.bigCircleView.frame)/2 + CGRectGetWidth(KMGuideInfoWindowController.currentWC().compareItemRect)/2
- self.tipImage.image = NSImage(named: "guidePDFCompare")
- self.tipTitleLabel.stringValue = NSLocalizedString("Compare PDFs", comment: "")
- self.tipSubTitleLabel.stringValue = NSLocalizedString("The document compare feature lets you quickly spot differences between two versions of a PDF for a better review process.", comment: "")
- self.getItLabel.stringValue = NSLocalizedString("Got it", comment: "")
-
- }
- self.shadowView.layer?.shadowPath = nil
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
- self.shadowView.frame = self.tipInfoView.frame
- let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
- if #available(macOS 14.0, *) {
- self.shadowView.layer?.shadowPath = shadowPath.kmCGPath()
- }
- }
- self.getItBox.fillColor = KMAppearance.KMColor_Interactive_A0()
-
- if KMAppearance.isDarkMode() {
- self.tipInfoView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
- self.tipInfoView.layer?.backgroundColor = NSColor.black.cgColor
- self.ntipView.layer?.backgroundColor = NSColor(red: 0, green: 207/255, blue: 133/255, alpha: 1).cgColor
- self.ntipLabel.textColor = NSColor.white
- self.tipTitleLabel.textColor = NSColor.white
- self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H1()
- self.getItLabel.textColor = NSColor.white
-
- self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
- self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
- } else {
- self.tipInfoView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
- self.tipInfoView.layer?.backgroundColor = NSColor.white.cgColor
- self.ntipView.layer?.backgroundColor = NSColor(red: 0, green: 207/255, blue: 133/255, alpha: 1).cgColor
- self.ntipLabel.textColor = NSColor.white
- self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_M()
- self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
- self.getItLabel.textColor = NSColor.white
-
- self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
- self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
- }
- }
-
-
- //MARK: Setter
- @objc var type: KMGuideInfoType {
- set {
- _type = newValue;
- }
- get {
- return _type;
- }
- }
-
- @objc var circleRect: CGRect {
- set {
- _circleRect = newValue;
- }
- get {
- return _circleRect;
- }
- }
-
- @IBAction func getItAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .getIt)
- }
-
- @objc func themeChange() {
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
- self.updateViewColor()
- }
- }
-
- }
|