File indexing completed on 2024-04-28 15:51:42
0001 /* 0002 SPDX-FileCopyrightText: 2006 Pino Toscano <toscano.pino@tiscali.it> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "dlgaccessibility.h" 0008 0009 #include "settings.h" 0010 0011 #include <KColorButton> 0012 #include <KLocalizedString> 0013 0014 #include <QCheckBox> 0015 #include <QComboBox> 0016 #include <QFormLayout> 0017 #include <QLabel> 0018 #include <QStackedWidget> 0019 0020 #if HAVE_SPEECH 0021 #include <QTextToSpeech> 0022 #endif 0023 0024 DlgAccessibility::DlgAccessibility(QWidget *parent) 0025 : QWidget(parent) 0026 , m_colorModeConfigStack(new QStackedWidget(this)) 0027 { 0028 QFormLayout *layout = new QFormLayout(this); 0029 0030 // BEGIN Checkboxes: draw border around images/links 0031 // ### not working yet, hide for now 0032 // QCheckBox *highlightImages = new QCheckBox(this); 0033 // highlightImages->setText(i18nc("@option:check Config dialog, accessibility page", "Draw border around images")); 0034 // highlightImages->setObjectName(QStringLiteral("kcfg_HighlightImages")); 0035 // layout->addRow(QString(), highlightImages); 0036 0037 QCheckBox *highlightLinks = new QCheckBox(this); 0038 highlightLinks->setText(i18nc("@option:check Config dialog, accessibility page", "Draw border around links")); 0039 highlightLinks->setObjectName(QStringLiteral("kcfg_HighlightLinks")); 0040 layout->addRow(QString(), highlightLinks); 0041 // END Checkboxes: draw border around images/links 0042 0043 layout->addRow(new QLabel(this)); 0044 0045 // BEGIN Change colors section 0046 // Checkbox: enable Change Colors feature 0047 QCheckBox *enableChangeColors = new QCheckBox(this); 0048 enableChangeColors->setText(i18nc("@option:check Config dialog, accessibility page", "Change colors")); 0049 enableChangeColors->setObjectName(QStringLiteral("kcfg_ChangeColors")); 0050 layout->addRow(QString(), enableChangeColors); 0051 0052 // Label: Performance warning 0053 QLabel *warningLabel = new QLabel(this); 0054 warningLabel->setText(i18nc("@info Config dialog, accessibility page", "<b>Warning:</b> these options can badly affect drawing speed.")); 0055 warningLabel->setWordWrap(true); 0056 layout->addRow(warningLabel); 0057 0058 // Combobox: color modes 0059 QComboBox *colorMode = new QComboBox(this); 0060 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert colors")); 0061 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Change paper color")); 0062 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Change dark & light colors")); 0063 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Convert to black & white")); 0064 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert lightness")); 0065 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert luma (sRGB linear)")); 0066 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert luma (symmetric)")); 0067 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Shift hue positive")); 0068 colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Shift hue negative")); 0069 colorMode->setObjectName(QStringLiteral("kcfg_RenderMode")); 0070 layout->addRow(i18nc("@label:listbox Config dialog, accessibility page", "Color mode:"), colorMode); 0071 0072 m_colorModeConfigStack->setSizePolicy({QSizePolicy::Preferred, QSizePolicy::Fixed}); 0073 0074 // BEGIN Empty page (Only needed to hide the other pages, but it shouldn’t be huge...) 0075 QWidget *pageWidget = new QWidget(this); 0076 QFormLayout *pageLayout = new QFormLayout(pageWidget); 0077 m_colorModeConfigStack->addWidget(pageWidget); 0078 // END Empty page 0079 0080 // BEGIN Change paper color page 0081 pageWidget = new QWidget(this); 0082 pageLayout = new QFormLayout(pageWidget); 0083 0084 // Color button: paper color 0085 KColorButton *paperColor = new KColorButton(this); 0086 paperColor->setObjectName(QStringLiteral("kcfg_PaperColor")); 0087 pageLayout->addRow(i18nc("@label:chooser Config dialog, accessibility page", "Paper color:"), paperColor); 0088 0089 m_colorModeConfigStack->addWidget(pageWidget); 0090 // END Change paper color page 0091 0092 // BEGIN Change to dark & light colors page 0093 pageWidget = new QWidget(this); 0094 pageLayout = new QFormLayout(pageWidget); 0095 0096 // Color button: dark color 0097 KColorButton *darkColor = new KColorButton(this); 0098 darkColor->setObjectName(QStringLiteral("kcfg_RecolorForeground")); 0099 pageLayout->addRow(i18nc("@label:chooser Config dialog, accessibility page", "Dark color:"), darkColor); 0100 0101 // Color button: light color 0102 KColorButton *lightColor = new KColorButton(this); 0103 lightColor->setObjectName(QStringLiteral("kcfg_RecolorBackground")); 0104 pageLayout->addRow(i18nc("@label:chooser Config dialog, accessibility page", "Light color:"), lightColor); 0105 0106 m_colorModeConfigStack->addWidget(pageWidget); 0107 // END Change to dark & light colors page 0108 0109 // BEGIN Convert to black & white page 0110 pageWidget = new QWidget(this); 0111 pageLayout = new QFormLayout(pageWidget); 0112 0113 // Slider: threshold 0114 QSlider *thresholdSlider = new QSlider(this); 0115 thresholdSlider->setMinimum(2); 0116 thresholdSlider->setMaximum(253); 0117 thresholdSlider->setOrientation(Qt::Horizontal); 0118 thresholdSlider->setObjectName(QStringLiteral("kcfg_BWThreshold")); 0119 pageLayout->addRow(i18nc("@label:slider Config dialog, accessibility page", "Threshold:"), thresholdSlider); 0120 0121 // Slider: contrast 0122 QSlider *contrastSlider = new QSlider(this); 0123 contrastSlider->setMinimum(2); 0124 contrastSlider->setMaximum(6); 0125 contrastSlider->setOrientation(Qt::Horizontal); 0126 contrastSlider->setObjectName(QStringLiteral("kcfg_BWContrast")); 0127 pageLayout->addRow(i18nc("@label:slider Config dialog, accessibility page", "Contrast:"), contrastSlider); 0128 0129 m_colorModeConfigStack->addWidget(pageWidget); 0130 // END Convert to black & white page 0131 0132 layout->addRow(QString(), m_colorModeConfigStack); 0133 0134 // Setup controls enabled states: 0135 colorMode->setCurrentIndex(0); 0136 slotColorModeSelected(0); 0137 connect(colorMode, qOverload<int>(&QComboBox::currentIndexChanged), this, &DlgAccessibility::slotColorModeSelected); 0138 0139 enableChangeColors->setChecked(false); 0140 colorMode->setEnabled(false); 0141 connect(enableChangeColors, &QCheckBox::toggled, colorMode, &QComboBox::setEnabled); 0142 m_colorModeConfigStack->setEnabled(false); 0143 connect(enableChangeColors, &QCheckBox::toggled, m_colorModeConfigStack, &QWidget::setEnabled); 0144 // END Change colors section 0145 0146 #if HAVE_SPEECH 0147 layout->addRow(new QLabel(this)); 0148 0149 // BEGIN Text-to-speech section 0150 m_ttsEngineBox = new QComboBox(this); 0151 // Populate tts engines and use their names directly as key and item text: 0152 const QStringList engines = QTextToSpeech::availableEngines(); 0153 for (const QString &engine : engines) { 0154 m_ttsEngineBox->addItem(engine); 0155 } 0156 m_ttsEngineBox->setProperty("kcfg_property", QByteArray("currentText")); 0157 m_ttsEngineBox->setObjectName(QStringLiteral("kcfg_ttsEngine")); 0158 layout->addRow(i18nc("@label:listbox Config dialog, accessibility page", "Text-to-speech engine:"), m_ttsEngineBox); 0159 0160 connect(m_ttsEngineBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &DlgAccessibility::slotTTSEngineChanged); 0161 0162 m_ttsVoiceBox = new QComboBox(this); 0163 m_ttsVoiceBox->setProperty("kcfg_property", QByteArray("currentText")); 0164 m_ttsVoiceBox->setObjectName(QStringLiteral("kcfg_ttsVoice")); 0165 layout->addRow(i18nc("&label:listbox Config dialog, accessibility page", "Text-to-speech voice:"), m_ttsVoiceBox); 0166 0167 slotTTSEngineChanged(); 0168 // END Text-to-speech section 0169 #endif 0170 } 0171 0172 #if HAVE_SPEECH 0173 void DlgAccessibility::slotTTSEngineChanged() 0174 { 0175 QString engine = m_ttsEngineBox->currentText(); 0176 QTextToSpeech *ttsEngine = new QTextToSpeech(engine); 0177 const QVector<QVoice> voices = ttsEngine->availableVoices(); 0178 m_ttsVoiceBox->clear(); 0179 for (const QVoice &voice : voices) { 0180 m_ttsVoiceBox->addItem(voice.name()); 0181 } 0182 delete ttsEngine; 0183 } 0184 #endif 0185 0186 void DlgAccessibility::slotColorModeSelected(int mode) 0187 { 0188 if (mode == Okular::Settings::EnumRenderMode::Paper) { 0189 m_colorModeConfigStack->setCurrentIndex(1); 0190 } else if (mode == Okular::Settings::EnumRenderMode::Recolor) { 0191 m_colorModeConfigStack->setCurrentIndex(2); 0192 } else if (mode == Okular::Settings::EnumRenderMode::BlackWhite) { 0193 m_colorModeConfigStack->setCurrentIndex(3); 0194 } else { 0195 m_colorModeConfigStack->setCurrentIndex(0); 0196 } 0197 }