// // KMWatermarkFileOutsideView.swift // PDF Master // // Created by tangchao on 2022/12/22. // import Cocoa class KMWatermarkFileOutsideView: KMWatermarkAdjectiveBaseView { var titleLabel: NSTextField! var rotateButton: NSButton! var rotateComboBox: NSView! var alphaButton: NSButton! var alphaComboBox: NSComboBox! var pageAboveComboBox: NSComboBox! var pageTargetScale: NSButton! var pageTargetScaleComboBox: NSComboBox! var rComboBox: NSComboBox! override var isFlipped: Bool { return true } override init(frame frameRect: NSRect) { super.init(frame: frameRect) self.titleLabel = NSTextField(labelWithString: "") self.rotateButton = NSButton() self.rotateComboBox = NSView() self.alphaButton = NSButton() self.alphaComboBox = NSComboBox() self.pageAboveComboBox = NSComboBox() self.pageTargetScale = NSButton(checkboxWithTitle: NSLocalizedString("Appearance", comment: ""), target: self, action: #selector(pageTargetScaleAction)) self.pageTargetScaleComboBox = NSComboBox() self.addSubview(self.titleLabel) self.addSubview(self.rotateButton) self.addSubview(self.rotateComboBox) self.addSubview(self.alphaButton) self.addSubview(self.alphaComboBox) self.addSubview(self.pageAboveComboBox) self.addSubview(self.pageTargetScale) self.addSubview(self.pageTargetScaleComboBox) self.rComboBox = NSComboBox() self.addSubview(self.rComboBox) titleLabel.stringValue = NSLocalizedString("Appearance", comment: "") rotateButton.isBordered = false rotateButton.title = NSLocalizedString("", comment: "") rComboBox.isEditable = false rComboBox.delegate = self rComboBox.removeAllItems() for i in 0 ... 360 { rComboBox.addItem(withObjectValue: i) } rComboBox.selectItem(withObjectValue: 0) alphaButton.isBordered = false alphaButton.title = NSLocalizedString("", comment: "") alphaComboBox.isEditable = false alphaComboBox.delegate = self alphaComboBox.removeAllItems() for i in 0 ... 100 { alphaComboBox.addItem(withObjectValue: "\(i)%") } alphaComboBox.selectItem(withObjectValue: "100%") pageAboveComboBox.isEditable = false pageAboveComboBox.delegate = self pageAboveComboBox.removeAllItems() pageAboveComboBox.addItems(withObjectValues: [NSLocalizedString("At the top of the page", comment: ""),NSLocalizedString("At the top of the page", comment: "")]) pageAboveComboBox.selectItem(at: 0) self.pageTargetScaleComboBox.delegate = self self.pageTargetScaleComboBox.removeAllItems() for i in 0 ... 100 { pageTargetScaleComboBox.addItem(withObjectValue: "\(i)%") } self.pageTargetScaleComboBox.selectItem(withObjectValue: "50%") } required init?(coder: NSCoder) { super.init(coder: coder) } override func layout() { super.layout() let width: CGFloat = NSWidth(self.bounds) let heigth: CGFloat = NSHeight(self.bounds) let leftMargin: CGFloat = 16 self.titleLabel.frame = NSMakeRect(leftMargin, 0, width-2*leftMargin, 16) let rotateY = self.titleLabel.frame.maxY+10 self.rotateButton.frame = NSMakeRect(leftMargin, rotateY, 22, 22) self.rComboBox.frame = NSMakeRect(self.rotateButton.frame.maxX+10, rotateY, 80, 22) self.alphaButton.frame = NSMakeRect(self.rComboBox.frame.maxX+10, rotateY, 22, 22) self.alphaComboBox.frame = NSMakeRect(self.alphaButton.frame.maxX+10, rotateY, 80, 22) self.pageAboveComboBox.frame = NSMakeRect(leftMargin, self.rotateButton.frame.maxY+10, width-1*leftMargin, 22) self.pageTargetScale.frame = NSMakeRect(leftMargin, self.pageAboveComboBox.frame.maxY+10, width-2*leftMargin, 16) self.pageTargetScaleComboBox.frame = NSMakeRect(leftMargin, self.pageTargetScale.frame.maxY+10, 100, 22) } override func setModel(model: KMWatermarkModel) { super.setModel(model: model) rComboBox.stringValue = "\(abs(Int(-model.rotation)))" alphaComboBox.stringValue = "\(Int(model.opacity*100))%" if (model.isFront) { pageAboveComboBox.selectItem(at: 0) } else { pageAboveComboBox.selectItem(at: 1) } } @objc func pageTargetScaleAction(sender: NSButton) { } } extension KMWatermarkFileOutsideView: NSComboBoxDelegate { func comboBoxSelectionDidChange(_ notification: Notification) { if (rComboBox.isEqual(to: notification.object)) { /// 旋转 if (rComboBox.indexOfSelectedItem < 0) { return } guard let callback = itemClick else { return } callback(1, rComboBox.indexOfSelectedItem) } else if (alphaComboBox.isEqual(to: notification.object)) { /// 透明度 if (alphaComboBox.indexOfSelectedItem < 0) { return } guard let callback = itemClick else { return } callback(2, alphaComboBox.indexOfSelectedItem) } else if (pageAboveComboBox.isEqual(to: notification.object)) { if (pageAboveComboBox.indexOfSelectedItem < 0) { return } guard let callback = itemClick else { return } callback(3, pageAboveComboBox.indexOfSelectedItem) } else if (pageTargetScaleComboBox.isEqual(to: notification.object)) { if (pageTargetScaleComboBox.indexOfSelectedItem < 0) { return } guard let callback = itemClick else { return } callback(4, pageTargetScaleComboBox.indexOfSelectedItem) } } }