12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301 |
- //
- // KMEditImagePropertyViewController.swift
- // PDF Reader Pro
- //
- // Created by lxy on 2022/12/28.
- //
- import Cocoa
- public enum KMOperationState {
- case none
- case began
- case changed
- case ended
- }
- enum KMEditImagePropertyViewControllerChangeType {
- case rotate
- case flip
- case add
- case move
- }
- protocol KMEditImagePropertyViewControllerDelegate: NSObject {
- func editImagePropertyViewControllerDidChanged(controller: KMEditImagePropertyViewController, type: KMEditImagePropertyViewControllerChangeType)
- }
- class KMEditImagePropertyViewController: NSViewController {
- @IBOutlet weak var backgroundView: NSView!
- @IBOutlet weak var titleLabel: NSTextField!
-
- @IBOutlet weak var headerBox: NSBox!
- @IBOutlet weak var headerBoxHeight: NSLayoutConstraint!
-
- @IBOutlet weak var whTitleLabel: NSTextField!
- @IBOutlet weak var wTextFieldItemView: KMCustomTextField!
- @IBOutlet weak var whBox: NSBox!
- @IBOutlet weak var hTextFieldItemView: KMCustomTextField!
-
- var whVC: KMDesignButton?
- private var whState_: KMDesignTokenState = .None
-
- @IBOutlet weak var rotateTitleLabel: NSTextField!
- @IBOutlet weak var rotateTextFieldItemView: KMDesignTextField!
- @IBOutlet weak var leftRotateBox: NSBox!
- @IBOutlet weak var rightRotateBox: NSBox!
-
- var leftRotateVC: KMDesignButton?
- var rightRotateVC: KMDesignButton?
-
- @IBOutlet weak var opacityTitleLabel: NSTextField!
- @IBOutlet weak var opacitySlider: NSSlider!
- @IBOutlet weak var opacityBox: NSBox!
- @IBOutlet weak var opacityBoxBottomMaginConstraint: NSLayoutConstraint!
- @IBOutlet weak var opacityBoxTopConstraint: NSLayoutConstraint!
-
- @IBOutlet weak var turnOverBox: NSBox!
- @IBOutlet weak var turnOverTitleLabel: NSTextField!
- @IBOutlet weak var reverseXBox: NSView!
- @IBOutlet weak var reverseYBox: NSView!
-
- var reverseXVC: KMDesignButton?
- var reverseYVC: KMDesignButton?
-
- @IBOutlet weak var cropBox: NSBox!
- @IBOutlet weak var confirmBox: NSBox!
- @IBOutlet weak var cancelBox: NSBox!
- @IBOutlet weak var replaceBox: NSBox!
- @IBOutlet weak var exportBox: NSBox!
- @IBOutlet weak var opacityBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var buttonBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var buttonBox: NSBox!
-
- @IBOutlet weak var alignmentView: KMEditPropertyAlignmentView!
- @IBOutlet weak var alignmentViewTopConstraint: NSLayoutConstraint!
-
- //NO Image
-
- @IBOutlet weak var noImageView: NSImageView!
- @IBOutlet weak var noTitleLabel: NSTextField!
- @IBOutlet weak var noSubtitleLabel: NSTextField!
- @IBOutlet weak var noBackgroundView: NSView!
-
- var rotateLeftVC: KMDesignPropertySelector?
- var rotateRightVC: KMDesignPropertySelector?
- var flipHorizontalVC: KMDesignPropertySelector?
- var flipVerticalVC: KMDesignPropertySelector?
- var opacityVC: KMDesignSelect?
-
- @IBOutlet weak var toolsTitleLabel: NSTextField!
-
- var cropVC: KMDesignButton?
- var confirmVC: KMDesignButton?
- var cancelVC: KMDesignButton?
- var replaceVC: KMDesignButton?
- var exportVC: KMDesignButton?
-
- var imagesAreas : [CPDFEditImageArea] = []
- var listView : CPDFListView!
-
- var editingAreas: [Any] {
- get {
- return self.listView.editingAreas() ?? []
- }
- }
-
- weak var delegate: KMEditImagePropertyViewControllerDelegate?
-
- weak var handdler: KMEditPDfHanddler?
-
- @objc func changeEffectiveAppearance() {
- print("changeEffectiveAppearance")
- let isDarkModel = NSView.isDarkModel()
- if isDarkModel {
- self.view.appearance = NSAppearance(named: .darkAqua)
- } else {
- self.view.appearance = NSAppearance(named: .aqua)
- }
- self.updateUI()
- }
-
- // func updateUI() {
- // let isDarkModel = NSView.isDarkModel()
- // if isDarkModel {
- // self.backgroundView.backgroundColor(NSColor.km_init(hex: "#252526"))
- // self.noBackgroundView.backgroundColor(NSColor.km_init(hex: "#252526"))
- // } else {
- // self.backgroundView.backgroundColor(NSColor.km_init(hex: "#FAFAFA"))
- // self.noBackgroundView.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
- // }
- // }
- static let keepProportionsKey = "KMEditPDFKeepProportionsKey"
-
- deinit {
- KMPrint("KMEditImagePropertyViewController deinit.")
- self.removeNotification()
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.setup()
- self.initData()
- self.updateLanguage()
- self.updateButtonState(hidden: true)
- self.reloadData()
- self.addNotification()
- self.updateUI()
- }
-
- func initData() {
- self.updateButtonState(hidden: true)
- }
-
- func setup() {
- self.titleLabel.font = NSFont.SFProTextSemiboldFont(14.0)
- self.titleLabel.textColor = KMAppearance.Layout.h0Color()
-
- self.opacityTitleLabel.font = NSFont.SFProTextRegularFont(12.0)
- // self.opacityTitleLabel.textColor = KMAppearance.Layout.h0Color()
-
- self.whTitleLabel.font = NSFont.SFProTextRegularFont(12)
- self.whTitleLabel.stringValue = NSLocalizedString("Size", comment: "")
- self.wTextFieldItemView.backgroundView.wantsLayer = true
- self.wTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.wTextFieldItemView.backgroundView.layer?.borderWidth = 1
- self.wTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#DFE1E5").cgColor
- self.wTextFieldItemView.backgroundView.layer?.cornerRadius = 4
- self.wTextFieldItemView.delegate = self
- self.wTextFieldItemView.offset = 8
- self.wTextFieldItemView.rightViewMode = .always
- let wRightView = NSView()
- wRightView.frame = NSMakeRect(0, 0, 24, 32)
- let wIv = NSImageView()
- wIv.frame = NSMakeRect(0, 8, 16, 16)
- wIv.image = NSImage(named: "KMImageNameEditPDFWidthIcon")
- wRightView.addSubview(wIv)
- self.wTextFieldItemView.rightView = wRightView
- var formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- // formatter.maximum = NSNumber(value: 999)
- // formatter.minimum = NSNumber(value: 1)
- self.wTextFieldItemView.textFiled.formatter = formatter
-
- self.hTextFieldItemView.backgroundView.wantsLayer = true
- self.hTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.hTextFieldItemView.backgroundView.layer?.borderWidth = 1
- self.hTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#DFE1E5").cgColor
- self.hTextFieldItemView.backgroundView.layer?.cornerRadius = 4
- self.hTextFieldItemView.delegate = self
- self.hTextFieldItemView.textFiled.formatter = formatter
- let hRightView = NSView()
- hRightView.frame = NSMakeRect(0, 0, 24, 32)
- let hIv = NSImageView()
- hIv.frame = NSMakeRect(0, 8, 16, 16)
- hIv.image = NSImage(named: "KMImageNameEditPDFHeightIcon")
- hRightView.addSubview(hIv)
- self.hTextFieldItemView.rightView = hRightView
- self.hTextFieldItemView.rightViewMode = .always
-
- self.alignmentView.didChange = {[unowned self] view, areasArray, boundsArray in
- self._trackEvent()
- let textAreas = self.handdler?.editingTextAreas ?? []
- let imageAreas = self.handdler?.editingImageAreas ?? []
- if textAreas.count > 0 && imageAreas.count > 0 {
- self._trackAlignEvent()
- }
-
- self.changeAreasAlign(areas: areasArray, newBounds: boundsArray)
- }
-
- self.whVC = KMDesignButton(withType: .Image)
- self.whBox.contentView = self.whVC?.view
- self.whBox.borderWidth = 0
- self.whVC?.target = self
- self.whVC?.action = #selector(whAction)
- self.whVC?.image = NSImage(named: "KMImageNameEditPDFWhExchange")!
- self.whVC?.image_act = NSImage(named: "KMImageNameEditPDFWhExchangeSelected")!
- self.whVC?.pagination()
- whVC?.cornerRadius = 4
- whVC?.cornerRadius_hov = 4
- whVC?.cornerRadius_disabled = 4
- self.whVC?.toolTip = NSLocalizedString("Keep Proportions", comment: "")
- // self.whVC?.state = self._getKeepProportionsButtonState() ? .Act : .Norm
- let whState: KMDesignTokenState = self._getKeepProportionsButtonState() ? .Act : .Norm
- self.whVC?.state = .Norm
- self._setWHButtonState(whState)
-
-
- self.rotateTitleLabel.stringValue = NSLocalizedString("Rotate", comment: "")
- self.rotateTitleLabel.font = NSFont.SFProTextRegularFont(12)
- self.rotateTextFieldItemView.delegate = self
- self.rotateTextFieldItemView.enterKeyEndEdit = true
- self.rotateTextFieldItemView.useToken = false
-
- self.leftRotateVC = KMDesignButton(withType: .Image)
- self.leftRotateBox.contentView = self.leftRotateVC?.view
- self.leftRotateBox.borderWidth = 0
- self.leftRotateVC?.target = self
- self.leftRotateVC?.action = #selector(leftRotationImageAction)
- self.leftRotateVC?.image = NSImage(named: "KMImageNameEditPDFRotationLeft")!
- self.leftRotateVC?.pagination()
-
-
- self.rightRotateVC = KMDesignButton(withType: .Image)
- self.rightRotateBox.contentView = self.rightRotateVC?.view
- self.rightRotateBox.borderWidth = 0
- self.rightRotateVC?.target = self
- self.rightRotateVC?.action = #selector(rightRotationImageAction)
- self.rightRotateVC?.image = NSImage(named: "KMImageNameEditPDFRotationRight")!
- self.rightRotateVC?.pagination()
-
- opacityVC = KMDesignSelect.init(withType: .PopButton)
- opacityBox.contentView = opacityVC?.view
- opacityBox.fillColor = KMAppearance.Layout.bgDrakColor()
- opacityVC?.addItems(withObjectValues: ["25%","50%","75%","100%"])
- opacityVC?.selectItem(at: 0)
- opacityVC?.delete = self
- opacityVC?.borderColor = KMAppearance.Interactive.s0Color()
- opacityVC?.borderColor_disabled = KMAppearance.Interactive.s0Color()
- opacityVC?.background = KMAppearance.Layout.l1Color()
- opacityVC?.background_hov = KMAppearance.Layout.l1Color()
- opacityVC?.background_focus = KMAppearance.Layout.l1Color()
- opacityVC?.background_disabled = KMAppearance.Layout.l1Color()
- opacityVC?.textColor = KMAppearance.Layout.h1Color()
- opacityVC?.textColor_hov = KMAppearance.Layout.h1Color()
- opacityVC?.textColor_focus = KMAppearance.Layout.h1Color()
- opacityVC?.popViewControllerBackground = KMAppearance.Layout.bgColor()
- opacityVC?.popViewControllerTextColor = KMAppearance.Layout.h0Color()
- opacityVC?.popViewControllerEnterFillColor = KMAppearance.Interactive.s0Color()
- opacityVC?.updateUI()
-
- let customCell = CustomSliderCell()
- customCell.knobImage = NSImage(named: "KMImageNameEditPDFSlider")
- opacitySlider.cell = customCell
- opacitySlider.target = self
- opacitySlider.action = #selector(sliderValueChanged(_:))
- opacitySlider.isContinuous = false
-
- self.turnOverTitleLabel.stringValue = NSLocalizedString("Flip", comment: "")
- self.reverseXVC = KMDesignButton(withType: .Image)
- self.reverseXBox.addSubview(self.reverseXVC!.view)
- self.reverseXVC?.view.frame = self.reverseXBox.bounds
- self.reverseXVC?.view.autoresizingMask = [.width, .height]
- self.reverseXVC?.target = self
- self.reverseXVC?.action = #selector(flipHorizontalImageAction)
- self.reverseXVC?.image = NSImage(named: "KMImageNameEditPDFReverseX")!
- self.reverseXVC?.pagination()
-
- self.reverseYVC = KMDesignButton(withType: .Image)
- self.reverseYBox.addSubview(self.reverseYVC!.view)
- self.reverseYVC?.view.frame = self.reverseXBox.bounds
- self.reverseYVC?.view.autoresizingMask = [.width, .height]
- self.reverseYVC?.target = self
- self.reverseYVC?.action = #selector(flipVerticalImageAction)
- self.reverseYVC?.image = NSImage(named: "KMImageNameEditPDFReverseY")!
- self.reverseYVC?.pagination()
-
- self.toolsTitleLabel.stringValue = NSLocalizedString("Tools", comment: "")
- self.toolsTitleLabel.font = NSFont.SFProTextRegularFont(12)
-
- cropVC = KMDesignButton.init(withType: .Text)
- cropBox.contentView = cropVC?.view
- cropBox.fillColor = NSColor.clear
- cropVC?.target = self
- cropVC?.action = #selector(cutImageAction)
- cropVC?.button(type: .Sec, size: .m)
- cropVC?.stringValue = NSLocalizedString("Crop", comment: "")
- // cropVC?.borderColor = KMAppearance.Interactive.s0Color()
- // cropVC?.background = KMAppearance.Layout.l1Color()
- // cropVC?.background_hov = KMAppearance.Layout.l1Color()
- // cropVC?.background_focus = KMAppearance.Layout.l1Color()
- // cropVC?.textColor = KMAppearance.Layout.h1Color()
- // cropVC?.textColor_hov = KMAppearance.Layout.h1Color()
- // cropVC?.textColor_focus = KMAppearance.Layout.h1Color()
- // cropVC?.updateUI()
- cropVC?.borderColor = KMAppearance.Interactive.s0Color()
- cropVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- cropVC?.borderColor_disabled = KMAppearance.Interactive.s0Color()
- cropVC?.background = KMAppearance.Layout.l1Color()
- cropVC?.background_hov = KMAppearance.Layout.l1Color()
- cropVC?.background_focus = KMAppearance.Layout.l1Color()
- cropVC?.background_disabled = KMAppearance.Layout.l1Color()
- cropVC?.textColor = KMAppearance.Layout.h1Color()
- cropVC?.textColor_hov = KMAppearance.Layout.h1Color()
- cropVC?.textColor_focus = KMAppearance.Layout.h1Color()
- cropVC?.updateUI()
-
- confirmVC = KMDesignButton.init(withType: .Text)
- confirmBox.contentView = confirmVC?.view
- confirmBox.fillColor = NSColor.clear
- confirmVC?.target = self
- confirmVC?.action = #selector(confirmVCImageAction)
- confirmVC?.button(type: .Cta, size: .m)
- confirmVC?.stringValue = NSLocalizedString("Confirm", comment: "")
- confirmVC?.updateUI()
-
- cancelVC = KMDesignButton.init(withType: .Text)
- cancelBox.contentView = cancelVC?.view
- cancelBox.fillColor = NSColor.clear
- cancelVC?.target = self
- cancelVC?.action = #selector(cancelCutImageAction)
- cancelVC?.button(type: .Sec, size: .m)
- cancelVC?.stringValue = NSLocalizedString("Cancel", comment: "")
- cancelVC?.borderColor = KMAppearance.Interactive.s0Color()
- cancelVC?.background = KMAppearance.Layout.l1Color()
- cancelVC?.background_hov = KMAppearance.Layout.l1Color()
- cancelVC?.background_focus = KMAppearance.Layout.l1Color()
- cancelVC?.textColor = KMAppearance.Layout.h1Color()
- cancelVC?.textColor_hov = KMAppearance.Layout.h1Color()
- cancelVC?.textColor_focus = KMAppearance.Layout.h1Color()
- cancelVC?.updateUI()
-
- replaceVC = KMDesignButton.init(withType: .Text)
- replaceBox.contentView = replaceVC?.view
- replaceBox.fillColor = NSColor.clear
- replaceVC?.target = self
- replaceVC?.action = #selector(replaceImageAction)
- replaceVC?.button(type: .Sec, size: .m)
- replaceVC?.stringValue = NSLocalizedString("Replace", comment: "")
- replaceVC?.borderColor = KMAppearance.Interactive.s0Color()
- replaceVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- replaceVC?.borderColor_disabled = KMAppearance.Interactive.s0Color()
- replaceVC?.background = KMAppearance.Layout.l1Color()
- replaceVC?.background_hov = KMAppearance.Layout.l1Color()
- replaceVC?.background_focus = KMAppearance.Layout.l1Color()
- replaceVC?.background_disabled = KMAppearance.Layout.l1Color()
- replaceVC?.textColor = KMAppearance.Layout.h1Color()
- replaceVC?.textColor_hov = KMAppearance.Layout.h1Color()
- replaceVC?.textColor_focus = KMAppearance.Layout.h1Color()
- replaceVC?.updateUI()
-
- exportVC = KMDesignButton.init(withType: .Text)
- exportBox.contentView = exportVC?.view
- exportBox.fillColor = NSColor.clear
- exportVC?.target = self
- exportVC?.action = #selector(exportImageAction)
- exportVC?.button(type: .Sec, size: .m)
- exportVC?.stringValue = NSLocalizedString("Export", comment: "")
- exportVC?.borderColor = KMAppearance.Interactive.s0Color()
- exportVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- exportVC?.borderColor_disabled = KMAppearance.Interactive.s0Color()
- exportVC?.background = KMAppearance.Layout.l1Color()
- exportVC?.background_hov = KMAppearance.Layout.l1Color()
- exportVC?.background_focus = KMAppearance.Layout.l1Color()
- exportVC?.background_disabled = KMAppearance.Layout.l1Color()
- exportVC?.textColor = KMAppearance.Layout.h1Color()
- exportVC?.textColor_hov = KMAppearance.Layout.h1Color()
- exportVC?.textColor_focus = KMAppearance.Layout.h1Color()
- exportVC?.updateUI()
-
- self.noTitleLabel.textColor = KMAppearance.Layout.h1Color()
- self.noTitleLabel.font = NSFont.SFProTextRegularFont(14)
-
- self.noImageView.image = NSImage(named: "No_addimage")
- self.noImageView.alphaValue = 0.4
-
- let string = self.noSubtitleLabel.stringValue
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.lineHeightMultiple = 1.32
- paragraphStyle.alignment = .center
- self.noSubtitleLabel.attributedStringValue = NSMutableAttributedString(string: NSLocalizedString(string, comment: ""), attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle, .foregroundColor : NSColor.km_init(hex: "#94989C"), NSAttributedString.Key.font: NSFont.SFProTextRegularFont(12.0)])
- self.noBackgroundView.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
- }
-
- func addNotification() {
- NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
- }
-
- func removeNotification() {
- NotificationCenter.default.removeObserver(self)
- DistributedNotificationCenter.default().removeObserver(self)
- }
-
- // @objc func changeEffectiveAppearance() {
- // let isDarkModel = KMAdvertisementConfig.isDarkModel()
- // if isDarkModel {
- // self.view.appearance = NSAppearance(named: .darkAqua)
- // } else {
- // self.view.appearance = NSAppearance(named: .aqua)
- // }
- // self.updateUI()
- // }
-
- func updateUI() {
- let isDarkModel = NSView.isDarkModel()
- if isDarkModel {
- self.backgroundView.backgroundColor(NSColor.km_init(hex: "#252526"))
- self.noBackgroundView.backgroundColor(NSColor.km_init(hex: "#252526"))
-
- self.whTitleLabel.textColor = NSColor.km_init(hex: "#C8C9CC")
- self.rotateTitleLabel.textColor = NSColor.km_init(hex: "#C8C9CC")
- self.opacityTitleLabel.textColor = NSColor.km_init(hex: "#C8C9CC")
- self.toolsTitleLabel.textColor = NSColor.km_init(hex: "#C8C9CC")
- self.alignmentView.alignmentLabel.textColor = NSColor.km_init(hex: "#C8C9CC")
-
- whVC?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
- // whVC?.background_focus = KMAppearance.Layout.l1Color()
- whVC?.background_disabled = KMAppearance.buttonDisabledColor()
-
- leftRotateVC?.borderColor = KMAppearance.Interactive.s0Color()
- leftRotateVC?.background = KMAppearance.Layout.l1Color()
- leftRotateVC?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
- leftRotateVC?.background_focus = KMAppearance.Layout.l1Color()
- leftRotateVC?.textColor = KMAppearance.Layout.h1Color()
- leftRotateVC?.textColor_hov = KMAppearance.Layout.h1Color()
- leftRotateVC?.textColor_focus = KMAppearance.Layout.h1Color()
- leftRotateVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- leftRotateVC?.background_disabled = NSColor(white: 96/255.0, alpha: 1.0)
- // cropVC?.borderColor = KMAppearance.Interactive.s0Color()
- // cropVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- // leftRotateVC?.borderColor_disabled = KMAppearance.Interactive.s0Color()
- // leftRotateVC?.background = KMAppearance.Layout.l1Color()
- // leftRotateVC?.background_hov = KMAppearance.Layout.l1Color()
- // leftRotateVC?.background_focus = KMAppearance.Layout.l1Color()
- // leftRotateVC?.background_disabled = KMAppearance.Layout.l1Color()
- // cropVC?.textColor = KMAppearance.Layout.h1Color()
- // cropVC?.textColor_hov = KMAppearance.Layout.h1Color()
- // cropVC?.textColor_focus = KMAppearance.Layout.h1Color()
-
- leftRotateVC?.updateUI()
-
- rightRotateVC?.borderColor = KMAppearance.Interactive.s0Color()
- rightRotateVC?.background = KMAppearance.Layout.l1Color()
- rightRotateVC?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
- rightRotateVC?.background_focus = KMAppearance.Layout.l1Color()
- rightRotateVC?.textColor = KMAppearance.Layout.h1Color()
- rightRotateVC?.textColor_hov = KMAppearance.Layout.h1Color()
- rightRotateVC?.textColor_focus = KMAppearance.Layout.h1Color()
- rightRotateVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- rightRotateVC?.background_disabled = NSColor(white: 96/255.0, alpha: 1.0)
- rightRotateVC?.updateUI()
-
- reverseXVC?.borderColor = KMAppearance.Interactive.s0Color()
- reverseXVC?.background = KMAppearance.Layout.l1Color()
- reverseXVC?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
- reverseXVC?.background_focus = KMAppearance.Layout.l1Color()
- reverseXVC?.textColor = KMAppearance.Layout.h1Color()
- reverseXVC?.textColor_hov = KMAppearance.Layout.h1Color()
- reverseXVC?.textColor_focus = KMAppearance.Interactive.a0Color()
- reverseXVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- reverseXVC?.background_disabled = NSColor(white: 96/255.0, alpha: 1.0)
- reverseXVC?.updateUI()
-
- reverseYVC?.borderColor = KMAppearance.Interactive.s0Color()
- reverseYVC?.background = KMAppearance.Layout.l1Color()
- reverseYVC?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
- reverseYVC?.background_focus = KMAppearance.Layout.l1Color()
- reverseYVC?.textColor = KMAppearance.Layout.h1Color()
- reverseYVC?.textColor_hov = KMAppearance.Layout.h1Color()
- reverseYVC?.textColor_focus = KMAppearance.Interactive.a0Color()
- reverseYVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- reverseYVC?.background_disabled = NSColor(white: 96/255.0, alpha: 1.0)
- reverseYVC?.updateUI()
-
- self.wTextFieldItemView.backgroundView.layer?.backgroundColor = KMAppearance.Layout.w15Color().cgColor
- self.wTextFieldItemView.backgroundView.layer?.borderColor = KMAppearance.Layout.w15Color().cgColor
-
- self.hTextFieldItemView.backgroundView.layer?.backgroundColor = KMAppearance.Layout.w15Color().cgColor
- self.hTextFieldItemView.backgroundView.layer?.borderColor = KMAppearance.Layout.w15Color().cgColor
-
- self.rotateTextFieldItemView.fillColor = KMAppearance.Layout.w15Color()
- self.rotateTextFieldItemView.textF?.backgroundView.layer?.backgroundColor = KMAppearance.Layout.w15Color().cgColor
- // self.rotateTextFieldItemView.updateUI(state: self.rotateTextFieldItemView.state)
-
- if self.rotateTextFieldItemView.state == .Focus {
- let borderColor = NSColor.km_init(hex: "68ACF8")
- self.rotateTextFieldItemView.textF?.backgroundView.layer?.borderColor = borderColor.cgColor
- } else {
- let borderColor = NSColor.km_init(hex: "56585A")
- self.rotateTextFieldItemView.textF?.backgroundView.layer?.borderColor = borderColor.cgColor
- }
- } else {
- self.backgroundView.backgroundColor(NSColor.km_init(hex: "#FAFAFA"))
- self.noBackgroundView.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
-
- self.whTitleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.rotateTitleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.opacityTitleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.toolsTitleLabel.textColor = NSColor.km_init(hex: "#616469")
- self.alignmentView.alignmentLabel.textColor = NSColor.km_init(hex: "#616469")
-
- leftRotateVC?.borderColor = KMAppearance.Interactive.s0Color()
- leftRotateVC?.background = KMAppearance.Layout.l1Color()
- leftRotateVC?.background_hov = KMAppearance.view_bg_dis_color()
- leftRotateVC?.background_focus = KMAppearance.Layout.l1Color()
- leftRotateVC?.textColor = KMAppearance.Layout.h1Color()
- leftRotateVC?.textColor_hov = KMAppearance.Layout.h1Color()
- leftRotateVC?.textColor_focus = KMAppearance.Layout.h1Color()
- leftRotateVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
-
- leftRotateVC?.borderColor_disabled = KMAppearance.Interactive.s0Color()
- leftRotateVC?.background = KMAppearance.Layout.l1Color()
- leftRotateVC?.background_hov = KMAppearance.Layout.l1Color()
- leftRotateVC?.background_focus = KMAppearance.Layout.l1Color()
- leftRotateVC?.background_disabled = KMAppearance.Layout.l1Color()
-
- leftRotateVC?.updateUI()
-
- whVC?.background_hov = KMAppearance.view_bg_dis_color()
- // whVC?.background_focus = KMAppearance.Layout.l1Color()
- whVC?.background_disabled = KMAppearance.buttonDisabledColor()
-
- reverseXVC?.borderColor = KMAppearance.Interactive.s0Color()
- reverseXVC?.background = KMAppearance.Layout.l1Color()
- reverseXVC?.background_hov = KMAppearance.view_bg_dis_color()
- reverseXVC?.background_focus = KMAppearance.Layout.l1Color()
- reverseXVC?.textColor = KMAppearance.Layout.h1Color()
- reverseXVC?.textColor_hov = KMAppearance.Layout.h1Color()
- reverseXVC?.textColor_focus = KMAppearance.Layout.h1Color()
- reverseXVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- reverseXVC?.updateUI()
-
- reverseYVC?.borderColor = KMAppearance.Interactive.s0Color()
- reverseYVC?.background = KMAppearance.Layout.l1Color()
- reverseYVC?.background_hov = KMAppearance.view_bg_dis_color()
- reverseYVC?.background_focus = KMAppearance.Layout.l1Color()
- reverseYVC?.textColor = KMAppearance.Layout.h1Color()
- reverseYVC?.textColor_hov = KMAppearance.Layout.h1Color()
- reverseYVC?.textColor_focus = KMAppearance.Layout.h1Color()
- reverseYVC?.borderColor_hov = KMAppearance.Interactive.s0Color()
- reverseYVC?.updateUI()
-
- self.wTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.wTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#DFE1E5").cgColor
-
- self.hTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.hTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#DFE1E5").cgColor
-
- self.rightRotateVC?.initDefaultValue()
- self.leftRotateVC?.initDefaultValue()
-
- self.rotateTextFieldItemView.fillColor = .white
- // self.rotateTextFieldItemView.updateUI(state: self.rotateTextFieldItemView.state)
- self.rotateTextFieldItemView.textF?.backgroundView.layer?.backgroundColor = .white
- if self.rotateTextFieldItemView.state == .Focus {
- let borderColor = NSColor.km_init(hex: "68ACF8")
- self.rotateTextFieldItemView.textF?.backgroundView.layer?.borderColor = borderColor.cgColor
- } else {
- let borderColor = NSColor.km_init(hex: "DFE1E5")
- self.rotateTextFieldItemView.textF?.backgroundView.layer?.borderColor = borderColor.cgColor
- }
- }
-
- // for label in [self.whTitleLabel, self.opacityTitleLabel,
- // self.turnOverTitleLabel] {
- // label?.font = NSFont.SFProTextSemiboldFont(12.0)
- // label?.textColor = NSColor.km_init(hex: "#616469")
- // }
- }
-
- func updateLanguage() {
- let areas = self.editingAreas
- if imagesAreas.count > 0 && imagesAreas.count != areas.count { //多选图片跟文字
- self.titleLabel.stringValue = NSLocalizedString("General Properties", comment: "")
- } else {
- self.titleLabel.stringValue = NSLocalizedString("Image", comment: "")
- }
-
- self.noTitleLabel.stringValue = NSLocalizedString("Add Image", comment: "")
-
- self.opacityTitleLabel.stringValue = NSLocalizedString("Opacity", comment: "")
- self.cropVC?.stringValue = NSLocalizedString("Crop", comment: "")
- self.confirmVC?.stringValue = NSLocalizedString("Confirm", comment: "")
- self.cancelVC?.stringValue = NSLocalizedString("Cancel", comment: "")
- self.replaceVC?.stringValue = NSLocalizedString("Replace", comment: "")
- self.exportVC?.stringValue = NSLocalizedString("Export", comment: "")
- }
-
- func reloadData() {
- imagesAreas = []
- if self.editingAreas.count > 0 {
- self.noBackgroundView.isHidden = true
-
- let areas = self.editingAreas
- self.alignmentView.editingAreas = areas
-
- for i in 0 ... areas.count-1 {
- if areas[i] is CPDFEditImageArea {
- imagesAreas.append(areas[i] as! CPDFEditImageArea)
- }
- }
- if imagesAreas.count == 1 && imagesAreas.count == areas.count{ //单个图片
- self.listView.selectImageAreas = imagesAreas.first
- self.headerBox.isHidden = false
- self.headerBoxHeight.constant = 176
- self.opacityBox.isHidden = false
- self.opacityBoxHeight.constant = 56
- self.opacityBoxBottomMaginConstraint.constant = 66
- self.opacityBoxTopConstraint.constant = 16
- self.buttonBox.isHidden = false
- self.buttonBoxHeight.constant = 112+16+8
- self.alignmentViewTopConstraint.constant = 16
- let opacity: CGFloat = self.listView.opacity(for: imagesAreas.first)
- self.updateImageAreasOpacity(opacity: opacity, state: .ended, needListView: false)
- self.turnOverBox.isHidden = false
- self.opacityTitleLabel.isHidden = false
- // self.whVC?.state = self._getKeepProportionsButtonState() ? .Act : .Norm
- let whSta: KMDesignTokenState = self._getKeepProportionsButtonState() ? .Act : .Norm
- self.whVC?.state = .Norm
- self._setWHButtonState(whSta)
- self.cropVC?.state = .Norm
- let isCropMode = self.listView.isCropMode
- self.replaceVC?.state = isCropMode ? .Disabled : .Norm
- } else if imagesAreas.count > 1 && imagesAreas.count == areas.count { //多选图片
- self.headerBox.isHidden = false
- self.headerBoxHeight.constant = 176
- self.opacityBox.isHidden = false
- self.opacityBoxHeight.constant = 56
- self.opacityBoxBottomMaginConstraint.constant = 66
- self.opacityBoxTopConstraint.constant = 0
- self.buttonBox.isHidden = false
- self.buttonBoxHeight.constant = 112+16+8
- self.alignmentViewTopConstraint.constant = 16
- var opacity = self.listView.opacity(for: imagesAreas.first)
- for area in imagesAreas {
- let newOpacity = self.listView.opacity(for: area)
- if (opacity < newOpacity) {
- opacity = newOpacity
- }
- }
- self.updateImageAreasOpacity(opacity: opacity, state: .ended, needListView: false)
- self.turnOverBox.isHidden = false
- self.opacityTitleLabel.isHidden = false
-
- self._updateWHProportionButtonEnableState()
- self.cropVC?.state = .Disabled
- self.replaceVC?.state = .Disabled
-
- if let data = self.handdler?.editAreasOpacityIsEqual(), data {
- self.opacitySlider.isEnabled = true
- self.opacityVC?.state = .Norm
- } else {
- self.opacitySlider.isEnabled = true
- self.opacityVC?.state = .Norm
- self.opacitySlider.doubleValue = 0
- self.opacityVC?.stringValue = "--";
- }
- } else if imagesAreas.count > 0 && imagesAreas.count != areas.count { //多选图片跟文字
- self.opacityBoxBottomMaginConstraint.constant = 8
- self.alignmentViewTopConstraint.constant = 0
- self.opacityBoxTopConstraint.constant = 0
- self.headerBoxHeight.constant = 40
- self.opacityBox.isHidden = true
- self.opacityBoxHeight.constant = 0
- self.buttonBox.isHidden = true
- self.buttonBoxHeight.constant = 0
- self.turnOverBox.isHidden = true
- self.opacityTitleLabel.isHidden = true
- }
- self.updateLanguage()
- } else {
- self.noBackgroundView.isHidden = false
- }
-
- self.updateWHData()
- self.updateRotateData()
- }
-
- func updateButtonState(hidden: Bool) {
- if hidden {
- self.cancelBox.isHidden = true
- self.confirmBox.isHidden = true
- self.cropBox.isHidden = false
- self.replaceVC?.enabled = true
- self.replaceVC?.state = .Norm
- self.exportVC?.enabled = true
- self.opacitySlider.isEnabled = true
- self.opacityVC?.enabled = true
- self.rotateLeftVC?.button.isEnabled = true
- self.rotateLeftVC?.view.alphaValue = 1.0
- self.rotateRightVC?.button.isEnabled = true
- self.rotateRightVC?.view.alphaValue = 1.0
- self.flipVerticalVC?.button.isEnabled = true
- self.flipVerticalVC?.view.alphaValue = 1.0
- self.flipHorizontalVC?.button.isEnabled = true
- self.flipHorizontalVC?.view.alphaValue = 1.0
-
- self.wTextFieldItemView.textFiled.isEnabled = true
- self.hTextFieldItemView.textFiled.isEnabled = true
- // self.whVC?.state = self._getKeepProportionsButtonState() ? .Act : .Norm
- let whSta: KMDesignTokenState = self._getKeepProportionsButtonState() ? .Act : .Norm
- self.whVC?.state = .Norm
- self._setWHButtonState(whSta)
- self.rotateTextFieldItemView.state = .Norm
- self.rotateTextFieldItemView.kmEnabled = true
- self.leftRotateVC?.state = .Norm
- self.leftRotateVC?.button.isEnabled = true
- self.rightRotateVC?.state = .Norm
- self.leftRotateVC?.button.isEnabled = true
- self.reverseXVC?.state = .Norm
- self.reverseXVC?.button.isEnabled = true
- self.reverseYVC?.state = .Norm
- self.reverseYVC?.button.isEnabled = true
- self.leftRotateVC?.button.isEnabled = true
- self.rightRotateVC?.button.isEnabled = true
- self.reverseXVC?.button.isEnabled = true
- self.reverseYVC?.button.isEnabled = true
- } else {
- self.cancelBox.isHidden = false
- self.confirmBox.isHidden = false
- self.cropBox.isHidden = true
- self.replaceVC?.enabled = false
- self.replaceVC?.state = .Disabled
- self.exportVC?.enabled = false
- self.opacitySlider.isEnabled = false
- self.opacityVC?.enabled = false
- self.rotateLeftVC?.button.isEnabled = false
- self.rotateLeftVC?.view.alphaValue = 0.5
- self.rotateRightVC?.button.isEnabled = false
- self.rotateRightVC?.view.alphaValue = 0.5
- self.flipVerticalVC?.button.isEnabled = false
- self.flipVerticalVC?.view.alphaValue = 0.5
- self.flipHorizontalVC?.button.isEnabled = false
- self.flipHorizontalVC?.view.alphaValue = 0.5
-
- self.wTextFieldItemView.textFiled.isEnabled = false
- self.hTextFieldItemView.textFiled.isEnabled = false
- self.whVC?.state = .Disabled
- self._setWHButtonState(.Disabled)
- self.rotateTextFieldItemView.state = .Disabled
- self.rotateTextFieldItemView.kmEnabled = false
- self.leftRotateVC?.state = .Disabled
- self.leftRotateVC?.button.isEnabled = false
- self.rightRotateVC?.state = .Disabled
- self.leftRotateVC?.button.isEnabled = false
- self.reverseXVC?.state = .Disabled
- self.reverseXVC?.button.isEnabled = false
- self.reverseYVC?.state = .Disabled
- self.reverseYVC?.button.isEnabled = false
- self.leftRotateVC?.button.isEnabled = false
- self.rightRotateVC?.button.isEnabled = false
- self.reverseXVC?.button.isEnabled = false
- self.reverseYVC?.button.isEnabled = false
- }
- self.reloadData()
- if self.noBackgroundView.isHidden == false {
- self.opacityVC?.enabled = false
- }
- }
-
- func updateWHData() {
- if let data = self.handdler?.editAreasBoundsIsEqualForWidth(), data {
- let areaFrame = self.handdler?.editingAreas.first?.bounds ?? .zero
- self.wTextFieldItemView.stringValue = String(format: "%.1f", areaFrame.size.width)
- } else {
- self.wTextFieldItemView.stringValue = "--"
- }
- if let data = self.handdler?.editAreasBoundsIsEqualForHeight(), data {
- let areaFrame = self.handdler?.editingAreas.first?.bounds ?? .zero
- self.hTextFieldItemView.stringValue = String(format: "%.1f", areaFrame.size.height)
- } else {
- self.hTextFieldItemView.stringValue = "--"
- }
- }
-
- func updateRotateData() {
- if let data = self.handdler?.editAreasRotateIsEqual(), data {
- let area = self.handdler?.editingImageAreas.first
- let rotate = self.listView.getRotateWith(area)
- let stringValue = self.rotateTextFieldItemView.stringValue?.replacingOccurrences(of: "°", with: "")
- let number = NSNumber(value: rotate)
- let formatter = NumberFormatter()
- let string = formatter.string(for: number)
- self.rotateTextFieldItemView.stringValue = "\(string ?? "0") °"
- } else {
- self.rotateTextFieldItemView.stringValue = "--"
- }
- }
-
- func updateImageAreasOpacity(opacity: CGFloat, state: KMOperationState, needListView: Bool = true) {
- if self.editingAreas.count >= 1 {
- if needListView {
- for area in imagesAreas {
- self.listView.setOpacityEditArea(area, opacity: opacity)
- }
- }
-
- // self.listView.editingAreas()!.count == 1 &&
- if (self.listView.editingAreas()?.first is CPDFEditImageArea) {
- self.listView.selectImageAreas = self.listView.editingAreas()!.first as? CPDFEditImageArea
- // self.editImageView.image = self.listView.selectImageAreas.thumbnailImage
- self.opacitySlider.objectValue = self.listView.opacity(for: self.listView.selectImageAreas)
- self.opacityVC?.stringValue = Int(opacity * 100).description + "%"
- // self.editImageView.alphaValue = opacity
- }
- }
- }
-
- // MARK: - Private Methods
-
- private func changeAreasAlign(areas:[Any],newBounds:[String]) {
- var oldBounds : [String] = []
- for i in 0 ... areas.count-1 {
- let area : CPDFEditArea = areas[i] as! CPDFEditArea
- oldBounds.append(NSStringFromRect(area.bounds))
- self.listView.setBoundsEditArea(area, withBounds: NSRectFromString(newBounds[i]))
- }
- self.listView.setNeedsDisplayForVisiblePages()
- }
-
- private func _setKeepProportionsButtonState(state: Bool) {
- KMDataManager.ud_set(state, forKey: Self.keepProportionsKey)
- }
-
- private func _getKeepProportionsButtonState() -> Bool {
- let defaultV = true
- guard let state = KMDataManager.ud_object(forKey: Self.keepProportionsKey) else {
- return defaultV
- }
- return state as? Bool ?? defaultV
- }
-
- private func _updateWHProportionButtonEnableState() {
- let wEqual = self.handdler?.editAreasBoundsIsEqualForWidth() ?? false
- let hEqual = self.handdler?.editAreasBoundsIsEqualForHeight() ?? false
- if (wEqual && hEqual) {
- // self.whVC?.state = self._getKeepProportionsButtonState() ? .Act : .Norm
- let state: KMDesignTokenState = self._getKeepProportionsButtonState() ? .Act : .Norm
- self.whVC?.state = .Norm
- self._setWHButtonState(state)
- } else {
- self.whVC?.state = .Disabled
- self._setWHButtonState(.Disabled)
- }
- }
-
- private func _setWHButtonState(_ state: KMDesignTokenState) {
- self.whState_ = state
- if state == .Act {
- self.whVC?.image = NSImage(named: "KMImageNameEditPDFWhExchangeSelected")!
- } else if state == .Norm {
- self.whVC?.image = NSImage(named: "KMImageNameEditPDFWhExchange")!
- }
- }
-
- private func _trackEvent() {
- // kTrackEventManager.trackEvent(event: "SubTbr_EditPDF", withProperties: ["SubTbr_EditImage":"SubTbr_EditImage_PropertiesPanel_All"])
- }
-
- private func _trackAlignEvent() {
- // kTrackEventManager.trackEvent(event: "SubTbr_EditPDF", withProperties: ["SubTbr_EditText":"SubTbr_EditContent_AlignContent"])
- }
-
- //MARK: - MouseEvent
- override func mouseDown(with event: NSEvent) {
- super.mouseDown(with: event)
-
- self.view.window?.makeFirstResponder(nil)
- }
- }
- //MARK: - Action
- extension KMEditImagePropertyViewController {
- @objc func sliderValueChanged(_ sender: NSSlider) {
- let sliderValue = sender.floatValue
- self.updateImageAreasOpacity(opacity:CGFloat(sliderValue), state: .changed)
- }
-
- @objc func whAction(_ sender: AnyObject) {
- // let state = self.whVC?.state ?? .None
- let state = self.whState_
- if state == .Disabled {
- return
- }
- if state == .Act {
- // self.whVC?.state = .Norm
- self.whVC?.state = .Norm
- self._setWHButtonState(.Norm)
-
- self._setKeepProportionsButtonState(state: false)
- } else {
- // self.whVC?.state = .Act
- self.whVC?.state = .Norm
- self._setWHButtonState(.Act)
-
- self._setKeepProportionsButtonState(state: true)
- }
- }
-
- @IBAction func rightRotationImageAction(_ sender: Any) {
- if self.listView.editingAreas()?.count ?? 0 < 1 {
- return
- }
- // FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Rotate"])
- self._trackEvent()
- let areas = self.listView.editingAreas()
- if areas!.count == 1 && (areas!.first is CPDFEditImageArea) {
- let imageArea = areas!.first as! CPDFEditImageArea
- self.listView.rotate(with: imageArea, rotate: 90)
- self.listView.selectImageAreas = imageArea
- // self.editImageView.image = self.listView.selectImageAreas.thumbnailImage
- } else if areas!.count > 1 {
- for imagesArea in imagesAreas {
- self.listView.rotate(with: imagesArea, rotate: 90)
- }
- }
-
- self.delegate?.editImagePropertyViewControllerDidChanged(controller: self, type: .rotate)
- }
-
- @IBAction func leftRotationImageAction(_ sender: Any) {
- if self.listView.editingAreas()?.count ?? 0 < 1 {
- return
- }
- // FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Rotate"])
- self._trackEvent()
- let areas = self.listView.editingAreas()
- if areas!.count == 1 && (areas!.first is CPDFEditImageArea) {
- self.listView.rotate(with: self.listView.selectImageAreas, rotate: -90)
- if self.listView.editingAreas()!.count == 1 && (self.listView.editingAreas()!.first is CPDFEditImageArea) {
- self.listView.selectImageAreas = self.listView.editingAreas()!.first as? CPDFEditImageArea
- }
- // self.editImageView.image = self.listView.selectImageAreas.thumbnailImage
- } else {
- for imagesArea in imagesAreas {
- self.listView.rotate(with: imagesArea, rotate: -90)
- }
- }
-
- self.delegate?.editImagePropertyViewControllerDidChanged(controller: self, type: .rotate)
- }
-
- @IBAction func flipHorizontalImageAction(_ sender: Any) {
- if self.listView.editingAreas()?.count ?? 0 < 1 {
- return
- }
- // FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Reverse"])
- self._trackEvent()
- let areas = self.listView.editingAreas()
- if areas != nil {
- for item in areas! {
- if item is CPDFEditImageArea {
- self.listView.horizontalMirror(with: item as? CPDFEditImageArea)
- if areas?.count == 1 {
- // self.editImageView.image = (item as AnyObject).thumbnailImage
- }
- } else {
- for imagesArea in imagesAreas {
- self.listView.horizontalMirror(with: imagesArea)
- }
- }
- }
- }
-
- self.delegate?.editImagePropertyViewControllerDidChanged(controller: self, type: .flip)
- }
-
- @IBAction func flipVerticalImageAction(_ sender: Any) {
- if self.listView.editingAreas()?.count ?? 0 < 1 {
- return
- }
- // FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Reverse"])
- self._trackEvent()
- let areas = self.listView.editingAreas()
- if areas != nil {
- for item in areas! {
- if item is CPDFEditImageArea {
- self.listView.verticalMirror(with: item as? CPDFEditImageArea)
- // self.editImageView.image = self.listView.selectImageAreas.thumbnailImage
- } else {
- for imagesArea in imagesAreas {
- self.listView.verticalMirror(with: imagesArea)
- }
- }
- }
- }
- self.delegate?.editImagePropertyViewControllerDidChanged(controller: self, type: .flip)
- }
-
- @IBAction func cutImageAction(_ sender: Any) {
- let state = self.cropVC?.state ?? .None
- if state == .Disabled {
- return
- }
- self._trackEvent()
- self.handdler?.cropAction()
- }
-
- @IBAction func confirmVCImageAction(_ sender: Any) {
- self.handdler?.cropComfirmAction()
- }
-
- @IBAction func cancelCutImageAction(_ sender: Any) {
- self.handdler?.cropCancelAction()
- }
-
- @IBAction func restoreCutImageAction(_ sender: Any) {
- if self.listView.selectImageAreas == nil {
- return
- }
- self.listView.resetCrop(with: self.listView.selectImageAreas)
- }
-
- @IBAction func replaceImageAction(_ sender: NSButton) {
- let state = self.replaceVC?.state ?? .None
- if state == .Disabled {
- return
- }
-
- if self.listView.selectImageAreas == nil {
- return
- }
- // let panel = NSOpenPanel()
- // panel.allowsMultipleSelection = false
- // panel.allowedFileTypes = ["png","jpg"]
- // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
- // if response == .OK {
- // let openPath = panel.url?.path
- //// let s = self.listView.extractImage(with: self.selectImageAreas, toImagePath: openPath!)
- // let s = self.listView.replace(self.listView.selectImageAreas, imagePath: openPath!)
- // if s {
- // FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Replace"])
- self._trackEvent()
-
- self.handdler?.replaceAction()
- }
-
- @IBAction func exportImageAction(_ sender: Any) {
- self._trackEvent()
- if let data = sender as? NSView {
- self.handdler?.showExportMenu(data)
- }
- }
- }
- // MARK: - KMSelectPopButtonDelegate
- extension KMEditImagePropertyViewController: KMSelectPopButtonDelegate {
- func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
- if obj == opacityVC {
- let index = obj.indexOfSelectedItem
- var string = obj.items[index]
- string = string.replacingOccurrences(of: "%", with: "")
- let value = CGFloat(Float(string)! * 0.01)
- self.updateImageAreasOpacity(opacity: value, state: .changed)
- }
- }
-
- func km_controlTextDidEndEditing(_ obj: KMDesignSelect) {
- if obj == opacityVC {
- let index = obj.indexOfSelectedItem
- var string = obj.items[index]
- string = string.replacingOccurrences(of: "%", with: "")
- let value = CGFloat(Float(string)! * 0.01)
- self.updateImageAreasOpacity(opacity: value, state: .ended)
- }
- }
- }
- // MARK: - KMTextFieldDelegate
- extension KMEditImagePropertyViewController: KMTextFieldDelegate {
- func km_didBecomeFirstResponder(textField: AnyObject) {
- if self.wTextFieldItemView.isEqual(to: textField) {
- if KMAppearance.isDarkMode() {
- self.wTextFieldItemView.backgroundView.layer?.backgroundColor = KMAppearance.Layout.w15Color().cgColor
- self.wTextFieldItemView.backgroundView.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- } else {
- self.wTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.wTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#4982E6").cgColor
- }
- self.wTextFieldItemView.backgroundView.layer?.borderWidth = 1
- self.wTextFieldItemView.backgroundView.layer?.cornerRadius = 4
-
- } else if self.hTextFieldItemView.isEqual(to: textField) {
- if KMAppearance.isDarkMode() {
- self.hTextFieldItemView.backgroundView.layer?.backgroundColor = KMAppearance.Layout.w15Color().cgColor
- self.hTextFieldItemView.backgroundView.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- } else {
- self.hTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.hTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#4982E6").cgColor
-
- }
- }
- }
-
- func km_controlTextDidEndEditing(textField: AnyObject) {
- if self.wTextFieldItemView.isEqual(to: textField) {
- if KMAppearance.isDarkMode() {
- self.wTextFieldItemView.backgroundView.layer?.backgroundColor = KMAppearance.Layout.w15Color().cgColor
- self.wTextFieldItemView.backgroundView.layer?.borderColor = KMAppearance.Layout.w15Color().cgColor
- } else {
- self.wTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.wTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#DFE1E5").cgColor
- }
- self.wTextFieldItemView.backgroundView.layer?.borderWidth = 1
- self.wTextFieldItemView.backgroundView.layer?.cornerRadius = 4
- let value = self.wTextFieldItemView.stringValue?.stringToCGFloat() ?? 0
- let ss = String(format: "%.1f", value)
- self.wTextFieldItemView.stringValue = ss
-
- } else if self.hTextFieldItemView.isEqual(to: textField) {
- if KMAppearance.isDarkMode() {
- self.hTextFieldItemView.backgroundView.layer?.backgroundColor = KMAppearance.Layout.w15Color().cgColor
- self.hTextFieldItemView.backgroundView.layer?.borderColor = KMAppearance.Layout.w15Color().cgColor
- } else {
- self.hTextFieldItemView.backgroundView.layer?.backgroundColor = .white
- self.hTextFieldItemView.backgroundView.layer?.borderColor = NSColor.km_init(hex: "#DFE1E5").cgColor
- }
- let value = self.hTextFieldItemView.stringValue?.stringToCGFloat() ?? 0
- let ss = String(format: "%.1f", value)
- self.hTextFieldItemView.stringValue = ss
- } else if self.rotateTextFieldItemView.isEqual(to: textField) {
- let stringValue = self.rotateTextFieldItemView.stringValue?.replacingOccurrences(of: "°", with: "")
- let formatter = NumberFormatter()
- let number = NSNumber(value: Int(stringValue ?? "") ?? 0)
- let string = formatter.string(for: number)
- self.rotateTextFieldItemView.stringValue = "\(string ?? "0") °"
-
- let areas = self.handdler?.editingImageAreas ?? []
- for area in areas {
- let rotate = self.listView.getRotateWith(area)
- let rotate2 = string?.stringToCGFloat() ?? 0
- let offset = rotate2-rotate
- if offset != 0 {
- self.listView.rotate(with: area, rotate: offset)
-
- // kTrackEventManager.trackEvent(event: "SubTbr_EditPDF", withProperties: ["SubTbr_EditImage":"SubTbr_EditImage_PropertiesPanel_CustomRotate"])
- }
- }
- }
- }
-
- func km_controlTextDidChange(textField: AnyObject) {
- if self.wTextFieldItemView.isEqual(to: textField) {
- let number = NSNumber(value: Int(self.wTextFieldItemView.stringValue ?? "") ?? 0)
- let string = self.wTextFieldItemView.textFiled.formatter?.string(for: number)
- self.wTextFieldItemView.stringValue = string ?? ""
-
- let areas = self.handdler?.editingImageAreas ?? []
- self.listView.editAreaBoundUpdating = true
- for area in areas {
- // let state = self.whVC?.state ?? .None
- let state = self.whState_
- var bounds = area.bounds
- var width = string?.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)
- self.wTextFieldItemView.stringValue = value
- }
- let wOffset = width-bounds.size.width
- // bounds.origin.x = max(0, (pageBounds.size.width-width)*0.5)
- bounds.origin.x = max(0, bounds.origin.x-wOffset * 0.5)
- bounds.origin.x = min(bounds.origin.x, pageBounds.size.width-width)
-
- if state == .Act { // 寛高约束
- var scale: CGFloat = 0
- if bounds.size.width != 0 {
- scale = width / bounds.size.width
- }
- bounds.size.height *= scale
- bounds.size.width = width
-
- let value = String(format: "%.1f", bounds.size.height)
- self.hTextFieldItemView.stringValue = value
- } else {
- bounds.size.width = width
- }
- self.listView.setBoundsEditArea(area, withBounds: bounds)
- }
-
- DispatchQueue.main.async {
- self._updateWHProportionButtonEnableState()
- }
- } else if self.hTextFieldItemView.isEqual(to: textField) {
- let number = NSNumber(value: Int(self.hTextFieldItemView.stringValue ?? "") ?? 0)
- let string = self.hTextFieldItemView.textFiled.formatter?.string(for: number)
- self.hTextFieldItemView.stringValue = string ?? ""
-
- // let areas = self.listView?.editingAreas() as? [CPDFEditArea] ?? []
- let areas = self.handdler?.editingImageAreas ?? []
- self.listView.editAreaBoundUpdating = true
- for area in areas {
- // if let area = areas.first as? CPDFEditImageArea {
- // let state = self.whVC?.state ?? .None
- let state = self.whState_
- var bounds = area.bounds
- var height = string?.stringToCGFloat() ?? 0
- if height == 0 {
- return
- }
- let pageBounds = area.page?.bounds ?? .zero
- if height > NSHeight(pageBounds) {
- height = NSHeight(pageBounds)
-
- let value = String(format: "%.1f", height)
- self.hTextFieldItemView.stringValue = value
- }
- let hOffset = height-bounds.size.height
- // bounds.origin.y = max(0, (pageBounds.size.height-height)*0.5)
- bounds.origin.y = max(0, bounds.origin.y-hOffset * 0.5)
- bounds.origin.y = min(bounds.origin.y, pageBounds.size.height-height)
-
- if state == .Act { // 寛高约束
- var scale: CGFloat = 0
- if bounds.size.height != 0 {
- scale = height / bounds.size.height
- }
- bounds.size.width *= scale
- bounds.size.height = height
-
- let value = String(format: "%.1f", bounds.size.width)
- self.wTextFieldItemView.stringValue = value
- } else {
- bounds.size.height = height
- }
-
- self.listView.setBoundsEditArea(area, withBounds: bounds)
- }
-
- DispatchQueue.main.async {
- self._updateWHProportionButtonEnableState()
- }
- } else if self.rotateTextFieldItemView.isEqual(to: textField) {
- // let stringValue = self.rotateTextFieldItemView.stringValue
- // let number = NSNumber(value: Int(stringValue ?? "") ?? 0)
- // let formatter = NumberFormatter()
- // let string = formatter.string(for: number)
- // let string = self.rotateTextFieldItemView.kFormatter?.string(for: number)
- // self.rotateTextFieldItemView.stringValue = string
- }
- }
- }
- class CustomSliderCell: NSSliderCell {
- var knobImage: NSImage?
-
- override func drawKnob(_ knobRect: NSRect) {
- if let image = knobImage {
- let imageSize = NSSize(width: knobRect.size.height, height: knobRect.size.height)
- let imageRect = NSRect(origin: knobRect.origin, size: imageSize)
- image.draw(in: imageRect)
- } else {
- super.drawKnob(knobRect)
- }
- }
- }
|