1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <QtVirtualKeyboard/private/settings_p.h> |
5 | #include <QtCore/private/qobject_p.h> |
6 | #include <QStandardPaths> |
7 | #include <QFileInfo> |
8 | #include <QDir> |
9 | #include "virtualkeyboarddebug_p.h" |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | namespace QtVirtualKeyboard { |
13 | |
14 | class SettingsPrivate : public QObjectPrivate |
15 | { |
16 | public: |
17 | SettingsPrivate() : |
18 | QObjectPrivate(), |
19 | style(), |
20 | styleName(), |
21 | locale(), |
22 | availableLocales(), |
23 | activeLocales(), |
24 | layoutPath(), |
25 | wclAutoHideDelay(5000), |
26 | wclAlwaysVisible(false), |
27 | wclAutoCommitWord(false), |
28 | fullScreenMode(false), |
29 | userDataPath(QStringLiteral("%1/qtvirtualkeyboard") |
30 | .arg(a: QStandardPaths::writableLocation( |
31 | type: QStandardPaths::GenericConfigLocation))), |
32 | hwrTimeoutForAlphabetic(500), |
33 | hwrTimeoutForCjk(500), |
34 | handwritingModeDisabled(false), |
35 | defaultInputMethodDisabled(false), |
36 | defaultDictionaryDisabled(false), |
37 | visibleFunctionKeys(QtVirtualKeyboard::KeyboardFunctionKey::All), |
38 | closeOnReturn(false) |
39 | { |
40 | ensureUserDataPathExists(); |
41 | } |
42 | |
43 | void ensureUserDataPathExists() const |
44 | { |
45 | if (!userDataPath.isEmpty() && !QFileInfo::exists(file: userDataPath)) { |
46 | if (!QDir::root().mkpath(dirPath: userDataPath)) { |
47 | VIRTUALKEYBOARD_WARN() << "Cannot create directory for user data"<< userDataPath; |
48 | } |
49 | } |
50 | } |
51 | |
52 | QString style; |
53 | QString styleName; |
54 | QString locale; |
55 | QStringList availableLocales; |
56 | QStringList activeLocales; |
57 | QUrl layoutPath; |
58 | int wclAutoHideDelay; |
59 | bool wclAlwaysVisible; |
60 | bool wclAutoCommitWord; |
61 | bool fullScreenMode; |
62 | QString userDataPath; |
63 | int hwrTimeoutForAlphabetic; |
64 | int hwrTimeoutForCjk; |
65 | Qt::InputMethodHints inputMethodHints; |
66 | bool handwritingModeDisabled; |
67 | bool defaultInputMethodDisabled; |
68 | bool defaultDictionaryDisabled; |
69 | QtVirtualKeyboard::KeyboardFunctionKeys visibleFunctionKeys; |
70 | bool closeOnReturn; |
71 | }; |
72 | |
73 | static QScopedPointer<Settings> s_settingsInstance; |
74 | |
75 | /*! |
76 | \class QtVirtualKeyboard::Settings |
77 | \internal |
78 | */ |
79 | |
80 | Settings::Settings(QObject *parent) : |
81 | QObject(*new SettingsPrivate(), parent) |
82 | { |
83 | } |
84 | |
85 | Settings *Settings::instance() |
86 | { |
87 | if (!s_settingsInstance) |
88 | s_settingsInstance.reset(other: new Settings()); |
89 | return s_settingsInstance.data(); |
90 | } |
91 | |
92 | QString Settings::style() const |
93 | { |
94 | Q_D(const Settings); |
95 | return d->style; |
96 | } |
97 | |
98 | void Settings::setStyle(const QString &style) |
99 | { |
100 | Q_D(Settings); |
101 | if (d->style != style) { |
102 | d->style = style; |
103 | emit styleChanged(); |
104 | } |
105 | } |
106 | |
107 | QString Settings::styleName() const |
108 | { |
109 | Q_D(const Settings); |
110 | return d->styleName; |
111 | } |
112 | |
113 | void Settings::setStyleName(const QString &styleName) |
114 | { |
115 | Q_D(Settings); |
116 | if (d->styleName != styleName) { |
117 | d->styleName = styleName; |
118 | emit styleNameChanged(); |
119 | } |
120 | } |
121 | |
122 | QString Settings::locale() const |
123 | { |
124 | Q_D(const Settings); |
125 | return d->locale; |
126 | } |
127 | |
128 | void Settings::setLocale(const QString &locale) |
129 | { |
130 | Q_D(Settings); |
131 | if (d->locale != locale) { |
132 | d->locale = locale; |
133 | emit localeChanged(); |
134 | } |
135 | } |
136 | |
137 | QStringList Settings::availableLocales() const |
138 | { |
139 | Q_D(const Settings); |
140 | return d->availableLocales; |
141 | } |
142 | |
143 | void Settings::setAvailableLocales(const QStringList &availableLocales) |
144 | { |
145 | Q_D(Settings); |
146 | if (d->availableLocales != availableLocales) { |
147 | d->availableLocales = availableLocales; |
148 | emit availableLocalesChanged(); |
149 | } |
150 | } |
151 | |
152 | QStringList Settings::activeLocales() const |
153 | { |
154 | Q_D(const Settings); |
155 | return d->activeLocales; |
156 | } |
157 | |
158 | void Settings::setActiveLocales(const QStringList &activeLocales) |
159 | { |
160 | Q_D(Settings); |
161 | if (d->activeLocales != activeLocales) { |
162 | d->activeLocales = activeLocales; |
163 | emit activeLocalesChanged(); |
164 | } |
165 | } |
166 | |
167 | QUrl Settings::layoutPath() const |
168 | { |
169 | Q_D(const Settings); |
170 | return d->layoutPath; |
171 | } |
172 | |
173 | void Settings::setLayoutPath(const QUrl &layoutPath) |
174 | { |
175 | Q_D(Settings); |
176 | if (d->layoutPath != layoutPath) { |
177 | d->layoutPath = layoutPath; |
178 | emit layoutPathChanged(); |
179 | } |
180 | } |
181 | |
182 | int Settings::wclAutoHideDelay() const |
183 | { |
184 | Q_D(const Settings); |
185 | return d->wclAutoHideDelay; |
186 | } |
187 | |
188 | void Settings::setWclAutoHideDelay(int wclAutoHideDelay) |
189 | { |
190 | Q_D(Settings); |
191 | if (d->wclAutoHideDelay != wclAutoHideDelay) { |
192 | d->wclAutoHideDelay = wclAutoHideDelay; |
193 | emit wclAutoHideDelayChanged(); |
194 | } |
195 | } |
196 | |
197 | bool Settings::wclAlwaysVisible() const |
198 | { |
199 | Q_D(const Settings); |
200 | return d->wclAlwaysVisible; |
201 | } |
202 | |
203 | void Settings::setWclAlwaysVisible(bool wclAlwaysVisible) |
204 | { |
205 | Q_D(Settings); |
206 | if (d->wclAlwaysVisible != wclAlwaysVisible) { |
207 | d->wclAlwaysVisible = wclAlwaysVisible; |
208 | emit wclAlwaysVisibleChanged(); |
209 | } |
210 | } |
211 | |
212 | bool Settings::wclAutoCommitWord() const |
213 | { |
214 | Q_D(const Settings); |
215 | return d->wclAutoCommitWord; |
216 | } |
217 | |
218 | void Settings::setWclAutoCommitWord(bool wclAutoCommitWord) |
219 | { |
220 | Q_D(Settings); |
221 | if (d->wclAutoCommitWord != wclAutoCommitWord) { |
222 | d->wclAutoCommitWord = wclAutoCommitWord; |
223 | emit wclAutoCommitWordChanged(); |
224 | } |
225 | } |
226 | |
227 | bool Settings::fullScreenMode() const |
228 | { |
229 | Q_D(const Settings); |
230 | return d->fullScreenMode; |
231 | } |
232 | |
233 | void Settings::setFullScreenMode(bool fullScreenMode) |
234 | { |
235 | Q_D(Settings); |
236 | if (d->fullScreenMode != fullScreenMode) { |
237 | d->fullScreenMode = fullScreenMode; |
238 | emit fullScreenModeChanged(); |
239 | } |
240 | } |
241 | |
242 | QString Settings::userDataPath() const |
243 | { |
244 | Q_D(const Settings); |
245 | return d->userDataPath; |
246 | } |
247 | |
248 | void Settings::setUserDataPath(const QString &userDataPath) |
249 | { |
250 | Q_D(Settings); |
251 | if (d->userDataPath != userDataPath) { |
252 | d->userDataPath = userDataPath; |
253 | d->ensureUserDataPathExists(); |
254 | emit userDataPathChanged(); |
255 | } |
256 | } |
257 | |
258 | int Settings::hwrTimeoutForAlphabetic() const |
259 | { |
260 | Q_D(const Settings); |
261 | return d->hwrTimeoutForAlphabetic; |
262 | } |
263 | |
264 | void Settings::setHwrTimeoutForAlphabetic(int hwrTimeoutForAlphabetic) |
265 | { |
266 | Q_D(Settings); |
267 | if (d->hwrTimeoutForAlphabetic != hwrTimeoutForAlphabetic) { |
268 | d->hwrTimeoutForAlphabetic = hwrTimeoutForAlphabetic; |
269 | emit hwrTimeoutForAlphabeticChanged(); |
270 | } |
271 | } |
272 | |
273 | int Settings::hwrTimeoutForCjk() const |
274 | { |
275 | Q_D(const Settings); |
276 | return d->hwrTimeoutForCjk; |
277 | } |
278 | |
279 | void Settings::setHwrTimeoutForCjk(int hwrTimeoutForCjk) |
280 | { |
281 | Q_D(Settings); |
282 | if (d->hwrTimeoutForCjk != hwrTimeoutForCjk) { |
283 | d->hwrTimeoutForCjk = hwrTimeoutForCjk; |
284 | emit hwrTimeoutForCjkChanged(); |
285 | } |
286 | } |
287 | |
288 | Qt::InputMethodHints Settings::inputMethodHints() const |
289 | { |
290 | Q_D(const Settings); |
291 | return d->inputMethodHints; |
292 | } |
293 | |
294 | void Settings::setInputMethodHints(const Qt::InputMethodHints &inputMethodHints) |
295 | { |
296 | Q_D(Settings); |
297 | if (d->inputMethodHints != inputMethodHints) { |
298 | d->inputMethodHints = inputMethodHints; |
299 | emit inputMethodHintsChanged(); |
300 | } |
301 | } |
302 | |
303 | bool Settings::isHandwritingModeDisabled() const |
304 | { |
305 | Q_D(const Settings); |
306 | return d->handwritingModeDisabled; |
307 | } |
308 | |
309 | void Settings::setHandwritingModeDisabled(bool handwritingModeDisabled) |
310 | { |
311 | Q_D(Settings); |
312 | if (d->handwritingModeDisabled != handwritingModeDisabled) { |
313 | d->handwritingModeDisabled = handwritingModeDisabled; |
314 | emit handwritingModeDisabledChanged(); |
315 | } |
316 | } |
317 | |
318 | bool Settings::isDefaultInputMethodDisabled() const |
319 | { |
320 | Q_D(const Settings); |
321 | return d->defaultInputMethodDisabled; |
322 | } |
323 | |
324 | void Settings::setDefaultInputMethodDisabled(bool defaultInputMethodDisabled) |
325 | { |
326 | Q_D(Settings); |
327 | if (d->defaultInputMethodDisabled != defaultInputMethodDisabled) { |
328 | d->defaultInputMethodDisabled = defaultInputMethodDisabled; |
329 | emit defaultInputMethodDisabledChanged(); |
330 | } |
331 | } |
332 | |
333 | bool QtVirtualKeyboard::Settings::isDefaultDictionaryDisabled() const |
334 | { |
335 | Q_D(const Settings); |
336 | return d->defaultDictionaryDisabled; |
337 | } |
338 | |
339 | void QtVirtualKeyboard::Settings::setDefaultDictionaryDisabled(bool defaultDictionaryDisabled) |
340 | { |
341 | Q_D(Settings); |
342 | if (d->defaultDictionaryDisabled != defaultDictionaryDisabled) { |
343 | d->defaultDictionaryDisabled = defaultDictionaryDisabled; |
344 | emit defaultDictionaryDisabledChanged(); |
345 | } |
346 | } |
347 | |
348 | QtVirtualKeyboard::KeyboardFunctionKeys Settings::visibleFunctionKeys() const |
349 | { |
350 | Q_D(const Settings); |
351 | return d->visibleFunctionKeys; |
352 | } |
353 | |
354 | void Settings::setVisibleFunctionKeys(QtVirtualKeyboard::KeyboardFunctionKeys newVisibleFunctionKeys) |
355 | { |
356 | Q_D(Settings); |
357 | if (d->visibleFunctionKeys != newVisibleFunctionKeys) { |
358 | d->visibleFunctionKeys = newVisibleFunctionKeys; |
359 | emit visibleFunctionKeysChanged(); |
360 | } |
361 | } |
362 | |
363 | bool Settings::closeOnReturn() const |
364 | { |
365 | Q_D(const Settings); |
366 | return d->closeOnReturn; |
367 | } |
368 | |
369 | void Settings::setCloseOnReturn(bool enabled) |
370 | { |
371 | Q_D(Settings); |
372 | if (d->closeOnReturn != enabled) { |
373 | d->closeOnReturn = enabled; |
374 | emit closeOnReturnChanged(); |
375 | } |
376 | } |
377 | |
378 | } // namespace QtVirtualKeyboard |
379 | QT_END_NAMESPACE |
380 |
Definitions
- SettingsPrivate
- SettingsPrivate
- ensureUserDataPathExists
- s_settingsInstance
- Settings
- instance
- style
- setStyle
- styleName
- setStyleName
- locale
- setLocale
- availableLocales
- setAvailableLocales
- activeLocales
- setActiveLocales
- layoutPath
- setLayoutPath
- wclAutoHideDelay
- setWclAutoHideDelay
- wclAlwaysVisible
- setWclAlwaysVisible
- wclAutoCommitWord
- setWclAutoCommitWord
- fullScreenMode
- setFullScreenMode
- userDataPath
- setUserDataPath
- hwrTimeoutForAlphabetic
- setHwrTimeoutForAlphabetic
- hwrTimeoutForCjk
- setHwrTimeoutForCjk
- inputMethodHints
- setInputMethodHints
- isHandwritingModeDisabled
- setHandwritingModeDisabled
- isDefaultInputMethodDisabled
- setDefaultInputMethodDisabled
- isDefaultDictionaryDisabled
- setDefaultDictionaryDisabled
- visibleFunctionKeys
- setVisibleFunctionKeys
- closeOnReturn
Start learning QML with our Intro Training
Find out more