KMAlignmentController.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // KMAlignmentController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/7/10.
  6. //
  7. import Cocoa
  8. class KMAlignmentController: NSViewController {
  9. @IBOutlet weak var box1: NSBox!
  10. @IBOutlet weak var box2: NSBox!
  11. @IBOutlet weak var box3: NSBox!
  12. @IBOutlet weak var box4: NSBox!
  13. private var vc1_: KMDesignButton?
  14. private var vc2_: KMDesignButton?
  15. private var vc3_: KMDesignButton?
  16. private var vc4_: KMDesignButton?
  17. var itemAction: KMCommonClickBlock?
  18. private var isHor_ = false
  19. var isHor: Bool {
  20. get {
  21. return self.isHor_
  22. }
  23. }
  24. private var areaCount_ : Int = 0
  25. var areaCount: Int {
  26. get {
  27. return self.areaCount_
  28. }
  29. }
  30. deinit {
  31. KMPrint("KMAlignmentController deinit.")
  32. }
  33. convenience init(withIsHor isHor: Bool, areaCount: Int) {
  34. self.init(nibName: "KMAlignmentController", bundle: nil)
  35. self.isHor_ = isHor
  36. self.areaCount_ = areaCount
  37. }
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. self.view.wantsLayer = true
  41. self.view.layer?.backgroundColor = .white
  42. self.vc1_ = KMDesignButton(withType: .Image)
  43. self.box1.contentView = self.vc1_!.view
  44. self.box1.borderWidth = 0
  45. self.vc1_?.pagination()
  46. self.vc1_?.target = self
  47. self.vc1_?.action = #selector(_itemClick)
  48. if self.isHor {
  49. self.vc1_?.image = NSImage(named: "KMImageNameEditPDFImage45_1")!
  50. } else {
  51. self.vc1_?.image = NSImage(named: "KMImageNameEditPDFImage48_1")!
  52. }
  53. self.vc1_?.tag = 0
  54. self.vc2_ = KMDesignButton(withType: .Image)
  55. self.box2.contentView = self.vc2_!.view
  56. self.box2.borderWidth = 0
  57. self.vc2_?.pagination()
  58. self.vc2_?.target = self
  59. self.vc2_?.action = #selector(_itemClick)
  60. if self.isHor {
  61. self.vc2_?.image = NSImage(named: "KMImageNameEditPDFImage46_1")!
  62. } else {
  63. self.vc2_?.image = NSImage(named: "KMImageNameEditPDFImage49_1")!
  64. }
  65. self.vc2_?.tag = 1
  66. self.vc3_ = KMDesignButton(withType: .Image)
  67. self.box3.contentView = self.vc3_!.view
  68. self.box3.borderWidth = 0
  69. self.vc3_?.pagination()
  70. self.vc3_?.target = self
  71. self.vc3_?.action = #selector(_itemClick)
  72. if self.isHor {
  73. self.vc3_?.image = NSImage(named: "KMImageNameEditPDFImage47_1")!
  74. } else {
  75. self.vc3_?.image = NSImage(named: "KMImageNameEditPDFImage50_1")!
  76. }
  77. self.vc3_?.tag = 2
  78. self.vc4_ = KMDesignButton(withType: .Image)
  79. self.box4.contentView = self.vc4_!.view
  80. self.box4.borderWidth = 0
  81. self.vc4_?.pagination()
  82. self.vc4_?.target = self
  83. self.vc4_?.action = #selector(_itemClick)
  84. if self.isHor {
  85. // KMImageNameEditPDFImage21
  86. self.vc4_?.image = NSImage(named: "KMImageNameEditPDFImage21_1")!
  87. self.vc4_?._image_disabled = NSImage(named: "KMImageNameEditPDFImage21")!
  88. } else {
  89. // KMImageNameEditPDFImage20
  90. self.vc4_?.image = NSImage(named: "KMImageNameEditPDFImage20_1")!
  91. self.vc4_?._image_disabled = NSImage(named: "KMImageNameEditPDFImage20")!
  92. }
  93. self.vc4_?.tag = 3
  94. self.vc4_?.state = self.areaCount > 2 ? .Norm : .Disabled
  95. self.vc4_?.button.isEnabled = self.areaCount > 2
  96. self.reloadData()
  97. }
  98. @objc private func _itemClick(_ sender: NSButton) {
  99. self.itemAction?(sender.tag)
  100. }
  101. func reloadData() {
  102. if KMAppearance.isDarkMode() {
  103. self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  104. self.vc1_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  105. self.vc2_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  106. self.vc3_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  107. self.vc4_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  108. } else {
  109. self.view.layer?.backgroundColor = .white
  110. self.vc1_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  111. self.vc2_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  112. self.vc3_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  113. self.vc4_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  114. }
  115. }
  116. }