KMFunctionGuideMultiController.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // KMFunctionGuideMultiController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/6.
  6. //
  7. import Cocoa
  8. class KMFunctionGuideMultiController: NSViewController {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var titleInfoView: NSView!
  11. @IBOutlet weak var titleLabel: NSTextField!
  12. @IBOutlet weak var typeNameView: NSView!
  13. @IBOutlet weak var getStartBox: KMBox!
  14. @IBOutlet weak var getStartLabel: NSTextField!
  15. @IBOutlet weak var getStartButton: KMButton!
  16. @IBOutlet weak var learnButton: HyperLinkButton!
  17. @IBOutlet weak var nameHeightConst: NSLayoutConstraint!
  18. @IBOutlet weak var descriptionBGView: NSView!
  19. @IBOutlet weak var iconImage: NSImageView!
  20. @IBOutlet weak var previousButton: KMButton!
  21. @IBOutlet weak var nextButton: KMButton!
  22. @IBOutlet weak var desLabel: NSTextField!
  23. @IBOutlet weak var desSubLabel: NSTextField!
  24. let DigitalSignatureKey = "DigitalSignatureKey"
  25. let ComparePDFsKey = "ComparePDFsKey"
  26. let AIInfoKey = "AIInfoKey"
  27. let MeasureInfoKey = "MeasureInfoKey"
  28. var namesArr = Array<Any>()
  29. var currentNameKEY = String()
  30. var clickHandle: ((_ controller: KMFunctionGuideMultiController)->Void)?
  31. deinit {
  32. DistributedNotificationCenter.default.removeObserver(self)
  33. }
  34. override func viewDidLoad() {
  35. super.viewDidLoad()
  36. // Do view setup here.
  37. self.namesArr = [["name":"Measuring Tools",
  38. "key":MeasureInfoKey,
  39. "infoTitle":"Easily Annotate Dimensional Data on PDFs",
  40. "imageName":"KMImageNameWhatNewMeasure",
  41. "description":NSLocalizedString("The measuring tool allows users to measure distance, perimeter, area and angle accurately, making it an ideal solution for the construction industry to annotate dimensional data on PDFs.", comment: "")],
  42. ["name":"AI Tools",
  43. "key":AIInfoKey,
  44. "infoTitle":"Experience the Power of PDF AI Tools",
  45. "imageName":"whatNew_AIGuide",
  46. "description":NSLocalizedString("• AI Summarize with a deep understanding of document", comment: "") + "\n" + NSLocalizedString("• AI Translate your document without leaving a PDF", comment: "") + "\n" + NSLocalizedString("• Check grammar, fix spelling errors to ensure a professional file", comment: "") + "\n" + NSLocalizedString("• Rewrite your PDF to enhance style and polish content", comment: "")]
  47. // ["name":"Compare PDFs",
  48. // "key":ComparePDFsKey,
  49. // "infoTitle":"Experience the Power of PDF AI Tools 2222",
  50. // "imageName":"guideMeasure",
  51. // "description":NSLocalizedString("The document compare feature lets you quickly spot differences between two versions of a PDF for a better review process.", comment: "")]
  52. ]
  53. let dict = self.namesArr.first as! NSDictionary
  54. self.currentNameKEY = dict["key"] as! String
  55. self.loadTypeNameView()
  56. self.reloadNameViewInfo()
  57. self.reloadDescriptionInfo()
  58. self.descriptionBGView.wantsLayer = true
  59. self.titleInfoView.wantsLayer = true
  60. self.getStartBox.wantsLayer = true
  61. self.getStartBox.layer?.cornerRadius = NSHeight(self.getStartBox.frame)/2
  62. self.getStartBox.layer?.masksToBounds = true
  63. self.titleLabel.stringValue = NSLocalizedString("What‘s New", comment: "")
  64. self.getStartLabel.stringValue = NSLocalizedString("Experience Now", comment: "")
  65. self.learnButton.title = NSLocalizedString("Feedback", comment: "")
  66. self.learnButton.toolTip = NSLocalizedString("Feedback", comment: "")
  67. self.titleLabel.font = NSFont.SFProTextHeavyFont(20)
  68. self.getStartLabel.font = NSFont.SFProTextSemiboldFont(14)
  69. self.learnButton.font = NSFont.SFProTextSemiboldFont(14)
  70. self.desLabel.font = NSFont.SFProTextSemiboldFont(14)
  71. self.desSubLabel.font = NSFont.SFProTextRegularFont(14)
  72. self.previousButton.image = NSImage(named: "KMImageNameGuidePreviousIcon")
  73. self.nextButton.image = NSImage(named: "KMImageNameGuideNextIcon")
  74. self.getStartButton.wantsLayer = true
  75. self.getStartButton.mouseMoveCallback = { [weak self] mouseEntered in
  76. if KMAppearance.isDarkMode() {
  77. if mouseEntered {
  78. self?.getStartButton.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.2).cgColor
  79. } else {
  80. self?.getStartButton.layer?.backgroundColor = NSColor.clear.cgColor
  81. }
  82. } else {
  83. if mouseEntered {
  84. self?.getStartButton.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.2).cgColor
  85. } else {
  86. self?.getStartButton.layer?.backgroundColor = NSColor.clear.cgColor
  87. }
  88. }
  89. }
  90. self.learnButton.mouseMoveCallback = { [weak self] mouseEntered in
  91. if mouseEntered {
  92. self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M1())
  93. } else {
  94. self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0())
  95. }
  96. }
  97. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  98. self.updateViewColor()
  99. }
  100. func loadTypeNameView() {
  101. // self.typeNameView.wantsLayer = true
  102. // self.typeNameView.layer?.backgroundColor = NSColor.red.cgColor
  103. var offsetY: CGFloat = 0
  104. let itemHeight: CGFloat = 32
  105. let viewHeight: CGFloat = itemHeight * CGFloat(self.namesArr.count)
  106. self.nameHeightConst.constant = viewHeight
  107. for i in 0...self.namesArr.count - 1 {
  108. let dict = self.namesArr[i]
  109. let nameItem: KMFunctionGuideNameItemView = KMFunctionGuideNameItemView.createFromNib()!
  110. nameItem.frame = NSMakeRect(0, viewHeight - offsetY - itemHeight, NSWidth(self.typeNameView.frame), itemHeight)
  111. nameItem.infoDict = dict as! NSDictionary
  112. nameItem.clickHandle = {[weak self] view in
  113. self?.currentNameKEY = view.infoDict["key"] as! String
  114. self?.reloadNameViewInfo()
  115. self?.reloadDescriptionInfo()
  116. }
  117. nameItem.autoresizingMask = [.width, .maxYMargin]
  118. self.typeNameView.addSubview(nameItem)
  119. offsetY += itemHeight
  120. }
  121. if self.namesArr.count > 1 {
  122. self.previousButton.isHidden = false
  123. self.nextButton.isHidden = false
  124. } else {
  125. self.previousButton.isHidden = true
  126. self.nextButton.isHidden = true
  127. }
  128. }
  129. func reloadNameViewInfo() {
  130. for view in self.typeNameView.subviews {
  131. if view is KMFunctionGuideNameItemView {
  132. let itemView = view as! KMFunctionGuideNameItemView
  133. if itemView.infoDict["key"] as! String == self.currentNameKEY {
  134. itemView.isSelected = true
  135. } else {
  136. itemView.isSelected = false
  137. }
  138. }
  139. }
  140. if self.currentNameKEY == self.AIInfoKey {
  141. self.learnButton.isHidden = false
  142. } else if self.currentNameKEY == self.MeasureInfoKey {
  143. self.learnButton.isHidden = true
  144. }
  145. }
  146. func reloadDescriptionInfo() {
  147. self.previousButton.isEnabled = true
  148. self.nextButton.isEnabled = true
  149. for i in 0...self.namesArr.count - 1 {
  150. let dict = self.namesArr[i] as! NSDictionary
  151. if dict["key"] as! String == self.currentNameKEY {
  152. self.desLabel.stringValue = NSLocalizedString(dict["infoTitle"] as! String, comment: "")
  153. self.desSubLabel.stringValue = NSLocalizedString(dict["description"] as! String, comment: "")
  154. self.iconImage.image = NSImage(named: dict["imageName"] as! String)
  155. }
  156. let keyValue = dict["key"] as! String
  157. if i == 0 && keyValue == self.currentNameKEY {
  158. self.previousButton.isEnabled = false
  159. } else if i == self.namesArr.count - 1 && keyValue == self.currentNameKEY {
  160. self.nextButton.isEnabled = false
  161. }
  162. }
  163. }
  164. func updateViewColor() {
  165. self.getStartBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  166. self.getStartLabel.textColor = KMAppearance.KMColor_Layout_W0()
  167. self.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0())
  168. if KMAppearance.isDarkMode() {
  169. self.titleInfoView.layer?.backgroundColor = NSColor(red: 14/255.0, green: 17/255, blue: 20/255, alpha: 1).cgColor
  170. self.descriptionBGView.layer?.backgroundColor = NSColor(red: 40/255.0, green: 40/255, blue: 40/255, alpha: 1).cgColor
  171. self.titleLabel.textColor = NSColor.white
  172. self.desLabel.textColor = NSColor.white
  173. self.desSubLabel.textColor = NSColor(red: 200/255, green: 201/255, blue: 204/255, alpha: 1)
  174. self.getStartBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  175. } else {
  176. self.titleInfoView.layer?.backgroundColor = NSColor(red: 249/255.0, green: 249/255, blue: 252/255, alpha: 1).cgColor
  177. self.descriptionBGView.layer?.backgroundColor = NSColor.white.cgColor
  178. self.titleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  179. self.desLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1)
  180. self.desSubLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1)
  181. self.getStartBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  182. }
  183. for view in self.typeNameView.subviews {
  184. if view is KMFunctionGuideNameItemView {
  185. let itemView = view as! KMFunctionGuideNameItemView
  186. itemView.updateViewColor()
  187. }
  188. }
  189. }
  190. //MARK: IBAction
  191. @IBAction func getStartAction(_ sender: Any) {
  192. guard let callBack = self.clickHandle else {
  193. return
  194. }
  195. callBack(self)
  196. }
  197. @IBAction func learnMoreAction(_ sender: Any) {
  198. let url = URL(string:NSLocalizedString("https://forms.gle/crjCAW4cnF7eq1vQ6", comment: ""))!
  199. NSWorkspace.shared.open(url)
  200. }
  201. @IBAction func previousAction(_ sender: Any) {
  202. for i in 0...self.namesArr.count - 1 {
  203. let dict = self.namesArr[i] as! NSDictionary
  204. if dict["key"] as! String == self.currentNameKEY {
  205. if i > 0 {
  206. let preDic = self.namesArr[i-1] as! NSDictionary
  207. self.currentNameKEY = preDic["key"] as! String
  208. break
  209. }
  210. }
  211. }
  212. self.reloadNameViewInfo()
  213. self.reloadDescriptionInfo()
  214. }
  215. @IBAction func nextAction(_ sender: Any) {
  216. for i in 0...self.namesArr.count - 1 {
  217. let dict = self.namesArr[i] as! NSDictionary
  218. if dict["key"] as! String == self.currentNameKEY {
  219. if i < self.namesArr.count {
  220. let nextDic = self.namesArr[i+1] as! NSDictionary
  221. self.currentNameKEY = nextDic["key"] as! String
  222. break
  223. }
  224. }
  225. }
  226. self.reloadNameViewInfo()
  227. self.reloadDescriptionInfo()
  228. }
  229. @objc func themeChange() {
  230. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  231. self.updateViewColor()
  232. }
  233. }
  234. }