// // KMNAlignmentController.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/10/21. // import Cocoa import KMComponentLibrary @objc protocol KMNAlignmentControllerDelegate: AnyObject { @objc optional func alignmentControllerDidClick(_ controller: KMNAlignmentController, _ alignmentType: KMPDFActiveFormsAlignType) } class KMNAlignmentController: NSViewController { @IBOutlet var contendBox: NSBox! @IBOutlet var titleLabel: NSTextField! @IBOutlet var aligLeftButton: ComponentButton! @IBOutlet var aligLeftCenterButton: ComponentButton! @IBOutlet var aligRightButton: ComponentButton! @IBOutlet var aligTopButton: ComponentButton! @IBOutlet var aligTopCenterButton: ComponentButton! @IBOutlet var aligBottomButton: ComponentButton! @IBOutlet var aligHorizontalXButton: ComponentButton! @IBOutlet var aligVerticalYButton: ComponentButton! weak open var delegate: KMNAlignmentControllerDelegate? override func viewDidLoad() { super.viewDidLoad() // Do view setup here. titleLabel.stringValue = KMLocalizedString("Alignment") aligLeftButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligLeftButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignLeft") aligLeftCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligLeftCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignXCenter") aligRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligRightButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignRight") aligTopButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligTopButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignTop") aligTopCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligTopCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignYCenter") aligBottomButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligBottomButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignBottom") aligHorizontalXButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligHorizontalXButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignHorizonal") aligHorizontalXButton.properties.isDisabled = true aligVerticalYButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true, keepPressState: false) aligVerticalYButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignAverageVertical") aligVerticalYButton.properties.isDisabled = true for button in [aligLeftButton, aligLeftCenterButton, aligRightButton, aligTopButton, aligTopCenterButton, aligBottomButton, aligHorizontalXButton, aligVerticalYButton] { button?.reloadData() button?.setTarget(self, action: #selector(buttonClicked(_:))) } } func updateMulti(_ enable: Bool) { if enable == true { aligHorizontalXButton.properties.isDisabled = false aligVerticalYButton.properties.isDisabled = false } else { aligHorizontalXButton.properties.isDisabled = true aligVerticalYButton.properties.isDisabled = true } aligHorizontalXButton.reloadData() aligVerticalYButton.reloadData() } @objc func buttonClicked(_ sender: ComponentButton) { var alignType: KMPDFActiveFormsAlignType = .left if sender == aligLeftButton { alignType = .left } else if sender == aligLeftCenterButton { alignType = .horizontally } else if sender == aligRightButton { alignType = .right } else if sender == aligTopButton { alignType = .top } else if sender == aligTopCenterButton { alignType = .vertical } else if sender == aligBottomButton { alignType = .bottom } else if sender == aligHorizontalXButton { alignType = .disHorizontally } else if sender == aligVerticalYButton { alignType = .disVertical } delegate?.alignmentControllerDidClick?(self, alignType) } }