123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- //
- // KMFastToolCollectionViewItem.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2022/10/20.
- //
- import Cocoa
- public enum DataNavigationViewButtonActionType : Int, CaseIterable {
- case Batch = 0 // 批量处理
- case ConvertPDF // 转换PDF
- case ImageToPDF // 图片转PDF
- case MergePDF // 合并
- case Compression // 压缩
- case Security // 安全
- case PDFToPPT // PDF转PPT
- case PDFToExcel // PDF转Excel
- case PDFToWord // PDF转Word
- case PDFToImage // PDF转图片
- case Watermark // 水印
- case Background // 背景
- case HeaderAndFooter// 页眉页脚
- case BatesCode // 贝茨码
- case Print // 打印
- case PrintMultipage // 多页
- case PrintPoster // 海报
- case PrintBooklet // 小册子
- case BatchRemove // 批量移除
- case Insert // 插入
- case BreakUp // 拆分
- case Extract // 提取
- case MarkCipher // 标记密文
- case PageEdit // 页面编辑
- case OCR // 批量OCR
- case AutomaticFormRecognition //表单自动识别
- case FileCompare // 文件对比
- case ComparativeTable // 比较表
- case equity // 权益弹窗
- case AITools //AI Tools
- }
- class KMFastToolMode: NSObject {
- var toolImageName: String? //图片名称
- var toolTitle: String? //主标题
- var toolSubtitle: String? //副标题
-
- class func toolModeData(type: DataNavigationViewButtonActionType) -> KMFastToolMode {
- let mode: KMFastToolMode = KMFastToolMode()
- switch type {
- case .Batch:
- mode.toolTitle = NSLocalizedString("Batch", comment: "")
- mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
- mode.toolImageName = "icon_pdftools_batch"
- break
- case .OCR:
- mode.toolTitle = NSLocalizedString("OCR", comment: "")
- mode.toolSubtitle = NSLocalizedString("Recognize text from image or scanned PDF with OCR", comment: "")
- mode.toolImageName = "icon_pdftools_ocr"
- break
- case .ConvertPDF:
- mode.toolTitle = NSLocalizedString("Convert PDF", comment: "")
- mode.toolSubtitle = NSLocalizedString("Convert PDFs to Word/HTML/TXT/JPEG/PNG files", comment: "")
- mode.toolImageName = "icon_pdftools_convert"
- break
- case .ImageToPDF:
- mode.toolTitle = NSLocalizedString("Image To PDF", comment: "")
- mode.toolSubtitle = NSLocalizedString("Convert JPEG/JPG/PNG/TIFF/BMP/PSD files to PDF", comment: "")
- mode.toolImageName = "icon_pdftools_image"
- break
- case .MergePDF:
- mode.toolTitle = NSLocalizedString("Merge", comment: "")
- mode.toolSubtitle = NSLocalizedString("Combine multiple documents into a new PDF file", comment: "")
- mode.toolImageName = "icon_pdftools_merge"
- break
- case .Compression:
- mode.toolTitle = NSLocalizedString("Compress", comment: "")
- mode.toolSubtitle = NSLocalizedString("Reduce files size to make sure you can easily send them by mail", comment: "")
- mode.toolImageName = "icon_pdftools_compress"
- break
- case .Security:
- mode.toolTitle = NSLocalizedString("Security", comment: "")
- mode.toolSubtitle = NSLocalizedString("Limit access to PDFs, restrict copying and printing permission with passwords", comment: "")
- mode.toolImageName = "icon_pdftools_security"
- break
- case .FileCompare:
- mode.toolTitle = NSLocalizedString("Compare", comment: "")
- mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
- mode.toolImageName = "icon_pdftools_compare"
- break
- case .PDFToPPT:
- mode.toolTitle = NSLocalizedString("PDF To PPT", comment: "")
- mode.toolSubtitle = NSLocalizedString("Turn your PDF into a formatted PPT file that you can edit", comment: "")
- mode.toolImageName = "icon_pdftools_pdfToPPT"
- break
- case .PDFToExcel:
- mode.toolTitle = NSLocalizedString("PDF To Excel", comment: "")
- mode.toolSubtitle = NSLocalizedString("Turn PDF table into a formatted Excel file", comment: "")
- mode.toolImageName = "icon_pdftools_pdfToExcel"
- break
- case .PDFToWord:
- mode.toolTitle = NSLocalizedString("PDF To Word", comment: "")
- mode.toolSubtitle = NSLocalizedString("Convert PDF to Word, fonts & formatting get converted", comment: "")
- mode.toolImageName = "icon_pdftools_pdfToWord"
- break
- case .PDFToImage:
- mode.toolTitle = NSLocalizedString("PDF To Image", comment: "")
- mode.toolSubtitle = NSLocalizedString("Convert PDF to image, such as JPEG, JPG, PNG, GIF, TIFF, TAG,BMP", comment: "")
- mode.toolImageName = "icon_pdftools_pdfToImage"
- break
- case .Watermark:
- mode.toolTitle = NSLocalizedString("Watermark", comment: "")
- mode.toolSubtitle = NSLocalizedString("Protect PDFs with image/text watermarks from plagiarism", comment: "")
- mode.toolImageName = "icon_pdftools_watermark"
- break
- case .Background:
- mode.toolTitle = NSLocalizedString("Background", comment: "")
- mode.toolSubtitle = NSLocalizedString("Customize PDFs background with colors or images", comment: "")
- mode.toolImageName = "icon_pdftools_background"
- break
- case .HeaderAndFooter:
- mode.toolTitle = NSLocalizedString("Header & Footer", comment: "")
- mode.toolSubtitle = NSLocalizedString("Customize PDFs header&footer or add page number", comment: "")
- mode.toolImageName = "icon_pdftools_headerfooter"
- break
- case .BatesCode:
- mode.toolTitle = NSLocalizedString("Bates Numbers", comment: "")
- mode.toolSubtitle = NSLocalizedString("Easily retrieval indexing legal document by Bates Numbers", comment: "")
- mode.toolImageName = "icon_pdftools_batesnumbers"
- break
- case .Print:
- mode.toolTitle = NSLocalizedString("Print", comment: "")
- mode.toolSubtitle = NSLocalizedString("Powerful PDF printer allows to print PDF from any computer without much hassle", comment: "")
- mode.toolImageName = "icon_pdftools_print"
- break
- case .BatchRemove:
- mode.toolTitle = NSLocalizedString("Batch Remove", comment: "")
- mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
- mode.toolImageName = "icon_pdftools_remove"
- break
- case .Insert:
- mode.toolTitle = NSLocalizedString("Insert", comment: "")
- mode.toolSubtitle = NSLocalizedString("Insert blank pages to PDF or insert a new file", comment: "")
- mode.toolImageName = "icon_pdftools_insert"
- break
- case .BreakUp:
- mode.toolTitle = NSLocalizedString("Split", comment: "")
- mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
- mode.toolImageName = "icon_pdftools_split"
- break
- case .Extract:
- mode.toolTitle = NSLocalizedString("Extract", comment: "")
- mode.toolSubtitle = NSLocalizedString("Extract selected pages to a new PDF", comment: "")
- mode.toolImageName = "icon_pdftools_extract"
- break
- case .MarkCipher:
- mode.toolTitle = NSLocalizedString("Redact", comment: "")
- mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
- mode.toolImageName = "icon_pdftools_reduct"
- break
- case .AutomaticFormRecognition:
- mode.toolTitle = NSLocalizedString("Form Filed Recognition", comment: "")
- mode.toolSubtitle = NSLocalizedString("content content content content content content content content", comment: "")
- mode.toolImageName = "icon_pdftools_formfiledrecognition"
- break
- case .PageEdit:
- mode.toolTitle = NSLocalizedString("Page Edit", comment: "")
- mode.toolSubtitle = NSLocalizedString("Delete/Rotate/Copy/Paste PDF pages", comment: "")
- mode.toolImageName = "icon_pdftools_pageEdit"
- break
- case .ComparativeTable:
- break
- case .equity:
- break
- case .PrintMultipage:
- break
- case .PrintPoster:
- break
- case .PrintBooklet:
- break
- case .AITools:
- break
- }
- return mode
- }
- }
- class KMFastToolCollectionViewItem: NSCollectionViewItem {
-
- @IBOutlet weak var fastToolItemBox: KMBox!
- @IBOutlet weak var fastToolItemImageView: NSImageView!
- @IBOutlet weak var fastToolIteTitleLabel: NSTextField!
- @IBOutlet weak var fastToolItemSubtitleLabel: NSTextField!
- @IBOutlet weak var fastToolItemBoxHeightConstraint: NSLayoutConstraint!
- @IBOutlet weak var padding_top: NSLayoutConstraint!
- @IBOutlet weak var padding_left: NSLayoutConstraint!
- // @IBOutlet weak var padding_down: NSLayoutConstraint!
- @IBOutlet weak var padding_right: NSLayoutConstraint!
- @IBOutlet weak var itemspacing_1: NSLayoutConstraint!
- @IBOutlet weak var itemspacing_2: NSLayoutConstraint!
-
- @IBOutlet weak var addBox: NSBox!
- @IBOutlet weak var addLabel: NSTextField!
-
- var horizontalPadding : Float = 16.0
- var horizontalPadding_hov : Float = 16.0
- var horizontalPadding_sel : Float = 16.0
- var horizontalPadding_custom : Float = 16.0
- var horizontalPadding_none : Float = 16.0
- var horizontalPadding_change : Float = 16.0
- var borderColor : NSColor = .clear
- var borderColor_hov : NSColor = .clear
- var borderColor_sel : NSColor = .clear
- var borderColor_custom : NSColor = .clear
- var borderColor_none : NSColor = .clear
- var borderColor_change : NSColor = .clear
- var borderRadius : Float = 8.0
- var borderRadius_hov : Float = 8.0
- var borderRadius_sel : Float = 8.0
- var borderRadius_custom : Float = 8.0
- var borderRadius_none : Float = 8.0
- var borderRadius_change : Float = 8.0
- var borderWidth : Float = 1.0
- var borderWidth_hov : Float = 1.0
- var borderWidth_sel : Float = 1.0
- var borderWidth_custom : Float = 1.0
- var borderWidth_none : Float = 1.0
- var borderWidth_change : Float = 1.0
- var itemSpacing : Float = 8.0
- var itemSpacing_hov : Float = 8.0
- var itemSpacing_sel : Float = 8.0
- var itemSpacing_custom : Float = 8.0
- var itemSpacing_none : Float = 8.0
- var itemSpacing_change : Float = 8.0
- var background : NSColor = .clear
- var background_hov : NSColor = .clear
- var background_sel : NSColor = .clear
- var background_custom : NSColor = .clear
- var background_none : NSColor = .clear
- var background_change : NSColor = .clear
- var textColor : NSColor = .black
- var textColor_hov : NSColor = .black
- var textColor_sel : NSColor = .black
- var textColor_custom: NSColor = .black
- var textColor_change: NSColor = .black
- var font : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var font_hov : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var font_sel : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var font_custom : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var font_change : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var lineHeight : CGFloat = 20.0 // 默认 内容行高
- var lineHeight_hov : CGFloat = 20.0 // 默认 内容行高
- var lineHeight_sel : CGFloat = 20.0 // 默认 内容行高
- var lineHeight_custom : CGFloat = 20.0 // 默认 内容行高
- var lineHeight_change : CGFloat = 20.0 // 默认 内容行高
- var descTextColor : NSColor = .black
- var descTextColor_hov : NSColor = .black
- var descTextColor_sel : NSColor = .black
- var descTextColor_custom: NSColor = .black
- var descTextColor_change: NSColor = .black
- var descFont : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var descFont_hov : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var descFont_sel : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var descFont_custom : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var descFont_change : NSFont = NSFont.systemFont(ofSize: 14.0) // 默认 内容字体
- var descLineHeight : CGFloat = 6.0 // 默认 内容行高
- var descLineHeight_hov : CGFloat = 6.0 // 默认 内容行高
- var descLineHeight_sel : CGFloat = 6.0 // 默认 内容行高
- var descLineHeight_custom : CGFloat = 6.0 // 默认 内容行高
- var descLineHeight_change : CGFloat = 6.0 // 默认 内容行高
- var itemSpacing2 : Float = 8.0
- var itemSpacing2_hov : Float = 8.0
- var itemSpacing2_sel : Float = 8.0
- var itemSpacing2_custom : Float = 8.0
- var itemSpacing2_change : Float = 8.0
- var state: KMDesignTokenState = .Norm
- var canHover: Bool = true // 是否可悬浮
- var isCustomize: Bool = false
- // MARK: init
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- addBox.isHidden = true
-
- fastToolItemBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
- if self != nil {
- if mouseEntered {
- if self!.state != .Sel && self!.canHover {
- self!.state = .Hov
- self!.updateUI()
- }
- } else {
- if self!.state != .Sel && self!.canHover {
- self!.state = .Norm
- self!.updateUI()
- }
- }
- }
- }
- updateUI()
- }
-
- // MARK: private
-
- func quickToolsCollectionCellItem(type: DataNavigationViewButtonActionType) {
- let paragraphStyle1 = NSMutableParagraphStyle()
- let paragraphStyle2 = NSMutableParagraphStyle()
- if (state == .Norm) {
- paragraphStyle1.lineSpacing = lineHeight
- paragraphStyle2.lineSpacing = descLineHeight
- } else if (state == .Hov) {
- paragraphStyle1.lineSpacing = lineHeight_hov
- paragraphStyle2.lineSpacing = descLineHeight_hov
- } else if (state == .Sel) {
- paragraphStyle1.lineSpacing = lineHeight_sel
- paragraphStyle2.lineSpacing = descLineHeight_sel
- } else if (state == .Custom) {
- paragraphStyle1.lineSpacing = lineHeight_custom
- paragraphStyle2.lineSpacing = descLineHeight_custom
- } else if (state == .Change) {
- paragraphStyle1.lineSpacing = lineHeight_change
- paragraphStyle2.lineSpacing = descLineHeight_change
- }
- let mode: KMFastToolMode = KMFastToolMode.toolModeData(type: type)
- self.fastToolIteTitleLabel.attributedStringValue = NSAttributedString(string: mode.toolTitle!, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle1])
- self.fastToolItemSubtitleLabel.lineBreakMode = .byTruncatingTail
- self.fastToolItemSubtitleLabel.cell?.truncatesLastVisibleLine = true
- self.fastToolItemSubtitleLabel.attributedStringValue = NSAttributedString(string: mode.toolSubtitle!, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle2])
- self.fastToolItemImageView.image = NSImage(named: mode.toolImageName!)
- }
-
- func refreshHoverStatus(_ canHover: Bool, _ canClick: Bool) -> Void {
- fastToolItemBox.canHover = canHover
- fastToolItemBox.canClick = canClick
- }
-
- func refreshUIColor(_ customize: Bool) -> Void {
- self.isCustomize = customize
- if isCustomize {
- fastToolItemBox.isDottedLine = true
- fastToolItemBox.fillColor = NSColor.km_init(hex: "#F7F8FA")
- fastToolIteTitleLabel.textColor = NSColor.km_init(hex: "#252629")
- fastToolItemSubtitleLabel.textColor = NSColor.km_init(hex: "#616469")
- } else {
- fastToolItemBox.isDottedLine = false
- fastToolItemBox.fillColor = NSColor.km_init(hex: "#FFFFFF")
- fastToolIteTitleLabel.textColor = NSColor.km_init(hex: "#252629")
- fastToolItemSubtitleLabel.textColor = NSColor.km_init(hex: "#616469")
- }
- }
-
- func updateUI() -> Void {
- if (state == .Norm) {
- fastToolItemBox.fillColor = background
- fastToolItemBox.borderWidth = CGFloat(borderWidth)
- fastToolItemBox.borderColor = borderColor
- fastToolItemBox.cornerRadius = CGFloat(borderRadius)
- fastToolIteTitleLabel.font = font
- fastToolIteTitleLabel.textColor = textColor
- fastToolItemSubtitleLabel.font = descFont
- fastToolItemSubtitleLabel.textColor = descTextColor
- padding_top.constant = CGFloat(horizontalPadding)
- padding_left.constant = CGFloat(horizontalPadding)
- // padding_down.constant = CGFloat(horizontalPadding)
- padding_right.constant = CGFloat(horizontalPadding)
- itemspacing_1.constant = CGFloat(itemSpacing)
- itemspacing_2.constant = CGFloat(itemSpacing2)
- } else if (state == .Hov) {
- fastToolItemBox.fillColor = background_hov
- fastToolItemBox.borderWidth = CGFloat(borderWidth_hov)
- fastToolItemBox.borderColor = borderColor_hov
- fastToolItemBox.cornerRadius = CGFloat(borderRadius_hov)
- fastToolIteTitleLabel.font = font_hov
- fastToolIteTitleLabel.textColor = textColor_hov
- fastToolItemSubtitleLabel.font = descFont_hov
- fastToolItemSubtitleLabel.textColor = descTextColor_hov
- padding_top.constant = CGFloat(horizontalPadding_hov)
- padding_left.constant = CGFloat(horizontalPadding_hov)
- // padding_down.constant = CGFloat(horizontalPadding_hov)
- padding_right.constant = CGFloat(horizontalPadding_hov)
- itemspacing_1.constant = CGFloat(itemSpacing_hov)
- itemspacing_2.constant = CGFloat(itemSpacing2_hov)
- } else if (state == .Sel) {
- fastToolItemBox.fillColor = background_sel
- fastToolItemBox.borderWidth = CGFloat(borderWidth_sel)
- fastToolItemBox.borderColor = borderColor_sel
- fastToolItemBox.cornerRadius = CGFloat(borderRadius_sel)
- fastToolIteTitleLabel.font = font_sel
- fastToolIteTitleLabel.textColor = textColor_sel
- fastToolItemSubtitleLabel.font = descFont_sel
- fastToolItemSubtitleLabel.textColor = descTextColor_sel
- padding_top.constant = CGFloat(horizontalPadding_sel)
- padding_left.constant = CGFloat(horizontalPadding_sel)
- // padding_down.constant = CGFloat(horizontalPadding_sel)
- padding_right.constant = CGFloat(horizontalPadding_sel)
- itemspacing_1.constant = CGFloat(itemSpacing_sel)
- itemspacing_2.constant = CGFloat(itemSpacing2_sel)
- } else if (state == .Custom) {
- fastToolItemBox.fillColor = background_custom
- fastToolItemBox.borderWidth = CGFloat(borderWidth_custom)
- fastToolItemBox.borderColor = borderColor_custom
- fastToolItemBox.cornerRadius = CGFloat(borderRadius_custom)
- fastToolIteTitleLabel.font = font_custom
- fastToolIteTitleLabel.textColor = textColor_custom
- fastToolItemSubtitleLabel.font = descFont_custom
- fastToolItemSubtitleLabel.textColor = descTextColor_custom
- padding_top.constant = CGFloat(horizontalPadding_custom)
- padding_left.constant = CGFloat(horizontalPadding_custom)
- // padding_down.constant = CGFloat(horizontalPadding_custom)
- padding_right.constant = CGFloat(horizontalPadding_custom)
- itemspacing_1.constant = CGFloat(itemSpacing_custom)
- itemspacing_2.constant = CGFloat(itemSpacing2_custom)
- } else if (state == .None) {
- fastToolItemBox.fillColor = background_none
- fastToolItemBox.borderWidth = CGFloat(borderWidth_none)
- fastToolItemBox.borderColor = borderColor_none
- fastToolItemBox.cornerRadius = CGFloat(borderRadius_none)
- padding_top.constant = CGFloat(horizontalPadding_none)
- padding_left.constant = CGFloat(horizontalPadding_none)
- // padding_down.constant = CGFloat(horizontalPadding_none)
- padding_right.constant = CGFloat(horizontalPadding_none)
- itemspacing_1.constant = CGFloat(itemSpacing_none)
- } else if (state == .Change) {
- fastToolItemBox.fillColor = background_change
- fastToolItemBox.borderWidth = CGFloat(borderWidth_change)
- fastToolItemBox.borderColor = borderColor_change
- fastToolItemBox.cornerRadius = CGFloat(borderRadius_change)
- fastToolIteTitleLabel.font = font_change
- fastToolIteTitleLabel.textColor = textColor_change
- fastToolItemSubtitleLabel.font = descFont_change
- fastToolItemSubtitleLabel.textColor = descTextColor_change
- padding_top.constant = CGFloat(horizontalPadding_change)
- padding_left.constant = CGFloat(horizontalPadding_change)
- // 吧 padding_right.constant = CGFloat(horizontalPadding_change)
- itemspacing_1.constant = CGFloat(itemSpacing_change)
- itemspacing_2.constant = CGFloat(itemSpacing2_change)
- }
- }
- }
|