KMPDFViewPanelSetViewController.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. //
  2. // KMPDFViewPanelSetViewController.swift
  3. // PDF Master
  4. //
  5. // Created by lxy on 2023/1/17.
  6. //
  7. import Cocoa
  8. protocol KMPDFViewPanelSetViewControllerDelegate: AnyObject {
  9. func controller(_ controller: KMPDFViewPanelSetViewController, dispayDidChange dispay: KMPDFDisplayType)
  10. func controller(_ controller: KMPDFViewPanelSetViewController, pageBreaksClick pageBreaks: Bool)
  11. func controller(_ controller: KMPDFViewPanelSetViewController, rotateClick rotateType: KMRotateType)
  12. }
  13. extension KMPDFViewPanelSetViewControllerDelegate {
  14. func controller(_ controller: KMPDFViewPanelSetViewController, pageBreaksClick pageBreaks: Bool) {
  15. }
  16. func controller(_ controller: KMPDFViewPanelSetViewController, rotateClick rotateType: KMRotateType) {
  17. }
  18. }
  19. class KMPDFViewPanelSetViewController: NSViewController {
  20. @IBOutlet weak var contentView: NSView!
  21. @IBOutlet weak var shouModelTitleLabel: NSTextField!
  22. @IBOutlet weak var mainTitleLabel: NSTextField!
  23. @IBOutlet weak var slideLabel: NSTextField!
  24. @IBOutlet weak var bookLabel: NSTextField!
  25. @IBOutlet weak var doublePageLabel: NSTextField!
  26. @IBOutlet weak var singlePageLabel: NSTextField!
  27. @IBOutlet weak var readLabel: NSTextField!
  28. @IBOutlet weak var fullScreenLabel: NSTextField!
  29. @IBOutlet weak var rightRotationButton: NSButton!
  30. @IBOutlet weak var leftRotationButton: NSButton!
  31. @IBOutlet weak var rotationLabel: NSTextField!
  32. @IBOutlet weak var continuousRollingButton: NSButton!
  33. @IBOutlet weak var pageBreakButton: NSButton!
  34. @IBOutlet weak var pptImageView: NSImageView!
  35. @IBOutlet weak var fullSceenImageView: NSImageView!
  36. @IBOutlet weak var readImageView: NSImageView!
  37. @IBOutlet weak var bookImageView: NSImageView!
  38. @IBOutlet weak var singlePageImageView: NSImageView!
  39. @IBOutlet weak var twoPageImageView: NSImageView!
  40. weak var listView : CPDFListView?
  41. weak var delegate: KMPDFViewPanelSetViewControllerDelegate?
  42. override func viewDidLoad() {
  43. super.viewDidLoad()
  44. self.setup()
  45. self.updateUI()
  46. self.updateLanguage()
  47. }
  48. deinit {
  49. NotificationCenter.default.removeObserver(self)
  50. }
  51. func addNotification() {
  52. NotificationCenter.default.addObserver(self, selector: #selector(displayModeChangedNotification), name: NSNotification.Name.CPDFViewDisplayModeChanged, object:nil)
  53. }
  54. func setup() {
  55. }
  56. func updateLanguage() {
  57. self.shouModelTitleLabel.stringValue = NSLocalizedString("Display Model", comment: "")
  58. self.mainTitleLabel.stringValue = NSLocalizedString("View", comment: "")
  59. self.slideLabel.stringValue = NSLocalizedString("Read Mode", comment: "")
  60. self.bookLabel.stringValue = NSLocalizedString("Book Mode", comment: "")
  61. self.doublePageLabel.stringValue = NSLocalizedString("Two Pages", comment: "")
  62. self.singlePageLabel.stringValue = NSLocalizedString("Single Page", comment: "")
  63. self.readLabel.stringValue = NSLocalizedString("PPT", comment: "")
  64. self.rotationLabel.stringValue = NSLocalizedString("Rotate", comment: "")
  65. self.fullScreenLabel.stringValue = NSLocalizedString("Full Screen", comment: "")
  66. self.continuousRollingButton.title = NSLocalizedString("Continuous Scroll", comment: "")
  67. self.pageBreakButton.title = NSLocalizedString("Page Breaks", comment: "")
  68. }
  69. func updateUI() {
  70. self.contentView!.backgroundColor(NSColor(hex: "#F7F8FA"))
  71. self.rotationLabel.textColor = NSColor(hex: "#616469")
  72. self.rotationLabel.font = NSFont.SFProTextRegular(11.0)
  73. self.shouModelTitleLabel.textColor = NSColor(hex: "#616469")
  74. self.shouModelTitleLabel.font = NSFont.SFProTextRegular(11.0)
  75. self.singlePageLabel.textColor = NSColor(hex: "#616469")
  76. self.singlePageLabel.font = NSFont.SFProTextRegular(11.0)
  77. self.doublePageLabel.textColor = NSColor(hex: "#616469")
  78. self.doublePageLabel.font = NSFont.SFProTextRegular(11.0)
  79. self.bookLabel.textColor = NSColor(hex: "#616469")
  80. self.bookLabel.font = NSFont.SFProTextRegular(11.0)
  81. self.readLabel.font = NSFont.SFProTextRegular(11.0)
  82. self.readLabel.font = NSFont.SFProTextRegular(11.0)
  83. self.fullScreenLabel.font = NSFont.SFProTextRegular(11.0)
  84. self.fullScreenLabel.font = NSFont.SFProTextRegular(11.0)
  85. self.slideLabel.font = NSFont.SFProTextRegular(11.0)
  86. self.slideLabel.font = NSFont.SFProTextRegular(11.0)
  87. self.leftRotationButton.wantsLayer = true
  88. self.leftRotationButton.layer?.borderWidth = 1
  89. self.leftRotationButton.layer?.cornerRadius = 4
  90. self.leftRotationButton.layer?.borderColor = NSColor(hex: "#DFE1E5").cgColor
  91. self.leftRotationButton.layer?.backgroundColor = NSColor.white.cgColor
  92. self.rightRotationButton.wantsLayer = true
  93. self.rightRotationButton.layer?.borderWidth = 1
  94. self.rightRotationButton.layer?.cornerRadius = 4
  95. self.rightRotationButton.layer?.borderColor = NSColor(hex: "#DFE1E5").cgColor
  96. self.rightRotationButton.layer?.backgroundColor = NSColor.white.cgColor
  97. self.reloadListViewModel()
  98. }
  99. func reloadListViewModel() {
  100. if(self.listView?.displayTwoUp == true) {
  101. if self.listView?.displaysAsBook == true {
  102. self.updateDispalyMode(currentImgae: bookImageView)
  103. } else {
  104. self.updateDispalyMode(currentImgae: twoPageImageView)
  105. }
  106. } else {
  107. self.updateDispalyMode(currentImgae: singlePageImageView)
  108. }
  109. if(self.listView?.displayDirection == .vertical) {
  110. self.continuousRollingButton.state = .on
  111. } else {
  112. self.continuousRollingButton.state = .off
  113. }
  114. if self.listView?.displaysPageBreaks == true {
  115. self.pageBreakButton.state = .on
  116. } else {
  117. self.pageBreakButton.state = .off
  118. }
  119. }
  120. @IBAction func setPDFViewShow_Click(_ sender: NSButton) {
  121. let continous = self.continuousRollingButton.state == .on
  122. switch sender.tag {
  123. case 0:
  124. self.delegate?.controller(self, dispayDidChange: continous ? .singlePageContinuous : .singlePage)
  125. self.updateDispalyMode(currentImgae: singlePageImageView)
  126. break
  127. case 1:
  128. self.delegate?.controller(self, dispayDidChange: continous ? .twoUpContinuous : .twoUp)
  129. self.updateDispalyMode(currentImgae: twoPageImageView)
  130. break
  131. case 2:
  132. self.delegate?.controller(self, dispayDidChange: continous ? .bookContinuous : .bookMode)
  133. self.updateDispalyMode(currentImgae: bookImageView)
  134. break
  135. case 3:
  136. self.delegate?.controller(self, dispayDidChange: continous ? .readContinuous : .readModel)
  137. break
  138. case 4:
  139. self.view.window?.toggleFullScreen(nil)
  140. break
  141. case 5:
  142. break
  143. default:
  144. break
  145. }
  146. }
  147. private func updateDispalyMode(currentImgae:NSImageView) {
  148. let images : [NSImageView] = [singlePageImageView,twoPageImageView,bookImageView,readImageView,fullSceenImageView,pptImageView]
  149. let imageNor : [String] = ["KMImageNamePDFViewSignleNor","KMImageNamePDFViewTwoNor","KMImageNamePDFViewBookNor","KMImageNamePDFViewReadNor","KMImageNamePDFViewFullScreenNor","KMImageNamePDFViewTTSNor"]
  150. let imageSel : [String] = ["KMImageNamePDFViewSignleSel","KMImageNamePDFViewTwoSel","KMImageNamePDFViewBookSel","KMImageNamePDFViewReadSel","KMImageNamePDFViewFullScreenSel","KMImageNamePDFViewTTSSel"]
  151. for index in 0 ..< images.count - 1 {
  152. let image = images[index]
  153. image.wantsLayer = true
  154. image.layer?.borderWidth = 1.0
  155. image.layer?.cornerRadius = 4.0
  156. if currentImgae == image {
  157. image.layer?.backgroundColor = NSColor(hex: "#CED0D4",alpha:0.6).cgColor
  158. image.layer?.borderColor = NSColor(hex: "#CED0D4").cgColor
  159. image.image = NSImage(named: imageSel[index])
  160. } else {
  161. image.layer?.backgroundColor = NSColor.clear.cgColor
  162. image.layer?.borderColor = NSColor.clear.cgColor
  163. image.image = NSImage(named: imageNor[index])
  164. }
  165. }
  166. }
  167. @IBAction func singlePageAction(_ sender: Any) {
  168. // mainVC?.singlePageScreen(isSinglePage: true, doublePagesScreen: false)
  169. }
  170. @IBAction func verticalSplitAction(_ sender: Any) {
  171. // mainVC?.singlePageScreen(isSinglePage: false, doublePagesScreen: false)
  172. }
  173. @IBAction func horizontalSplitAction(_ sender: Any) {
  174. // mainVC!.singlePageScreen(isSinglePage: false, doublePagesScreen: true)
  175. }
  176. @IBAction func setSplitModel_Click(_ sender: Any) {
  177. }
  178. @IBAction func continuousRollingButton_Click(_ sender: Any) {
  179. let continous = self.continuousRollingButton.state == .on
  180. if self.listView?.displayMode() == .singlePage {
  181. if (continous) {
  182. self.delegate?.controller(self, dispayDidChange: .singlePageContinuous)
  183. }
  184. } else if self.listView?.displayMode() == .singlePageContinuous {
  185. if (continous == false) {
  186. self.delegate?.controller(self, dispayDidChange: .singlePage)
  187. }
  188. } else if self.listView?.displayMode() == .twoUp {
  189. if (continous) {
  190. self.delegate?.controller(self, dispayDidChange: .twoUpContinuous)
  191. }
  192. } else if self.listView?.displayMode() == .twoUpContinuous {
  193. if (continous == false) {
  194. self.delegate?.controller(self, dispayDidChange: .twoUp)
  195. }
  196. }
  197. }
  198. @IBAction func pageBreakButton_Click(_ sender: Any) {
  199. self.delegate?.controller(self, pageBreaksClick: self.pageBreakButton.state == .on)
  200. }
  201. @IBAction func rotationButton_Click(_ sender: Any) {
  202. self.delegate?.controller(self, rotateClick: .clockwise)
  203. }
  204. @IBAction func rotationButtonRight_Click(_ sender: Any) {
  205. self.delegate?.controller(self, rotateClick: .anticlockwise)
  206. }
  207. @objc func displayModeChangedNotification(_ notification: Notification) -> Void {
  208. if notification.object is CPDFListView {
  209. let pdfview = notification.object as! CPDFListView
  210. if(pdfview.document == self.listView?.document) {
  211. self.reloadListViewModel()
  212. }
  213. }
  214. }
  215. }