KMEraserController.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // KMEraserController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/11/26.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMEraserController: NSViewController {
  10. @IBOutlet var eraserBGView: NSView!
  11. @IBOutlet var eraserLabel: NSTextField!
  12. @IBOutlet var eraserSlider: ComponentSlider!
  13. @IBOutlet var eraserSelect: ComponentSelect!
  14. //MARK: - func
  15. override func viewDidAppear() {
  16. super.viewDidAppear()
  17. eraserSlider.reloadData()
  18. }
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. // Do view setup here.
  22. setupProperty()
  23. }
  24. func setupProperty() {
  25. eraserLabel.stringValue = KMLocalizedString("Line")
  26. eraserLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  27. eraserLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  28. eraserSlider.properties = ComponentSliderProperty(size: .m, percent: 1)
  29. eraserSlider.delegate = self
  30. eraserSelect.properties = ComponentSelectProperties(size: .s,
  31. state: .normal,
  32. creatable: true,
  33. text: "2",
  34. textUnit: " pt",
  35. regexString: "0123456789 pt")
  36. if true {
  37. var opacityItems: [ComponentMenuitemProperty] = []
  38. for string in ["1 pt", "3 pt", "6 pt", "9 pt", "12 pt", "15 pt", "18 pt"] {
  39. let item = ComponentMenuitemProperty(type: .normal, text: string)
  40. opacityItems.append(item)
  41. }
  42. eraserSelect.updateMenuItemsArr(opacityItems)
  43. }
  44. eraserSelect.delegate = self
  45. }
  46. func reloadData() {
  47. }
  48. }
  49. //MARK: - ComponentSliderDelegate
  50. extension KMEraserController: ComponentSliderDelegate {
  51. func componentSliderDidUpdate(_ view: ComponentSlider) {
  52. if view == eraserSlider {
  53. let percent = view.properties.percent * 17 + 1
  54. CPDFAnnotationConfig.setDefaultFloatValue(percent, toKey: CEraserkNoteLineWidthKey)
  55. }
  56. reloadData()
  57. }
  58. }
  59. //MARK: - ComponentSelectDelegate
  60. extension KMEraserController: ComponentSelectDelegate {
  61. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  62. if let result = menuItemProperty?.text {
  63. let result = result.stringByDeleteCharString(view?.properties.textUnit ?? "")
  64. var value = result.stringToCGFloat()
  65. if value > 18 {
  66. value = 18
  67. } else if value < 1 {
  68. value = 1
  69. }
  70. CPDFAnnotationConfig.setDefaultFloatValue(value, toKey: CEraserkNoteLineWidthKey)
  71. }
  72. }
  73. func componentSelectTextDidEndEditing(_ view: ComponentSelect, removeUnit text: String?) {
  74. if let result = text {
  75. if view == eraserSelect {
  76. var value = result.stringToCGFloat()
  77. if value > 18 {
  78. value = 18
  79. } else if value < 1 {
  80. value = 1
  81. }
  82. CPDFAnnotationConfig.setDefaultFloatValue(value, toKey: CEraserkNoteLineWidthKey)
  83. }
  84. reloadData()
  85. }
  86. }
  87. }