// // KMBatchCompressView.swift // PDF Master // // Created by lizhe on 2023/1/16. // import Cocoa class KMBatchCompressView: KMBatchSettingItemView { @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var subTitleLabel: NSTextField! @IBOutlet weak var largeButton: KMImageTitleButton! @IBOutlet weak var standardButton: KMImageTitleButton! @IBOutlet weak var smallButton: KMImageTitleButton! @IBOutlet weak var minimumButton: KMImageTitleButton! @IBOutlet weak var compressButton: NSButton! var data: KMBatchCompressViewModel = KMBatchCompressViewModel() override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func setup() { super.setup() self.largeButton.title = NSLocalizedString("Large File Size", comment: "") self.largeButton.imageName = "btn_radio_unsel_on" self.largeButton.action = { [unowned self] (view, button) in self.data.type = .large self.reloadData() } self.standardButton.title = NSLocalizedString("Standard File Size", comment: "") self.standardButton.imageName = "btn_radio_unsel_on" self.standardButton.action = { [unowned self] (view, button) in self.data.type = .standard self.reloadData() } self.smallButton.title = NSLocalizedString("Small File Size", comment: "") self.smallButton.imageName = "btn_radio_unsel_on" self.smallButton.action = { [unowned self] (view, button) in self.data.type = .small self.reloadData() } self.minimumButton.title = NSLocalizedString("Minimum File Size", comment: "") self.minimumButton.imageName = "btn_radio_unsel_on" self.minimumButton.action = { [unowned self] (view, button) in self.data.type = .minimum self.reloadData() } self.titleLabel.textColor = NSColor.km_init(hex: "#252629") self.titleLabel.stringValue = NSLocalizedString("Settings", comment: "") self.titleLabel.font = NSFont.SFProTextRegularFont(16.0) self.subTitleLabel.textColor = NSColor.km_init(hex: "#616469") self.subTitleLabel.stringValue = NSLocalizedString("Optimization Options", comment: "") self.subTitleLabel.font = NSFont.SFProTextRegularFont(12.0) self.compressButton.wantsLayer = true self.compressButton.layer?.cornerRadius = 4 self.compressButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF") self.compressButton.stringValue = NSLocalizedString("Compress", comment: "") self.compressButton.font = NSFont.SFProTextRegularFont(14.0) self.compressButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor self.largeButton.titleLabel.textColor = NSColor.km_init(hex: "#252629") self.largeButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0) self.standardButton.titleLabel.textColor = NSColor.km_init(hex: "#252629") self.standardButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0) self.smallButton.titleLabel.textColor = NSColor.km_init(hex: "#252629") self.smallButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0) self.minimumButton.titleLabel.textColor = NSColor.km_init(hex: "#252629") self.minimumButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0) } override func reloadData() { let array = [self.smallButton, self.minimumButton, self.largeButton, self.standardButton] for button in array { button?.imageName = "btn_radio_unsel_on" } switch self.data.type { case .large: self.largeButton.imageName = "btn_radio_sel_on" case .standard: self.standardButton.imageName = "btn_radio_sel_on" case .small: self.smallButton.imageName = "btn_radio_sel_on" case .minimum: self.minimumButton.imageName = "btn_radio_sel_on" } if (self.filesData.count != 0) { self.compressButton.layer?.backgroundColor = NSColor.km_init(hex: "#1770F4").cgColor self.compressButton.isEnabled = true } else { self.compressButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor self.compressButton.isEnabled = false } } } protocol KMBatchCompressViewAction {} extension KMBatchCompressView: KMBatchCompressViewAction { @IBAction func compressButtonAction(_ sender: Any) { if self.export != nil { self.export!(self, self.data) } } }