|
@@ -9,7 +9,7 @@ import Cocoa
|
|
import KMComponentLibrary
|
|
import KMComponentLibrary
|
|
|
|
|
|
class KMEditImageController: NSViewController {
|
|
class KMEditImageController: NSViewController {
|
|
-
|
|
|
|
|
|
+
|
|
@IBOutlet var scrollView: NSScrollView!
|
|
@IBOutlet var scrollView: NSScrollView!
|
|
@IBOutlet var contendView: NSView!
|
|
@IBOutlet var contendView: NSView!
|
|
|
|
|
|
@@ -27,7 +27,7 @@ class KMEditImageController: NSViewController {
|
|
@IBOutlet var rotateRightButton: ComponentButton!
|
|
@IBOutlet var rotateRightButton: ComponentButton!
|
|
@IBOutlet var flipVerticalButton: ComponentButton!
|
|
@IBOutlet var flipVerticalButton: ComponentButton!
|
|
@IBOutlet var flipHorizontalButton: ComponentButton!
|
|
@IBOutlet var flipHorizontalButton: ComponentButton!
|
|
-
|
|
|
|
|
|
+
|
|
@IBOutlet var opacityBGView: NSView!
|
|
@IBOutlet var opacityBGView: NSView!
|
|
@IBOutlet var opacityLabel: NSTextField!
|
|
@IBOutlet var opacityLabel: NSTextField!
|
|
@IBOutlet var opacitySlider: ComponentSlider!
|
|
@IBOutlet var opacitySlider: ComponentSlider!
|
|
@@ -37,6 +37,8 @@ class KMEditImageController: NSViewController {
|
|
@IBOutlet var replaceButton: ComponentButton!
|
|
@IBOutlet var replaceButton: ComponentButton!
|
|
@IBOutlet var ExtrackButton: ComponentButton!
|
|
@IBOutlet var ExtrackButton: ComponentButton!
|
|
|
|
|
|
|
|
+ private var syncChangeBounds: Bool = true //同步修改宽高
|
|
|
|
+
|
|
private var groupView: ComponentGroup!
|
|
private var groupView: ComponentGroup!
|
|
|
|
|
|
var pdfView: CPDFListView? {
|
|
var pdfView: CPDFListView? {
|
|
@@ -44,20 +46,20 @@ class KMEditImageController: NSViewController {
|
|
reloadData()
|
|
reloadData()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
var currentArea: CPDFEditImageArea?
|
|
var currentArea: CPDFEditImageArea?
|
|
|
|
|
|
//MARK: - func
|
|
//MARK: - func
|
|
override func viewDidAppear() {
|
|
override func viewDidAppear() {
|
|
super.viewDidAppear()
|
|
super.viewDidAppear()
|
|
-
|
|
|
|
|
|
+
|
|
opacitySlider.reloadData()
|
|
opacitySlider.reloadData()
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
override func viewDidLoad() {
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
super.viewDidLoad()
|
|
-
|
|
|
|
|
|
+
|
|
setupProperty()
|
|
setupProperty()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -67,38 +69,34 @@ class KMEditImageController: NSViewController {
|
|
sizeLabel.stringValue = KMLocalizedString("Size")
|
|
sizeLabel.stringValue = KMLocalizedString("Size")
|
|
sizeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
|
|
sizeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
|
|
sizeLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
|
|
sizeLabel.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 = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "sync_Change_unlock"), keepPressState: true)
|
|
- sizeSyncButton.properties.propertyInfo.rightIcon_press = NSImage(named: "sync_Change_lock")
|
|
|
|
- sizeSyncButton.setTarget(self, action: #selector(buttonClicked(_:)))
|
|
|
|
|
|
+ sizeSyncButton.properties.propertyInfo.leftIcon_press = NSImage(named: "sync_Change_lock")
|
|
|
|
+ sizeSyncButton.setTarget(self, action: #selector(sizeSyncButtonClicked(_:)))
|
|
sizeSyncButton.reloadData()
|
|
sizeSyncButton.reloadData()
|
|
|
|
|
|
sizeWidthInput.properties = ComponentInputNumberProperty(alignment: .center,
|
|
sizeWidthInput.properties = ComponentInputNumberProperty(alignment: .center,
|
|
size: .s,
|
|
size: .s,
|
|
state: .normal,
|
|
state: .normal,
|
|
- isError: false,
|
|
|
|
- showErrorInfo: false,
|
|
|
|
- isDisabled: true,
|
|
|
|
showPrefix: true,
|
|
showPrefix: true,
|
|
leftIcon: NSImage(named: "w_icon"),
|
|
leftIcon: NSImage(named: "w_icon"),
|
|
showSuffix: false,
|
|
showSuffix: false,
|
|
minSize: 1,
|
|
minSize: 1,
|
|
maxSize: 1000,
|
|
maxSize: 1000,
|
|
text:"100")
|
|
text:"100")
|
|
|
|
+ sizeWidthInput.delegate = self
|
|
|
|
|
|
sizeHeightInput.properties = ComponentInputNumberProperty(alignment: .center,
|
|
sizeHeightInput.properties = ComponentInputNumberProperty(alignment: .center,
|
|
- size: .s,
|
|
|
|
- state: .normal,
|
|
|
|
- isError: false,
|
|
|
|
- showErrorInfo: false,
|
|
|
|
- isDisabled: true,
|
|
|
|
- showPrefix: true,
|
|
|
|
- leftIcon: NSImage(named: "h_icon"),
|
|
|
|
- showSuffix: false,
|
|
|
|
- minSize: 1,
|
|
|
|
- maxSize: 1000,
|
|
|
|
- text:"100")
|
|
|
|
-
|
|
|
|
|
|
+ size: .s,
|
|
|
|
+ state: .normal,
|
|
|
|
+ showPrefix: true,
|
|
|
|
+ leftIcon: NSImage(named: "h_icon"),
|
|
|
|
+ showSuffix: false,
|
|
|
|
+ minSize: 1,
|
|
|
|
+ maxSize: 1000,
|
|
|
|
+ text:"100")
|
|
|
|
+ sizeHeightInput.delegate = self
|
|
|
|
+
|
|
//Rotate
|
|
//Rotate
|
|
rotateLabel.stringValue = KMLocalizedString("Rotate & Flip")
|
|
rotateLabel.stringValue = KMLocalizedString("Rotate & Flip")
|
|
rotateLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
|
|
rotateLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
|
|
@@ -158,7 +156,7 @@ class KMEditImageController: NSViewController {
|
|
|
|
|
|
cropButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, buttonText: KMLocalizedString("Crop"), keepPressState: false)
|
|
cropButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, buttonText: KMLocalizedString("Crop"), keepPressState: false)
|
|
cropButton.setTarget(self, action: #selector(buttonClicked(_:)))
|
|
cropButton.setTarget(self, action: #selector(buttonClicked(_:)))
|
|
-
|
|
|
|
|
|
+
|
|
replaceButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, buttonText: KMLocalizedString("Replace"), keepPressState: false)
|
|
replaceButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, buttonText: KMLocalizedString("Replace"), keepPressState: false)
|
|
replaceButton.setTarget(self, action: #selector(buttonClicked(_:)))
|
|
replaceButton.setTarget(self, action: #selector(buttonClicked(_:)))
|
|
|
|
|
|
@@ -180,8 +178,33 @@ class KMEditImageController: NSViewController {
|
|
}
|
|
}
|
|
|
|
|
|
if let area = currentArea {
|
|
if let area = currentArea {
|
|
|
|
+ //Size
|
|
|
|
+ if syncChangeBounds {
|
|
|
|
+ sizeSyncButton.properties.state = .pressed
|
|
|
|
+ } else {
|
|
|
|
+ sizeSyncButton.properties.state = .normal
|
|
|
|
+ }
|
|
|
|
+ sizeSyncButton.reloadData()
|
|
|
|
|
|
|
|
+ let areaFrame = area.bounds
|
|
|
|
+ sizeWidthInput.properties.text = String(format: "%.1f", areaFrame.size.width)
|
|
|
|
+ sizeWidthInput.reloadData()
|
|
|
|
|
|
|
|
+ sizeHeightInput.properties.text = String(format: "%.1f", areaFrame.size.height)
|
|
|
|
+ sizeHeightInput.reloadData()
|
|
|
|
+
|
|
|
|
+ //Rotate
|
|
|
|
+ if let rotates = pdfView?.km_editAreasRotates([area]) {
|
|
|
|
+ if rotates.count > 0 {
|
|
|
|
+ var rotate = rotates.first ?? 1
|
|
|
|
+
|
|
|
|
+ rotateSelect.properties.text = String(format: "%.0f%@", rotate, "°")
|
|
|
|
+ rotateSelect.reloadData()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Opacity
|
|
if let opacitys = pdfView?.km_editAreasOpacitys([area]) {
|
|
if let opacitys = pdfView?.km_editAreasOpacitys([area]) {
|
|
if opacitys.count > 0 {
|
|
if opacitys.count > 0 {
|
|
var opacity = opacitys.first ?? 1
|
|
var opacity = opacitys.first ?? 1
|
|
@@ -196,15 +219,6 @@ class KMEditImageController: NSViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if let rotates = pdfView?.km_editAreasRotates([area]) {
|
|
|
|
- if rotates.count > 0 {
|
|
|
|
- var rotate = rotates.first ?? 1
|
|
|
|
-
|
|
|
|
- rotateSelect.properties.text = String(format: "%.0f%@", rotate, "°")
|
|
|
|
- rotateSelect.reloadData()
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
if pdfView?.isEditImage == true {
|
|
if pdfView?.isEditImage == true {
|
|
cropButton.properties.buttonText = KMLocalizedString("Cancel Crop")
|
|
cropButton.properties.buttonText = KMLocalizedString("Cancel Crop")
|
|
@@ -219,10 +233,19 @@ class KMEditImageController: NSViewController {
|
|
}
|
|
}
|
|
|
|
|
|
//MARK: - Action
|
|
//MARK: - Action
|
|
|
|
+ @objc func sizeSyncButtonClicked(_ sender: ComponentButton) {
|
|
|
|
+ syncChangeBounds = !syncChangeBounds
|
|
|
|
+
|
|
|
|
+ if syncChangeBounds {
|
|
|
|
+ sizeSyncButton.properties.state = .pressed
|
|
|
|
+ } else {
|
|
|
|
+ sizeSyncButton.properties.state = .normal
|
|
|
|
+ }
|
|
|
|
+ sizeSyncButton.reloadData()
|
|
|
|
+ }
|
|
|
|
+
|
|
@objc func buttonClicked(_ sender: ComponentButton) {
|
|
@objc func buttonClicked(_ sender: ComponentButton) {
|
|
- if sender == sizeSyncButton {
|
|
|
|
-
|
|
|
|
- } else if sender == rotateLeftButton {
|
|
|
|
|
|
+ if sender == rotateLeftButton {
|
|
self.pdfView?.leftRotateAction()
|
|
self.pdfView?.leftRotateAction()
|
|
} else if sender == rotateRightButton {
|
|
} else if sender == rotateRightButton {
|
|
self.pdfView?.rightRotateAction()
|
|
self.pdfView?.rightRotateAction()
|
|
@@ -294,6 +317,70 @@ class KMEditImageController: NSViewController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+extension KMEditImageController: ComponentInputNumberDelegate {
|
|
|
|
+ func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
|
|
|
|
+ if inputNumber == sizeWidthInput {
|
|
|
|
+ let areas = self.pdfView?.km_editingImageAreas() ?? []
|
|
|
|
+ self.pdfView?.editAreaBoundUpdating = true
|
|
|
|
+ for area in areas {
|
|
|
|
+ var bounds = area.bounds
|
|
|
|
+ var width = inputNumber?.properties.text?.stringToCGFloat() ?? 0
|
|
|
|
+ if width == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let pageBounds = area.page?.bounds ?? .zero
|
|
|
|
+ if width > NSWidth(pageBounds) {
|
|
|
|
+ width = NSWidth(pageBounds)
|
|
|
|
+ let value = String(format: "%.1f", width)
|
|
|
|
+ }
|
|
|
|
+ let wOffset = width-bounds.size.width
|
|
|
|
+ bounds.origin.x = max(0, bounds.origin.x-wOffset * 0.5)
|
|
|
|
+ bounds.origin.x = min(bounds.origin.x, pageBounds.size.width-width)
|
|
|
|
+
|
|
|
|
+ if syncChangeBounds {
|
|
|
|
+ var scale: CGFloat = 0
|
|
|
|
+ if bounds.size.width != 0 {
|
|
|
|
+ scale = width / bounds.size.width
|
|
|
|
+ }
|
|
|
|
+ bounds.size.height *= scale
|
|
|
|
+ bounds.size.width = width
|
|
|
|
+ } else {
|
|
|
|
+ bounds.size.width = width
|
|
|
|
+ }
|
|
|
|
+ self.pdfView?.setBoundsEditArea(area, withBounds: bounds)
|
|
|
|
+ }
|
|
|
|
+ } else if inputNumber == sizeHeightInput {
|
|
|
|
+ let areas = self.pdfView?.km_editingImageAreas() ?? []
|
|
|
|
+ self.pdfView?.editAreaBoundUpdating = true
|
|
|
|
+ for area in areas {
|
|
|
|
+ var bounds = area.bounds
|
|
|
|
+ var height = inputNumber?.properties.text?.stringToCGFloat() ?? 0
|
|
|
|
+ if height == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let pageBounds = area.page?.bounds ?? .zero
|
|
|
|
+ if height > NSHeight(pageBounds) {
|
|
|
|
+ height = NSHeight(pageBounds)
|
|
|
|
+ }
|
|
|
|
+ let hOffset = height-bounds.size.height
|
|
|
|
+ bounds.origin.y = max(0, bounds.origin.y-hOffset * 0.5)
|
|
|
|
+ bounds.origin.y = min(bounds.origin.y, pageBounds.size.height-height)
|
|
|
|
+ if syncChangeBounds { // 寛高约束
|
|
|
|
+ var scale: CGFloat = 0
|
|
|
|
+ if bounds.size.height != 0 {
|
|
|
|
+ scale = height / bounds.size.height
|
|
|
|
+ }
|
|
|
|
+ bounds.size.width *= scale
|
|
|
|
+ bounds.size.height = height
|
|
|
|
+ } else {
|
|
|
|
+ bounds.size.height = height
|
|
|
|
+ }
|
|
|
|
+ self.pdfView?.setBoundsEditArea(area, withBounds: bounds)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ reloadData()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
//MARK: - ComponentSelectDelegate
|
|
//MARK: - ComponentSelectDelegate
|
|
extension KMEditImageController: ComponentSelectDelegate {
|
|
extension KMEditImageController: ComponentSelectDelegate {
|
|
@@ -344,7 +431,7 @@ extension KMEditImageController: ComponentSelectDelegate {
|
|
|
|
|
|
//MARK: - ComponentCColorDelegate
|
|
//MARK: - ComponentCColorDelegate
|
|
extension KMEditImageController: ComponentCColorDelegate {
|
|
extension KMEditImageController: ComponentCColorDelegate {
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
//MARK: - ComponentSliderDelegate
|
|
//MARK: - ComponentSliderDelegate
|