KMFastToolCollectionViewItem.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. //
  2. // KMFastToolCollectionViewItem.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2022/10/20.
  6. //
  7. import Cocoa
  8. public enum DataNavigationViewButtonActionType : Int {
  9. case Batch = 0 // 批量处理
  10. case ConvertPDF // 转换PDF
  11. case ImageToPDF // 图片转PDF
  12. case MergePDF // 合并
  13. case Compression // 压缩
  14. case Security // 安全
  15. case PDFToPPT // PDF转PPT
  16. case PDFToExcel // PDF转Excel
  17. case PDFToWord // PDF转Word
  18. case PDFToImage // PDF转图片
  19. case Watermark // 水印
  20. case Background // 背景
  21. case HeaderAndFooter// 页眉页脚
  22. case BatesCode // 贝茨码
  23. case Print // 打印
  24. case BatchRemove // 批量移除
  25. case Insert // 插入
  26. case BreakUp // 拆分
  27. case Extract // 提取
  28. case MarkCipher // 标记密文
  29. case PageEdit // 页面编辑
  30. case OCR // 批量OCR
  31. case AutomaticFormRecognition //表单自动识别
  32. case FileCompare // 文件对比
  33. }
  34. class KMFastToolMode: NSObject {
  35. var toolImageName: String? //图片名称
  36. var toolTitle: String? //主标题
  37. var toolSubtitle: String? //副标题
  38. class func toolModeData(type: DataNavigationViewButtonActionType) -> KMFastToolMode {
  39. let mode: KMFastToolMode = KMFastToolMode()
  40. switch type {
  41. case .Batch:
  42. mode.toolTitle = NSLocalizedString("Batch", comment: "")
  43. mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
  44. mode.toolImageName = "icon_pdftools_batch"
  45. break
  46. case .OCR:
  47. mode.toolTitle = NSLocalizedString("OCR", comment: "")
  48. mode.toolSubtitle = NSLocalizedString("Recognize text from image or scanned PDF with OCR", comment: "")
  49. mode.toolImageName = "icon_pdftools_ocr"
  50. break
  51. case .ConvertPDF:
  52. mode.toolTitle = NSLocalizedString("Convert PDF", comment: "")
  53. mode.toolSubtitle = NSLocalizedString("Convert PDFs to Word/HTML/TXT/JPEG/PNG files", comment: "")
  54. mode.toolImageName = "icon_pdftools_convert"
  55. break
  56. case .ImageToPDF:
  57. mode.toolTitle = NSLocalizedString("Image To PDF", comment: "")
  58. mode.toolSubtitle = NSLocalizedString("Convert JPEG/JPG/PNG/TIFF/BMP/PSD files to PDF", comment: "")
  59. mode.toolImageName = "icon_pdftools_image"
  60. break
  61. case .MergePDF:
  62. mode.toolTitle = NSLocalizedString("Merge", comment: "")
  63. mode.toolSubtitle = NSLocalizedString("Combine multiple documents into a new PDF file", comment: "")
  64. mode.toolImageName = "icon_pdftools_merge"
  65. break
  66. case .Compression:
  67. mode.toolTitle = NSLocalizedString("Compress", comment: "")
  68. mode.toolSubtitle = NSLocalizedString("Reduce files size to make sure you can easily send them by mail", comment: "")
  69. mode.toolImageName = "icon_pdftools_compress"
  70. break
  71. case .Security:
  72. mode.toolTitle = NSLocalizedString("Security", comment: "")
  73. mode.toolSubtitle = NSLocalizedString("Limit access to PDFs, restrict copying and printing permission with passwords", comment: "")
  74. mode.toolImageName = "icon_pdftools_security"
  75. break
  76. case .FileCompare:
  77. mode.toolTitle = NSLocalizedString("Compare", comment: "")
  78. mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
  79. mode.toolImageName = "icon_pdftools_compare"
  80. break
  81. case .PDFToPPT:
  82. mode.toolTitle = NSLocalizedString("PDF To PPT", comment: "")
  83. mode.toolSubtitle = NSLocalizedString("Turn your PDF into a formatted PPT file that you can edit", comment: "")
  84. mode.toolImageName = "icon_pdftools_pdfToPPT"
  85. break
  86. case .PDFToExcel:
  87. mode.toolTitle = NSLocalizedString("PDF To Excel", comment: "")
  88. mode.toolSubtitle = NSLocalizedString("Turn PDF table into a formatted Excel file", comment: "")
  89. mode.toolImageName = "icon_pdftools_pdfToExcel"
  90. break
  91. case .PDFToWord:
  92. mode.toolTitle = NSLocalizedString("PDF To Word", comment: "")
  93. mode.toolSubtitle = NSLocalizedString("Convert PDF to Word, fonts & formatting get converted", comment: "")
  94. mode.toolImageName = "icon_pdftools_pdfToWord"
  95. break
  96. case .PDFToImage:
  97. mode.toolTitle = NSLocalizedString("PDF To Image", comment: "")
  98. mode.toolSubtitle = NSLocalizedString("Convert PDF to image, such as JPEG, JPG, PNG, GIF, TIFF, TAG,BMP", comment: "")
  99. mode.toolImageName = "icon_pdftools_pdfToImage"
  100. break
  101. case .Watermark:
  102. mode.toolTitle = NSLocalizedString("Watermark", comment: "")
  103. mode.toolSubtitle = NSLocalizedString("Protect PDFs with image/text watermarks from plagiarism", comment: "")
  104. mode.toolImageName = "icon_pdftools_watermark"
  105. break
  106. case .Background:
  107. mode.toolTitle = NSLocalizedString("Background", comment: "")
  108. mode.toolSubtitle = NSLocalizedString("Customize PDFs background with colors or images", comment: "")
  109. mode.toolImageName = "icon_pdftools_background"
  110. break
  111. case .HeaderAndFooter:
  112. mode.toolTitle = NSLocalizedString("Header & Footer", comment: "")
  113. mode.toolSubtitle = NSLocalizedString("Customize PDFs header&footer or add page number", comment: "")
  114. mode.toolImageName = "icon_pdftools_headerfooter"
  115. break
  116. case .BatesCode:
  117. mode.toolTitle = NSLocalizedString("Bates Numbers", comment: "")
  118. mode.toolSubtitle = NSLocalizedString("Easily retrieval indexing legal document by Bates Numbers", comment: "")
  119. mode.toolImageName = "icon_pdftools_batesnumbers"
  120. break
  121. case .Print:
  122. mode.toolTitle = NSLocalizedString("Print", comment: "")
  123. mode.toolSubtitle = NSLocalizedString("Powerful PDF printer allows to print PDF from any computer without much hassle", comment: "")
  124. mode.toolImageName = "icon_pdftools_print"
  125. break
  126. case .BatchRemove:
  127. mode.toolTitle = NSLocalizedString("Batch Remove", comment: "")
  128. mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
  129. mode.toolImageName = "icon_pdftools_remove"
  130. break
  131. case .Insert:
  132. mode.toolTitle = NSLocalizedString("Insert", comment: "")
  133. mode.toolSubtitle = NSLocalizedString("Insert blank pages to PDF or insert a new file", comment: "")
  134. mode.toolImageName = "icon_pdftools_insert"
  135. break
  136. case .BreakUp:
  137. mode.toolTitle = NSLocalizedString("Split", comment: "")
  138. mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
  139. mode.toolImageName = "icon_pdftools_split"
  140. break
  141. case .Extract:
  142. mode.toolTitle = NSLocalizedString("Extract", comment: "")
  143. mode.toolSubtitle = NSLocalizedString("Extract selected pages to a new PDF", comment: "")
  144. mode.toolImageName = "icon_pdftools_extract"
  145. break
  146. case .MarkCipher:
  147. mode.toolTitle = NSLocalizedString("Redact", comment: "")
  148. mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
  149. mode.toolImageName = "icon_pdftools_reduct"
  150. break
  151. case .AutomaticFormRecognition:
  152. mode.toolTitle = NSLocalizedString("Form Filed Recognition", comment: "")
  153. mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
  154. mode.toolImageName = "icon_pdftools_formfiledrecognition"
  155. break
  156. case .PageEdit:
  157. mode.toolTitle = NSLocalizedString("Page Edit", comment: "")
  158. mode.toolSubtitle = NSLocalizedString("Delete/Rotate/Copy/Paste PDF pages", comment: "")
  159. mode.toolImageName = "icon_pdftools_pageEdit"
  160. break
  161. }
  162. return mode
  163. }
  164. }
  165. class KMFastToolCollectionViewItem: NSCollectionViewItem {
  166. @IBOutlet weak var fastToolItemBox: KMBox!
  167. @IBOutlet weak var fastToolItemImageView: NSImageView!
  168. @IBOutlet weak var fastToolIteTitleLabel: NSTextField!
  169. @IBOutlet weak var fastToolItemSubtitleLabel: NSTextField!
  170. @IBOutlet weak var fastToolItemBoxHeightConstraint: NSLayoutConstraint!
  171. @IBOutlet weak var padding_top: NSLayoutConstraint!
  172. @IBOutlet weak var padding_left: NSLayoutConstraint!
  173. // @IBOutlet weak var padding_down: NSLayoutConstraint!
  174. @IBOutlet weak var padding_right: NSLayoutConstraint!
  175. @IBOutlet weak var itemspacing_1: NSLayoutConstraint!
  176. @IBOutlet weak var itemspacing_2: NSLayoutConstraint!
  177. @IBOutlet weak var addBox: NSBox!
  178. @IBOutlet weak var addLabel: NSTextField!
  179. var horizontalPadding : Float = 16.0
  180. var horizontalPadding_hov : Float = 16.0
  181. var horizontalPadding_sel : Float = 16.0
  182. var horizontalPadding_custom : Float = 16.0
  183. var horizontalPadding_none : Float = 16.0
  184. var horizontalPadding_change : Float = 16.0
  185. var borderColor : NSColor = .clear
  186. var borderColor_hov : NSColor = .clear
  187. var borderColor_sel : NSColor = .clear
  188. var borderColor_custom : NSColor = .clear
  189. var borderColor_none : NSColor = .clear
  190. var borderColor_change : NSColor = .clear
  191. var borderRadius : Float = 8.0
  192. var borderRadius_hov : Float = 8.0
  193. var borderRadius_sel : Float = 8.0
  194. var borderRadius_custom : Float = 8.0
  195. var borderRadius_none : Float = 8.0
  196. var borderRadius_change : Float = 8.0
  197. var borderWidth : Float = 1.0
  198. var borderWidth_hov : Float = 1.0
  199. var borderWidth_sel : Float = 1.0
  200. var borderWidth_custom : Float = 1.0
  201. var borderWidth_none : Float = 1.0
  202. var borderWidth_change : Float = 1.0
  203. var itemSpacing : Float = 8.0
  204. var itemSpacing_hov : Float = 8.0
  205. var itemSpacing_sel : Float = 8.0
  206. var itemSpacing_custom : Float = 8.0
  207. var itemSpacing_none : Float = 8.0
  208. var itemSpacing_change : Float = 8.0
  209. var background : NSColor = .clear
  210. var background_hov : NSColor = .clear
  211. var background_sel : NSColor = .clear
  212. var background_custom : NSColor = .clear
  213. var background_none : NSColor = .clear
  214. var background_change : NSColor = .clear
  215. var textColor : NSColor = .black
  216. var textColor_hov : NSColor = .black
  217. var textColor_sel : NSColor = .black
  218. var textColor_custom: NSColor = .black
  219. var textColor_change: NSColor = .black
  220. var font : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  221. var font_hov : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  222. var font_sel : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  223. var font_custom : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  224. var font_change : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  225. var lineHeight : CGFloat = 20.0 // 默认 内容行高
  226. var lineHeight_hov : CGFloat = 20.0 // 默认 内容行高
  227. var lineHeight_sel : CGFloat = 20.0 // 默认 内容行高
  228. var lineHeight_custom : CGFloat = 20.0 // 默认 内容行高
  229. var lineHeight_change : CGFloat = 20.0 // 默认 内容行高
  230. var descTextColor : NSColor = .black
  231. var descTextColor_hov : NSColor = .black
  232. var descTextColor_sel : NSColor = .black
  233. var descTextColor_custom: NSColor = .black
  234. var descTextColor_change: NSColor = .black
  235. var descFont : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  236. var descFont_hov : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  237. var descFont_sel : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  238. var descFont_custom : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  239. var descFont_change : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
  240. var descLineHeight : CGFloat = 6.0 // 默认 内容行高
  241. var descLineHeight_hov : CGFloat = 6.0 // 默认 内容行高
  242. var descLineHeight_sel : CGFloat = 6.0 // 默认 内容行高
  243. var descLineHeight_custom : CGFloat = 6.0 // 默认 内容行高
  244. var descLineHeight_change : CGFloat = 6.0 // 默认 内容行高
  245. var itemSpacing2 : Float = 8.0
  246. var itemSpacing2_hov : Float = 8.0
  247. var itemSpacing2_sel : Float = 8.0
  248. var itemSpacing2_custom : Float = 8.0
  249. var itemSpacing2_change : Float = 8.0
  250. var state: KMDesignTokenState = .Norm
  251. var canHover: Bool = true // 是否可悬浮
  252. var isCustomize: Bool = false
  253. // MARK: init
  254. override func viewDidLoad() {
  255. super.viewDidLoad()
  256. // Do view setup here.
  257. addBox.isHidden = true
  258. fastToolItemBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  259. if self != nil {
  260. if mouseEntered {
  261. if self!.state != .Sel && self!.canHover {
  262. self!.state = .Hov
  263. self!.updateUI()
  264. }
  265. } else {
  266. if self!.state != .Sel && self!.canHover {
  267. self!.state = .Norm
  268. self!.updateUI()
  269. }
  270. }
  271. }
  272. }
  273. updateUI()
  274. }
  275. // MARK: private
  276. func quickToolsCollectionCellItem(type: DataNavigationViewButtonActionType) {
  277. let paragraphStyle1 = NSMutableParagraphStyle()
  278. let paragraphStyle2 = NSMutableParagraphStyle()
  279. if (state == .Norm) {
  280. paragraphStyle1.lineSpacing = lineHeight
  281. paragraphStyle2.lineSpacing = descLineHeight
  282. } else if (state == .Hov) {
  283. paragraphStyle1.lineSpacing = lineHeight_hov
  284. paragraphStyle2.lineSpacing = descLineHeight_hov
  285. } else if (state == .Sel) {
  286. paragraphStyle1.lineSpacing = lineHeight_sel
  287. paragraphStyle2.lineSpacing = descLineHeight_sel
  288. } else if (state == .Custom) {
  289. paragraphStyle1.lineSpacing = lineHeight_custom
  290. paragraphStyle2.lineSpacing = descLineHeight_custom
  291. } else if (state == .Change) {
  292. paragraphStyle1.lineSpacing = lineHeight_change
  293. paragraphStyle2.lineSpacing = descLineHeight_change
  294. }
  295. let mode: KMFastToolMode = KMFastToolMode.toolModeData(type: type)
  296. self.fastToolIteTitleLabel.attributedStringValue = NSAttributedString(string: mode.toolTitle!, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle1])
  297. self.fastToolItemSubtitleLabel.lineBreakMode = .byTruncatingTail
  298. self.fastToolItemSubtitleLabel.cell?.truncatesLastVisibleLine = true
  299. self.fastToolItemSubtitleLabel.attributedStringValue = NSAttributedString(string: mode.toolSubtitle!, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle2])
  300. self.fastToolItemImageView.image = NSImage(named: mode.toolImageName!)
  301. }
  302. func refreshHoverStatus(_ canHover: Bool, _ canClick: Bool) -> Void {
  303. fastToolItemBox.canHover = canHover
  304. fastToolItemBox.canClick = canClick
  305. }
  306. func refreshUIColor(_ customize: Bool) -> Void {
  307. self.isCustomize = customize
  308. if isCustomize {
  309. fastToolItemBox.isDottedLine = true
  310. fastToolItemBox.fillColor = NSColor(hex: "#F7F8FA")
  311. fastToolIteTitleLabel.textColor = NSColor(hex: "#252629")
  312. fastToolItemSubtitleLabel.textColor = NSColor(hex: "#616469")
  313. } else {
  314. fastToolItemBox.isDottedLine = false
  315. fastToolItemBox.fillColor = NSColor(hex: "#FFFFFF")
  316. fastToolIteTitleLabel.textColor = NSColor(hex: "#252629")
  317. fastToolItemSubtitleLabel.textColor = NSColor(hex: "#616469")
  318. }
  319. }
  320. func updateUI() -> Void {
  321. if (state == .Norm) {
  322. fastToolItemBox.fillColor = background
  323. fastToolItemBox.borderWidth = CGFloat(borderWidth)
  324. fastToolItemBox.borderColor = borderColor
  325. fastToolItemBox.cornerRadius = CGFloat(borderRadius)
  326. fastToolIteTitleLabel.font = font
  327. fastToolIteTitleLabel.textColor = textColor
  328. fastToolItemSubtitleLabel.font = descFont
  329. fastToolItemSubtitleLabel.textColor = descTextColor
  330. padding_top.constant = CGFloat(horizontalPadding)
  331. padding_left.constant = CGFloat(horizontalPadding)
  332. // padding_down.constant = CGFloat(horizontalPadding)
  333. padding_right.constant = CGFloat(horizontalPadding)
  334. itemspacing_1.constant = CGFloat(itemSpacing)
  335. itemspacing_2.constant = CGFloat(itemSpacing2)
  336. } else if (state == .Hov) {
  337. fastToolItemBox.fillColor = background_hov
  338. fastToolItemBox.borderWidth = CGFloat(borderWidth_hov)
  339. fastToolItemBox.borderColor = borderColor_hov
  340. fastToolItemBox.cornerRadius = CGFloat(borderRadius_hov)
  341. fastToolIteTitleLabel.font = font_hov
  342. fastToolIteTitleLabel.textColor = textColor_hov
  343. fastToolItemSubtitleLabel.font = descFont_hov
  344. fastToolItemSubtitleLabel.textColor = descTextColor_hov
  345. padding_top.constant = CGFloat(horizontalPadding_hov)
  346. padding_left.constant = CGFloat(horizontalPadding_hov)
  347. // padding_down.constant = CGFloat(horizontalPadding_hov)
  348. padding_right.constant = CGFloat(horizontalPadding_hov)
  349. itemspacing_1.constant = CGFloat(itemSpacing_hov)
  350. itemspacing_2.constant = CGFloat(itemSpacing2_hov)
  351. } else if (state == .Sel) {
  352. fastToolItemBox.fillColor = background_sel
  353. fastToolItemBox.borderWidth = CGFloat(borderWidth_sel)
  354. fastToolItemBox.borderColor = borderColor_sel
  355. fastToolItemBox.cornerRadius = CGFloat(borderRadius_sel)
  356. fastToolIteTitleLabel.font = font_sel
  357. fastToolIteTitleLabel.textColor = textColor_sel
  358. fastToolItemSubtitleLabel.font = descFont_sel
  359. fastToolItemSubtitleLabel.textColor = descTextColor_sel
  360. padding_top.constant = CGFloat(horizontalPadding_sel)
  361. padding_left.constant = CGFloat(horizontalPadding_sel)
  362. // padding_down.constant = CGFloat(horizontalPadding_sel)
  363. padding_right.constant = CGFloat(horizontalPadding_sel)
  364. itemspacing_1.constant = CGFloat(itemSpacing_sel)
  365. itemspacing_2.constant = CGFloat(itemSpacing2_sel)
  366. } else if (state == .Custom) {
  367. fastToolItemBox.fillColor = background_custom
  368. fastToolItemBox.borderWidth = CGFloat(borderWidth_custom)
  369. fastToolItemBox.borderColor = borderColor_custom
  370. fastToolItemBox.cornerRadius = CGFloat(borderRadius_custom)
  371. fastToolIteTitleLabel.font = font_custom
  372. fastToolIteTitleLabel.textColor = textColor_custom
  373. fastToolItemSubtitleLabel.font = descFont_custom
  374. fastToolItemSubtitleLabel.textColor = descTextColor_custom
  375. padding_top.constant = CGFloat(horizontalPadding_custom)
  376. padding_left.constant = CGFloat(horizontalPadding_custom)
  377. // padding_down.constant = CGFloat(horizontalPadding_custom)
  378. padding_right.constant = CGFloat(horizontalPadding_custom)
  379. itemspacing_1.constant = CGFloat(itemSpacing_custom)
  380. itemspacing_2.constant = CGFloat(itemSpacing2_custom)
  381. } else if (state == .None) {
  382. fastToolItemBox.fillColor = background_none
  383. fastToolItemBox.borderWidth = CGFloat(borderWidth_none)
  384. fastToolItemBox.borderColor = borderColor_none
  385. fastToolItemBox.cornerRadius = CGFloat(borderRadius_none)
  386. padding_top.constant = CGFloat(horizontalPadding_none)
  387. padding_left.constant = CGFloat(horizontalPadding_none)
  388. // padding_down.constant = CGFloat(horizontalPadding_none)
  389. padding_right.constant = CGFloat(horizontalPadding_none)
  390. itemspacing_1.constant = CGFloat(itemSpacing_none)
  391. } else if (state == .Change) {
  392. fastToolItemBox.fillColor = background_change
  393. fastToolItemBox.borderWidth = CGFloat(borderWidth_change)
  394. fastToolItemBox.borderColor = borderColor_change
  395. fastToolItemBox.cornerRadius = CGFloat(borderRadius_change)
  396. fastToolIteTitleLabel.font = font_change
  397. fastToolIteTitleLabel.textColor = textColor_change
  398. fastToolItemSubtitleLabel.font = descFont_change
  399. fastToolItemSubtitleLabel.textColor = descTextColor_change
  400. padding_top.constant = CGFloat(horizontalPadding_change)
  401. padding_left.constant = CGFloat(horizontalPadding_change)
  402. // 吧 padding_right.constant = CGFloat(horizontalPadding_change)
  403. itemspacing_1.constant = CGFloat(itemSpacing_change)
  404. itemspacing_2.constant = CGFloat(itemSpacing2_change)
  405. }
  406. }
  407. }