KMOpenFileFunctionView.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // KMOpenFileFunctionView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/11.
  6. //
  7. import Cocoa
  8. class KMOpenFileFunctionView: NSView, NibLoadable {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var shadowView: NSView!
  11. @IBOutlet weak var bigCircleView: NSView!
  12. @IBOutlet weak var smallCircleView: NSView!
  13. @IBOutlet weak var circleLeftConst: NSLayoutConstraint!
  14. @IBOutlet weak var circleTopConst: NSLayoutConstraint!
  15. @IBOutlet weak var tipInfoView: NSView!
  16. @IBOutlet weak var tipImage: NSImageView!
  17. @IBOutlet weak var ntipView: NSView!
  18. @IBOutlet weak var ntipLabel: NSTextField!
  19. @IBOutlet weak var tipTitleLabel: NSTextField!
  20. @IBOutlet weak var tipSubTitleLabel: NSTextField!
  21. @IBOutlet weak var getItBox: KMBox!
  22. @IBOutlet weak var getItLabel: NSTextField!
  23. @IBOutlet weak var getItButton: KMButton!
  24. @objc var _type: KMGuideInfoType = .none
  25. @objc var _circleRect: CGRect = .zero
  26. var clickHandle: ((_ view: KMOpenFileFunctionView, _ actionType: KMGuideActionType)->Void)?
  27. override func draw(_ dirtyRect: NSRect) {
  28. super.draw(dirtyRect)
  29. // Drawing code here.
  30. }
  31. deinit {
  32. DistributedNotificationCenter.default.removeObserver(self)
  33. }
  34. override func awakeFromNib() {
  35. super.awakeFromNib()
  36. self.bigCircleView.wantsLayer = true
  37. self.bigCircleView.layer?.cornerRadius = CGRectGetWidth(self.bigCircleView.frame)/2
  38. self.bigCircleView.layer?.borderWidth = 3
  39. self.smallCircleView.wantsLayer = true
  40. self.smallCircleView.layer?.cornerRadius = CGRectGetWidth(self.smallCircleView.frame)/2
  41. self.smallCircleView.layer?.borderWidth = 3
  42. self.tipInfoView.wantsLayer = true
  43. self.tipInfoView.layer?.borderWidth = 2
  44. self.tipInfoView.layer?.cornerRadius = 8
  45. self.tipInfoView.layer?.masksToBounds = true
  46. self.ntipView.wantsLayer = true
  47. self.ntipView.layer?.cornerRadius = 10
  48. self.ntipView.layer?.masksToBounds = true
  49. self.getItBox.wantsLayer = true
  50. self.getItBox.fillColor = NSColor.clear
  51. self.getItBox.cornerRadius = 4
  52. self.getItButton.mouseMoveCallback = { [weak self] mouseEntered in
  53. if KMAppearance.isDarkMode() {
  54. if mouseEntered {
  55. self?.getItBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
  56. } else {
  57. self?.getItBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  58. }
  59. } else {
  60. if mouseEntered {
  61. self?.getItBox.fillColor = NSColor(red: 56/255, green: 100/255, blue: 176/255, alpha: 1)
  62. } else {
  63. self?.getItBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  64. }
  65. }
  66. }
  67. self.ntipLabel.stringValue = NSLocalizedString("New", comment: "")
  68. self.shadowView.wantsLayer = true
  69. self.shadowView.layer?.borderWidth = 0
  70. self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
  71. self.shadowView.layer?.shadowOpacity = 0.1
  72. self.shadowView.layer?.shadowRadius = 3.0
  73. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  74. self.updateViewColor()
  75. }
  76. @objc func updateViewColor() {
  77. if self.type == .digitalSignGuide {
  78. self.circleTopConst.constant = 20
  79. self.circleLeftConst.constant = CGRectGetMinX(self.circleRect) - CGRectGetWidth(self.bigCircleView.frame)/2 + CGRectGetWidth(self.circleRect)/2
  80. self.tipImage.image = NSImage(named: "guideDigitalSign")
  81. self.tipTitleLabel.stringValue = NSLocalizedString("Digital Signature", comment: "")
  82. 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: "")
  83. self.getItLabel.stringValue = NSLocalizedString("Got it", comment: "")
  84. } else if self.type == .pdfCompareGuide {
  85. if self.window != nil {
  86. self.circleTopConst.constant = (self.window?.frame.size.height)! - self.circleRect.origin.y - CGRectGetHeight(self.bigCircleView.frame) + 50
  87. }
  88. self.circleLeftConst.constant = CGRectGetMinX(KMGuideInfoWindowController.currentWC().compareItemRect) - CGRectGetWidth(self.bigCircleView.frame)/2 + CGRectGetWidth(KMGuideInfoWindowController.currentWC().compareItemRect)/2
  89. self.tipImage.image = NSImage(named: "guidePDFCompare")
  90. self.tipTitleLabel.stringValue = NSLocalizedString("Compare PDFs", comment: "")
  91. 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: "")
  92. self.getItLabel.stringValue = NSLocalizedString("Got it", comment: "")
  93. }
  94. self.shadowView.layer?.shadowPath = nil
  95. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  96. self.shadowView.frame = self.tipInfoView.frame
  97. let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
  98. if #available(macOS 14.0, *) {
  99. self.shadowView.layer?.shadowPath = shadowPath.kmCGPath()
  100. }
  101. }
  102. self.getItBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  103. if KMAppearance.isDarkMode() {
  104. self.tipInfoView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
  105. self.tipInfoView.layer?.backgroundColor = NSColor.black.cgColor
  106. self.ntipView.layer?.backgroundColor = NSColor(red: 0, green: 207/255, blue: 133/255, alpha: 1).cgColor
  107. self.ntipLabel.textColor = NSColor.white
  108. self.tipTitleLabel.textColor = NSColor.white
  109. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H1()
  110. self.getItLabel.textColor = NSColor.white
  111. self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  112. self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  113. } else {
  114. self.tipInfoView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  115. self.tipInfoView.layer?.backgroundColor = NSColor.white.cgColor
  116. self.ntipView.layer?.backgroundColor = NSColor(red: 0, green: 207/255, blue: 133/255, alpha: 1).cgColor
  117. self.ntipLabel.textColor = NSColor.white
  118. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_M()
  119. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  120. self.getItLabel.textColor = NSColor.white
  121. self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  122. self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  123. }
  124. }
  125. //MARK: Setter
  126. @objc var type: KMGuideInfoType {
  127. set {
  128. _type = newValue;
  129. }
  130. get {
  131. return _type;
  132. }
  133. }
  134. @objc var circleRect: CGRect {
  135. set {
  136. _circleRect = newValue;
  137. }
  138. get {
  139. return _circleRect;
  140. }
  141. }
  142. @IBAction func getItAction(_ sender: Any) {
  143. guard let callBack = self.clickHandle else {
  144. return
  145. }
  146. callBack(self, .getIt)
  147. }
  148. @objc func themeChange() {
  149. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  150. self.updateViewColor()
  151. }
  152. }
  153. }