123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- //
- // KMNPopDetailsViewController.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/12/6.
- //
- import Cocoa
- import KMComponentLibrary
- typealias FontChangeAlighCallback = (_ alight:NSTextAlignment) -> ()
- typealias ObjectChangeAlighCallback = (_ alight:ObjectAlignType) -> ()
- class KMNPopDetailsViewController: KMNBaseViewController {
- public var detailPopType:DetailPopType = .detailNone {
- didSet {
- switch detailPopType {
- case .freeTextAlight :
- alightRightConstraint.constant = 4
- alightJustifiedButton.isHidden = true
- fontAlightView.layoutSubtreeIfNeeded()
-
- operationWidthConstraint.constant = fontAlightView.bounds.width
- operationHeightConstraint.constant = fontAlightView.bounds.height
- self.view.layoutSubtreeIfNeeded()
- contentBox.contentView = fontAlightView
- break
- case .contentEditAlight:
- alightRightConstraint.constant = 44
- alightJustifiedButton.isHidden = false
- fontAlightView.layoutSubtreeIfNeeded()
-
- operationWidthConstraint.constant = fontAlightView.bounds.width
- operationHeightConstraint.constant = fontAlightView.bounds.height
- self.view.layoutSubtreeIfNeeded()
- contentBox.contentView = fontAlightView
- break
- case .doubleObjectAlight:
- objectRightConstraint.constant = 4
- objectAlightView.layoutSubtreeIfNeeded()
- objectAverageHorButton.isHidden = true
- objectAverageVerButton.isHidden = true
- operationWidthConstraint.constant = objectAlightView.bounds.width
- operationHeightConstraint.constant = objectAlightView.bounds.height
- self.view.layoutSubtreeIfNeeded()
- contentBox.contentView = objectAlightView
-
- break
- case .freeTextDoubleAlight:
- objectRightConstraint.constant = 4
- objectAlightView.layoutSubtreeIfNeeded()
- objectAverageHorButton.isHidden = true
- objectAverageVerButton.isHidden = true
- operationWidthConstraint.constant = objectAlightView.bounds.width
- operationHeightConstraint.constant = objectAlightView.bounds.height
- self.view.layoutSubtreeIfNeeded()
- contentBox.contentView = objectAlightView
-
- break
- case .multpleObjectAlight:
- objectRightConstraint.constant = 80
- objectAlightView.layoutSubtreeIfNeeded()
- objectAverageHorButton.isHidden = false
- objectAverageVerButton.isHidden = false
-
- operationWidthConstraint.constant = objectAlightView.bounds.width
- operationHeightConstraint.constant = objectAlightView.bounds.height
- self.view.layoutSubtreeIfNeeded()
- contentBox.contentView = objectAlightView
- break
- case .freeTextMultpleAlight:
- objectRightConstraint.constant = 80
- objectAlightView.layoutSubtreeIfNeeded()
- objectAverageHorButton.isHidden = false
- objectAverageVerButton.isHidden = false
- operationWidthConstraint.constant = objectAlightView.bounds.width
- operationHeightConstraint.constant = objectAlightView.bounds.height
- self.view.layoutSubtreeIfNeeded()
- contentBox.contentView = objectAlightView
- break
- case .detailNone:
- break
- }
- }
- }
-
- public var fontAlight:NSTextAlignment = .left {
- didSet {
- if alightRightButton.properties.state == .pressed {
- alightRightButton.properties.state = .normal
- alightRightButton.reloadData()
- }
- if alightCenteButton.properties.state == .pressed {
- alightCenteButton.properties.state = .normal
- alightCenteButton.reloadData()
- }
- if alightJustifiedButton.properties.state == .pressed {
- alightJustifiedButton.properties.state = .normal
- alightJustifiedButton.reloadData()
- }
- if alightLeftButton.properties.state == .pressed {
- alightLeftButton.properties.state = .normal
- alightLeftButton.reloadData()
- }
-
- if fontAlight == .left {
- alightLeftButton.properties.state = .pressed
- alightLeftButton.reloadData()
- } else if fontAlight == .right {
- alightRightButton.properties.state = .pressed
- alightRightButton.reloadData()
- } else if fontAlight == .center {
- alightCenteButton.properties.state = .pressed
- alightCenteButton.reloadData()
- } else if fontAlight == .justified {
- alightJustifiedButton.properties.state = .pressed
- alightJustifiedButton.reloadData()
- }
- }
- }
-
- public var objectAlignType:ObjectAlignType = .alightLeft {
- didSet {
- if objectAlightLeftButton.properties.state == .pressed {
- objectAlightLeftButton.properties.state = .normal
- objectAlightLeftButton.reloadData()
- }
- if objectAlightRightButton.properties.state == .pressed {
- objectAlightRightButton.properties.state = .normal
- objectAlightRightButton.reloadData()
- }
- if objectAlightTopButton.properties.state == .pressed {
- objectAlightTopButton.properties.state = .normal
- objectAlightTopButton.reloadData()
- }
- if objectAlightHorButton.properties.state == .pressed {
- objectAlightHorButton.properties.state = .normal
- objectAlightHorButton.reloadData()
- }
- if objectAlightBottomButton.properties.state == .pressed {
- objectAlightBottomButton.properties.state = .normal
- objectAlightBottomButton.reloadData()
- }
- if objectAverageVerButton.properties.state == .pressed {
- objectAverageVerButton.properties.state = .normal
- objectAverageVerButton.reloadData()
- }
- if objectAverageHorButton.properties.state == .pressed {
- objectAverageHorButton.properties.state = .normal
- objectAverageHorButton.reloadData()
- }
- if objectAlightVerButton.properties.state == .pressed {
- objectAlightVerButton.properties.state = .normal
- objectAlightVerButton.reloadData()
- }
-
- var button:ComponentButton = objectAlightLeftButton
- switch objectAlignType {
- case .alightLeft :
- button = objectAlightLeftButton
- break
- case .alightRight:
- button = objectAlightRightButton
- break
- case .alightTop:
- button = objectAlightTopButton
- break
- case .alightVer:
- button = objectAlightVerButton
- break
- case .alightHor:
- button = objectAlightHorButton
- break
- case .alightBottom:
- button = objectAlightBottomButton
- break
- case .averageVer:
- button = objectAverageVerButton
- break
- case .averageHor:
- button = objectAverageHorButton
- break
- }
- button.properties.state = .pressed
- button.reloadData()
- }
- }
-
- var fontChangeAlighCallback: FontChangeAlighCallback?
- var objectChangeAlighCallback: ObjectChangeAlighCallback?
- @IBOutlet weak var contentBox: NSBox!
- @IBOutlet weak var operationWidthConstraint: NSLayoutConstraint!
- @IBOutlet weak var operationHeightConstraint: NSLayoutConstraint!
- @IBOutlet var fontAlightView: NSView!
- @IBOutlet var alightLeftButton: ComponentButton!
- @IBOutlet var alightRightButton: ComponentButton!
- @IBOutlet var alightCenteButton: ComponentButton!
- @IBOutlet var alightJustifiedButton: ComponentButton!
- @IBOutlet weak var alightRightConstraint: NSLayoutConstraint!
-
- @IBOutlet var objectAlightView: NSView!
- @IBOutlet var objectAlightLeftButton: ComponentButton!
- @IBOutlet var objectAlightRightButton: ComponentButton!
- @IBOutlet var objectAlightTopButton: ComponentButton!
- @IBOutlet var objectAlightVerButton: ComponentButton!
- @IBOutlet var objectAlightHorButton: ComponentButton!
- @IBOutlet var objectAlightBottomButton: ComponentButton!
- @IBOutlet var objectAverageVerButton: ComponentButton!
- @IBOutlet var objectAverageHorButton: ComponentButton!
- @IBOutlet weak var objectRightConstraint: NSLayoutConstraint!
- override func viewDidLoad() {
- super.viewDidLoad()
- }
-
- override func initContentView() {
- super.initContentView()
-
- alightLeftButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopAlightLeft"))
- alightLeftButton.setTarget(self, action: #selector(alightLeftButtonClicked(_ :)))
-
- alightRightButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopAlightRight"))
- alightRightButton.setTarget(self, action: #selector(alightRightButtonClicked(_ :)))
-
- alightCenteButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopAlightCenter"))
- alightCenteButton.setTarget(self, action: #selector(alightCenterButtonClicked(_ :)))
-
- alightJustifiedButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopAlightJus"))
- alightJustifiedButton.setTarget(self, action: #selector(alightJustButtonClicked(_ :)))
-
- objectAlightLeftButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightLeft"))
- objectAlightLeftButton.setTarget(self, action: #selector(objectAlightLeftClick(_ :)))
-
- objectAlightRightButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightRight"))
- objectAlightRightButton.setTarget(self, action: #selector(objectAlightRightClick(_ :)))
-
- objectAlightTopButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightTop"))
- objectAlightTopButton.setTarget(self, action: #selector(objectAlightTopClick(_ :)))
-
- objectAlightVerButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightVer"))
- objectAlightVerButton.setTarget(self, action: #selector(objectAlightVerClick(_ :)))
-
- objectAlightHorButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightHor"))
- objectAlightHorButton.setTarget(self, action: #selector(objectAlightHorClick(_ :)))
-
- objectAlightBottomButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightBottom"))
- objectAlightBottomButton.setTarget(self, action: #selector(objectAlightBottomClicked(_ :)))
-
- objectAverageVerButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjecAlignAverageVer"))
- objectAverageVerButton.setTarget(self, action: #selector(objectAverageVerClicked(_ :)))
-
- objectAverageHorButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjecAlignAverageHor"))
- objectAverageHorButton.setTarget(self, action: #selector(objectAverageHorClicked(_ :)))
-
- }
-
- override func updateUIThemeColor() {
- super.updateUIThemeColor()
-
- contentBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup")
- contentBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/3-default")
- }
-
- override func updateUILanguage() {
- super.updateUILanguage()
-
- }
-
- //MARK: - Action
- @objc func alightLeftButtonClicked(_ sender: NSView) {
- if fontAlight != .left {
- fontAlight = .left
- fontChangeAlighCallback?(fontAlight)
- }
- }
-
- @objc func alightRightButtonClicked(_ sender: NSView) {
- if fontAlight != .right {
- fontAlight = .right
- fontChangeAlighCallback?(fontAlight)
- }
- }
-
- @objc func alightCenterButtonClicked(_ sender: NSView) {
- if fontAlight != .center {
- fontAlight = .center
- fontChangeAlighCallback?(fontAlight)
- }
- }
-
- @objc func alightJustButtonClicked(_ sender: NSView) {
- if fontAlight != .justified {
- fontAlight = .justified
- fontChangeAlighCallback?(fontAlight)
- }
- }
-
- @objc func objectAlightLeftClick(_ sender: NSView) {
- if objectAlignType != .alightLeft {
- objectAlignType = .alightLeft
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- @objc func objectAlightRightClick(_ sender: NSView) {
- if objectAlignType != .alightRight {
- objectAlignType = .alightRight
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- @objc func objectAlightTopClick(_ sender: NSView) {
- if objectAlignType != .alightTop {
- objectAlignType = .alightTop
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- @objc func objectAlightVerClick(_ sender: NSView) {
- if objectAlignType != .alightVer {
- objectAlignType = .alightVer
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- @objc func objectAlightHorClick(_ sender: NSView) {
- if objectAlignType != .alightHor {
- objectAlignType = .alightHor
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- @objc func objectAlightBottomClicked(_ sender: NSView) {
- if objectAlignType != .alightBottom {
- objectAlignType = .alightBottom
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- @objc func objectAverageVerClicked(_ sender: NSView) {
- if objectAlignType != .averageVer {
- objectAlignType = .averageVer
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- @objc func objectAverageHorClicked(_ sender: NSView) {
- if objectAlignType != .averageHor {
- objectAlignType = .averageHor
- objectChangeAlighCallback?(objectAlignType)
- }
- }
-
- }
|