123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- //
- // KMPrintChooseView.swift
- // PDF Master
- //
- // Created by lizhe on 2022/12/8.
- //
- import Cocoa
- typealias KMPrintChooseViewDataDidChange = (_ view: KMPrintChooseView, _ data: KMPrintModel) -> Void
- class KMPrintChooseView: KMBaseXibView {
- @IBOutlet weak var printerLabel: NSTextField!
- @IBOutlet weak var printerButton: KMTextfieldButton!
- @IBOutlet weak var pageSetButton: NSButton!
- @IBOutlet weak var blackAndWhiteButton: KMImageTitleButton!
- @IBOutlet weak var pageNumberLabel: NSTextField!
- @IBOutlet weak var textFieldStepperView: KMTextFieldStepperView!
- @IBOutlet weak var printerSetLabel: NSTextField!
- @IBOutlet weak var pageRangeLabel: NSTextField!
- @IBOutlet weak var pageRangeButton: KMTextfieldButton!
- @IBOutlet weak var printDirectionLabel: NSTextField!
- @IBOutlet weak var printDirectionButton: KMTextfieldButton!
- @IBOutlet weak var printContentLabel: NSTextField!
- @IBOutlet weak var printContentButton: KMTextfieldButton!
- @IBOutlet weak var choosePageSizeView: KMPrintChoosePageSizeView!
- @IBOutlet weak var reversePagesButton: KMImageTitleButton!
-
- weak var delegate: KMPrintChooseViewDelegate?
- lazy var presenter: KMPrintChoosePresenter = KMPrintChoosePresenter()
- lazy var outputData: KMPrintModel = KMPrintModel()
-
- var inputPageRange: KMPrintPageRange = KMPrintPageRange() {
- didSet {
- self.outputData.page.range = inputPageRange
- self.pageRangeButton.stringValue = self.outputData.page.range.type.rawValue
- self.presenter.pageRangeAction(inputPageRange.type.rawValue)
- }
- }
- var inputData: URL? {
- didSet {
- self.presenter.initPresenter(delegate: self, data: inputData!)
- self.choosePageSizeView.inputData = self.presenter.model.page.operation
- }
- }
-
- deinit {
- self.delegate = nil
- }
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
-
- }
-
- override func setup() {
- super.setup()
-
- //打印机名称
- self.printerButton.data = NSPrinter.printerNames
-
- //页面范围
- self.pageRangeButton.data = KMPrintPageRange.PageRangeType.allValues()
-
- //打印方向
- self.printDirectionButton.data = KMPrintPaperDirectionType.allValues()
-
- //打印内容
- self.printContentButton.data = KMPrintContentType.allValues()
-
-
- let model: KMBaseTextFieldModel = KMBaseTextFieldModel()
- model.minValue = 1
- model.maxValue = 100
- self.textFieldStepperView.model = model
- self.textFieldStepperView.valueDidChange = { [unowned self] view, value in
- self.presenter.pageNumberAction(copies: Int(value)!)
- }
-
- self.choosePageSizeView.dataDidChange = { [unowned self] view, data in
- //数据传递
- self.presenter.printDealModelAction(data: data)
- }
-
- self.printerLabel.stringValue = NSLocalizedString("Print", comment: "") + ":"
- self.printerLabel.font = NSFont.SFProTextRegularFont(14.0)
- self.printerLabel.textColor = NSColor.km_init(hex: "#252629")
-
- self.pageRangeLabel.stringValue = NSLocalizedString("Print", comment: "") + ":"
- self.pageRangeLabel.font = NSFont.SFProTextRegularFont(14.0)
- self.pageRangeLabel.textColor = NSColor.km_init(hex: "#252629")
-
- self.pageNumberLabel.stringValue = NSLocalizedString("Print", comment: "") + ":"
- self.pageNumberLabel.font = NSFont.SFProTextRegularFont(14.0)
- self.pageNumberLabel.textColor = NSColor.km_init(hex: "#252629")
-
- self.printerSetLabel.stringValue = NSLocalizedString("Print Settings", comment: "") + ":"
- self.printerSetLabel.font = NSFont.SFProTextRegularFont(12.0)
- self.printerSetLabel.textColor = NSColor.km_init(hex: "#616469")
-
- self.printContentLabel.stringValue = NSLocalizedString("Contents", comment: "") + ":"
- self.printContentLabel.font = NSFont.SFProTextRegularFont(14.0)
- self.printContentLabel.textColor = NSColor.km_init(hex: "#252629")
-
- self.printDirectionLabel.stringValue = NSLocalizedString("Direction", comment: "") + ":"
- self.printDirectionLabel.font = NSFont.SFProTextRegularFont(14.0)
- self.printDirectionLabel.textColor = NSColor.km_init(hex: "#252629")
-
- self.pageSetButton.border(NSColor.km_init(hex: "#DFE1E5"), 1, 4)
- self.pageSetButton.stringValue = NSLocalizedString("Page Settings", comment: "") + ":"
- self.pageSetButton.font = NSFont.SFProTextRegularFont(14.0)
- self.pageSetButton.contentTintColor = NSColor.km_init(hex: "#252629")
-
- self.printerButton.border(NSColor.km_init(hex: "#DFE1E5"), 1, 4)
- self.printerButton.stringValue = NSLocalizedString("EPSON L4260 Series", comment: "") + ":"
- self.printerButton.font = NSFont.SFProTextRegularFont(14.0)
- self.printerButton.textColor = NSColor.km_init(hex: "#252629")
- self.printerButton.mouseDownAction = {[unowned self] (button, itemString) in
- self.presenter.printerAction(itemString)
- }
-
- self.pageRangeButton.border(NSColor.km_init(hex: "#DFE1E5"), 1, 4)
- self.pageRangeButton.stringValue = NSLocalizedString("All pages", comment: "") + ":"
- self.pageRangeButton.font = NSFont.SFProTextRegularFont(14.0)
- self.pageRangeButton.textColor = NSColor.km_init(hex: "#252629")
- self.pageRangeButton.mouseDownAction = {[unowned self] (button, itemString) in
- self.presenter.pageRangeAction(itemString)
- }
-
- self.printDirectionButton.border(NSColor.km_init(hex: "#DFE1E5"), 1, 4)
- self.printDirectionButton.stringValue = NSLocalizedString("Portrait", comment: "") + ":"
- self.printDirectionButton.font = NSFont.SFProTextRegularFont(14.0)
- self.printDirectionButton.textColor = NSColor.km_init(hex: "#252629")
- self.printDirectionButton.mouseDownAction = {[unowned self] (button, itemString) in
- self.presenter.printDirectionAction(itemString)
- }
-
- self.printContentButton.border(NSColor.km_init(hex: "#DFE1E5"), 1, 4)
- self.printContentButton.stringValue = NSLocalizedString("Document and Markups", comment: "") + ":"
- self.printContentButton.font = NSFont.SFProTextRegularFont(14.0)
- self.printContentButton.textColor = NSColor.km_init(hex: "#252629")
- self.printContentButton.mouseDownAction = {[unowned self] (button, itemString) in
- self.presenter.printContentAction(itemString)
- }
-
- self.blackAndWhiteButton.title = NSLocalizedString("Black and white", comment: "")
- self.blackAndWhiteButton.imageName = "btn_checkbox_unsel_on"
- self.blackAndWhiteButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
- self.blackAndWhiteButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- self.blackAndWhiteButton.action = { [unowned self] (view, button) in
- self.presenter.blackAndWhiteAction(button)
- }
-
- self.reversePagesButton.title = NSLocalizedString("Reverse pages", comment: "")
- self.reversePagesButton.imageName = "btn_checkbox_unsel_on"
- self.reversePagesButton.titleLabel.font = NSFont.SFProTextRegularFont(14.0)
- self.reversePagesButton.titleLabel.textColor = NSColor.km_init(hex: "#252629")
- self.reversePagesButton.action = { [unowned self] (view, button) in
- self.presenter.printReverseAction(button)
- }
- }
-
- //刷新界面UI 和 数据
- override func reloadData() {
- super.reloadData()
-
- self.printerButton.stringValue = self.outputData.printer.name
- self.pageSetButton.title = self.outputData.paper.info.type.rawValue
- self.textFieldStepperView.stringValue = self.outputData.printer.copies.description
- self.pageRangeButton.stringValue = self.outputData.page.range.type.rawValue
- self.printDirectionButton.stringValue = self.outputData.paper.direction.rawValue
- self.printContentButton.stringValue = self.outputData.page.contentType.rawValue
-
- if self.outputData.printer.options.contains(.blackAndWhite) {
- self.blackAndWhiteButton.imageName = "btn_checkbox_sel_on"
- } else {
- self.blackAndWhiteButton.imageName = "btn_checkbox_unsel_on"
- }
-
- if self.outputData.page.range.reversePrintOrder {
- self.reversePagesButton.imageName = "btn_checkbox_sel_on"
- } else {
- self.reversePagesButton.imageName = "btn_checkbox_unsel_on"
- }
- }
- }
- protocol KMPrintChooseViewAction {}
- extension KMPrintChooseView: KMPrintChooseViewAction {
- @IBAction func pageSetAction(_ sender: NSButton) {
- let printPaperSetWindowController: KMPrintPaperSetWindowController = KMPrintPaperSetWindowController.init(windowNibName: "KMPrintPaperSetWindowController")
- NSApp.mainWindow?.beginCriticalSheet(printPaperSetWindowController.window!)
- weak var weakSelf = self
- printPaperSetWindowController.data = self.outputData.paper.info
- printPaperSetWindowController.completion = { window, data in
- weakSelf!.presenter.pageSetAction(data)
- }
- }
- }
- extension KMPrintChooseView: KMPrintChoosePresenterDelegate {
- func printDealModelChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if (self.delegate != nil) {
- self.delegate?.printDealModelChange(sender: self, data: data)
- }
- }
-
- func showData(sender: Any, data: KMPrintModel) {
- self.outputData = data
- self.reloadData()
- }
-
- func printerChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.printerChange(sender: self, data: data)
- }
- }
-
- func pageSetChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.pageSetChange(sender: self, data: data)
- }
- }
-
- func pageNumberChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.pageNumberChange(sender: self, data: data)
- }
- }
-
- func blackAndWhiteChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.blackAndWhiteChange(sender: self, data: data)
- }
- }
-
- func printOnBothSidesChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.printOnBothSidesChange(sender: self, data: data)
- }
- }
-
- func pageRangeChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.pageRangeChange(sender: self, data: data)
- }
- }
-
- func printDirectionChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.printDirectionChange(sender: self, data: data)
- }
- }
-
- func printContentChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.printContentChange(sender: self, data: data)
- }
- }
-
- func printReverseChange(sender: Any, data: KMPrintModel) {
- self.reloadData()
-
- if self.delegate != nil {
- self.delegate?.printReverseChange(sender: self, data: data)
- }
- }
- func showData(presenter: KMPrintChoosePresenter, data: KMPrintModel) {
- self.outputData = data
- self.reloadData()
- }
- }
- protocol KMPrintChooseViewDelegate: KMPrintChoosePresenterDelegate {
- }
|