// // KMCompressContentView.swift // PDF Reader Pro // // Created by lizhe on 2024/11/18. // import Cocoa import KMComponentLibrary typealias KMBatchOperateCompressViewSelectTypeBlcok = (_ view: KMCompressContentView, _ model: KMCompressSettingModel) -> Void class KMCompressContentView: BaseXibView { @IBOutlet weak var standardButton: ComponentRadio! @IBOutlet weak var mobileButton: ComponentRadio! @IBOutlet weak var customButton: ComponentRadio! @IBOutlet weak var tipButton: ComponentToolTipsHelp! @IBOutlet weak var settingButton: NSButton! @IBOutlet weak var mobileWidthConstraint: NSLayoutConstraint! @IBOutlet weak var customButtonWidthConstraint: NSLayoutConstraint! var compressSettingViewController: KMCompressSettingViewController? var popOver: NSPopover! var selectTypeAction: KMBatchOperateCompressViewSelectTypeBlcok? var model: KMCompressSettingModel = KMCompressSettingModel(modelsType: .standard) { didSet { self.reloadData() } } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func setup() { updateUI() updateUILanguage() reloadData() } override func updateUILanguage() { standardButton.properties.text = KMLocalizedString("Standard (Recommend)", comment: "") mobileButton.properties.text = KMLocalizedString("Mobile", comment: "") customButton.properties.text = KMLocalizedString("Custom", comment: "") settingButton.stringValue = KMLocalizedString("Setting", comment: "") tipButton.toolTip = KMLocalizedString("This mode is specifically tuned for mobile devices to improve compression quality and ensure clear viewing on mobile devices.", comment: "") } override func updateUIThemeColor() { settingButton.setTitleColor(NSColor(hex: "#1EB3F9")) } func updateUI() { standardButton.properties = ComponentCheckBoxProperty(size: .s, text: KMLocalizedString("Standard (Recommend)", comment: ""), checkboxType: .normal) standardButton.setTarget(self, action: #selector(standardButtonAction(_:))) mobileButton.properties = ComponentCheckBoxProperty(size: .s, text: KMLocalizedString("Mobile", comment: ""), checkboxType: .normal) mobileButton.setTarget(self, action: #selector(mobileButtonAction(_:))) mobileWidthConstraint.constant = mobileButton.properties.propertyInfo.viewWidth customButton.properties = ComponentCheckBoxProperty(size: .s, text: KMLocalizedString("Custom", comment: ""), checkboxType: .normal) customButton.setTarget(self, action: #selector(customButtonAction(_:))) customButtonWidthConstraint.constant = mobileButton.properties.propertyInfo.viewWidth // self.tipButton.mouseMoveCallback = {[unowned self] mouseEntered in // if mouseEntered { // let tipString = KMLocalizedString("This mode is specifically tuned for mobile devices to improve compression quality and ensure clear viewing on mobile devices.", comment: "") // // let popViewController = KMToolbarItemPopViewController.init() // if self.popOver == nil { // self.popOver = NSPopover.init() // } // self.popOver.contentViewController = popViewController // self.popOver.animates = false // self.popOver.behavior = .semitransient // self.popOver.contentSize = (popViewController.view.frame.size) // self.popOver.setBackgroundColor(NSColor(hex: "#000000").withAlphaComponent(0.9)) // popViewController.updateWithHelpTip(helpTip: tipString) // self.popOver.show(relativeTo: self.tipButton.frame, of: self.tipButton.superview!, preferredEdge: .maxY) // } else { // self.popOver.close() // } // } } func reloadData() { self.updateType(type: model.modelsType) } func updateType(type: KMCompressModelsType) { self.standardButton.properties.checkboxType = .normal self.mobileButton.properties.checkboxType = .normal self.customButton.properties.checkboxType = .normal switch type { case .standard: self.standardButton.properties.checkboxType = .selected case .custom: self.customButton.properties.checkboxType = .selected case .mobile: self.mobileButton.properties.checkboxType = .selected } self.standardButton.reloadData() self.mobileButton.reloadData() self.customButton.reloadData() } } extension KMCompressContentView { func standardButtonAction(_ sender: Any) { self.updateType(type: .standard) self.model = KMCompressSettingModel(modelsType: .standard) guard let callBack = selectTypeAction else { return } callBack(self, model) } func mobileButtonAction(_ sender: Any) { self.updateType(type: .mobile) self.model = KMCompressSettingModel(modelsType: .mobile) guard let callBack = selectTypeAction else { return } callBack(self, model) } func customButtonAction(_ sender: Any) { self.updateType(type: .custom) self.model = KMCompressSettingModel(modelsType: .custom) guard let callBack = selectTypeAction else { return } callBack(self, model) } @IBAction func settingButtonAction(_ sender: Any) { compressSettingViewController = KMCompressSettingViewController(nibName: "KMCompressSettingViewController", bundle: nil) let window = NSWindow(contentViewController: compressSettingViewController!) window.minSize = CGSizeMake(624, 513) window.maxSize = CGSizeMake(624, 513) window.styleMask.remove(.resizable) let currentWindow = NSWindow.currentWindow() currentWindow.beginSheet(window) compressSettingViewController?.model = self.model compressSettingViewController?.cancelAction = { resultControler in currentWindow.endSheet(window) } compressSettingViewController?.doneAction = { resultControler in currentWindow.endSheet(window) } } }