KMRedactPropertyWindowController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // KMRedactPropertyWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/1/17.
  6. //
  7. import Cocoa
  8. class KMRedactPropertyWindowController: KMRedactBaseWindowController {
  9. var colorViewIndex: Int = 0
  10. var outsideColor: NSColor {
  11. get {
  12. return (self.contentView as! KMRedactPropertyContentView).outsideColorView.color!
  13. }
  14. }
  15. var fillColor: NSColor {
  16. get {
  17. return (self.contentView as! KMRedactPropertyContentView).fillColorView.color!
  18. }
  19. }
  20. var isOver: Bool {
  21. get {
  22. return (self.contentView as! KMRedactPropertyContentView).overTextCheck.state == .on
  23. }
  24. }
  25. var overText: String {
  26. get {
  27. return (self.contentView as! KMRedactPropertyContentView).overTextView.string
  28. }
  29. }
  30. var fontColor: NSColor {
  31. get {
  32. return (self.contentView as! KMRedactPropertyContentView).textColorView.color!
  33. }
  34. }
  35. var aligement: NSTextAlignment = .left
  36. var font: NSFont = NSFont(name: "Helvetica", size: 0)!
  37. override func windowDidLoad() {
  38. super.windowDidLoad()
  39. self.setContentSize(NSSize(width: 444, height: 527))
  40. self.topLineIsShow(false)
  41. self.titleLabel.stringValue = NSLocalizedString("Settings", comment: "")
  42. self.funcButton.title = NSLocalizedString("Apply", comment: "")
  43. self.funcButton.layer?.backgroundColor = NSColor.black.cgColor
  44. self.funcButton.attributedTitle = NSMutableAttributedString(string: self.funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
  45. let contentView = KMRedactPropertyContentView.createFromNib()
  46. contentView?.frame = self.contentBox.contentView!.bounds
  47. contentView?.autoresizingMask = [.width,.height]
  48. self.contentBox.contentView?.addSubview(contentView!)
  49. self.contentView = contentView
  50. contentView?.annotation = self.annotation
  51. contentView?.itemClick = { [weak self] index, value in
  52. if (index == 1) { /// 外观
  53. self?.colorViewIndex = 1
  54. self?.showColorPanel()
  55. return
  56. } else if (index == 2) { /// 填充
  57. self?.colorViewIndex = 2
  58. self?.showColorPanel()
  59. return
  60. } else if (index == 3) { /// 覆盖文本check
  61. } else if (index == 4) { /// 覆盖文本编辑
  62. } else if (index == 5) { /// 字体类型
  63. self?.font = NSFont(name: value as! String, size: (self?.font.pointSize)!)!
  64. } else if (index == 6) { /// 字体大小
  65. self?.font = NSFont(name: (self?.font.fontName)!, size: CGFloat(value as! Int))!
  66. } else if (index == 7) { /// 字体相关
  67. } else if (index == 8) { /// 字体颜色
  68. self?.colorViewIndex = 3
  69. self?.showColorPanel()
  70. return
  71. } else if (index == 9) { /// 字体aligement
  72. if (value as! Int == 0) {
  73. self?.aligement = .left
  74. } else if (value as! Int == 1) {
  75. self?.aligement = .center
  76. } else if (value as! Int == 2) {
  77. self?.aligement = .right
  78. }
  79. }
  80. }
  81. }
  82. // MARK: Private Methods
  83. @objc private func showColorPanel() {
  84. let panel = NSColorPanel.shared
  85. panel.setTarget(self)
  86. panel.setAction(#selector(colorPanelAction))
  87. panel.orderFront(nil)
  88. }
  89. @objc private func colorPanelAction(sender: NSColorPanel) {
  90. if (self.colorViewIndex == 1) { /// 外观
  91. (self.contentView as! KMRedactPropertyContentView).outsideColorView.color = sender.color
  92. } else if (self.colorViewIndex == 2) {
  93. (self.contentView as! KMRedactPropertyContentView).fillColorView.color = sender.color
  94. } else if (self.colorViewIndex == 3) {
  95. (self.contentView as! KMRedactPropertyContentView).textColorView.color = sender.color
  96. }
  97. }
  98. }