123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // KMSplitToolbar.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/10/29.
- //
- import Cocoa
- import KMComponentLibrary
- class KMSplitToolbar: BaseXibView {
-
- @IBOutlet var contendView: NSView!
- @IBOutlet var paginationView: ComponentPagination!
- @IBOutlet var dividerView: ComponentDivider!
- @IBOutlet var selectView: ComponentSelect!
-
- var pdfView: CPDFListView?
- //MARK: - func
- public override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
-
- // Drawing code here.
- }
-
- public required init?(coder decoder: NSCoder) {
- super.init(coder: decoder)
-
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
- }
-
- public override func awakeFromNib() {
- super.awakeFromNib()
-
- setUpUI()
-
- setupProperty()
- }
-
- func setUpUI() {
- contendView.wantsLayer = true
- contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup").cgColor
- contendView.layer?.borderWidth = 1
- contendView.layer?.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/3-default").cgColor
- if let value = ComponentLibrary.shared.getComponentValueFromKey("radius/s") {
- let currentValue = value as! CGFloat
- contendView.layer?.cornerRadius = currentValue
- }
- }
-
- func setupProperty() {
-
- paginationView.properties = ComponentPaginationProperty(doubleArrow_show: false, currentIndex: 0, totalCount: 1)
- paginationView.delegate = self
-
- dividerView.properties = ComponentDividerProperty(type: .vertical, dash: false)
-
- selectView.properties = ComponentSelectProperties(size: .xxs, text: "100%")
- selectView.delegate = self
-
- }
-
- func reloadData() {
- selectView.updateMenuItemsArr(KMPDFToolbarConfig.scaleZoomItems())
-
- if let pdfview = self.pdfView, let document = pdfview.document {
- let curIndex = Int(pdfview.currentPageIndex) + 1
- paginationView.properties.currentIndex = curIndex
- paginationView.properties.totalCount = Int(document.pageCount)
- paginationView.reloadData()
-
- selectView.properties.text = (NSString(format: "%.0f", pdfview.scaleFactor * 100) as String) + "%"
- selectView.reloadData()
- }
- }
-
- }
- //MARK: - ComponentPaginationDelegate
- extension KMSplitToolbar: ComponentPaginationDelegate {
- public func componentPaginationDidValueChanged(pagination: ComponentPagination) {
- if let pdfview = self.pdfView, let document = pdfview.document {
- pdfview.go(toPageIndex: pagination.properties.currentIndex-1, animated: true)
- }
- }
- }
- //MARK: - ComponentSelectDelegate
- extension KMSplitToolbar: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- if menuItemProperty?.identifier == KMPDFToolbar_Zoom_AdapWidth_Identifier {
- if pdfView?.scaleFactor != 1.0 {
- pdfView?.scaleFactor = 1.0
- pdfView?.autoScales = false
- }
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_AdapPage_Identifier {
- let pageHeight = pdfView?.currentPage()!.size.height
- let pdfviewHeight = pdfView?.bounds.size.height
- pdfView?.scaleFactor = pdfviewHeight!/pageHeight!
- pdfView?.autoScales = false
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_ActualSize_Identifier {
- pdfView?.autoScales = true
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_10_Identifier {
- pdfView?.scaleFactor = 0.1
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_25_Identifier {
- pdfView?.scaleFactor = 0.25
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_50_Identifier {
- pdfView?.scaleFactor = 0.5
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_75_Identifier {
- pdfView?.scaleFactor = 0.75
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_100_Identifier {
- pdfView?.scaleFactor = 1.0
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_150_Identifier {
- pdfView?.scaleFactor = 1.5
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_200_Identifier {
- pdfView?.scaleFactor = 2.0
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_400_Identifier {
- pdfView?.scaleFactor = 4.0
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_800_Identifier {
- pdfView?.scaleFactor = 8.0
-
- }
- }
- }
|