KMOpenFileFunctionView.swift 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 = NSWidth(self.bigCircleView.frame)/2
  38. self.bigCircleView.layer?.borderWidth = 3
  39. self.smallCircleView.wantsLayer = true
  40. self.smallCircleView.layer?.cornerRadius = NSWidth(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 = NSMinX(self.circleRect) - NSWidth(self.bigCircleView.frame)/2 + NSWidth(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 - NSHeight(self.bigCircleView.frame) + 50
  87. }
  88. self.circleLeftConst.constant = NSMinX(KMGuideInfoWindowController.currentWC().compareItemRect) - NSWidth(self.bigCircleView.frame)/2 + NSWidth(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. } else if self.type == .measureGuide {
  94. if self.window != nil {
  95. self.circleTopConst.constant = (self.window?.frame.size.height)! - self.circleRect.origin.y - NSHeight(self.bigCircleView.frame) + 50
  96. }
  97. self.circleLeftConst.constant = NSMinX(KMGuideInfoWindowController.currentWC().compareItemRect) - NSWidth(self.bigCircleView.frame)/2 + NSWidth(KMGuideInfoWindowController.currentWC().compareItemRect)/2
  98. self.tipImage.image = NSImage(named: "guideMeasure")
  99. self.tipTitleLabel.stringValue = NSLocalizedString("Measure", comment: "")
  100. self.tipSubTitleLabel.stringValue = NSLocalizedString("You can measure distance, perimeter, area and angle accurately with the measuring tools.", comment: "")
  101. self.getItLabel.stringValue = NSLocalizedString("Got it", comment: "")
  102. }
  103. self.shadowView.layer?.shadowPath = nil
  104. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  105. self.shadowView.frame = self.tipInfoView.frame
  106. let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
  107. if #available(macOS 14.0, *) {
  108. self.shadowView.layer?.shadowPath = shadowPath.kmCGPath()
  109. }
  110. }
  111. self.getItBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  112. if KMAppearance.isDarkMode() {
  113. self.tipInfoView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
  114. self.tipInfoView.layer?.backgroundColor = NSColor.black.cgColor
  115. self.ntipView.layer?.backgroundColor = NSColor(red: 0, green: 207/255, blue: 133/255, alpha: 1).cgColor
  116. self.ntipLabel.textColor = NSColor.white
  117. self.tipTitleLabel.textColor = NSColor.white
  118. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H1()
  119. self.getItLabel.textColor = NSColor.white
  120. self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  121. self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  122. } else {
  123. self.tipInfoView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  124. self.tipInfoView.layer?.backgroundColor = NSColor.white.cgColor
  125. self.ntipView.layer?.backgroundColor = NSColor(red: 0, green: 207/255, blue: 133/255, alpha: 1).cgColor
  126. self.ntipLabel.textColor = NSColor.white
  127. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_M()
  128. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  129. self.getItLabel.textColor = NSColor.white
  130. self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  131. self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  132. }
  133. }
  134. //MARK: Setter
  135. @objc var type: KMGuideInfoType {
  136. set {
  137. _type = newValue;
  138. }
  139. get {
  140. return _type;
  141. }
  142. }
  143. @objc var circleRect: CGRect {
  144. set {
  145. _circleRect = newValue;
  146. }
  147. get {
  148. return _circleRect;
  149. }
  150. }
  151. @IBAction func getItAction(_ sender: Any) {
  152. guard let callBack = self.clickHandle else {
  153. return
  154. }
  155. callBack(self, .getIt)
  156. }
  157. @objc func themeChange() {
  158. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  159. self.updateViewColor()
  160. }
  161. }
  162. }