KMWatermarkAdjectivePositionView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // KMWatermarkAdjectivePositionView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/17.
  6. //
  7. import Cocoa
  8. class KMWatermarkAdjectivePositionView: KMWatermarkAdjectiveBaseView {
  9. @IBOutlet weak var titleLabel: NSTextField!
  10. @IBOutlet weak var positionView: NSView!
  11. var myPositionView: KMWatermarkPositionView!
  12. @IBOutlet weak var xOffsetTitleLabel: NSTextField!
  13. @IBOutlet weak var xOffsetBox: NSBox!
  14. var xOffsetStepper: KMWatermarkAdjectiveStepper!
  15. @IBOutlet weak var yOffsetTitleLabel: NSTextField!
  16. @IBOutlet weak var yOffsetBox: NSBox!
  17. var yOffsetStepper: KMWatermarkAdjectiveStepper!
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. titleLabel.stringValue = NSLocalizedString("Position", comment: "")
  21. let positionView = KMWatermarkPositionView()
  22. positionView.frame = self.positionView.bounds
  23. positionView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
  24. self.positionView.addSubview(positionView)
  25. self.myPositionView = positionView
  26. positionView.itemClick = {
  27. (position: KMWatermarkPosition) in
  28. guard let callback = self.itemClick else {
  29. return
  30. }
  31. callback(1, position)
  32. }
  33. xOffsetTitleLabel.stringValue = NSLocalizedString("X", comment: "")
  34. let xStepper = KMWatermarkAdjectiveStepper()
  35. xStepper.frame = self.xOffsetBox.contentView!.bounds
  36. xStepper.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
  37. self.xOffsetBox.contentView?.addSubview(xStepper)
  38. self.xOffsetStepper = xStepper
  39. xStepper.valueDidChange = {
  40. (value: Double) in
  41. guard let callback = self.itemClick else {
  42. return
  43. }
  44. callback(2, value)
  45. }
  46. yOffsetTitleLabel.stringValue = NSLocalizedString("Y", comment: "")
  47. let yStepper = KMWatermarkAdjectiveStepper()
  48. yStepper.frame = self.yOffsetBox.contentView!.bounds
  49. yStepper.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
  50. self.yOffsetBox.contentView?.addSubview(yStepper)
  51. self.yOffsetStepper = yStepper
  52. yStepper.valueDidChange = {
  53. (value: Double) in
  54. guard let callback = self.itemClick else {
  55. return
  56. }
  57. callback(3, value)
  58. }
  59. }
  60. override func setModel(model: KMWatermarkModel) {
  61. super.setModel(model: model)
  62. if (model.horizontalMode == 0) {
  63. if (model.verticalMode == 0) {
  64. self.myPositionView.selectPosition(positon: .leftTop)
  65. } else if (model.verticalMode == 1) {
  66. self.myPositionView.selectPosition(positon: .top)
  67. } else if (model.verticalMode == 2) {
  68. self.myPositionView.selectPosition(positon: .rightTop)
  69. }
  70. }
  71. if (model.horizontalMode == 1) {
  72. if (model.verticalMode == 0) {
  73. self.myPositionView.selectPosition(positon: .leftMiddle)
  74. } else if (model.verticalMode == 1) {
  75. self.myPositionView.selectPosition(positon: .middle)
  76. } else if (model.verticalMode == 2) {
  77. self.myPositionView.selectPosition(positon: .rightMiddle)
  78. }
  79. }
  80. if (model.horizontalMode == 2) {
  81. if (model.verticalMode == 0) {
  82. self.myPositionView.selectPosition(positon: .leftBottom)
  83. } else if (model.verticalMode == 1) {
  84. self.myPositionView.selectPosition(positon: .bottom)
  85. } else if (model.verticalMode == 2) {
  86. self.myPositionView.selectPosition(positon: .rightBottom)
  87. }
  88. }
  89. self.xOffsetStepper.value = model.horizontalSpace
  90. self.yOffsetStepper.value = model.verticalSpace
  91. }
  92. }