KMNPopDetailsViewController.swift 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. //
  2. // KMNPopDetailsViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/12/6.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. typealias FontChangeAlighCallback = (_ alight:NSTextAlignment) -> ()
  10. typealias ObjectChangeAlighCallback = (_ alight:ObjectAlignType) -> ()
  11. class KMNPopDetailsViewController: KMNBaseViewController {
  12. public var detailPopType:DetailPopType = .detailNone {
  13. didSet {
  14. switch detailPopType {
  15. case .freeTextAlight :
  16. alightRightConstraint.constant = 4
  17. alightJustifiedButton.isHidden = true
  18. fontAlightView.layoutSubtreeIfNeeded()
  19. operationWidthConstraint.constant = fontAlightView.bounds.width
  20. operationHeightConstraint.constant = fontAlightView.bounds.height
  21. self.view.layoutSubtreeIfNeeded()
  22. contentBox.contentView = fontAlightView
  23. break
  24. case .contentEditAlight:
  25. alightRightConstraint.constant = 44
  26. alightJustifiedButton.isHidden = false
  27. fontAlightView.layoutSubtreeIfNeeded()
  28. operationWidthConstraint.constant = fontAlightView.bounds.width
  29. operationHeightConstraint.constant = fontAlightView.bounds.height
  30. self.view.layoutSubtreeIfNeeded()
  31. contentBox.contentView = fontAlightView
  32. break
  33. case .doubleObjectAlight:
  34. objectRightConstraint.constant = 4
  35. objectAlightView.layoutSubtreeIfNeeded()
  36. objectAverageHorButton.isHidden = true
  37. objectAverageVerButton.isHidden = true
  38. operationWidthConstraint.constant = objectAlightView.bounds.width
  39. operationHeightConstraint.constant = objectAlightView.bounds.height
  40. self.view.layoutSubtreeIfNeeded()
  41. contentBox.contentView = objectAlightView
  42. break
  43. case .freeTextDoubleAlight:
  44. objectRightConstraint.constant = 4
  45. objectAlightView.layoutSubtreeIfNeeded()
  46. objectAverageHorButton.isHidden = true
  47. objectAverageVerButton.isHidden = true
  48. operationWidthConstraint.constant = objectAlightView.bounds.width
  49. operationHeightConstraint.constant = objectAlightView.bounds.height
  50. self.view.layoutSubtreeIfNeeded()
  51. contentBox.contentView = objectAlightView
  52. break
  53. case .multpleObjectAlight:
  54. objectRightConstraint.constant = 80
  55. objectAlightView.layoutSubtreeIfNeeded()
  56. objectAverageHorButton.isHidden = false
  57. objectAverageVerButton.isHidden = false
  58. operationWidthConstraint.constant = objectAlightView.bounds.width
  59. operationHeightConstraint.constant = objectAlightView.bounds.height
  60. self.view.layoutSubtreeIfNeeded()
  61. contentBox.contentView = objectAlightView
  62. break
  63. case .freeTextMultpleAlight:
  64. objectRightConstraint.constant = 80
  65. objectAlightView.layoutSubtreeIfNeeded()
  66. objectAverageHorButton.isHidden = false
  67. objectAverageVerButton.isHidden = false
  68. operationWidthConstraint.constant = objectAlightView.bounds.width
  69. operationHeightConstraint.constant = objectAlightView.bounds.height
  70. self.view.layoutSubtreeIfNeeded()
  71. contentBox.contentView = objectAlightView
  72. break
  73. case .detailNone:
  74. break
  75. }
  76. }
  77. }
  78. public var fontAlight:NSTextAlignment = .left {
  79. didSet {
  80. if alightRightButton.properties.state == .pressed {
  81. alightRightButton.properties.state = .normal
  82. alightRightButton.reloadData()
  83. }
  84. if alightCenteButton.properties.state == .pressed {
  85. alightCenteButton.properties.state = .normal
  86. alightCenteButton.reloadData()
  87. }
  88. if alightJustifiedButton.properties.state == .pressed {
  89. alightJustifiedButton.properties.state = .normal
  90. alightJustifiedButton.reloadData()
  91. }
  92. if alightLeftButton.properties.state == .pressed {
  93. alightLeftButton.properties.state = .normal
  94. alightLeftButton.reloadData()
  95. }
  96. if fontAlight == .left {
  97. alightLeftButton.properties.state = .pressed
  98. alightLeftButton.reloadData()
  99. } else if fontAlight == .right {
  100. alightRightButton.properties.state = .pressed
  101. alightRightButton.reloadData()
  102. } else if fontAlight == .center {
  103. alightCenteButton.properties.state = .pressed
  104. alightCenteButton.reloadData()
  105. } else if fontAlight == .justified {
  106. alightJustifiedButton.properties.state = .pressed
  107. alightJustifiedButton.reloadData()
  108. }
  109. }
  110. }
  111. public var objectAlignType:ObjectAlignType = .alightLeft {
  112. didSet {
  113. if objectAlightLeftButton.properties.state == .pressed {
  114. objectAlightLeftButton.properties.state = .normal
  115. objectAlightLeftButton.reloadData()
  116. }
  117. if objectAlightRightButton.properties.state == .pressed {
  118. objectAlightRightButton.properties.state = .normal
  119. objectAlightRightButton.reloadData()
  120. }
  121. if objectAlightTopButton.properties.state == .pressed {
  122. objectAlightTopButton.properties.state = .normal
  123. objectAlightTopButton.reloadData()
  124. }
  125. if objectAlightHorButton.properties.state == .pressed {
  126. objectAlightHorButton.properties.state = .normal
  127. objectAlightHorButton.reloadData()
  128. }
  129. if objectAlightBottomButton.properties.state == .pressed {
  130. objectAlightBottomButton.properties.state = .normal
  131. objectAlightBottomButton.reloadData()
  132. }
  133. if objectAverageVerButton.properties.state == .pressed {
  134. objectAverageVerButton.properties.state = .normal
  135. objectAverageVerButton.reloadData()
  136. }
  137. if objectAverageHorButton.properties.state == .pressed {
  138. objectAverageHorButton.properties.state = .normal
  139. objectAverageHorButton.reloadData()
  140. }
  141. if objectAlightVerButton.properties.state == .pressed {
  142. objectAlightVerButton.properties.state = .normal
  143. objectAlightVerButton.reloadData()
  144. }
  145. var button:ComponentButton = objectAlightLeftButton
  146. switch objectAlignType {
  147. case .alightLeft :
  148. button = objectAlightLeftButton
  149. break
  150. case .alightRight:
  151. button = objectAlightRightButton
  152. break
  153. case .alightTop:
  154. button = objectAlightTopButton
  155. break
  156. case .alightVer:
  157. button = objectAlightVerButton
  158. break
  159. case .alightHor:
  160. button = objectAlightHorButton
  161. break
  162. case .alightBottom:
  163. button = objectAlightBottomButton
  164. break
  165. case .averageVer:
  166. button = objectAverageVerButton
  167. break
  168. case .averageHor:
  169. button = objectAverageHorButton
  170. break
  171. }
  172. button.properties.state = .pressed
  173. button.reloadData()
  174. }
  175. }
  176. var fontChangeAlighCallback: FontChangeAlighCallback?
  177. var objectChangeAlighCallback: ObjectChangeAlighCallback?
  178. @IBOutlet weak var contentBox: NSBox!
  179. @IBOutlet weak var operationWidthConstraint: NSLayoutConstraint!
  180. @IBOutlet weak var operationHeightConstraint: NSLayoutConstraint!
  181. @IBOutlet var fontAlightView: NSView!
  182. @IBOutlet var alightLeftButton: ComponentButton!
  183. @IBOutlet var alightRightButton: ComponentButton!
  184. @IBOutlet var alightCenteButton: ComponentButton!
  185. @IBOutlet var alightJustifiedButton: ComponentButton!
  186. @IBOutlet weak var alightRightConstraint: NSLayoutConstraint!
  187. @IBOutlet var objectAlightView: NSView!
  188. @IBOutlet var objectAlightLeftButton: ComponentButton!
  189. @IBOutlet var objectAlightRightButton: ComponentButton!
  190. @IBOutlet var objectAlightTopButton: ComponentButton!
  191. @IBOutlet var objectAlightVerButton: ComponentButton!
  192. @IBOutlet var objectAlightHorButton: ComponentButton!
  193. @IBOutlet var objectAlightBottomButton: ComponentButton!
  194. @IBOutlet var objectAverageVerButton: ComponentButton!
  195. @IBOutlet var objectAverageHorButton: ComponentButton!
  196. @IBOutlet weak var objectRightConstraint: NSLayoutConstraint!
  197. override func viewDidLoad() {
  198. super.viewDidLoad()
  199. }
  200. override func initContentView() {
  201. super.initContentView()
  202. alightLeftButton.properties = ComponentButtonProperty(type: .text_gray,
  203. size: .s,
  204. state: .normal,
  205. onlyIcon: true,
  206. icon:NSImage(named: "KMNImageNameListViewPopAlightLeft"))
  207. alightLeftButton.setTarget(self, action: #selector(alightLeftButtonClicked(_ :)))
  208. alightRightButton.properties = ComponentButtonProperty(type: .text_gray,
  209. size: .s,
  210. state: .normal,
  211. onlyIcon: true,
  212. icon:NSImage(named: "KMNImageNameListViewPopAlightRight"))
  213. alightRightButton.setTarget(self, action: #selector(alightRightButtonClicked(_ :)))
  214. alightCenteButton.properties = ComponentButtonProperty(type: .text_gray,
  215. size: .s,
  216. state: .normal,
  217. onlyIcon: true,
  218. icon:NSImage(named: "KMNImageNameListViewPopAlightCenter"))
  219. alightCenteButton.setTarget(self, action: #selector(alightCenterButtonClicked(_ :)))
  220. alightJustifiedButton.properties = ComponentButtonProperty(type: .text_gray,
  221. size: .s,
  222. state: .normal,
  223. onlyIcon: true,
  224. icon:NSImage(named: "KMNImageNameListViewPopAlightJus"))
  225. alightJustifiedButton.setTarget(self, action: #selector(alightJustButtonClicked(_ :)))
  226. objectAlightLeftButton.properties = ComponentButtonProperty(type: .text_gray,
  227. size: .s,
  228. state: .normal,
  229. onlyIcon: true,
  230. icon:NSImage(named: "KMNImageNameObjectPopAlightLeft"))
  231. objectAlightLeftButton.setTarget(self, action: #selector(objectAlightLeftClick(_ :)))
  232. objectAlightRightButton.properties = ComponentButtonProperty(type: .text_gray,
  233. size: .s,
  234. state: .normal,
  235. onlyIcon: true,
  236. icon:NSImage(named: "KMNImageNameObjectPopAlightRight"))
  237. objectAlightRightButton.setTarget(self, action: #selector(objectAlightRightClick(_ :)))
  238. objectAlightTopButton.properties = ComponentButtonProperty(type: .text_gray,
  239. size: .s,
  240. state: .normal,
  241. onlyIcon: true,
  242. icon:NSImage(named: "KMNImageNameObjectPopAlightTop"))
  243. objectAlightTopButton.setTarget(self, action: #selector(objectAlightTopClick(_ :)))
  244. objectAlightVerButton.properties = ComponentButtonProperty(type: .text_gray,
  245. size: .s,
  246. state: .normal,
  247. onlyIcon: true,
  248. icon:NSImage(named: "KMNImageNameObjectPopAlightVer"))
  249. objectAlightVerButton.setTarget(self, action: #selector(objectAlightVerClick(_ :)))
  250. objectAlightHorButton.properties = ComponentButtonProperty(type: .text_gray,
  251. size: .s,
  252. state: .normal,
  253. onlyIcon: true,
  254. icon:NSImage(named: "KMNImageNameObjectPopAlightHor"))
  255. objectAlightHorButton.setTarget(self, action: #selector(objectAlightHorClick(_ :)))
  256. objectAlightBottomButton.properties = ComponentButtonProperty(type: .text_gray,
  257. size: .s,
  258. state: .normal,
  259. onlyIcon: true,
  260. icon:NSImage(named: "KMNImageNameObjectPopAlightBottom"))
  261. objectAlightBottomButton.setTarget(self, action: #selector(objectAlightBottomClicked(_ :)))
  262. objectAverageVerButton.properties = ComponentButtonProperty(type: .text_gray,
  263. size: .s,
  264. state: .normal,
  265. onlyIcon: true,
  266. icon:NSImage(named: "KMNImageNameObjecAlignAverageVer"))
  267. objectAverageVerButton.setTarget(self, action: #selector(objectAverageVerClicked(_ :)))
  268. objectAverageHorButton.properties = ComponentButtonProperty(type: .text_gray,
  269. size: .s,
  270. state: .normal,
  271. onlyIcon: true,
  272. icon:NSImage(named: "KMNImageNameObjecAlignAverageHor"))
  273. objectAverageHorButton.setTarget(self, action: #selector(objectAverageHorClicked(_ :)))
  274. }
  275. override func updateUIThemeColor() {
  276. super.updateUIThemeColor()
  277. contentBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup")
  278. contentBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/3-default")
  279. }
  280. override func updateUILanguage() {
  281. super.updateUILanguage()
  282. }
  283. //MARK: - Action
  284. @objc func alightLeftButtonClicked(_ sender: NSView) {
  285. if fontAlight != .left {
  286. fontAlight = .left
  287. fontChangeAlighCallback?(fontAlight)
  288. }
  289. }
  290. @objc func alightRightButtonClicked(_ sender: NSView) {
  291. if fontAlight != .right {
  292. fontAlight = .right
  293. fontChangeAlighCallback?(fontAlight)
  294. }
  295. }
  296. @objc func alightCenterButtonClicked(_ sender: NSView) {
  297. if fontAlight != .center {
  298. fontAlight = .center
  299. fontChangeAlighCallback?(fontAlight)
  300. }
  301. }
  302. @objc func alightJustButtonClicked(_ sender: NSView) {
  303. if fontAlight != .justified {
  304. fontAlight = .justified
  305. fontChangeAlighCallback?(fontAlight)
  306. }
  307. }
  308. @objc func objectAlightLeftClick(_ sender: NSView) {
  309. if objectAlignType != .alightLeft {
  310. objectAlignType = .alightLeft
  311. objectChangeAlighCallback?(objectAlignType)
  312. }
  313. }
  314. @objc func objectAlightRightClick(_ sender: NSView) {
  315. if objectAlignType != .alightRight {
  316. objectAlignType = .alightRight
  317. objectChangeAlighCallback?(objectAlignType)
  318. }
  319. }
  320. @objc func objectAlightTopClick(_ sender: NSView) {
  321. if objectAlignType != .alightTop {
  322. objectAlignType = .alightTop
  323. objectChangeAlighCallback?(objectAlignType)
  324. }
  325. }
  326. @objc func objectAlightVerClick(_ sender: NSView) {
  327. if objectAlignType != .alightVer {
  328. objectAlignType = .alightVer
  329. objectChangeAlighCallback?(objectAlignType)
  330. }
  331. }
  332. @objc func objectAlightHorClick(_ sender: NSView) {
  333. if objectAlignType != .alightHor {
  334. objectAlignType = .alightHor
  335. objectChangeAlighCallback?(objectAlignType)
  336. }
  337. }
  338. @objc func objectAlightBottomClicked(_ sender: NSView) {
  339. if objectAlignType != .alightBottom {
  340. objectAlignType = .alightBottom
  341. objectChangeAlighCallback?(objectAlignType)
  342. }
  343. }
  344. @objc func objectAverageVerClicked(_ sender: NSView) {
  345. if objectAlignType != .averageVer {
  346. objectAlignType = .averageVer
  347. objectChangeAlighCallback?(objectAlignType)
  348. }
  349. }
  350. @objc func objectAverageHorClicked(_ sender: NSView) {
  351. if objectAlignType != .averageHor {
  352. objectAlignType = .averageHor
  353. objectChangeAlighCallback?(objectAlignType)
  354. }
  355. }
  356. }