KMConvertImageSettingView.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // KMConvertImageSettingView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/6.
  6. //
  7. class KMConvertImageSettingView: KMConvertSettingView {
  8. @IBOutlet weak var fileTypeTitleLabel: NSTextField!
  9. @IBOutlet weak var formatBox: NSBox!
  10. @IBOutlet weak var pageRangeBox: NSBox!
  11. @IBOutlet weak var dpiTitleLabel: NSTextField!
  12. @IBOutlet weak var dpiSelectBox: NSBox!
  13. private var formartView: KMDesignSelect?
  14. private var dpiVC: KMDesignSelect?
  15. var selectedFormatIndex = 0
  16. var selectedResolutionIndex = 3
  17. override func initSubViews() {
  18. super.initSubViews()
  19. self.formartView = KMDesignSelect.init(withType: .Combox)
  20. self.formatBox.contentView = self.formartView!.view
  21. self.formartView = KMDesignSelect.init(withType: .Combox)
  22. self.formatBox.contentView = self.formartView!.view
  23. self.formartView?.removeAllItems()
  24. self.formartView?.addItems(withObjectValues: ["JPEG","JPG","PNG","GIF","TIFF","TGA","BMP","JPEG-2000"])
  25. self.formartView?.selectItem(at: 0)
  26. self.formartView?.editable = false //默认属性,初始化可不设置
  27. self.formartView?.delete = self
  28. self.formartView?.updateUI()
  29. self.dpiVC = KMDesignSelect(withType: .Combox)
  30. self.dpiSelectBox.contentView = self.dpiVC?.view
  31. self.dpiVC?.removeAllItems()
  32. self.dpiVC?.addItems(withObjectValues: ["50 dpi", "72 dpi", "96 dpi", "150 dpi", "300 dpi", "600 dpi"])
  33. self.dpiVC?.selectItem(at: self.selectedResolutionIndex)
  34. self.dpiVC?.delete = self
  35. self.dpiVC?.updateUI()
  36. self.tipView?.km_add_left_constraint(constant: 8)
  37. self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
  38. self.tipView?.km_add_right_constraint()
  39. self.tipView?.km_add_height_constraint(constant: 16+20+16)
  40. }
  41. override func initDefaultVlaue() {
  42. self.formatBox.fillColor = .clear
  43. self.fileTypeTitleLabel.stringValue = NSLocalizedString("Format", comment: "")
  44. self.fileTypeTitleLabel.textColor = NSColor.km_init(hex: "#616469")
  45. self.fileTypeTitleLabel.font = .SFProTextSemiboldFont(12)
  46. self.formatBox.fillColor = .clear
  47. self.dpiTitleLabel.stringValue = NSLocalizedString("Resolution", comment: "")
  48. self.dpiTitleLabel.textColor = NSColor.km_init(hex: "#616469")
  49. self.dpiTitleLabel.font = .SFProTextBoldFont(12)
  50. }
  51. override func viewDidMoveToWindow() {
  52. super.viewDidMoveToWindow()
  53. if (self.pageRangeItemView == nil) {
  54. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  55. self.pageRangeBox.contentView = self.pageRangeItemView
  56. // self.tipView?.km_add_left_constraint(constant: 8)
  57. // self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
  58. // self.tipView?.km_add_right_constraint()
  59. // self.tipView?.km_add_height_constraint(constant: 16+20+16)
  60. }
  61. self.pageRangeItemView?.pageCount = self.pageCount
  62. }
  63. override func getPageRangeString() -> String {
  64. if let view = self.pageRangeItemView {
  65. return view.pageRangeValue
  66. }
  67. return ""
  68. }
  69. }
  70. extension KMConvertImageSettingView: KMSelectPopButtonDelegate {
  71. func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
  72. if (obj.isEqual(to: self.formartView)) {
  73. guard let index = self.formartView?.indexOfSelectedItem, index >= 0 else {
  74. self.selectedFormatIndex = 0
  75. return
  76. }
  77. self.selectedFormatIndex = index
  78. if (index == 0 || index == 2) { // JPEG & PNG
  79. self.dpiVC?.enabled = true
  80. } else {
  81. self.dpiVC?.enabled = false
  82. }
  83. } else if (obj.isEqual(to: self.dpiVC)) {
  84. if let index = self.dpiVC?.indexOfSelectedItem {
  85. self.selectedResolutionIndex = max(index, 0)
  86. }
  87. }
  88. }
  89. }