KMWatermarkAdjectivePlainView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // KMWatermarkAdjectivePlainView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/17.
  6. //
  7. import Cocoa
  8. class KMWatermarkAdjectivePlainView: KMWatermarkAdjectiveBaseView {
  9. @IBOutlet weak var checkBox: NSButton!
  10. @IBOutlet weak var hImageView: NSImageView!
  11. @IBOutlet weak var hBox: NSBox!
  12. var hStepper: KMWatermarkAdjectiveStepper!
  13. @IBOutlet weak var vImageView: NSImageView!
  14. @IBOutlet weak var vBox: NSBox!
  15. var vStepper: KMWatermarkAdjectiveStepper!
  16. override init(frame frameRect: NSRect) {
  17. super.init(frame: frameRect)
  18. // initSubViews()
  19. }
  20. required init?(coder: NSCoder) {
  21. super.init(coder: coder)
  22. // initSubViews()
  23. }
  24. override func awakeFromNib() {
  25. super.awakeFromNib()
  26. initSubViews()
  27. }
  28. func initSubViews() {
  29. checkBox.title = NSLocalizedString("Tile", comment: "")
  30. checkBox.target = self
  31. checkBox.action = #selector(checkBoxAction)
  32. let hStepper = KMWatermarkAdjectiveStepper()
  33. hStepper.frame = self.hBox.contentView!.bounds
  34. hStepper.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
  35. self.hBox.contentView?.addSubview(hStepper)
  36. self.hStepper = hStepper
  37. hStepper.textField.doubleValue = 6
  38. hStepper.stepper.doubleValue = 6
  39. hStepper.valueDidChange = {
  40. (value: Double) in
  41. guard let callback = self.itemClick else {
  42. return
  43. }
  44. callback(2, value)
  45. }
  46. let vStepper = KMWatermarkAdjectiveStepper()
  47. vStepper.frame = self.vBox.contentView!.bounds
  48. vStepper.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
  49. self.vBox.contentView?.addSubview(vStepper)
  50. self.vStepper = vStepper
  51. vStepper.textField.doubleValue = 6
  52. vStepper.stepper.doubleValue = 6
  53. vStepper.valueDidChange = {
  54. (value: Double) in
  55. guard let callback = self.itemClick else {
  56. return
  57. }
  58. callback(3, value)
  59. }
  60. }
  61. @objc func checkBoxAction(sender: NSButton) {
  62. if (sender.state == .on) {
  63. self.hStepper.enabled = true
  64. self.vStepper.enabled = true
  65. } else {
  66. self.hStepper.enabled = false
  67. self.vStepper.enabled = false
  68. }
  69. guard let callback = itemClick else {
  70. return
  71. }
  72. callback(1, sender.state == .on)
  73. }
  74. override func setModel(model: KMWatermarkModel) {
  75. super.setModel(model: model)
  76. if (model.isTilePage) {
  77. self.checkBox.state = .on
  78. } else {
  79. self.checkBox.state = .off
  80. }
  81. self.checkBoxAction(sender: self.checkBox)
  82. self.hStepper.value = model.tileHorizontalSpace
  83. self.vStepper.value = model.tileVerticalSpace
  84. }
  85. }