KMSignatureController.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // KMSignatureController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/12/5.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMSignatureController: KMNBaseViewController {
  10. @IBOutlet var rotateBGView: NSView!
  11. @IBOutlet var rotateLabel: NSTextField!
  12. @IBOutlet var rotateRightButton: ComponentButton!
  13. @IBOutlet var rotateLeftButton: ComponentButton!
  14. private var annotations: [CPDFSignatureAnnotation] = []
  15. var pdfView: CPDFListView?
  16. //MARK: - func
  17. override func viewDidAppear() {
  18. super.viewDidAppear()
  19. }
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. // Do view setup here.
  23. setupProperty()
  24. }
  25. override func updateUILanguage() {
  26. super.updateUILanguage()
  27. setupProperty()
  28. }
  29. override func updateUIThemeColor() {
  30. super.updateUIThemeColor()
  31. setupProperty()
  32. }
  33. func setupProperty() {
  34. rotateLabel.stringValue = KMLocalizedString("Rotate")
  35. rotateLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  36. rotateLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  37. rotateRightButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, onlyIcon: true, icon: NSImage(named: "pageEdit_rotateRight"), keepPressState: false)
  38. rotateRightButton.setTarget(self, action: #selector(buttonClicked(_ :)))
  39. rotateLeftButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, onlyIcon: true, icon: NSImage(named: "pageEdit_rotateLeft"), keepPressState: false)
  40. rotateLeftButton.setTarget(self, action: #selector(buttonClicked(_ :)))
  41. }
  42. func reloadData() {
  43. guard let pdfView = self.pdfView else {
  44. return
  45. }
  46. self.annotations.removeAll()
  47. let allAnnotations: [CPDFAnnotation] = pdfView.activeAnnotations as? [CPDFAnnotation] ?? []
  48. for annotation in allAnnotations {
  49. if annotation is CPDFSignatureAnnotation {
  50. annotations.append((annotation as! CPDFSignatureAnnotation))
  51. }
  52. }
  53. }
  54. //MARK: - Action
  55. @objc func buttonClicked(_ button: ComponentButton) {
  56. if button == rotateLeftButton {
  57. CPDFSignatureAnnotation.rotateLeft(annotations, withPDFView: pdfView)
  58. } else if button == rotateRightButton {
  59. CPDFSignatureAnnotation.rotateRight(annotations, withPDFView: pdfView)
  60. }
  61. }
  62. }