CardVC.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // CardVC.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/9/14.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class CardVC: NSViewController {
  10. //PDFTool
  11. @IBOutlet weak var cardPDFTool: ComponentCardPDFTool!
  12. @IBOutlet weak var pdftoolCollaspseBtn: NSButton!
  13. @IBOutlet weak var pdfToolHeightConst: NSLayoutConstraint!
  14. //File
  15. @IBOutlet weak var cardFile: ComponentCardFile!
  16. @IBOutlet weak var fileFolderBtn: NSButton!
  17. @IBOutlet weak var fileHeightConst: NSLayoutConstraint!
  18. //Watermark
  19. @IBOutlet weak var cardWatermark: ComponentCardWatermark!
  20. //Header
  21. @IBOutlet weak var cardHeaderFooter: ComponentCardHeader!
  22. @IBOutlet weak var position00Btn: NSButton!
  23. @IBOutlet weak var position01Btn: NSButton!
  24. @IBOutlet weak var position10Btn: NSButton!
  25. @IBOutlet weak var position11Btn: NSButton!
  26. @IBOutlet weak var position20Btn: NSButton!
  27. @IBOutlet weak var position21Btn: NSButton!
  28. @IBOutlet weak var cardHeaderConst: NSLayoutConstraint!
  29. //Stamp
  30. @IBOutlet weak var cardStamp: ComponentCardStamp!
  31. override func viewDidLoad() {
  32. super.viewDidLoad()
  33. // Do view setup here.
  34. self.position00Btn.state = .on
  35. self.reloadData()
  36. }
  37. func reloadData() {
  38. //Tool
  39. let pdftoolProperty: ComponentCardPDFToolProperty = ComponentCardPDFToolProperty(collapse: self.pdftoolCollaspseBtn.state == .on,
  40. state: .normal,
  41. icon: ComponentLibrary.shared.image(forResource: "test"),
  42. text: "Example",
  43. subText: "content content content content content content content content")
  44. self.cardPDFTool.properties = pdftoolProperty
  45. self.pdfToolHeightConst.constant = self.cardPDFTool.properties.collapse == true ? 60 : 88
  46. //File
  47. let fileProperty: ComponentCardFileProperty = ComponentCardFileProperty(folder: self.fileFolderBtn.state == .on,
  48. state: .normal,
  49. icon: NSImage(named: "ic_propertybar_file_pdf"),
  50. text: "Sample text")
  51. self.cardFile.properties = fileProperty
  52. self.fileHeightConst.constant = self.fileFolderBtn.state == .on ? 182 : 224
  53. //Watermark
  54. let watermarkProperty: ComponentCardWMProperty = ComponentCardWMProperty(state: .normal,
  55. icon: NSImage(named: "ic_propertybar_file_pdf"),
  56. text: "Watermark")
  57. self.cardWatermark.properties = watermarkProperty
  58. //HeaderFooter
  59. var headeritems: [CardHeaderItemInfo] = []
  60. if self.position00Btn.state == .on {
  61. let property = ComponentCPositionProperty(rowCount: 2, columnCount: 3, dash: true, isDisable: true, selRow: 0, selColumn: 0)
  62. let itemInfo = CardHeaderItemInfo(property: property, text: "Text-Text")
  63. headeritems.append(itemInfo)
  64. }
  65. if self.position01Btn.state == .on {
  66. let property = ComponentCPositionProperty(rowCount: 2, columnCount: 3, dash: true, isDisable: true, selRow: 0, selColumn: 1)
  67. let itemInfo = CardHeaderItemInfo(property: property, text: "Text-Text")
  68. headeritems.append(itemInfo)
  69. }
  70. if self.position10Btn.state == .on {
  71. let property = ComponentCPositionProperty(rowCount: 2, columnCount: 3, dash: true, isDisable: true, selRow: 1, selColumn: 0)
  72. let itemInfo = CardHeaderItemInfo(property: property, text: "Text-Text")
  73. headeritems.append(itemInfo)
  74. }
  75. if self.position11Btn.state == .on {
  76. let property = ComponentCPositionProperty(rowCount: 2, columnCount: 3, dash: true, isDisable: true, selRow: 1, selColumn: 1)
  77. let itemInfo = CardHeaderItemInfo(property: property, text: "Text-Text")
  78. headeritems.append(itemInfo)
  79. }
  80. if self.position20Btn.state == .on {
  81. let property = ComponentCPositionProperty(rowCount: 2, columnCount: 3, dash: true, isDisable: true, selRow: 0, selColumn: 2)
  82. let itemInfo = CardHeaderItemInfo(property: property, text: "Text-Text")
  83. headeritems.append(itemInfo)
  84. }
  85. if self.position21Btn.state == .on {
  86. let property = ComponentCPositionProperty(rowCount: 2, columnCount: 3, dash: true, isDisable: true, selRow: 1, selColumn: 2)
  87. let itemInfo = CardHeaderItemInfo(property: property, text: "Text-Text")
  88. headeritems.append(itemInfo)
  89. }
  90. let headerProperty: ComponentCardHeaderProperty = ComponentCardHeaderProperty(state: .normal, text: "Header Footer", items: headeritems)
  91. self.cardHeaderFooter.properties = headerProperty
  92. self.cardHeaderConst.constant = self.cardHeaderFooter.properties.propertyInfo.viewHeight
  93. //Stamp
  94. let stampProperty = ComponentCardStampProperty(state: .normal, icon: NSImage(named: "ic_propertybar_file_pdf"))
  95. self.cardStamp.properties = stampProperty
  96. }
  97. @IBAction func clickAction(_ sender: Any) {
  98. self.reloadData()
  99. }
  100. }