KMNAlignmentController.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // KMNAlignmentController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/10/21.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. @objc protocol KMNAlignmentControllerDelegate: AnyObject {
  10. @objc optional func alignmentControllerDidClick(_ controller: KMNAlignmentController, _ alignmentType: KMPDFActiveFormsAlignType)
  11. }
  12. class KMNAlignmentController: NSViewController {
  13. @IBOutlet var contendBox: NSBox!
  14. @IBOutlet var titleLabel: NSTextField!
  15. @IBOutlet var contendLeftConst: NSLayoutConstraint!
  16. @IBOutlet var aligLeftButton: ComponentButton!
  17. @IBOutlet var aligLeftCenterButton: ComponentButton!
  18. @IBOutlet var aligRightButton: ComponentButton!
  19. @IBOutlet var aligTopButton: ComponentButton!
  20. @IBOutlet var aligTopCenterButton: ComponentButton!
  21. @IBOutlet var aligBottomButton: ComponentButton!
  22. @IBOutlet var aligHorizontalXButton: ComponentButton!
  23. @IBOutlet var aligVerticalYButton: ComponentButton!
  24. weak open var delegate: KMNAlignmentControllerDelegate?
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. // Do view setup here.
  28. titleLabel.stringValue = KMLocalizedString("Alignment")
  29. aligLeftButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  30. aligLeftButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignLeft")
  31. aligLeftCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  32. aligLeftCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignXCenter")
  33. aligRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  34. aligRightButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignRight")
  35. aligTopButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  36. aligTopButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignTop")
  37. aligTopCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  38. aligTopCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignYCenter")
  39. aligBottomButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  40. aligBottomButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignBottom")
  41. aligHorizontalXButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  42. aligHorizontalXButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignHorizonal")
  43. aligHorizontalXButton.properties.isDisabled = true
  44. aligVerticalYButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  45. aligVerticalYButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignAverageVertical")
  46. aligVerticalYButton.properties.isDisabled = true
  47. for button in [aligLeftButton, aligLeftCenterButton, aligRightButton, aligTopButton,
  48. aligTopCenterButton, aligBottomButton, aligHorizontalXButton, aligVerticalYButton] {
  49. button?.reloadData()
  50. button?.setTarget(self, action: #selector(buttonClicked(_:)))
  51. }
  52. self.contendLeftConst.constant = 0
  53. }
  54. func updateMulti(_ enable: Bool) {
  55. if enable == true {
  56. aligHorizontalXButton.properties.isDisabled = false
  57. aligVerticalYButton.properties.isDisabled = false
  58. } else {
  59. aligHorizontalXButton.properties.isDisabled = true
  60. aligVerticalYButton.properties.isDisabled = true
  61. }
  62. aligHorizontalXButton.reloadData()
  63. aligVerticalYButton.reloadData()
  64. }
  65. func updateContendLeftConst(_ const: CGFloat) {
  66. self.contendLeftConst.constant = const
  67. }
  68. @objc func buttonClicked(_ sender: ComponentButton) {
  69. var alignType: KMPDFActiveFormsAlignType = .left
  70. if sender == aligLeftButton {
  71. alignType = .left
  72. } else if sender == aligLeftCenterButton {
  73. alignType = .horizontally
  74. } else if sender == aligRightButton {
  75. alignType = .right
  76. } else if sender == aligTopButton {
  77. alignType = .top
  78. } else if sender == aligTopCenterButton {
  79. alignType = .vertical
  80. } else if sender == aligBottomButton {
  81. alignType = .bottom
  82. } else if sender == aligHorizontalXButton {
  83. alignType = .disHorizontally
  84. } else if sender == aligVerticalYButton {
  85. alignType = .disVertical
  86. }
  87. delegate?.alignmentControllerDidClick?(self, alignType)
  88. }
  89. }