forked from KDE/okular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlgaccessibility.cpp
197 lines (161 loc) · 8.28 KB
/
dlgaccessibility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
SPDX-FileCopyrightText: 2006 Pino Toscano <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "dlgaccessibility.h"
#include "settings.h"
#include <KColorButton>
#include <KLocalizedString>
#include <QCheckBox>
#include <QComboBox>
#include <QFormLayout>
#include <QLabel>
#include <QStackedWidget>
#if HAVE_SPEECH
#include <QTextToSpeech>
#endif
DlgAccessibility::DlgAccessibility(QWidget *parent)
: QWidget(parent)
, m_colorModeConfigStack(new QStackedWidget(this))
{
QFormLayout *layout = new QFormLayout(this);
// BEGIN Checkboxes: draw border around images/links
// ### not working yet, hide for now
// QCheckBox *highlightImages = new QCheckBox(this);
// highlightImages->setText(i18nc("@option:check Config dialog, accessibility page", "Draw border around images"));
// highlightImages->setObjectName(QStringLiteral("kcfg_HighlightImages"));
// layout->addRow(QString(), highlightImages);
QCheckBox *highlightLinks = new QCheckBox(this);
highlightLinks->setText(i18nc("@option:check Config dialog, accessibility page", "Draw border around links"));
highlightLinks->setObjectName(QStringLiteral("kcfg_HighlightLinks"));
layout->addRow(QString(), highlightLinks);
// END Checkboxes: draw border around images/links
layout->addRow(new QLabel(this));
// BEGIN Change colors section
// Checkbox: enable Change Colors feature
QCheckBox *enableChangeColors = new QCheckBox(this);
enableChangeColors->setText(i18nc("@option:check Config dialog, accessibility page", "Change colors"));
enableChangeColors->setObjectName(QStringLiteral("kcfg_ChangeColors"));
layout->addRow(QString(), enableChangeColors);
// Label: Performance warning
QLabel *warningLabel = new QLabel(this);
warningLabel->setText(i18nc("@info Config dialog, accessibility page", "<b>Warning:</b> these options can badly affect drawing speed."));
warningLabel->setWordWrap(true);
layout->addRow(warningLabel);
// Combobox: color modes
QComboBox *colorMode = new QComboBox(this);
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert colors"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Change paper color"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Change dark & light colors"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Convert to black & white"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert lightness"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert luma (sRGB linear)"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Invert luma (symmetric)"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Shift hue positive"));
colorMode->addItem(i18nc("@item:inlistbox Config dialog, accessibility page", "Shift hue negative"));
colorMode->setObjectName(QStringLiteral("kcfg_RenderMode"));
layout->addRow(i18nc("@label:listbox Config dialog, accessibility page", "Color mode:"), colorMode);
m_colorModeConfigStack->setSizePolicy({QSizePolicy::Preferred, QSizePolicy::Fixed});
// BEGIN Empty page (Only needed to hide the other pages, but it shouldn’t be huge...)
QWidget *pageWidget = new QWidget(this);
QFormLayout *pageLayout = new QFormLayout(pageWidget);
m_colorModeConfigStack->addWidget(pageWidget);
// END Empty page
// BEGIN Change paper color page
pageWidget = new QWidget(this);
pageLayout = new QFormLayout(pageWidget);
// Color button: paper color
KColorButton *paperColor = new KColorButton(this);
paperColor->setObjectName(QStringLiteral("kcfg_PaperColor"));
pageLayout->addRow(i18nc("@label:chooser Config dialog, accessibility page", "Paper color:"), paperColor);
m_colorModeConfigStack->addWidget(pageWidget);
// END Change paper color page
// BEGIN Change to dark & light colors page
pageWidget = new QWidget(this);
pageLayout = new QFormLayout(pageWidget);
// Color button: dark color
KColorButton *darkColor = new KColorButton(this);
darkColor->setObjectName(QStringLiteral("kcfg_RecolorForeground"));
pageLayout->addRow(i18nc("@label:chooser Config dialog, accessibility page", "Dark color:"), darkColor);
// Color button: light color
KColorButton *lightColor = new KColorButton(this);
lightColor->setObjectName(QStringLiteral("kcfg_RecolorBackground"));
pageLayout->addRow(i18nc("@label:chooser Config dialog, accessibility page", "Light color:"), lightColor);
m_colorModeConfigStack->addWidget(pageWidget);
// END Change to dark & light colors page
// BEGIN Convert to black & white page
pageWidget = new QWidget(this);
pageLayout = new QFormLayout(pageWidget);
// Slider: threshold
QSlider *thresholdSlider = new QSlider(this);
thresholdSlider->setMinimum(2);
thresholdSlider->setMaximum(253);
thresholdSlider->setOrientation(Qt::Horizontal);
thresholdSlider->setObjectName(QStringLiteral("kcfg_BWThreshold"));
pageLayout->addRow(i18nc("@label:slider Config dialog, accessibility page", "Threshold:"), thresholdSlider);
// Slider: contrast
QSlider *contrastSlider = new QSlider(this);
contrastSlider->setMinimum(2);
contrastSlider->setMaximum(6);
contrastSlider->setOrientation(Qt::Horizontal);
contrastSlider->setObjectName(QStringLiteral("kcfg_BWContrast"));
pageLayout->addRow(i18nc("@label:slider Config dialog, accessibility page", "Contrast:"), contrastSlider);
m_colorModeConfigStack->addWidget(pageWidget);
// END Convert to black & white page
layout->addRow(QString(), m_colorModeConfigStack);
// Setup controls enabled states:
colorMode->setCurrentIndex(0);
slotColorModeSelected(0);
connect(colorMode, qOverload<int>(&QComboBox::currentIndexChanged), this, &DlgAccessibility::slotColorModeSelected);
enableChangeColors->setChecked(false);
colorMode->setEnabled(false);
connect(enableChangeColors, &QCheckBox::toggled, colorMode, &QComboBox::setEnabled);
m_colorModeConfigStack->setEnabled(false);
connect(enableChangeColors, &QCheckBox::toggled, m_colorModeConfigStack, &QWidget::setEnabled);
// END Change colors section
#if HAVE_SPEECH
layout->addRow(new QLabel(this));
// BEGIN Text-to-speech section
m_ttsEngineBox = new QComboBox(this);
// Populate tts engines and use their names directly as key and item text:
const QStringList engines = QTextToSpeech::availableEngines();
for (const QString &engine : engines) {
m_ttsEngineBox->addItem(engine);
}
m_ttsEngineBox->setProperty("kcfg_property", QByteArray("currentText"));
m_ttsEngineBox->setObjectName(QStringLiteral("kcfg_ttsEngine"));
layout->addRow(i18nc("@label:listbox Config dialog, accessibility page", "Text-to-speech engine:"), m_ttsEngineBox);
connect(m_ttsEngineBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &DlgAccessibility::slotTTSEngineChanged);
m_ttsVoiceBox = new QComboBox(this);
m_ttsVoiceBox->setProperty("kcfg_property", QByteArray("currentText"));
m_ttsVoiceBox->setObjectName(QStringLiteral("kcfg_ttsVoice"));
layout->addRow(i18nc("&label:listbox Config dialog, accessibility page", "Text-to-speech voice:"), m_ttsVoiceBox);
slotTTSEngineChanged();
// END Text-to-speech section
#endif
}
#if HAVE_SPEECH
void DlgAccessibility::slotTTSEngineChanged()
{
QString engine = m_ttsEngineBox->currentText();
QTextToSpeech *ttsEngine = new QTextToSpeech(engine);
const QVector<QVoice> voices = ttsEngine->availableVoices();
m_ttsVoiceBox->clear();
for (const QVoice &voice : voices) {
m_ttsVoiceBox->addItem(voice.name());
}
delete ttsEngine;
}
#endif
void DlgAccessibility::slotColorModeSelected(int mode)
{
if (mode == Okular::Settings::EnumRenderMode::Paper) {
m_colorModeConfigStack->setCurrentIndex(1);
} else if (mode == Okular::Settings::EnumRenderMode::Recolor) {
m_colorModeConfigStack->setCurrentIndex(2);
} else if (mode == Okular::Settings::EnumRenderMode::BlackWhite) {
m_colorModeConfigStack->setCurrentIndex(3);
} else {
m_colorModeConfigStack->setCurrentIndex(0);
}
}