KMNPreView.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.paginationBox.borderWidth = 0
  51. }
  52. func setFileUrl(_ fileUrl: URL, password: String?) {
  53. pdfPreView.setFileUrl(fileUrl, password: password)
  54. }
  55. }