KMPageEditInsertDirectionItemView.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // KMPageEditInsertDirectionItemView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/1/11.
  6. //
  7. import Cocoa
  8. class KMPageEditInsertDirectionItemView: KMPageEditBaseItemView {
  9. private var horVC: KMDesignButton?
  10. private var verVC: KMDesignButton?
  11. override func initSubviews() {
  12. super.initSubviews()
  13. self.horVC = KMDesignButton(withType: .RadioButton)
  14. self.addSubview(self.horVC!.view)
  15. self.horVC?.target = self
  16. self.horVC?.action = #selector(horAction)
  17. self.horVC?.stringValue = NSLocalizedString("Horizontal page", comment: "")
  18. self.horVC?.checkbox_radio()
  19. self.verVC = KMDesignButton(withType: .RadioButton)
  20. self.addSubview(self.verVC!.view)
  21. self.verVC?.target = self
  22. self.verVC?.action = #selector(verAction)
  23. self.verVC?.stringValue = NSLocalizedString("Vertical pages", comment: "")
  24. self.verVC?.checkbox_radio()
  25. self.titleLabel.stringValue = NSLocalizedString("Direction", comment: "")
  26. self.titleLabel.font = .SFProTextSemiboldFont(12)
  27. self.titleLabel.textColor = NSColor.km_init(hex: "#616469")
  28. self.horVC?.state = .Norm
  29. self.verVC?.state = .Checked
  30. }
  31. override func layout() {
  32. super.layout()
  33. let raidoY: CGFloat = self.titleLabel.frame.maxY
  34. let radioSize = NSSize(width: 150, height: 22)
  35. self.verVC?.view.frame = NSMakeRect(self.contentInset.left, raidoY, radioSize.width, radioSize.height)
  36. self.horVC?.view.frame = NSMakeRect(self.contentInset.left + radioSize.width, raidoY , radioSize.width, radioSize.height)
  37. }
  38. @objc private func horAction() {
  39. self.verVC?.state = .Norm
  40. self.horVC?.state = .Checked
  41. guard let callback = self.itemClick else {
  42. return
  43. }
  44. callback(1, "")
  45. }
  46. @objc private func verAction() {
  47. self.horVC?.state = .Norm
  48. self.verVC?.state = .Checked
  49. guard let callback = self.itemClick else {
  50. return
  51. }
  52. callback(2, "")
  53. }
  54. public func switchDirection(isHor: Bool) {
  55. self.horVC?.state = .Norm
  56. self.verVC?.state = .Norm
  57. if (isHor) {
  58. self.horVC?.state = .Checked
  59. } else {
  60. self.verVC?.state = .Checked
  61. }
  62. }
  63. public func getDirection() -> Int {
  64. if let state = self.horVC?.state {
  65. return state == .Checked ? 1 : 0
  66. }
  67. return 0
  68. }
  69. }