KMWatermarkFileOutsideView.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // KMWatermarkFileOutsideView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/22.
  6. //
  7. import Cocoa
  8. class KMWatermarkFileOutsideView: KMWatermarkAdjectiveBaseView {
  9. var titleLabel: NSTextField!
  10. var rotateButton: NSButton!
  11. var rotateComboBox: NSView!
  12. var alphaButton: NSButton!
  13. var alphaComboBox: NSComboBox!
  14. var pageAboveComboBox: NSComboBox!
  15. var pageTargetScale: NSButton!
  16. var pageTargetScaleComboBox: NSComboBox!
  17. var rComboBox: NSComboBox!
  18. override var isFlipped: Bool {
  19. return true
  20. }
  21. override init(frame frameRect: NSRect) {
  22. super.init(frame: frameRect)
  23. self.titleLabel = NSTextField(labelWithString: "")
  24. self.rotateButton = NSButton()
  25. self.rotateComboBox = NSView()
  26. self.alphaButton = NSButton()
  27. self.alphaComboBox = NSComboBox()
  28. self.pageAboveComboBox = NSComboBox()
  29. self.pageTargetScale = NSButton(checkboxWithTitle: NSLocalizedString("Appearance", comment: ""), target: self, action: #selector(pageTargetScaleAction))
  30. self.pageTargetScaleComboBox = NSComboBox()
  31. self.addSubview(self.titleLabel)
  32. self.addSubview(self.rotateButton)
  33. self.addSubview(self.rotateComboBox)
  34. self.addSubview(self.alphaButton)
  35. self.addSubview(self.alphaComboBox)
  36. self.addSubview(self.pageAboveComboBox)
  37. self.addSubview(self.pageTargetScale)
  38. self.addSubview(self.pageTargetScaleComboBox)
  39. self.rComboBox = NSComboBox()
  40. self.addSubview(self.rComboBox)
  41. titleLabel.stringValue = NSLocalizedString("Appearance", comment: "")
  42. rotateButton.isBordered = false
  43. rotateButton.title = NSLocalizedString("", comment: "")
  44. rComboBox.isEditable = false
  45. rComboBox.delegate = self
  46. rComboBox.removeAllItems()
  47. for i in 0 ... 360 {
  48. rComboBox.addItem(withObjectValue: i)
  49. }
  50. rComboBox.selectItem(withObjectValue: 0)
  51. alphaButton.isBordered = false
  52. alphaButton.title = NSLocalizedString("", comment: "")
  53. alphaComboBox.isEditable = false
  54. alphaComboBox.delegate = self
  55. alphaComboBox.removeAllItems()
  56. for i in 0 ... 100 {
  57. alphaComboBox.addItem(withObjectValue: "\(i)%")
  58. }
  59. alphaComboBox.selectItem(withObjectValue: "100%")
  60. pageAboveComboBox.isEditable = false
  61. pageAboveComboBox.delegate = self
  62. pageAboveComboBox.removeAllItems()
  63. pageAboveComboBox.addItems(withObjectValues: [NSLocalizedString("At the top of the page", comment: ""),NSLocalizedString("At the top of the page", comment: "")])
  64. pageAboveComboBox.selectItem(at: 0)
  65. self.pageTargetScaleComboBox.delegate = self
  66. self.pageTargetScaleComboBox.removeAllItems()
  67. for i in 0 ... 100 {
  68. pageTargetScaleComboBox.addItem(withObjectValue: "\(i)%")
  69. }
  70. self.pageTargetScaleComboBox.selectItem(withObjectValue: "50%")
  71. }
  72. required init?(coder: NSCoder) {
  73. super.init(coder: coder)
  74. }
  75. override func layout() {
  76. super.layout()
  77. let width: CGFloat = NSWidth(self.bounds)
  78. let heigth: CGFloat = NSHeight(self.bounds)
  79. let leftMargin: CGFloat = 16
  80. self.titleLabel.frame = NSMakeRect(leftMargin, 0, width-2*leftMargin, 16)
  81. let rotateY = self.titleLabel.frame.maxY+10
  82. self.rotateButton.frame = NSMakeRect(leftMargin, rotateY, 22, 22)
  83. self.rComboBox.frame = NSMakeRect(self.rotateButton.frame.maxX+10, rotateY, 80, 22)
  84. self.alphaButton.frame = NSMakeRect(self.rComboBox.frame.maxX+10, rotateY, 22, 22)
  85. self.alphaComboBox.frame = NSMakeRect(self.alphaButton.frame.maxX+10, rotateY, 80, 22)
  86. self.pageAboveComboBox.frame = NSMakeRect(leftMargin, self.rotateButton.frame.maxY+10, width-1*leftMargin, 22)
  87. self.pageTargetScale.frame = NSMakeRect(leftMargin, self.pageAboveComboBox.frame.maxY+10, width-2*leftMargin, 16)
  88. self.pageTargetScaleComboBox.frame = NSMakeRect(leftMargin, self.pageTargetScale.frame.maxY+10, 100, 22)
  89. }
  90. override func setModel(model: KMWatermarkModel) {
  91. super.setModel(model: model)
  92. rComboBox.stringValue = "\(abs(Int(-model.rotation)))"
  93. alphaComboBox.stringValue = "\(Int(model.opacity*100))%"
  94. if (model.isFront) {
  95. pageAboveComboBox.selectItem(at: 0)
  96. } else {
  97. pageAboveComboBox.selectItem(at: 1)
  98. }
  99. }
  100. @objc func pageTargetScaleAction(sender: NSButton) {
  101. }
  102. }
  103. extension KMWatermarkFileOutsideView: NSComboBoxDelegate {
  104. func comboBoxSelectionDidChange(_ notification: Notification) {
  105. if (rComboBox.isEqual(to: notification.object)) { /// 旋转
  106. if (rComboBox.indexOfSelectedItem < 0) {
  107. return
  108. }
  109. guard let callback = itemClick else {
  110. return
  111. }
  112. callback(1, rComboBox.indexOfSelectedItem)
  113. } else if (alphaComboBox.isEqual(to: notification.object)) { /// 透明度
  114. if (alphaComboBox.indexOfSelectedItem < 0) {
  115. return
  116. }
  117. guard let callback = itemClick else {
  118. return
  119. }
  120. callback(2, alphaComboBox.indexOfSelectedItem)
  121. } else if (pageAboveComboBox.isEqual(to: notification.object)) {
  122. if (pageAboveComboBox.indexOfSelectedItem < 0) {
  123. return
  124. }
  125. guard let callback = itemClick else {
  126. return
  127. }
  128. callback(3, pageAboveComboBox.indexOfSelectedItem)
  129. } else if (pageTargetScaleComboBox.isEqual(to: notification.object)) {
  130. if (pageTargetScaleComboBox.indexOfSelectedItem < 0) {
  131. return
  132. }
  133. guard let callback = itemClick else {
  134. return
  135. }
  136. callback(4, pageTargetScaleComboBox.indexOfSelectedItem)
  137. }
  138. }
  139. }