KMNAlignmentController.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 aligLeftButton: ComponentButton!
  16. @IBOutlet var aligLeftCenterButton: ComponentButton!
  17. @IBOutlet var aligRightButton: ComponentButton!
  18. @IBOutlet var aligTopButton: ComponentButton!
  19. @IBOutlet var aligTopCenterButton: ComponentButton!
  20. @IBOutlet var aligBottomButton: ComponentButton!
  21. @IBOutlet var aligHorizontalXButton: ComponentButton!
  22. @IBOutlet var aligVerticalYButton: ComponentButton!
  23. weak open var delegate: KMNAlignmentControllerDelegate?
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. // Do view setup here.
  27. titleLabel.stringValue = KMLocalizedString("Alignment")
  28. aligLeftButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  29. aligLeftButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignLeft")
  30. aligLeftCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  31. aligLeftCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignXCenter")
  32. aligRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  33. aligRightButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignRight")
  34. aligTopButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  35. aligTopButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignTop")
  36. aligTopCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  37. aligTopCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignYCenter")
  38. aligBottomButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  39. aligBottomButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignBottom")
  40. aligHorizontalXButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  41. aligHorizontalXButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignHorizonal")
  42. aligHorizontalXButton.properties.isDisabled = true
  43. aligVerticalYButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false)
  44. aligVerticalYButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignAverageVertical")
  45. aligVerticalYButton.properties.isDisabled = true
  46. for button in [aligLeftButton, aligLeftCenterButton, aligRightButton, aligTopButton,
  47. aligTopCenterButton, aligBottomButton, aligHorizontalXButton, aligVerticalYButton] {
  48. button?.reloadData()
  49. button?.setTarget(self, action: #selector(buttonClicked(_:)))
  50. }
  51. }
  52. func updateMulti(_ enable: Bool) {
  53. if enable == true {
  54. aligHorizontalXButton.properties.isDisabled = false
  55. aligVerticalYButton.properties.isDisabled = false
  56. } else {
  57. aligHorizontalXButton.properties.isDisabled = true
  58. aligVerticalYButton.properties.isDisabled = true
  59. }
  60. aligHorizontalXButton.reloadData()
  61. aligVerticalYButton.reloadData()
  62. }
  63. @objc func buttonClicked(_ sender: ComponentButton) {
  64. var alignType: KMPDFActiveFormsAlignType = .left
  65. if sender == aligLeftButton {
  66. alignType = .left
  67. } else if sender == aligLeftCenterButton {
  68. alignType = .horizontally
  69. } else if sender == aligRightButton {
  70. alignType = .right
  71. } else if sender == aligTopButton {
  72. alignType = .top
  73. } else if sender == aligTopCenterButton {
  74. alignType = .vertical
  75. } else if sender == aligBottomButton {
  76. alignType = .bottom
  77. } else if sender == aligHorizontalXButton {
  78. alignType = .disHorizontally
  79. } else if sender == aligVerticalYButton {
  80. alignType = .disVertical
  81. }
  82. delegate?.alignmentControllerDidClick?(self, alignType)
  83. }
  84. }