// // KMCropPropertyController.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/11/20. // import Cocoa import KMComponentLibrary class KMCropPropertyController: NSViewController { @IBOutlet var contendView: NSView! //White Margin @IBOutlet var whiteMarginBGView: NSView! @IBOutlet var whiteMarginLabel: NSTextField! @IBOutlet var separateLabel: NSTextField! @IBOutlet var separateTip: ComponentToolTipsHelp! @IBOutlet var autoLabel: NSTextField! @IBOutlet var autoTipsView: ComponentToolTipsHelp! //PageSize @IBOutlet var pageSizeBGView: NSView! @IBOutlet var pageSizeLabel: NSTextField! @IBOutlet var sizeSyncButton: ComponentButton! @IBOutlet var sizeWidthInput: ComponentInputNumber! @IBOutlet var sizeHeightInput: ComponentInputNumber! //PageMargin @IBOutlet var pageMarginBGView: NSView! @IBOutlet var pageMarginLabel: NSTextField! @IBOutlet var pageLeftInput: ComponentInputNumber! @IBOutlet var pageTopInput: ComponentInputNumber! @IBOutlet var pageRightInput: ComponentInputNumber! @IBOutlet var pageBottomInput: ComponentInputNumber! //PageRange @IBOutlet var pageRangeBGView: NSView! @IBOutlet var pageRangeLabel: NSTextField! @IBOutlet var pangeRangeSelectView: KMPageRangeSelectView! @IBOutlet var cropButton: ComponentButton! private var syncChangeBounds: Bool = true //同步修改宽高 var pdfView: CPDFListView? override func viewDidLoad() { super.viewDidLoad() // Do view setup here. setupProperty() reloadData() } func setupProperty() { //White Margin whiteMarginLabel.stringValue = KMLocalizedString("Crop White Margins") whiteMarginLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") whiteMarginLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium") separateLabel.stringValue = KMLocalizedString("Separate") separateLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-form/colorText-label") separateLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-regular") autoLabel.stringValue = KMLocalizedString("Auto") autoLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-form/colorText-label") autoLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-regular") separateTip.toolTip = KMLocalizedString("separateTip tooltips") autoTipsView.toolTip = KMLocalizedString("autoTipsView tooltips") //PageSize whiteMarginLabel.stringValue = KMLocalizedString("Crop Page Size") whiteMarginLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") whiteMarginLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium") sizeSyncButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "sync_Change_unlock"), keepPressState: true) sizeSyncButton.properties.propertyInfo.leftIcon_press = NSImage(named: "sync_Change_lock") sizeSyncButton.setTarget(self, action: #selector(sizeSyncButtonClicked(_:))) sizeSyncButton.reloadData() sizeWidthInput.properties = ComponentInputNumberProperty(alignment: .center, size: .s, state: .normal, showPrefix: true, leftIcon: NSImage(named: "w_icon"), minSize: 0, maxSize: 1000, text:"100") sizeWidthInput.delegate = self sizeHeightInput.properties = ComponentInputNumberProperty(alignment: .center, size: .s, state: .normal, showPrefix: true, leftIcon: NSImage(named: "h_icon"), minSize: 0, maxSize: 1000, text:"100") sizeHeightInput.delegate = self //PageMargin whiteMarginLabel.stringValue = KMLocalizedString("Crop Page Margins") whiteMarginLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") whiteMarginLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium") pageLeftInput.properties = ComponentInputNumberProperty(size: .s, state: .normal, minSize: 0, maxSize: 1000, text:"0") pageTopInput.properties = ComponentInputNumberProperty(size: .s, state: .normal, minSize: 0, maxSize: 1000, text:"0") pageRightInput.properties = ComponentInputNumberProperty(size: .s, state: .normal, minSize: 0, maxSize: 1000, text:"0") pageBottomInput.properties = ComponentInputNumberProperty(size: .s, state: .normal, minSize: 0, maxSize: 1000, text:"0") pageLeftInput.delegate = self pageTopInput.delegate = self pageRightInput.delegate = self pageBottomInput.delegate = self //PageRange pageRangeLabel.stringValue = KMLocalizedString("Page Range") pageRangeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") pageRangeLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium") cropButton.properties = ComponentButtonProperty(type: .primary, size: .m, buttonText: KMLocalizedString("Apply"), keepPressState: false) } func reloadData() { guard let pdfView = self.pdfView else { return } guard let page = pdfView.currentSelectionPage() else { return } let pageBounds = page.bounds var selectionRect = pdfView.selectionRect //White Margin //PageSize sizeWidthInput.properties.maxSize = Int(pageBounds.size.width) sizeWidthInput.properties.text = String(format: "%.0f", selectionRect.size.width) sizeWidthInput.reloadData() sizeHeightInput.properties.maxSize = Int(pageBounds.size.height) sizeHeightInput.properties.text = String(format: "%.0f", selectionRect.size.height) sizeHeightInput.reloadData() //PageMargin pageLeftInput.properties.maxSize = Int(pageBounds.size.width) pageLeftInput.properties.text = String(format: "%.0f", selectionRect.origin.x) pageLeftInput.reloadData() pageRightInput.properties.maxSize = Int(pageBounds.size.width) pageRightInput.properties.text = String(format: "%.0f", pageBounds.size.width - CGRectGetMaxX(selectionRect)) pageRightInput.reloadData() pageTopInput.properties.maxSize = Int(pageBounds.size.height) pageTopInput.properties.text = String(format: "%.0f", pageBounds.size.height - CGRectGetMaxY(selectionRect)) pageTopInput.reloadData() pageBottomInput.properties.maxSize = Int(pageBounds.size.height) pageBottomInput.properties.text = String(format: "%.0f", selectionRect.origin.y) pageBottomInput.reloadData() //PageRange print(selectionRect) } //MARK: - Action @objc func sizeSyncButtonClicked(_ sender: ComponentButton) { syncChangeBounds = !syncChangeBounds if syncChangeBounds { sizeSyncButton.properties.state = .pressed } else { sizeSyncButton.properties.state = .normal } sizeSyncButton.reloadData() } } //MARK: - ComponentInputNumberDelegate extension KMCropPropertyController: ComponentInputNumberDelegate { } //MARK: - ComponentSelectDelegate extension KMCropPropertyController: ComponentSelectDelegate { }