KMSignatureController.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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: NSViewController {
  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. func setupProperty() {
  26. rotateLabel.stringValue = KMLocalizedString("Rotate")
  27. rotateLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  28. rotateLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  29. rotateRightButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, onlyIcon: true, icon: NSImage(named: "pageEdit_rotateRight"), keepPressState: false)
  30. rotateRightButton.setTarget(self, action: #selector(buttonClicked(_ :)))
  31. rotateLeftButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, onlyIcon: true, icon: NSImage(named: "pageEdit_rotateLeft"), keepPressState: false)
  32. rotateLeftButton.setTarget(self, action: #selector(buttonClicked(_ :)))
  33. }
  34. func reloadData() {
  35. guard let pdfView = self.pdfView else {
  36. return
  37. }
  38. self.annotations.removeAll()
  39. let allAnnotations: [CPDFAnnotation] = pdfView.activeAnnotations as? [CPDFAnnotation] ?? []
  40. for annotation in allAnnotations {
  41. if annotation is CPDFSignatureAnnotation {
  42. annotations.append((annotation as! CPDFSignatureAnnotation))
  43. }
  44. }
  45. }
  46. //MARK: - Action
  47. @objc func buttonClicked(_ button: ComponentButton) {
  48. if button == rotateLeftButton {
  49. CPDFSignatureAnnotation.rotateLeft(annotations, withPDFView: pdfView)
  50. } else if button == rotateRightButton {
  51. CPDFSignatureAnnotation.rotateRight(annotations, withPDFView: pdfView)
  52. }
  53. }
  54. }