KMToolbarRightView.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // KMToolbarRightView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2022/12/9.
  6. //
  7. import Cocoa
  8. @objc protocol KMToolbarRightViewDelegate {
  9. @objc func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?)
  10. @objc func userInfoButtonAction(_ sender: NSButton)
  11. @objc func homeRefreshButtonAction(_ sender: NSButton?)
  12. @objc func homeUploadButtonAction(_ sender: NSButton)
  13. @objc func homeMenuSortAction(_ sender: NSPopUpButton)
  14. @objc func homeMenuFilterAction(_ sender: NSPopUpButton)
  15. }
  16. @objcMembers class KMToolbarRightView: NSView {
  17. open var delete: KMToolbarRightViewDelegate?
  18. @IBOutlet weak var homeRefreshButton: NSButton!
  19. @IBOutlet weak var homeUploadButton: NSButton!
  20. @IBOutlet weak var userInfoButton: NSButton!
  21. @IBOutlet weak var sortPopUpButton: NSPopUpButton!
  22. @IBOutlet weak var filterPopUpButton: NSPopUpButton!
  23. @IBOutlet weak var homeRightSearchField: NSSearchField!
  24. @IBOutlet weak var pdfRightSegmentedBox: KMSegmentedBox!
  25. @IBOutlet weak var rightSegmentControlConstraint: NSLayoutConstraint!
  26. @IBOutlet weak var advancedContentView: NSView!
  27. @IBOutlet weak var advancedLabel: NSTextField!
  28. @IBOutlet weak var trailPositionView: NSView!
  29. @IBOutlet weak var trailPositionWidthConst: NSLayoutConstraint!
  30. @IBOutlet weak var filterPopUpButtonWidth: NSLayoutConstraint!
  31. @IBOutlet weak var filterPopUpButtonLeft: NSLayoutConstraint!
  32. @IBOutlet weak var advancedViewRightConstraint: NSLayoutConstraint!
  33. deinit {
  34. self.removeNotification()
  35. }
  36. override func draw(_ dirtyRect: NSRect) {
  37. super.draw(dirtyRect)
  38. // Drawing code here.
  39. }
  40. override func awakeFromNib() {
  41. super.awakeFromNib()
  42. self.updateView()
  43. self.addNotification()
  44. }
  45. @objc func updateView() -> Void {
  46. if canShowAdvanced() {
  47. if self.advancedLabel != nil {
  48. self.advancedContentView.isHidden = false
  49. self.advancedViewRightConstraint.constant = 8.0
  50. self.advancedLabel.font = NSFont.SFProTextRegularFont(12.0)
  51. self.advancedLabel.textColor = NSColor.km_init(hex: "#FFFFFF")
  52. var advancedString = NSLocalizedString("Upgrade", comment: "")
  53. self.advancedLabel.stringValue = advancedString
  54. }
  55. } else {
  56. if self.advancedContentView != nil {
  57. self.advancedContentView.isHidden = true
  58. self.advancedViewRightConstraint.constant = -163.0
  59. }
  60. }
  61. if self.userInfoButton != nil {
  62. }
  63. }
  64. func canShowAdvanced() -> Bool {
  65. return false
  66. }
  67. func fetchAdvancedViewSize() -> CGSize {
  68. var advancedString = NSLocalizedString("Upgrade", comment: "")
  69. let paragraphStyle = NSMutableParagraphStyle()
  70. paragraphStyle.lineHeightMultiple = 1.32
  71. paragraphStyle.alignment = .right
  72. let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle,
  73. NSAttributedString.Key.font : NSFont.SFProTextRegularFont(12.0)]
  74. let title: NSString = advancedString as NSString
  75. let size = title.boundingRect(with: CGSize(width: 300, height: 24) ,
  76. attributes: attributes).size
  77. let resultSize = CGSize(width: size.width + 8 + 16 + 8 + 8, height: size.height)
  78. if self.rightSegmentControlConstraint != nil {
  79. self.rightSegmentControlConstraint.constant = resultSize.width
  80. }
  81. return resultSize
  82. }
  83. func fetchAdvancedViewSize_update_rightSegmentControlConstraint() {
  84. if self.rightSegmentControlConstraint != nil {
  85. self.rightSegmentControlConstraint.constant = 89.0
  86. }
  87. }
  88. func addNotification() {
  89. self.removeNotification()
  90. }
  91. func updateAdvancedContentView() {
  92. self.updateView()
  93. self.delete?.homeRefreshButtonAction(nil)
  94. }
  95. func removeNotification() {
  96. NotificationCenter.default.removeObserver(self)
  97. }
  98. // MARK: Dark&Light
  99. // MARK: Action
  100. @IBAction func advancedButtonAction(_ sender: Any) {
  101. self.delete?.pdfRightSegmentedControlAction(nil)
  102. }
  103. @IBAction func homeRefreshButtonAction(_ sender: Any) {
  104. }
  105. @IBAction func homeUploadButtonAction(_ sender: Any) {
  106. }
  107. @IBAction func homeMenuSortAction(_ sender: Any) {
  108. }
  109. @IBAction func homeMenuFilterAction(_ sender: Any) {
  110. }
  111. @IBAction func userInfoButtonAction(_ sender: Any) {
  112. self.delete?.userInfoButtonAction(sender as! NSButton)
  113. }
  114. }