123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //
- // KMConvertImageSettingView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/6.
- //
- class KMConvertImageSettingView: KMConvertSettingView {
- @IBOutlet weak var fileTypeTitleLabel: NSTextField!
- @IBOutlet weak var formatBox: NSBox!
- @IBOutlet weak var pageRangeBox: NSBox!
-
- @IBOutlet weak var dpiTitleLabel: NSTextField!
- @IBOutlet weak var dpiSelectBox: NSBox!
-
- private var formartView: KMDesignSelect?
- private var dpiVC: KMDesignSelect?
-
- var selectedFormatIndex = 0
- var selectedResolutionIndex = 3
-
- override func initSubViews() {
- super.initSubViews()
-
- self.formartView = KMDesignSelect.init(withType: .Combox)
- self.formatBox.contentView = self.formartView!.view
-
- self.formartView = KMDesignSelect.init(withType: .Combox)
- self.formatBox.contentView = self.formartView!.view
- self.formartView?.removeAllItems()
- self.formartView?.addItems(withObjectValues: ["JPEG","JPG","PNG","GIF","TIFF","TGA","BMP","JPEG-2000"])
- self.formartView?.selectItem(at: 0)
- self.formartView?.editable = false //默认属性,初始化可不设置
- self.formartView?.delete = self
- self.formartView?.updateUI()
-
- self.dpiVC = KMDesignSelect(withType: .Combox)
- self.dpiSelectBox.contentView = self.dpiVC?.view
- self.dpiVC?.removeAllItems()
- self.dpiVC?.addItems(withObjectValues: ["50 dpi", "72 dpi", "96 dpi", "150 dpi", "300 dpi", "600 dpi"])
- self.dpiVC?.selectItem(at: self.selectedResolutionIndex)
- self.dpiVC?.delete = self
- self.dpiVC?.updateUI()
-
- self.tipView?.km_add_left_constraint(constant: 8)
- self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
- self.tipView?.km_add_right_constraint()
- self.tipView?.km_add_height_constraint(constant: 16+20+16)
- }
-
- override func initDefaultVlaue() {
- self.formatBox.fillColor = .clear
-
- self.fileTypeTitleLabel.stringValue = NSLocalizedString("Format", comment: "")
- self.fileTypeTitleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.fileTypeTitleLabel.font = .SFProTextSemiboldFont(12)
-
- self.formatBox.fillColor = .clear
-
- self.dpiTitleLabel.stringValue = NSLocalizedString("Resolution", comment: "")
- self.dpiTitleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.dpiTitleLabel.font = .SFProTextBoldFont(12)
- }
-
- override func viewDidMoveToWindow() {
- super.viewDidMoveToWindow()
-
- if (self.pageRangeItemView == nil) {
- self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
- self.pageRangeBox.contentView = self.pageRangeItemView
-
- // self.tipView?.km_add_left_constraint(constant: 8)
- // self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
- // self.tipView?.km_add_right_constraint()
- // self.tipView?.km_add_height_constraint(constant: 16+20+16)
- }
- self.pageRangeItemView?.pageCount = self.pageCount
- }
-
- override func getPageRangeString() -> String {
- if let view = self.pageRangeItemView {
- return view.pageRangeValue
- }
- return ""
- }
- }
- extension KMConvertImageSettingView: KMSelectPopButtonDelegate {
- func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
- if (obj.isEqual(to: self.formartView)) {
- guard let index = self.formartView?.indexOfSelectedItem, index >= 0 else {
- self.selectedFormatIndex = 0
- return
- }
- self.selectedFormatIndex = index
-
- if (index == 0 || index == 2) { // JPEG & PNG
- self.dpiVC?.enabled = true
- } else {
- self.dpiVC?.enabled = false
- }
- } else if (obj.isEqual(to: self.dpiVC)) {
- if let index = self.dpiVC?.indexOfSelectedItem {
- self.selectedResolutionIndex = max(index, 0)
- }
- }
- }
- }
|