/src/qtbase/src/gui/kernel/qstylehints.cpp
Line | Count | Source |
1 | | // Copyright (C) 2016 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | // Qt-Security score:significant reason:default |
4 | | |
5 | | #include "qaccessibilityhints_p.h" |
6 | | #include <qstylehints.h> |
7 | | #include "qstylehints_p.h" |
8 | | #include <qpa/qplatformintegration.h> |
9 | | #include <qpa/qplatformtheme.h> |
10 | | #include <private/qguiapplication_p.h> |
11 | | #include <qdebug.h> |
12 | | |
13 | | QT_BEGIN_NAMESPACE |
14 | | |
15 | | static inline QVariant hint(QPlatformIntegration::StyleHint h) |
16 | 0 | { |
17 | 0 | return QGuiApplicationPrivate::platformIntegration()->styleHint(h); |
18 | 0 | } |
19 | | |
20 | | static inline QVariant themeableHint(QPlatformTheme::ThemeHint th, |
21 | | QPlatformIntegration::StyleHint ih) |
22 | 0 | { |
23 | 0 | if (!QCoreApplication::instance()) { |
24 | 0 | qWarning("Must construct a QGuiApplication before accessing a platform theme hint."); |
25 | 0 | return QVariant(); |
26 | 0 | } |
27 | 0 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { |
28 | 0 | const QVariant themeHint = theme->themeHint(th); |
29 | 0 | if (themeHint.isValid()) |
30 | 0 | return themeHint; |
31 | 0 | } |
32 | 0 | return QGuiApplicationPrivate::platformIntegration()->styleHint(ih); |
33 | 0 | } |
34 | | |
35 | | static inline QVariant themeableHint(QPlatformTheme::ThemeHint th) |
36 | 0 | { |
37 | 0 | if (!QCoreApplication::instance()) { |
38 | 0 | qWarning("Must construct a QGuiApplication before accessing a platform theme hint."); |
39 | 0 | return QVariant(); |
40 | 0 | } |
41 | 0 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { |
42 | 0 | const QVariant themeHint = theme->themeHint(th); |
43 | 0 | if (themeHint.isValid()) |
44 | 0 | return themeHint; |
45 | 0 | } |
46 | 0 | return QPlatformTheme::defaultThemeHint(th); |
47 | 0 | } |
48 | | |
49 | | /*! |
50 | | \class QStyleHints |
51 | | \since 5.0 |
52 | | \brief The QStyleHints class contains platform specific hints and settings. |
53 | | \inmodule QtGui |
54 | | |
55 | | An object of this class, obtained from QGuiApplication, provides access to certain global |
56 | | user interface parameters of the current platform. |
57 | | |
58 | | The platform provides most of these settings, and they are typically read-only. |
59 | | End users can usually adjust them through platform-specific configuration mechanisms. |
60 | | However, you can also adjust some settings programmatically through dedicated setter |
61 | | functions, (for example, setColorScheme() or setShowShortcutsInContextMenus()), |
62 | | which can be useful for testing or specialized application behavior. Any such adjustments |
63 | | apply only to the current application. |
64 | | |
65 | | Authors of custom user interface components should read |
66 | | relevant settings to allow the components to exhibit the same behavior and feel as other |
67 | | components. |
68 | | |
69 | | \sa QGuiApplication::styleHints() |
70 | | */ |
71 | | QStyleHints::QStyleHints() |
72 | 0 | : QObject(*new QStyleHintsPrivate(), nullptr) |
73 | 0 | { |
74 | 0 | } |
75 | | |
76 | | /*! |
77 | | Sets the \a mouseDoubleClickInterval. |
78 | | \internal |
79 | | \sa mouseDoubleClickInterval() |
80 | | \since 5.3 |
81 | | */ |
82 | | void QStyleHints::setMouseDoubleClickInterval(int mouseDoubleClickInterval) |
83 | 0 | { |
84 | 0 | Q_D(QStyleHints); |
85 | 0 | if (d->m_mouseDoubleClickInterval == mouseDoubleClickInterval) |
86 | 0 | return; |
87 | 0 | d->m_mouseDoubleClickInterval = mouseDoubleClickInterval; |
88 | 0 | emit mouseDoubleClickIntervalChanged(mouseDoubleClickInterval); |
89 | 0 | } |
90 | | |
91 | | /*! |
92 | | \property QStyleHints::mouseDoubleClickInterval |
93 | | \brief the time limit in milliseconds that distinguishes a double click |
94 | | from two consecutive mouse clicks. |
95 | | */ |
96 | | int QStyleHints::mouseDoubleClickInterval() const |
97 | 0 | { |
98 | 0 | Q_D(const QStyleHints); |
99 | 0 | return d->m_mouseDoubleClickInterval >= 0 ? |
100 | 0 | d->m_mouseDoubleClickInterval : |
101 | 0 | themeableHint(QPlatformTheme::MouseDoubleClickInterval, QPlatformIntegration::MouseDoubleClickInterval).toInt(); |
102 | 0 | } |
103 | | |
104 | | /*! |
105 | | \property QStyleHints::mouseDoubleClickDistance |
106 | | \brief the maximum distance, in pixels, that the mouse can be moved between |
107 | | two consecutive mouse clicks and still have it detected as a double-click |
108 | | \since 5.14 |
109 | | */ |
110 | | int QStyleHints::mouseDoubleClickDistance() const |
111 | 0 | { |
112 | 0 | Q_D(const QStyleHints); |
113 | 0 | return d->m_mouseDoubleClickDistance >= 0 ? |
114 | 0 | d->m_mouseDoubleClickDistance : |
115 | 0 | themeableHint(QPlatformTheme::MouseDoubleClickDistance, QPlatformIntegration::MouseDoubleClickDistance).toInt(); |
116 | 0 | } |
117 | | |
118 | | /*! |
119 | | \property QStyleHints::touchDoubleTapDistance |
120 | | \brief the maximum distance, in pixels, that a finger can be moved between |
121 | | two consecutive taps and still have it detected as a double-tap |
122 | | \since 5.14 |
123 | | */ |
124 | | int QStyleHints::touchDoubleTapDistance() const |
125 | 0 | { |
126 | 0 | Q_D(const QStyleHints); |
127 | 0 | return d->m_touchDoubleTapDistance >= 0 ? |
128 | 0 | d->m_touchDoubleTapDistance : |
129 | 0 | themeableHint(QPlatformTheme::TouchDoubleTapDistance).toInt(); |
130 | 0 | } |
131 | | |
132 | | /*! |
133 | | \property QStyleHints::colorScheme |
134 | | \brief the color scheme used by the application. |
135 | | |
136 | | By default, this follows the system's default color scheme (also known as appearance), |
137 | | and changes when the system color scheme changes (e.g. during dusk or dawn). |
138 | | Setting the color scheme to an explicit value will override the system setting and |
139 | | ignore any changes to the system's color scheme. However, doing so is a hint to the |
140 | | system, and overriding the color scheme is not supported on all platforms. |
141 | | |
142 | | Resetting this property, or setting it to \l{Qt::ColorScheme::Unknown}, will remove |
143 | | the override and make the application follow the system default again. The property |
144 | | value will change to the color scheme the system currently has. |
145 | | |
146 | | When this property changes, Qt will read the system palette and update the default |
147 | | palette, but won't overwrite palette entries that have been explicitly set by the |
148 | | application. When the colorSchemeChange() signal gets emitted, the old palette is |
149 | | still in effect. |
150 | | |
151 | | Application-specific colors should be selected to work well with the effective |
152 | | palette, taking the current color scheme into account. To update application- |
153 | | specific colors when the effective palette changes, handle |
154 | | \l{QEvent::}{PaletteChange} or \l{QEvent::}{ApplicationPaletteChange} events. |
155 | | |
156 | | \sa Qt::ColorScheme, QGuiApplication::palette(), QEvent::PaletteChange |
157 | | \since 6.5 |
158 | | */ |
159 | | Qt::ColorScheme QStyleHints::colorScheme() const |
160 | 0 | { |
161 | 0 | Q_D(const QStyleHints); |
162 | 0 | return d->colorScheme(); |
163 | 0 | } |
164 | | |
165 | | /*! |
166 | | \since 6.8 |
167 | | |
168 | | Sets the color scheme used by the application to an explicit \a scheme, or |
169 | | revert to the system's current color scheme if \a scheme is Qt::ColorScheme::Unknown. |
170 | | */ |
171 | | void QStyleHints::setColorScheme(Qt::ColorScheme scheme) |
172 | 0 | { |
173 | 0 | if (!QCoreApplication::instance()) { |
174 | 0 | qWarning("Must construct a QGuiApplication before accessing a platform theme hint."); |
175 | 0 | return; |
176 | 0 | } |
177 | 0 | if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) |
178 | 0 | theme->requestColorScheme(scheme); |
179 | 0 | } |
180 | | |
181 | | /*! |
182 | | \fn void QStyleHints::unsetColorScheme() |
183 | | \since 6.8 |
184 | | |
185 | | Restores the color scheme to the system's current color scheme. |
186 | | */ |
187 | | |
188 | | |
189 | | /*! |
190 | | \property QStyleHints::accessibility |
191 | | \brief The application's accessibility hints. |
192 | | |
193 | | The accessibility hints encapsulates platform dependent accessibility settings |
194 | | such as whether the user wishes the application to be in high contrast or not. |
195 | | |
196 | | \sa QAccessibilityHints |
197 | | \since 6.10 |
198 | | */ |
199 | | const QAccessibilityHints *QStyleHints::accessibility() const |
200 | 0 | { |
201 | 0 | Q_D(const QStyleHints); |
202 | 0 | return d->accessibilityHints(); |
203 | 0 | } |
204 | | |
205 | | /*! |
206 | | \property QStyleHints::toolTipWakeUpDelay |
207 | | \brief The delay before tool tips should be shown. |
208 | | \since 6.12 |
209 | | \sa QWidget::toolTip, {QtQuick.Controls::ToolTip::delay} |
210 | | */ |
211 | | std::chrono::milliseconds QStyleHints::toolTipWakeUpDelay() const |
212 | 0 | { |
213 | 0 | Q_D(const QStyleHints); |
214 | 0 | return d->m_toolTipWakeUpDelay; |
215 | 0 | } |
216 | | |
217 | | void QStyleHints::setToolTipWakeUpDelay(std::chrono::milliseconds toolTipWakeUpDelay) |
218 | 0 | { |
219 | 0 | Q_D(QStyleHints); |
220 | 0 | if (d->m_toolTipWakeUpDelay == toolTipWakeUpDelay) |
221 | 0 | return; |
222 | 0 | d->m_toolTipWakeUpDelay = toolTipWakeUpDelay; |
223 | 0 | emit toolTipWakeUpDelayChanged(toolTipWakeUpDelay); |
224 | 0 | emit toolTipWakeUpDelayAsMSecChanged(toolTipWakeUpDelayAsMSec()); |
225 | 0 | } |
226 | | |
227 | | /*! |
228 | | \property QStyleHints::toolTipWakeUpDelayAsMSec |
229 | | \brief The delay, in milliseconds, before tool tips should be shown. |
230 | | \since 6.12 |
231 | | \sa toolTipWakeUpDelay, {QtQuick.Controls::ToolTip::delay} |
232 | | */ |
233 | | int QStyleHints::toolTipWakeUpDelayAsMSec() const |
234 | 0 | { |
235 | 0 | Q_D(const QStyleHints); |
236 | 0 | return q26::saturating_cast<int>(d->m_toolTipWakeUpDelay.count()); |
237 | 0 | } |
238 | | |
239 | | Qt::MouseButtons QStyleHints::menuActivationButtons() const |
240 | 0 | { |
241 | 0 | return themeableHint(QPlatformTheme::MenuActivationButtons).value<Qt::MouseButtons>(); |
242 | 0 | } |
243 | | |
244 | | /*! |
245 | | Sets the \a mousePressAndHoldInterval. |
246 | | \internal |
247 | | \sa mousePressAndHoldInterval() |
248 | | \since 5.7 |
249 | | */ |
250 | | void QStyleHints::setMousePressAndHoldInterval(int mousePressAndHoldInterval) |
251 | 0 | { |
252 | 0 | Q_D(QStyleHints); |
253 | 0 | if (d->m_mousePressAndHoldInterval == mousePressAndHoldInterval) |
254 | 0 | return; |
255 | 0 | d->m_mousePressAndHoldInterval = mousePressAndHoldInterval; |
256 | 0 | emit mousePressAndHoldIntervalChanged(mousePressAndHoldInterval); |
257 | 0 | } |
258 | | |
259 | | /*! |
260 | | \property QStyleHints::mousePressAndHoldInterval |
261 | | \brief the time limit in milliseconds that activates |
262 | | a press and hold. |
263 | | |
264 | | \since 5.3 |
265 | | */ |
266 | | int QStyleHints::mousePressAndHoldInterval() const |
267 | 0 | { |
268 | 0 | Q_D(const QStyleHints); |
269 | 0 | return d->m_mousePressAndHoldInterval >= 0 ? |
270 | 0 | d->m_mousePressAndHoldInterval : |
271 | 0 | themeableHint(QPlatformTheme::MousePressAndHoldInterval, QPlatformIntegration::MousePressAndHoldInterval).toInt(); |
272 | 0 | } |
273 | | |
274 | | /*! |
275 | | Sets the \a startDragDistance. |
276 | | \internal |
277 | | \sa startDragDistance() |
278 | | \since 5.3 |
279 | | */ |
280 | | void QStyleHints::setStartDragDistance(int startDragDistance) |
281 | 0 | { |
282 | 0 | Q_D(QStyleHints); |
283 | 0 | if (d->m_startDragDistance == startDragDistance) |
284 | 0 | return; |
285 | 0 | d->m_startDragDistance = startDragDistance; |
286 | 0 | emit startDragDistanceChanged(startDragDistance); |
287 | 0 | } |
288 | | |
289 | | /*! |
290 | | \property QStyleHints::startDragDistance |
291 | | \brief the distance, in pixels, that the mouse must be moved with a button |
292 | | held down before a drag and drop operation will begin. |
293 | | |
294 | | If you support drag and drop in your application, and want to start a drag |
295 | | and drop operation after the user has moved the cursor a certain distance |
296 | | with a button held down, you should use this property's value as the |
297 | | minimum distance required. |
298 | | |
299 | | For example, if the mouse position of the click is stored in \c startPos |
300 | | and the current position (e.g. in the mouse move event) is \c currentPos, |
301 | | you can find out if a drag should be started with code like this: |
302 | | |
303 | | \snippet code/src_gui_kernel_qapplication.cpp 6 |
304 | | |
305 | | \sa startDragTime, QPoint::manhattanLength(), {Drag and Drop} |
306 | | */ |
307 | | int QStyleHints::startDragDistance() const |
308 | 0 | { |
309 | 0 | Q_D(const QStyleHints); |
310 | 0 | return d->m_startDragDistance >= 0 ? |
311 | 0 | d->m_startDragDistance : |
312 | 0 | themeableHint(QPlatformTheme::StartDragDistance, QPlatformIntegration::StartDragDistance).toInt(); |
313 | 0 | } |
314 | | |
315 | | /*! |
316 | | Sets the \a startDragDragTime. |
317 | | \internal |
318 | | \sa startDragTime() |
319 | | \since 5.3 |
320 | | */ |
321 | | void QStyleHints::setStartDragTime(int startDragTime) |
322 | 0 | { |
323 | 0 | Q_D(QStyleHints); |
324 | 0 | if (d->m_startDragTime == startDragTime) |
325 | 0 | return; |
326 | 0 | d->m_startDragTime = startDragTime; |
327 | 0 | emit startDragTimeChanged(startDragTime); |
328 | 0 | } |
329 | | |
330 | | /*! |
331 | | \property QStyleHints::startDragTime |
332 | | \brief the time, in milliseconds, that a mouse button must be held down |
333 | | before a drag and drop operation will begin. |
334 | | |
335 | | If you support drag and drop in your application, and want to start a drag |
336 | | and drop operation after the user has held down a mouse button for a |
337 | | certain amount of time, you should use this property's value as the delay. |
338 | | |
339 | | \sa startDragDistance, {Drag and Drop} |
340 | | */ |
341 | | int QStyleHints::startDragTime() const |
342 | 0 | { |
343 | 0 | Q_D(const QStyleHints); |
344 | 0 | return d->m_startDragTime >= 0 ? |
345 | 0 | d->m_startDragTime : |
346 | 0 | themeableHint(QPlatformTheme::StartDragTime, QPlatformIntegration::StartDragTime).toInt(); |
347 | 0 | } |
348 | | |
349 | | /*! |
350 | | \property QStyleHints::startDragVelocity |
351 | | \brief the limit for the velocity, in pixels per second, that the mouse may |
352 | | be moved, with a button held down, for a drag and drop operation to begin. |
353 | | A value of 0 means there is no such limit. |
354 | | |
355 | | \sa startDragDistance, {Drag and Drop} |
356 | | */ |
357 | | int QStyleHints::startDragVelocity() const |
358 | 0 | { |
359 | 0 | return themeableHint(QPlatformTheme::StartDragVelocity, QPlatformIntegration::StartDragVelocity).toInt(); |
360 | 0 | } |
361 | | |
362 | | /*! |
363 | | Sets the \a keyboardInputInterval. |
364 | | \internal |
365 | | \sa keyboardInputInterval() |
366 | | \since 5.3 |
367 | | */ |
368 | | void QStyleHints::setKeyboardInputInterval(int keyboardInputInterval) |
369 | 0 | { |
370 | 0 | Q_D(QStyleHints); |
371 | 0 | if (d->m_keyboardInputInterval == keyboardInputInterval) |
372 | 0 | return; |
373 | 0 | d->m_keyboardInputInterval = keyboardInputInterval; |
374 | 0 | emit keyboardInputIntervalChanged(keyboardInputInterval); |
375 | 0 | } |
376 | | |
377 | | /*! |
378 | | \property QStyleHints::keyboardInputInterval |
379 | | \brief the time limit, in milliseconds, that distinguishes a key press |
380 | | from two consecutive key presses. |
381 | | */ |
382 | | int QStyleHints::keyboardInputInterval() const |
383 | 0 | { |
384 | 0 | Q_D(const QStyleHints); |
385 | 0 | return d->m_keyboardInputInterval >= 0 ? |
386 | 0 | d->m_keyboardInputInterval : |
387 | 0 | themeableHint(QPlatformTheme::KeyboardInputInterval, QPlatformIntegration::KeyboardInputInterval).toInt(); |
388 | 0 | } |
389 | | |
390 | | #if QT_DEPRECATED_SINCE(6, 5) |
391 | | /*! |
392 | | \property QStyleHints::keyboardAutoRepeatRate |
393 | | \brief the rate, in events per second, in which additional repeated key |
394 | | presses will automatically be generated if a key is being held down. |
395 | | \deprecated [6.5] Use keyboardAutoRepeatRateF() instead. |
396 | | */ |
397 | | int QStyleHints::keyboardAutoRepeatRate() const |
398 | 0 | { |
399 | 0 | return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toInt(); |
400 | 0 | } |
401 | | #endif |
402 | | |
403 | | /*! |
404 | | \property QStyleHints::keyboardAutoRepeatRateF |
405 | | \since 6.5 |
406 | | \brief the rate, in events per second, in which additional repeated key |
407 | | presses will automatically be generated if a key is being held down. |
408 | | */ |
409 | | qreal QStyleHints::keyboardAutoRepeatRateF() const |
410 | 0 | { |
411 | 0 | return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toReal(); |
412 | 0 | } |
413 | | |
414 | | /*! |
415 | | Sets the \a cursorFlashTime. |
416 | | \internal |
417 | | \sa cursorFlashTime() |
418 | | \since 5.3 |
419 | | */ |
420 | | void QStyleHints::setCursorFlashTime(int cursorFlashTime) |
421 | 0 | { |
422 | 0 | Q_D(QStyleHints); |
423 | 0 | if (d->m_cursorFlashTime == cursorFlashTime) |
424 | 0 | return; |
425 | 0 | d->m_cursorFlashTime = cursorFlashTime; |
426 | 0 | emit cursorFlashTimeChanged(cursorFlashTime); |
427 | 0 | } |
428 | | |
429 | | /*! |
430 | | \property QStyleHints::cursorFlashTime |
431 | | \brief the text cursor's flash (blink) time in milliseconds. |
432 | | |
433 | | The flash time is the time used to display, invert and restore the |
434 | | caret display. Usually the text cursor is displayed for half the cursor |
435 | | flash time, then hidden for the same amount of time. |
436 | | */ |
437 | | int QStyleHints::cursorFlashTime() const |
438 | 0 | { |
439 | 0 | Q_D(const QStyleHints); |
440 | 0 | return d->m_cursorFlashTime >= 0 ? |
441 | 0 | d->m_cursorFlashTime : |
442 | 0 | themeableHint(QPlatformTheme::CursorFlashTime, QPlatformIntegration::CursorFlashTime).toInt(); |
443 | 0 | } |
444 | | |
445 | | /*! |
446 | | \property QStyleHints::showIsFullScreen |
447 | | \brief whether the platform defaults to fullscreen windows. |
448 | | |
449 | | This property is \c true if the platform defaults to windows being fullscreen, |
450 | | otherwise \c false. |
451 | | |
452 | | \note The platform may still choose to show certain windows non-fullscreen, |
453 | | such as popups or dialogs. This property only reports the default behavior. |
454 | | |
455 | | \sa QWindow::show(), showIsMaximized() |
456 | | */ |
457 | | bool QStyleHints::showIsFullScreen() const |
458 | 0 | { |
459 | 0 | return hint(QPlatformIntegration::ShowIsFullScreen).toBool(); |
460 | 0 | } |
461 | | |
462 | | /*! |
463 | | \property QStyleHints::showIsMaximized |
464 | | \brief whether the platform defaults to maximized windows. |
465 | | |
466 | | This property is \c true if the platform defaults to windows being maximized, |
467 | | otherwise \c false. |
468 | | |
469 | | \note The platform may still choose to show certain windows non-maximized, |
470 | | such as popups or dialogs. This property only reports the default behavior. |
471 | | |
472 | | \sa QWindow::show(), showIsFullScreen() |
473 | | \since 5.6 |
474 | | */ |
475 | | bool QStyleHints::showIsMaximized() const |
476 | 0 | { |
477 | 0 | return hint(QPlatformIntegration::ShowIsMaximized).toBool(); |
478 | 0 | } |
479 | | |
480 | | /*! |
481 | | \property QStyleHints::showShortcutsInContextMenus |
482 | | \since 5.10 |
483 | | \brief \c true if the platform normally shows shortcut key sequences in |
484 | | context menus, otherwise \c false. |
485 | | |
486 | | Since Qt 5.13, the setShowShortcutsInContextMenus() function can be used to |
487 | | override the platform default. |
488 | | |
489 | | \sa Qt::AA_DontShowShortcutsInContextMenus |
490 | | */ |
491 | | bool QStyleHints::showShortcutsInContextMenus() const |
492 | 0 | { |
493 | 0 | Q_D(const QStyleHints); |
494 | 0 | return d->m_showShortcutsInContextMenus >= 0 |
495 | 0 | ? d->m_showShortcutsInContextMenus != 0 |
496 | 0 | : themeableHint(QPlatformTheme::ShowShortcutsInContextMenus, QPlatformIntegration::ShowShortcutsInContextMenus).toBool(); |
497 | 0 | } |
498 | | |
499 | | void QStyleHints::setShowShortcutsInContextMenus(bool s) |
500 | 0 | { |
501 | 0 | Q_D(QStyleHints); |
502 | 0 | if (s != showShortcutsInContextMenus()) { |
503 | 0 | d->m_showShortcutsInContextMenus = s ? 1 : 0; |
504 | 0 | emit showShortcutsInContextMenusChanged(s); |
505 | 0 | } |
506 | 0 | } |
507 | | |
508 | | /*! |
509 | | \property QStyleHints::contextMenuTrigger |
510 | | \since 6.8 |
511 | | \brief mouse event used to trigger a context menu event. |
512 | | |
513 | | The default on UNIX systems is to show context menu on mouse button press event, while on |
514 | | Windows it is the mouse button release event. This property can be used to override the default |
515 | | platform behavior. |
516 | | |
517 | | \note Developers must use this property with great care, as it changes the default interaction |
518 | | mode that their users will expect on the platform that they are running on. |
519 | | |
520 | | \sa Qt::ContextMenuTrigger |
521 | | */ |
522 | | Qt::ContextMenuTrigger QStyleHints::contextMenuTrigger() const |
523 | 0 | { |
524 | 0 | Q_D(const QStyleHints); |
525 | 0 | if (d->m_contextMenuTrigger == -1) { |
526 | 0 | return themeableHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() |
527 | 0 | ? Qt::ContextMenuTrigger::Release |
528 | 0 | : Qt::ContextMenuTrigger::Press; |
529 | 0 | } |
530 | 0 | return Qt::ContextMenuTrigger(d->m_contextMenuTrigger); |
531 | 0 | } |
532 | | |
533 | | void QStyleHints::setContextMenuTrigger(Qt::ContextMenuTrigger contextMenuTrigger) |
534 | 0 | { |
535 | 0 | Q_D(QStyleHints); |
536 | 0 | const Qt::ContextMenuTrigger currentTrigger = this->contextMenuTrigger(); |
537 | 0 | d->m_contextMenuTrigger = int(contextMenuTrigger); |
538 | 0 | if (currentTrigger != contextMenuTrigger) |
539 | 0 | emit contextMenuTriggerChanged(contextMenuTrigger); |
540 | 0 | } |
541 | | |
542 | | /*! |
543 | | \property QStyleHints::menuSelectionWraps |
544 | | \since 6.10 |
545 | | \brief menu selection wraps around. |
546 | | |
547 | | Returns \c true if menu selection wraps. That is, whether key navigation moves |
548 | | the selection to the first menu item again after the last menu item has been |
549 | | reached, and vice versa. |
550 | | */ |
551 | | bool QStyleHints::menuSelectionWraps() const |
552 | 0 | { |
553 | 0 | return themeableHint(QPlatformTheme::MenuSelectionWraps).toBool(); |
554 | 0 | } |
555 | | |
556 | | /*! |
557 | | \property QStyleHints::passwordMaskDelay |
558 | | \brief the time, in milliseconds, a typed letter is displayed unshrouded |
559 | | in a text input field in password mode. |
560 | | */ |
561 | | int QStyleHints::passwordMaskDelay() const |
562 | 0 | { |
563 | 0 | return themeableHint(QPlatformTheme::PasswordMaskDelay, QPlatformIntegration::PasswordMaskDelay).toInt(); |
564 | 0 | } |
565 | | |
566 | | /*! |
567 | | \property QStyleHints::passwordMaskCharacter |
568 | | \brief the character used to mask the characters typed into text input |
569 | | fields in password mode. |
570 | | */ |
571 | | QChar QStyleHints::passwordMaskCharacter() const |
572 | 0 | { |
573 | 0 | return themeableHint(QPlatformTheme::PasswordMaskCharacter, QPlatformIntegration::PasswordMaskCharacter).toChar(); |
574 | 0 | } |
575 | | |
576 | | /*! |
577 | | \property QStyleHints::fontSmoothingGamma |
578 | | \brief the gamma value used in font smoothing. |
579 | | */ |
580 | | qreal QStyleHints::fontSmoothingGamma() const |
581 | 0 | { |
582 | 0 | return hint(QPlatformIntegration::FontSmoothingGamma).toReal(); |
583 | 0 | } |
584 | | |
585 | | /*! |
586 | | \property QStyleHints::useRtlExtensions |
587 | | \brief the writing direction. |
588 | | |
589 | | This property is \c true if right-to-left writing direction is enabled, |
590 | | otherwise \c false. |
591 | | */ |
592 | | bool QStyleHints::useRtlExtensions() const |
593 | 0 | { |
594 | 0 | return hint(QPlatformIntegration::UseRtlExtensions).toBool(); |
595 | 0 | } |
596 | | |
597 | | /*! |
598 | | \property QStyleHints::setFocusOnTouchRelease |
599 | | \brief the event that should set input focus on focus objects. |
600 | | |
601 | | This property is \c true if focus objects (line edits etc) should receive |
602 | | input focus after a touch/mouse release. This is normal behavior on |
603 | | touch platforms. On desktop platforms, the standard is to set |
604 | | focus already on touch/mouse press. |
605 | | */ |
606 | | bool QStyleHints::setFocusOnTouchRelease() const |
607 | 0 | { |
608 | 0 | return themeableHint(QPlatformTheme::SetFocusOnTouchRelease, QPlatformIntegration::SetFocusOnTouchRelease).toBool(); |
609 | 0 | } |
610 | | |
611 | | /*! |
612 | | \property QStyleHints::tabFocusBehavior |
613 | | \since 5.5 |
614 | | \brief The focus behavior on press of the tab key. |
615 | | |
616 | | \note Do not bind this value in QML because the change notifier |
617 | | signal is not implemented yet. |
618 | | */ |
619 | | |
620 | | Qt::TabFocusBehavior QStyleHints::tabFocusBehavior() const |
621 | 0 | { |
622 | 0 | Q_D(const QStyleHints); |
623 | 0 | return Qt::TabFocusBehavior(d->m_tabFocusBehavior >= 0 ? |
624 | 0 | d->m_tabFocusBehavior : |
625 | 0 | themeableHint(QPlatformTheme::TabFocusBehavior, QPlatformIntegration::TabFocusBehavior).toInt()); |
626 | 0 | } |
627 | | |
628 | | /*! |
629 | | Sets the \a tabFocusBehavior. |
630 | | \internal |
631 | | \sa tabFocusBehavior() |
632 | | \since 5.7 |
633 | | */ |
634 | | void QStyleHints::setTabFocusBehavior(Qt::TabFocusBehavior tabFocusBehavior) |
635 | 0 | { |
636 | 0 | Q_D(QStyleHints); |
637 | 0 | if (d->m_tabFocusBehavior == tabFocusBehavior) |
638 | 0 | return; |
639 | 0 | d->m_tabFocusBehavior = tabFocusBehavior; |
640 | 0 | emit tabFocusBehaviorChanged(tabFocusBehavior); |
641 | 0 | } |
642 | | |
643 | | /*! |
644 | | \property QStyleHints::singleClickActivation |
645 | | \brief whether items are activated by single or double click. |
646 | | |
647 | | This property is \c true if items should be activated by single click, \c false |
648 | | if they should be activated by double click instead. |
649 | | |
650 | | \since 5.5 |
651 | | */ |
652 | | bool QStyleHints::singleClickActivation() const |
653 | 0 | { |
654 | 0 | return themeableHint(QPlatformTheme::ItemViewActivateItemOnSingleClick, QPlatformIntegration::ItemViewActivateItemOnSingleClick).toBool(); |
655 | 0 | } |
656 | | |
657 | | /*! |
658 | | \property QStyleHints::useHoverEffects |
659 | | \brief whether UI elements use hover effects. |
660 | | |
661 | | This property is \c true if UI elements should use hover effects. This is the |
662 | | standard behavior on desktop platforms with a mouse pointer, whereas |
663 | | on touch platforms the overhead of hover event delivery can be avoided. |
664 | | |
665 | | \since 5.8 |
666 | | */ |
667 | | bool QStyleHints::useHoverEffects() const |
668 | 0 | { |
669 | 0 | Q_D(const QStyleHints); |
670 | 0 | return (d->m_uiEffects >= 0 ? |
671 | 0 | d->m_uiEffects : |
672 | 0 | themeableHint(QPlatformTheme::UiEffects, QPlatformIntegration::UiEffects).toInt()) & QPlatformTheme::HoverEffect; |
673 | 0 | } |
674 | | |
675 | | void QStyleHints::setUseHoverEffects(bool useHoverEffects) |
676 | 0 | { |
677 | 0 | Q_D(QStyleHints); |
678 | 0 | if (d->m_uiEffects >= 0 && useHoverEffects == bool(d->m_uiEffects & QPlatformTheme::HoverEffect)) |
679 | 0 | return; |
680 | 0 | if (d->m_uiEffects == -1) |
681 | 0 | d->m_uiEffects = 0; |
682 | 0 | if (useHoverEffects) |
683 | 0 | d->m_uiEffects |= QPlatformTheme::HoverEffect; |
684 | 0 | else |
685 | 0 | d->m_uiEffects &= ~QPlatformTheme::HoverEffect; |
686 | 0 | emit useHoverEffectsChanged(useHoverEffects); |
687 | 0 | } |
688 | | |
689 | | /*! |
690 | | \property QStyleHints::wheelScrollLines |
691 | | \brief Number of lines to scroll by default for each wheel click. |
692 | | |
693 | | \since 5.9 |
694 | | */ |
695 | | int QStyleHints::wheelScrollLines() const |
696 | 0 | { |
697 | 0 | Q_D(const QStyleHints); |
698 | 0 | if (d->m_wheelScrollLines > 0) |
699 | 0 | return d->m_wheelScrollLines; |
700 | 0 | return themeableHint(QPlatformTheme::WheelScrollLines, QPlatformIntegration::WheelScrollLines).toInt(); |
701 | 0 | } |
702 | | |
703 | | /*! |
704 | | Sets the \a wheelScrollLines. |
705 | | \internal |
706 | | \sa wheelScrollLines() |
707 | | \since 5.9 |
708 | | */ |
709 | | void QStyleHints::setWheelScrollLines(int scrollLines) |
710 | 0 | { |
711 | 0 | Q_D(QStyleHints); |
712 | 0 | if (d->m_wheelScrollLines == scrollLines) |
713 | 0 | return; |
714 | 0 | d->m_wheelScrollLines = scrollLines; |
715 | 0 | emit wheelScrollLinesChanged(scrollLines); |
716 | 0 | } |
717 | | |
718 | | /*! |
719 | | Sets the mouse quick selection threshold. |
720 | | \internal |
721 | | \sa mouseQuickSelectionThreshold() |
722 | | \since 5.11 |
723 | | */ |
724 | | void QStyleHints::setMouseQuickSelectionThreshold(int threshold) |
725 | 0 | { |
726 | 0 | Q_D(QStyleHints); |
727 | 0 | if (d->m_mouseQuickSelectionThreshold == threshold) |
728 | 0 | return; |
729 | 0 | d->m_mouseQuickSelectionThreshold = threshold; |
730 | 0 | emit mouseQuickSelectionThresholdChanged(threshold); |
731 | 0 | } |
732 | | |
733 | | /*! |
734 | | \property QStyleHints::mouseQuickSelectionThreshold |
735 | | \brief Quick selection mouse threshold in QLineEdit. |
736 | | |
737 | | This property defines how much the mouse cursor should be moved along the y axis |
738 | | to trigger a quick selection during a normal QLineEdit text selection. |
739 | | |
740 | | If the property value is less than or equal to 0, the quick selection feature is disabled. |
741 | | |
742 | | \since 5.11 |
743 | | */ |
744 | | int QStyleHints::mouseQuickSelectionThreshold() const |
745 | 0 | { |
746 | 0 | Q_D(const QStyleHints); |
747 | 0 | if (d->m_mouseQuickSelectionThreshold >= 0) |
748 | 0 | return d->m_mouseQuickSelectionThreshold; |
749 | 0 | return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt(); |
750 | 0 | } |
751 | | |
752 | | /*! |
753 | | \internal |
754 | | QStyleHintsPrivate::updateColorScheme - set a new color scheme. |
755 | | |
756 | | This function is called by the QPA plugin when the system theme changes. This in |
757 | | turn might be the result of an explicit request of a color scheme via setColorScheme. |
758 | | |
759 | | Set \a colorScheme as the new color scheme of the QStyleHints. |
760 | | The colorSchemeChanged signal will be emitted if present and new color scheme differ. |
761 | | */ |
762 | | void QStyleHintsPrivate::updateColorScheme(Qt::ColorScheme colorScheme) |
763 | 0 | { |
764 | 0 | if (m_colorScheme == colorScheme) |
765 | 0 | return; |
766 | 0 | m_colorScheme = colorScheme; |
767 | 0 | Q_Q(QStyleHints); |
768 | 0 | emit q->colorSchemeChanged(colorScheme); |
769 | 0 | } |
770 | | |
771 | | /*! |
772 | | \internal |
773 | | |
774 | | Helper function that updates the style hints when the theme changes |
775 | | */ |
776 | | void QStyleHintsPrivate::update(const QPlatformTheme *theme) |
777 | 0 | { |
778 | 0 | Q_ASSERT(theme); |
779 | 0 | updateColorScheme(theme->colorScheme()); |
780 | 0 | auto *accessibilityHintsPrivate = QAccessibilityHintsPrivate::get(accessibilityHints()); |
781 | 0 | accessibilityHintsPrivate->updateContrastPreference(theme->contrastPreference()); |
782 | 0 | accessibilityHintsPrivate->updateMotionPreference(theme->motionPreference()); |
783 | 0 | } |
784 | | |
785 | | QAccessibilityHints *QStyleHintsPrivate::accessibilityHints() const |
786 | 0 | { |
787 | 0 | Q_Q(const QStyleHints); |
788 | 0 | if (!m_accessibilityHints) |
789 | 0 | const_cast<QStyleHintsPrivate *>(this)->m_accessibilityHints = new QAccessibilityHints(const_cast<QStyleHints*>(q)); |
790 | 0 | return m_accessibilityHints; |
791 | 0 | } |
792 | | |
793 | | QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q) |
794 | 0 | { |
795 | | Q_ASSERT(q); |
796 | 0 | return q->d_func(); |
797 | 0 | } |
798 | | |
799 | | QT_END_NAMESPACE |
800 | | |
801 | | #include "moc_qstylehints.cpp" |