KMConvertWordSettingView.swift 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // KMConvertWordSettingView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/6.
  6. //
  7. import KMComponentLibrary
  8. class KMConvertWordSettingView: KMConvertSettingView {
  9. @IBOutlet weak var pageSettingTitleLabel: NSTextField!
  10. @IBOutlet weak var saveFlowTextRadio: ComponentRadio!
  11. @IBOutlet weak var savePageLayoutRadio: ComponentRadio!
  12. @IBOutlet weak var textOCRBox: NSBox!
  13. @IBOutlet weak var pageRangeBox: NSBox!
  14. private var flowTextVC: KMDesignButton?
  15. private var pageLayoutVC: KMDesignButton?
  16. // 流排 0 框排 1
  17. var pageSettingSelectedIndex: Int = 0
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. saveFlowTextRadio.properties = ComponentCheckBoxProperty(size: .s,
  21. state: .normal,
  22. isDisabled: false,
  23. showhelp: false,
  24. text: NSLocalizedString("Retain Flowing Text", comment: ""),
  25. checkboxType: .normal)
  26. saveFlowTextRadio.setTarget(self, action: #selector(saveFlowTextRadioAction))
  27. savePageLayoutRadio.properties = ComponentCheckBoxProperty(size: .s,
  28. state: .normal,
  29. isDisabled: false,
  30. showhelp: false,
  31. text: NSLocalizedString("Retain Page Layout", comment: ""),
  32. checkboxType: .normal)
  33. savePageLayoutRadio.setTarget(self, action: #selector(savePageLayoutRadioAction))
  34. self._flowTextAction()
  35. }
  36. override func initSubViews() {
  37. super.initSubViews()
  38. // self.flowTextVC = KMDesignButton.init(withType: .RadioButton)
  39. // self.saveFlowTextRadio.addSubview(self.flowTextVC!.view)
  40. // self.flowTextVC?.view.frame = self.saveFlowTextRadio.bounds
  41. // self.flowTextVC?.view.autoresizingMask = [.width, .height]
  42. // self.flowTextVC?.target = self
  43. // self.flowTextVC?.action = #selector(saveFlowTextRadioAction)
  44. // self.flowTextVC?.stringValue = NSLocalizedString("Retain Flowing Text", comment: "")
  45. // self.flowTextVC?.checkbox_radio()
  46. // self.pageLayoutVC = KMDesignButton.init(withType: .RadioButton)
  47. // self.savePageLayoutRadio.addSubview(self.pageLayoutVC!.view)
  48. // self.pageLayoutVC?.view.frame = self.savePageLayoutRadio.bounds
  49. // self.pageLayoutVC?.view.autoresizingMask = [.width, .height]
  50. // self.pageLayoutVC?.target = self
  51. // self.pageLayoutVC?.action = #selector(savePageLayoutRadioAction)
  52. // self.pageLayoutVC?.stringValue = NSLocalizedString("Retain Page Layout", comment: "")
  53. // self.pageLayoutVC?.checkbox_radio()
  54. self.tipView?.km_add_left_constraint(constant: 8)
  55. self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
  56. self.tipView?.km_add_right_constraint()
  57. // self.tipView?.km_add_width_constraint(constant: 300)
  58. self.tipView?.km_add_height_constraint(constant: 16+20+16)
  59. }
  60. override func initDefaultVlaue() {
  61. super.initDefaultVlaue()
  62. self.pageSettingTitleLabel.stringValue = NSLocalizedString("Layout Settings", comment: "")
  63. self.pageSettingTitleLabel.textColor = NSColor.km_init(hex: "#616469")
  64. self.pageSettingTitleLabel.font = .SFProTextRegularFont(12)
  65. }
  66. override func viewDidMoveToWindow() {
  67. super.viewDidMoveToWindow()
  68. if (self.ocrItemView == nil) {
  69. self.ocrItemView = KMConvertOCRSettingItemView.createFromNib()
  70. self.textOCRBox.contentView = self.ocrItemView
  71. }
  72. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  73. if (self.pageRangeItemView == nil) {
  74. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  75. self.pageRangeBox.contentView = self.pageRangeItemView
  76. }
  77. }
  78. @objc func saveFlowTextRadioAction(sender: AnyObject) {
  79. self._flowTextAction()
  80. }
  81. @objc func savePageLayoutRadioAction(sender: AnyObject) {
  82. self._pageLayoutAction()
  83. }
  84. // MARK: - Private Methods
  85. private func _flowTextAction() {
  86. self.flowTextVC?.state = .Checked
  87. self.pageLayoutVC?.state = .Norm
  88. self.saveFlowTextRadio.properties.checkboxType = .selected
  89. self.saveFlowTextRadio.reloadData()
  90. self.savePageLayoutRadio.properties.checkboxType = .normal
  91. self.savePageLayoutRadio.reloadData()
  92. self.pageSettingSelectedIndex = 0
  93. }
  94. private func _pageLayoutAction() {
  95. self.pageLayoutVC?.state = .Checked
  96. self.flowTextVC?.state = .Norm
  97. self.savePageLayoutRadio.properties.checkboxType = .selected
  98. self.savePageLayoutRadio.reloadData()
  99. self.saveFlowTextRadio.properties.checkboxType = .normal
  100. self.saveFlowTextRadio.reloadData()
  101. self.pageSettingSelectedIndex = 1
  102. }
  103. }