KMCropController.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // KMCropController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/11/20.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMCropController: NSViewController {
  10. @IBOutlet var contendView: NSView!
  11. @IBOutlet var preInfoView: NSView!
  12. @IBOutlet var propertyInfoView: NSView!
  13. var pdfDocument: CPDFDocument?
  14. var documentPreview: KMEditDocumentController = KMEditDocumentController.init()
  15. var propertyController: KMCropPropertyController = KMCropPropertyController.init()
  16. var coverController: KMCropCoverController?
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. // Do view setup here.
  20. setup()
  21. }
  22. func setup() {
  23. view.wantsLayer = true
  24. view.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
  25. documentPreview.view.frame = preInfoView.bounds
  26. documentPreview.view.autoresizingMask = [.width, .height]
  27. documentPreview.pdfView.pdfListViewDelegate = self
  28. preInfoView.addSubview(documentPreview.view)
  29. propertyController.view.frame = propertyInfoView.bounds
  30. propertyController.view.autoresizingMask = [.width, .height]
  31. propertyInfoView.addSubview(propertyController.view)
  32. // if coverController == nil {
  33. // coverController = KMCropCoverController.init()
  34. // }
  35. // coverController?.view.frame = CGRectInset(documentPreview.pdfView.bounds, 0, 0)
  36. // coverController?.view.autoresizingMask = [.width, .height]
  37. // preInfoView.addSubview(coverController!.view)
  38. }
  39. func reloadData() {
  40. guard let pdfDocument = pdfDocument else {
  41. return
  42. }
  43. documentPreview.pdfDocument = pdfDocument
  44. documentPreview.reloadData()
  45. let page = pdfDocument.page(at: 0)
  46. let bounds = page?.bounds ?? CGRectZero
  47. documentPreview.pdfView.toolMode = .selectToolMode
  48. documentPreview.pdfView.selectionRect = bounds
  49. propertyController.pdfView = documentPreview.pdfView
  50. propertyController.reloadData()
  51. }
  52. }
  53. extension KMCropController: CPDFListViewDelegate {
  54. func pdfListViewChangedSelectionOrMagnification(_ pdfListView: CPDFListView!) {
  55. print("pdfListViewChangedSelectionOrMagnification")
  56. propertyController.reloadData()
  57. }
  58. func pdfListViewDidSelectionEnd(_ pdfListView: CPDFListView!) {
  59. print("pdfListViewDidSelectionEnd")
  60. propertyController.reloadData()
  61. }
  62. }