KMBatchCompressView.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // KMBatchCompressView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/1/16.
  6. //
  7. import Cocoa
  8. class KMBatchCompressView: KMBatchSettingItemView {
  9. @IBOutlet weak var titleLabel: NSTextField!
  10. @IBOutlet weak var subTitleLabel: NSTextField!
  11. @IBOutlet weak var largeButton: KMImageTitleButton!
  12. @IBOutlet weak var standardButton: KMImageTitleButton!
  13. @IBOutlet weak var smallButton: KMImageTitleButton!
  14. @IBOutlet weak var minimumButton: KMImageTitleButton!
  15. @IBOutlet weak var compressButton: NSButton!
  16. var data: KMBatchCompressViewModel = KMBatchCompressViewModel()
  17. override func draw(_ dirtyRect: NSRect) {
  18. super.draw(dirtyRect)
  19. // Drawing code here.
  20. }
  21. override func setup() {
  22. super.setup()
  23. self.largeButton.title = NSLocalizedString("Large File Size", comment: "")
  24. self.largeButton.imageName = "btn_radio_unsel_on"
  25. self.largeButton.action = { [unowned self] (view, button) in
  26. self.data.type = .large
  27. self.reloadData()
  28. }
  29. self.standardButton.title = NSLocalizedString("Standard File Size", comment: "")
  30. self.standardButton.imageName = "btn_radio_unsel_on"
  31. self.standardButton.action = { [unowned self] (view, button) in
  32. self.data.type = .standard
  33. self.reloadData()
  34. }
  35. self.smallButton.title = NSLocalizedString("Small File Size", comment: "")
  36. self.smallButton.imageName = "btn_radio_unsel_on"
  37. self.smallButton.action = { [unowned self] (view, button) in
  38. self.data.type = .small
  39. self.reloadData()
  40. }
  41. self.minimumButton.title = NSLocalizedString("Minimum File Size", comment: "")
  42. self.minimumButton.imageName = "btn_radio_unsel_on"
  43. self.minimumButton.action = { [unowned self] (view, button) in
  44. self.data.type = .minimum
  45. self.reloadData()
  46. }
  47. self.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  48. self.titleLabel.stringValue = NSLocalizedString("Settings", comment: "")
  49. self.titleLabel.font = NSFont.SFProTextRegularFont(16.0)
  50. self.subTitleLabel.textColor = NSColor.km_init(hex: "#616469")
  51. self.subTitleLabel.stringValue = NSLocalizedString("Optimization Options", comment: "")
  52. self.subTitleLabel.font = NSFont.SFProTextRegularFont(12.0)
  53. self.compressButton.wantsLayer = true
  54. self.compressButton.layer?.cornerRadius = 4
  55. self.compressButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF")
  56. self.compressButton.stringValue = NSLocalizedString("Compress", comment: "")
  57. self.compressButton.font = NSFont.SFProTextRegularFont(14.0)
  58. self.compressButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
  59. self.largeButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  60. self.largeButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  61. self.standardButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  62. self.standardButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  63. self.smallButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  64. self.smallButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  65. self.minimumButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  66. self.minimumButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
  67. }
  68. override func reloadData() {
  69. let array = [self.smallButton, self.minimumButton, self.largeButton, self.standardButton]
  70. for button in array {
  71. button?.imageName = "btn_radio_unsel_on"
  72. }
  73. switch self.data.type {
  74. case .large:
  75. self.largeButton.imageName = "btn_radio_sel_on"
  76. case .standard:
  77. self.standardButton.imageName = "btn_radio_sel_on"
  78. case .small:
  79. self.smallButton.imageName = "btn_radio_sel_on"
  80. case .minimum:
  81. self.minimumButton.imageName = "btn_radio_sel_on"
  82. }
  83. if (self.filesData.count != 0) {
  84. self.compressButton.layer?.backgroundColor = NSColor.km_init(hex: "#1770F4").cgColor
  85. self.compressButton.isEnabled = true
  86. } else {
  87. self.compressButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
  88. self.compressButton.isEnabled = false
  89. }
  90. }
  91. }
  92. protocol KMBatchCompressViewAction {}
  93. extension KMBatchCompressView: KMBatchCompressViewAction {
  94. @IBAction func compressButtonAction(_ sender: Any) {
  95. if self.export != nil {
  96. self.export!(self, self.data)
  97. }
  98. }
  99. }