KMNPopDetailsViewController.swift 18 KB

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