123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- //
- // KMDisplayPreferences.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/11/6.
- //
- import Cocoa
- @objcMembers class KMDisplayPreferences: NSViewController {
-
- @IBOutlet weak var thumbSizeLabel: NSTextField!
- @IBOutlet weak var pagesLabel: NSTextField!
- @IBOutlet weak var pagesSlider: NSSlider!
- @IBOutlet weak var snapshotLabel: NSTextField!
- @IBOutlet weak var snapshotSlider: NSSlider!
- @IBOutlet weak var discreteSizeCheckbox: NSButton!
-
- @IBOutlet var tableFontLabelField: NSTextField!
- @IBOutlet var tableFontComboBox: NSComboBox!
-
- @IBOutlet weak var displayLabel: NSTextField!
- @IBOutlet var greekingLabelField: NSTextField!
- @IBOutlet var greekingTextField: NSTextField!
- @IBOutlet var antiAliasCheckButton: NSButton!
-
- @IBOutlet weak var backgroundColorLabel: NSTextField!
- @IBOutlet weak var normalColorLabel: NSTextField!
- @IBOutlet weak var normalColorWell: NSColorWell!
- @IBOutlet weak var fullScreenLabel: NSTextField!
- @IBOutlet weak var fullScreenColorWell: NSColorWell!
-
- @IBOutlet weak var readBarLabel: NSTextField!
- @IBOutlet weak var readingbarColorLabel: NSTextField!
- @IBOutlet weak var readBarColorWell: NSColorWell!
- @IBOutlet weak var invertBarButton: NSButton!
-
- var thumbnailSizeLabels: [NSTextField] = []
- var thumbnailSizeControls: [NSControl] = []
-
- var colorLabels: [NSTextField] = []
- var colorControls: [NSControl] = []
-
- let SKDefaultFontSizes: [CGFloat] = [8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 16.0, 18.0, 20.0, 24.0, 28.0, 32.0, 48.0, 64.0]
-
- override var nibName: NSNib.Name? {
- return "DisplayPreferences"
- }
-
- override func loadView() {
- super.loadView()
-
- self.thumbnailSizeLabels = [self.pagesLabel, self.snapshotLabel]
- self.thumbnailSizeControls = [self.pagesSlider, self.snapshotSlider, self.discreteSizeCheckbox]
- _ = KMAutoSizeLabelFields(self.thumbnailSizeLabels, self.thumbnailSizeControls, false)
- self.discreteSizeCheckbox.sizeToFit()
- _ = KMAutoSizeLabelFields([self.tableFontLabelField], [self.tableFontComboBox], false)
- _ = KMAutoSizeLabelFields([self.greekingLabelField], [self.greekingTextField], false)
- self.antiAliasCheckButton.sizeToFit()
- self.colorLabels = [self.normalColorLabel, self.readingbarColorLabel]
- self.colorControls = [self.normalColorWell, self.fullScreenLabel, self.fullScreenColorWell, self.readBarColorWell, self.invertBarButton]
- _ = KMAutoSizeLabelFields(self.colorLabels, self.colorControls, false)
- _ = KMAutoSizeLabelFields([self.fullScreenLabel], [self.fullScreenColorWell], false);
- self.invertBarButton.sizeToFit()
-
- var w = 0.0
- for view in self.view.subviews {
- if view.autoresizingMask.contains(.width) == false {
- var x = NSMaxX(view.frame)
- if view.isKind(of: NSSlider.self) || view.isKind(of: NSButton.self) {
- x -= 2.0
- } else if view.isKind(of: NSComboBox.self) {
- x -= 3.0
- }
- w = fmax(w, x)
- }
- }
- var size = self.view.frame.size
- size.width = w + 20.0
- self.view.setFrameSize(size)
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
- thumbSizeLabel.stringValue = KMLocalizedString("Thumbnail sizes:")
- pagesLabel.stringValue = KMLocalizedString("Pages:")
- snapshotLabel.stringValue = KMLocalizedString("Snapshots:")
- discreteSizeCheckbox.title = KMLocalizedString("Discrete sizes")
- tableFontLabelField.stringValue = KMLocalizedString("Outline font size:")
- displayLabel.stringValue = KMLocalizedString("PDF display:")
- greekingLabelField.stringValue = KMLocalizedString("Greeking threshold:")
- antiAliasCheckButton.title = KMLocalizedString("Anti-alias text and line art")
- backgroundColorLabel.stringValue = KMLocalizedString("Background color:")
- normalColorLabel.stringValue = KMLocalizedString("Normal:")
- fullScreenLabel.stringValue = KMLocalizedString("Full Screen:")
- readBarLabel.stringValue = KMLocalizedString("Reading bar:")
- readingbarColorLabel.stringValue = KMLocalizedString("Color:")
- invertBarButton.title = KMLocalizedString("Invert bar")
-
- self.pagesSlider.target = self
- self.pagesSlider.action = #selector(pageSliderAction)
- self.snapshotSlider.target = self
- self.snapshotSlider.action = #selector(snapshotSliderAction)
-
- self.tableFontComboBox.addItems(withObjectValues: SKDefaultFontSizes)
- self.tableFontComboBox.selectItem(at: 4)
- self.tableFontComboBox.delegate = self
-
- self.greekingTextField.delegate = self
- self.antiAliasCheckButton.target = self
- self.antiAliasCheckButton.action = #selector(antiAliasCheckAction)
-
- self.normalColorWell.target = self
- self.normalColorWell.action = #selector(normalColorAction)
- self.fullScreenColorWell.target = self
- self.fullScreenColorWell.action = #selector(fullScreenColorAction)
-
- self.readBarColorWell.target = self
- self.readBarColorWell.action = #selector(readBarColorAction)
-
- self.invertBarButton.target = self
- self.invertBarButton.action = #selector(invertBarAction)
-
- self.greekingTextField.formatter = NumberFormatter()
-
- // 赋值
- self.initData()
- }
-
- override var title: String? {
- set {
- super.title = newValue
- }
- get {
- KMLocalizedString("Display", "Preference pane label")
- }
- }
-
- func initData() {
- self.pagesSlider.floatValue = KMPreference.shared.thumbPageSize
- self.snapshotSlider.floatValue = KMPreference.shared.thumbSnapshotSize
- self.tableFontComboBox.stringValue = String(format: "%.0f", KMPreference.shared.outlineFontSize)
- self.greekingTextField.stringValue = String(format: "%.0f", KMPreference.shared.greekThreshold)
- self.antiAliasCheckButton.state = KMPreference.shared.antiAliasText ? .on : .off
- self.normalColorWell.color = KMPreference.shared.displayBackgroundNormalColor
- self.fullScreenColorWell.color = KMPreference.shared.displayBackgroundFullScreenColor
- self.readBarColorWell.color = KMPreference.shared.readBarColor
- self.invertBarButton.state = KMPreference.shared.invertBar ? .on : .off
- }
-
- @objc func pageSliderAction(_ sender: NSSlider) {
- KMPreference.shared.thumbPageSize = self.pagesSlider.floatValue
- }
-
- @objc func snapshotSliderAction(_ sender: NSSlider) {
- KMPreference.shared.thumbSnapshotSize = self.snapshotSlider.floatValue
- }
-
- @IBAction func changeDiscreteThumbnailSizes(_ sender: AnyObject?) {
- let slider1 = self.pagesSlider
- let slider2 = self.snapshotSlider
- let button = sender as? NSButton
- if let data = button?.state, data == .on {
- slider1?.numberOfTickMarks = 8
- slider2?.numberOfTickMarks = 8
- slider1?.allowsTickMarkValuesOnly = true
- slider2?.allowsTickMarkValuesOnly = true
- } else {
- slider1?.superview?.setNeedsDisplay(slider1?.frame ?? .zero)
- slider2?.superview?.setNeedsDisplay(slider2?.frame ?? .zero)
-
- slider1?.numberOfTickMarks = 0
- slider2?.numberOfTickMarks = 0
- slider1?.allowsTickMarkValuesOnly = false
- slider2?.allowsTickMarkValuesOnly = false
- }
- slider1?.sizeToFit()
- slider2?.sizeToFit()
- }
-
- @objc func antiAliasCheckAction(_ sender: NSButton) {
- KMPreference.shared.antiAliasText = self.antiAliasCheckButton.state == .on
- }
-
- @objc func normalColorAction(_ sender: NSColorWell) {
- if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
- KMPreference.shared.displayBackgroundNormalColor = color
- }
- }
-
- @objc func fullScreenColorAction(_ sender: NSColorWell) {
- if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
- KMPreference.shared.displayBackgroundFullScreenColor = color
- }
- }
-
- @objc func readBarColorAction(_ sender: NSColorWell) {
- if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) {
- KMPreference.shared.readBarColor = color
- }
- }
-
- @objc func invertBarAction(_ sender: NSButton) {
- KMPreference.shared.invertBar = sender.state == .on
- }
- }
- extension KMDisplayPreferences: KMPreferencePane {
- func defaultsDidRevert() {
- // no things.
- }
-
- func reloadData() {
- self.initData()
- }
- }
- extension KMDisplayPreferences: NSComboBoxDelegate {
- func comboBoxSelectionDidChange(_ notification: Notification) {
- if self.tableFontComboBox.isEqual(to: notification.object) {
- KMPreference.shared.outlineFontSize = self.tableFontComboBox.floatValue
- }
- }
- }
- extension KMDisplayPreferences: NSTextFieldDelegate {
- func controlTextDidChange(_ obj: Notification) {
- if self.greekingTextField.isEqual(to: obj.object) {
- KMPreference.shared.greekThreshold = self.greekingTextField.floatValue
- }
- }
- }
|