KMNPreView.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // KMNPreView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/10/25.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNPreView: NSView, NibLoadable {
  10. @IBOutlet weak var pdfPreView: KMNPDFPreView!
  11. @IBOutlet weak var paginationBox: NSBox!
  12. @IBOutlet weak var pdfPreViewLeftConst: NSLayoutConstraint!
  13. @IBOutlet weak var pdfPreViewTopConst: NSLayoutConstraint!
  14. @IBOutlet weak var pdfPreViewRightConst: NSLayoutConstraint!
  15. @IBOutlet weak var paginationTopSpaceConst: NSLayoutConstraint!
  16. @IBOutlet weak var paginationLeftConst: NSLayoutConstraint!
  17. @IBOutlet weak var paginationRightConst: NSLayoutConstraint!
  18. @IBOutlet weak var paginationBottomConst: NSLayoutConstraint!
  19. var contentInset: NSEdgeInsets = .init(top: 16, left: 16, bottom: 16, right: 16) {
  20. didSet {
  21. pdfPreViewLeftConst.constant = contentInset.left
  22. pdfPreViewTopConst.constant = contentInset.top
  23. pdfPreViewRightConst.constant = contentInset.right
  24. paginationBottomConst.constant = contentInset.bottom
  25. }
  26. }
  27. private var pagination_ = ComponentPagination()
  28. deinit {
  29. KMPrint("KMNPreView deinit.")
  30. }
  31. override func draw(_ dirtyRect: NSRect) {
  32. super.draw(dirtyRect)
  33. // Drawing code here.
  34. }
  35. convenience init(fileUrl: URL, password: String?) {
  36. self.init()
  37. initSubviews()
  38. initDefaultValue()
  39. setFileUrl(fileUrl, password: password)
  40. }
  41. override func awakeFromNib() {
  42. super.awakeFromNib()
  43. initSubviews()
  44. initDefaultValue()
  45. }
  46. func initSubviews() {
  47. self.paginationBox.contentView = self.pagination_
  48. }
  49. func initDefaultValue() {
  50. // self.contentBox_.borderWidth = 2
  51. // self.contentBox_.borderColor = .red
  52. }
  53. func setFileUrl(_ fileUrl: URL, password: String?) {
  54. pdfPreView.setFileUrl(fileUrl, password: password)
  55. }
  56. }