/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 | 144k | { |
23 | 144k | if (!QCoreApplication::instance()) { |
24 | 0 | qWarning("Must construct a QGuiApplication before accessing a platform theme hint."); |
25 | 0 | return QVariant(); |
26 | 0 | } |
27 | 144k | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { |
28 | 144k | const QVariant themeHint = theme->themeHint(th); |
29 | 144k | if (themeHint.isValid()) |
30 | 144k | return themeHint; |
31 | 144k | } |
32 | 0 | return QGuiApplicationPrivate::platformIntegration()->styleHint(ih); |
33 | 144k | } |
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 | 144k | : QObject(*new QStyleHintsPrivate(), nullptr) |
73 | 144k | { |
74 | 144k | } |
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 in milliseconds before tool tips should be shown. |
208 | | \since 6.12 |
209 | | \sa QWidget::toolTip, {QtQuick.Controls::ToolTip::delay} |
210 | | */ |
211 | | int QStyleHints::toolTipWakeUpDelay() const |
212 | 0 | { |
213 | 0 | Q_D(const QStyleHints); |
214 | 0 | return d->m_toolTipWakeUpDelay; |
215 | 0 | } |
216 | | |
217 | | void QStyleHints::setToolTipWakeUpDelay(int 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 | } |
225 | | |
226 | | /*! |
227 | | Sets the \a mousePressAndHoldInterval. |
228 | | \internal |
229 | | \sa mousePressAndHoldInterval() |
230 | | \since 5.7 |
231 | | */ |
232 | | void QStyleHints::setMousePressAndHoldInterval(int mousePressAndHoldInterval) |
233 | 0 | { |
234 | 0 | Q_D(QStyleHints); |
235 | 0 | if (d->m_mousePressAndHoldInterval == mousePressAndHoldInterval) |
236 | 0 | return; |
237 | 0 | d->m_mousePressAndHoldInterval = mousePressAndHoldInterval; |
238 | 0 | emit mousePressAndHoldIntervalChanged(mousePressAndHoldInterval); |
239 | 0 | } |
240 | | |
241 | | /*! |
242 | | \property QStyleHints::mousePressAndHoldInterval |
243 | | \brief the time limit in milliseconds that activates |
244 | | a press and hold. |
245 | | |
246 | | \since 5.3 |
247 | | */ |
248 | | int QStyleHints::mousePressAndHoldInterval() const |
249 | 0 | { |
250 | 0 | Q_D(const QStyleHints); |
251 | 0 | return d->m_mousePressAndHoldInterval >= 0 ? |
252 | 0 | d->m_mousePressAndHoldInterval : |
253 | 0 | themeableHint(QPlatformTheme::MousePressAndHoldInterval, QPlatformIntegration::MousePressAndHoldInterval).toInt(); |
254 | 0 | } |
255 | | |
256 | | /*! |
257 | | Sets the \a startDragDistance. |
258 | | \internal |
259 | | \sa startDragDistance() |
260 | | \since 5.3 |
261 | | */ |
262 | | void QStyleHints::setStartDragDistance(int startDragDistance) |
263 | 0 | { |
264 | 0 | Q_D(QStyleHints); |
265 | 0 | if (d->m_startDragDistance == startDragDistance) |
266 | 0 | return; |
267 | 0 | d->m_startDragDistance = startDragDistance; |
268 | 0 | emit startDragDistanceChanged(startDragDistance); |
269 | 0 | } |
270 | | |
271 | | /*! |
272 | | \property QStyleHints::startDragDistance |
273 | | \brief the distance, in pixels, that the mouse must be moved with a button |
274 | | held down before a drag and drop operation will begin. |
275 | | |
276 | | If you support drag and drop in your application, and want to start a drag |
277 | | and drop operation after the user has moved the cursor a certain distance |
278 | | with a button held down, you should use this property's value as the |
279 | | minimum distance required. |
280 | | |
281 | | For example, if the mouse position of the click is stored in \c startPos |
282 | | and the current position (e.g. in the mouse move event) is \c currentPos, |
283 | | you can find out if a drag should be started with code like this: |
284 | | |
285 | | \snippet code/src_gui_kernel_qapplication.cpp 6 |
286 | | |
287 | | \sa startDragTime, QPoint::manhattanLength(), {Drag and Drop} |
288 | | */ |
289 | | int QStyleHints::startDragDistance() const |
290 | 0 | { |
291 | 0 | Q_D(const QStyleHints); |
292 | 0 | return d->m_startDragDistance >= 0 ? |
293 | 0 | d->m_startDragDistance : |
294 | 0 | themeableHint(QPlatformTheme::StartDragDistance, QPlatformIntegration::StartDragDistance).toInt(); |
295 | 0 | } |
296 | | |
297 | | /*! |
298 | | Sets the \a startDragDragTime. |
299 | | \internal |
300 | | \sa startDragTime() |
301 | | \since 5.3 |
302 | | */ |
303 | | void QStyleHints::setStartDragTime(int startDragTime) |
304 | 0 | { |
305 | 0 | Q_D(QStyleHints); |
306 | 0 | if (d->m_startDragTime == startDragTime) |
307 | 0 | return; |
308 | 0 | d->m_startDragTime = startDragTime; |
309 | 0 | emit startDragTimeChanged(startDragTime); |
310 | 0 | } |
311 | | |
312 | | /*! |
313 | | \property QStyleHints::startDragTime |
314 | | \brief the time, in milliseconds, that a mouse button must be held down |
315 | | before a drag and drop operation will begin. |
316 | | |
317 | | If you support drag and drop in your application, and want to start a drag |
318 | | and drop operation after the user has held down a mouse button for a |
319 | | certain amount of time, you should use this property's value as the delay. |
320 | | |
321 | | \sa startDragDistance, {Drag and Drop} |
322 | | */ |
323 | | int QStyleHints::startDragTime() const |
324 | 0 | { |
325 | 0 | Q_D(const QStyleHints); |
326 | 0 | return d->m_startDragTime >= 0 ? |
327 | 0 | d->m_startDragTime : |
328 | 0 | themeableHint(QPlatformTheme::StartDragTime, QPlatformIntegration::StartDragTime).toInt(); |
329 | 0 | } |
330 | | |
331 | | /*! |
332 | | \property QStyleHints::startDragVelocity |
333 | | \brief the limit for the velocity, in pixels per second, that the mouse may |
334 | | be moved, with a button held down, for a drag and drop operation to begin. |
335 | | A value of 0 means there is no such limit. |
336 | | |
337 | | \sa startDragDistance, {Drag and Drop} |
338 | | */ |
339 | | int QStyleHints::startDragVelocity() const |
340 | 0 | { |
341 | 0 | return themeableHint(QPlatformTheme::StartDragVelocity, QPlatformIntegration::StartDragVelocity).toInt(); |
342 | 0 | } |
343 | | |
344 | | /*! |
345 | | Sets the \a keyboardInputInterval. |
346 | | \internal |
347 | | \sa keyboardInputInterval() |
348 | | \since 5.3 |
349 | | */ |
350 | | void QStyleHints::setKeyboardInputInterval(int keyboardInputInterval) |
351 | 0 | { |
352 | 0 | Q_D(QStyleHints); |
353 | 0 | if (d->m_keyboardInputInterval == keyboardInputInterval) |
354 | 0 | return; |
355 | 0 | d->m_keyboardInputInterval = keyboardInputInterval; |
356 | 0 | emit keyboardInputIntervalChanged(keyboardInputInterval); |
357 | 0 | } |
358 | | |
359 | | /*! |
360 | | \property QStyleHints::keyboardInputInterval |
361 | | \brief the time limit, in milliseconds, that distinguishes a key press |
362 | | from two consecutive key presses. |
363 | | */ |
364 | | int QStyleHints::keyboardInputInterval() const |
365 | 0 | { |
366 | 0 | Q_D(const QStyleHints); |
367 | 0 | return d->m_keyboardInputInterval >= 0 ? |
368 | 0 | d->m_keyboardInputInterval : |
369 | 0 | themeableHint(QPlatformTheme::KeyboardInputInterval, QPlatformIntegration::KeyboardInputInterval).toInt(); |
370 | 0 | } |
371 | | |
372 | | #if QT_DEPRECATED_SINCE(6, 5) |
373 | | /*! |
374 | | \property QStyleHints::keyboardAutoRepeatRate |
375 | | \brief the rate, in events per second, in which additional repeated key |
376 | | presses will automatically be generated if a key is being held down. |
377 | | \deprecated [6.5] Use keyboardAutoRepeatRateF() instead |
378 | | */ |
379 | | int QStyleHints::keyboardAutoRepeatRate() const |
380 | 0 | { |
381 | 0 | return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toInt(); |
382 | 0 | } |
383 | | #endif |
384 | | |
385 | | /*! |
386 | | \property QStyleHints::keyboardAutoRepeatRateF |
387 | | \since 6.5 |
388 | | \brief the rate, in events per second, in which additional repeated key |
389 | | presses will automatically be generated if a key is being held down. |
390 | | */ |
391 | | qreal QStyleHints::keyboardAutoRepeatRateF() const |
392 | 0 | { |
393 | 0 | return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toReal(); |
394 | 0 | } |
395 | | |
396 | | /*! |
397 | | Sets the \a cursorFlashTime. |
398 | | \internal |
399 | | \sa cursorFlashTime() |
400 | | \since 5.3 |
401 | | */ |
402 | | void QStyleHints::setCursorFlashTime(int cursorFlashTime) |
403 | 0 | { |
404 | 0 | Q_D(QStyleHints); |
405 | 0 | if (d->m_cursorFlashTime == cursorFlashTime) |
406 | 0 | return; |
407 | 0 | d->m_cursorFlashTime = cursorFlashTime; |
408 | 0 | emit cursorFlashTimeChanged(cursorFlashTime); |
409 | 0 | } |
410 | | |
411 | | /*! |
412 | | \property QStyleHints::cursorFlashTime |
413 | | \brief the text cursor's flash (blink) time in milliseconds. |
414 | | |
415 | | The flash time is the time used to display, invert and restore the |
416 | | caret display. Usually the text cursor is displayed for half the cursor |
417 | | flash time, then hidden for the same amount of time. |
418 | | */ |
419 | | int QStyleHints::cursorFlashTime() const |
420 | 0 | { |
421 | 0 | Q_D(const QStyleHints); |
422 | 0 | return d->m_cursorFlashTime >= 0 ? |
423 | 0 | d->m_cursorFlashTime : |
424 | 0 | themeableHint(QPlatformTheme::CursorFlashTime, QPlatformIntegration::CursorFlashTime).toInt(); |
425 | 0 | } |
426 | | |
427 | | /*! |
428 | | \property QStyleHints::showIsFullScreen |
429 | | \brief whether the platform defaults to fullscreen windows. |
430 | | |
431 | | This property is \c true if the platform defaults to windows being fullscreen, |
432 | | otherwise \c false. |
433 | | |
434 | | \note The platform may still choose to show certain windows non-fullscreen, |
435 | | such as popups or dialogs. This property only reports the default behavior. |
436 | | |
437 | | \sa QWindow::show(), showIsMaximized() |
438 | | */ |
439 | | bool QStyleHints::showIsFullScreen() const |
440 | 0 | { |
441 | 0 | return hint(QPlatformIntegration::ShowIsFullScreen).toBool(); |
442 | 0 | } |
443 | | |
444 | | /*! |
445 | | \property QStyleHints::showIsMaximized |
446 | | \brief whether the platform defaults to maximized windows. |
447 | | |
448 | | This property is \c true if the platform defaults to windows being maximized, |
449 | | otherwise \c false. |
450 | | |
451 | | \note The platform may still choose to show certain windows non-maximized, |
452 | | such as popups or dialogs. This property only reports the default behavior. |
453 | | |
454 | | \sa QWindow::show(), showIsFullScreen() |
455 | | \since 5.6 |
456 | | */ |
457 | | bool QStyleHints::showIsMaximized() const |
458 | 0 | { |
459 | 0 | return hint(QPlatformIntegration::ShowIsMaximized).toBool(); |
460 | 0 | } |
461 | | |
462 | | /*! |
463 | | \property QStyleHints::showShortcutsInContextMenus |
464 | | \since 5.10 |
465 | | \brief \c true if the platform normally shows shortcut key sequences in |
466 | | context menus, otherwise \c false. |
467 | | |
468 | | Since Qt 5.13, the setShowShortcutsInContextMenus() function can be used to |
469 | | override the platform default. |
470 | | |
471 | | \sa Qt::AA_DontShowShortcutsInContextMenus |
472 | | */ |
473 | | bool QStyleHints::showShortcutsInContextMenus() const |
474 | 144k | { |
475 | 144k | Q_D(const QStyleHints); |
476 | 144k | return d->m_showShortcutsInContextMenus >= 0 |
477 | 144k | ? d->m_showShortcutsInContextMenus != 0 |
478 | 144k | : themeableHint(QPlatformTheme::ShowShortcutsInContextMenus, QPlatformIntegration::ShowShortcutsInContextMenus).toBool(); |
479 | 144k | } |
480 | | |
481 | | void QStyleHints::setShowShortcutsInContextMenus(bool s) |
482 | 0 | { |
483 | 0 | Q_D(QStyleHints); |
484 | 0 | if (s != showShortcutsInContextMenus()) { |
485 | 0 | d->m_showShortcutsInContextMenus = s ? 1 : 0; |
486 | 0 | emit showShortcutsInContextMenusChanged(s); |
487 | 0 | } |
488 | 0 | } |
489 | | |
490 | | /*! |
491 | | \property QStyleHints::contextMenuTrigger |
492 | | \since 6.8 |
493 | | \brief mouse event used to trigger a context menu event. |
494 | | |
495 | | The default on UNIX systems is to show context menu on mouse button press event, while on |
496 | | Windows it is the mouse button release event. This property can be used to override the default |
497 | | platform behavior. |
498 | | |
499 | | \note Developers must use this property with great care, as it changes the default interaction |
500 | | mode that their users will expect on the platform that they are running on. |
501 | | |
502 | | \sa Qt::ContextMenuTrigger |
503 | | */ |
504 | | Qt::ContextMenuTrigger QStyleHints::contextMenuTrigger() const |
505 | 0 | { |
506 | 0 | Q_D(const QStyleHints); |
507 | 0 | if (d->m_contextMenuTrigger == -1) { |
508 | 0 | return themeableHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() |
509 | 0 | ? Qt::ContextMenuTrigger::Release |
510 | 0 | : Qt::ContextMenuTrigger::Press; |
511 | 0 | } |
512 | 0 | return Qt::ContextMenuTrigger(d->m_contextMenuTrigger); |
513 | 0 | } |
514 | | |
515 | | void QStyleHints::setContextMenuTrigger(Qt::ContextMenuTrigger contextMenuTrigger) |
516 | 0 | { |
517 | 0 | Q_D(QStyleHints); |
518 | 0 | const Qt::ContextMenuTrigger currentTrigger = this->contextMenuTrigger(); |
519 | 0 | d->m_contextMenuTrigger = int(contextMenuTrigger); |
520 | 0 | if (currentTrigger != contextMenuTrigger) |
521 | 0 | emit contextMenuTriggerChanged(contextMenuTrigger); |
522 | 0 | } |
523 | | |
524 | | /*! |
525 | | \property QStyleHints::menuSelectionWraps |
526 | | \since 6.10 |
527 | | \brief menu selection wraps around. |
528 | | |
529 | | Returns \c true if menu selection wraps. That is, whether key navigation moves |
530 | | the selection to the first menu item again after the last menu item has been |
531 | | reached, and vice versa. |
532 | | */ |
533 | | bool QStyleHints::menuSelectionWraps() const |
534 | 0 | { |
535 | 0 | return themeableHint(QPlatformTheme::MenuSelectionWraps).toBool(); |
536 | 0 | } |
537 | | |
538 | | /*! |
539 | | \property QStyleHints::passwordMaskDelay |
540 | | \brief the time, in milliseconds, a typed letter is displayed unshrouded |
541 | | in a text input field in password mode. |
542 | | */ |
543 | | int QStyleHints::passwordMaskDelay() const |
544 | 0 | { |
545 | 0 | return themeableHint(QPlatformTheme::PasswordMaskDelay, QPlatformIntegration::PasswordMaskDelay).toInt(); |
546 | 0 | } |
547 | | |
548 | | /*! |
549 | | \property QStyleHints::passwordMaskCharacter |
550 | | \brief the character used to mask the characters typed into text input |
551 | | fields in password mode. |
552 | | */ |
553 | | QChar QStyleHints::passwordMaskCharacter() const |
554 | 0 | { |
555 | 0 | return themeableHint(QPlatformTheme::PasswordMaskCharacter, QPlatformIntegration::PasswordMaskCharacter).toChar(); |
556 | 0 | } |
557 | | |
558 | | /*! |
559 | | \property QStyleHints::fontSmoothingGamma |
560 | | \brief the gamma value used in font smoothing. |
561 | | */ |
562 | | qreal QStyleHints::fontSmoothingGamma() const |
563 | 0 | { |
564 | 0 | return hint(QPlatformIntegration::FontSmoothingGamma).toReal(); |
565 | 0 | } |
566 | | |
567 | | /*! |
568 | | \property QStyleHints::useRtlExtensions |
569 | | \brief the writing direction. |
570 | | |
571 | | This property is \c true if right-to-left writing direction is enabled, |
572 | | otherwise \c false. |
573 | | */ |
574 | | bool QStyleHints::useRtlExtensions() const |
575 | 0 | { |
576 | 0 | return hint(QPlatformIntegration::UseRtlExtensions).toBool(); |
577 | 0 | } |
578 | | |
579 | | /*! |
580 | | \property QStyleHints::setFocusOnTouchRelease |
581 | | \brief the event that should set input focus on focus objects. |
582 | | |
583 | | This property is \c true if focus objects (line edits etc) should receive |
584 | | input focus after a touch/mouse release. This is normal behavior on |
585 | | touch platforms. On desktop platforms, the standard is to set |
586 | | focus already on touch/mouse press. |
587 | | */ |
588 | | bool QStyleHints::setFocusOnTouchRelease() const |
589 | 0 | { |
590 | 0 | return themeableHint(QPlatformTheme::SetFocusOnTouchRelease, QPlatformIntegration::SetFocusOnTouchRelease).toBool(); |
591 | 0 | } |
592 | | |
593 | | /*! |
594 | | \property QStyleHints::tabFocusBehavior |
595 | | \since 5.5 |
596 | | \brief The focus behavior on press of the tab key. |
597 | | |
598 | | \note Do not bind this value in QML because the change notifier |
599 | | signal is not implemented yet. |
600 | | */ |
601 | | |
602 | | Qt::TabFocusBehavior QStyleHints::tabFocusBehavior() const |
603 | 0 | { |
604 | 0 | Q_D(const QStyleHints); |
605 | 0 | return Qt::TabFocusBehavior(d->m_tabFocusBehavior >= 0 ? |
606 | 0 | d->m_tabFocusBehavior : |
607 | 0 | themeableHint(QPlatformTheme::TabFocusBehavior, QPlatformIntegration::TabFocusBehavior).toInt()); |
608 | 0 | } |
609 | | |
610 | | /*! |
611 | | Sets the \a tabFocusBehavior. |
612 | | \internal |
613 | | \sa tabFocusBehavior() |
614 | | \since 5.7 |
615 | | */ |
616 | | void QStyleHints::setTabFocusBehavior(Qt::TabFocusBehavior tabFocusBehavior) |
617 | 0 | { |
618 | 0 | Q_D(QStyleHints); |
619 | 0 | if (d->m_tabFocusBehavior == tabFocusBehavior) |
620 | 0 | return; |
621 | 0 | d->m_tabFocusBehavior = tabFocusBehavior; |
622 | 0 | emit tabFocusBehaviorChanged(tabFocusBehavior); |
623 | 0 | } |
624 | | |
625 | | /*! |
626 | | \property QStyleHints::singleClickActivation |
627 | | \brief whether items are activated by single or double click. |
628 | | |
629 | | This property is \c true if items should be activated by single click, \c false |
630 | | if they should be activated by double click instead. |
631 | | |
632 | | \since 5.5 |
633 | | */ |
634 | | bool QStyleHints::singleClickActivation() const |
635 | 0 | { |
636 | 0 | return themeableHint(QPlatformTheme::ItemViewActivateItemOnSingleClick, QPlatformIntegration::ItemViewActivateItemOnSingleClick).toBool(); |
637 | 0 | } |
638 | | |
639 | | /*! |
640 | | \property QStyleHints::useHoverEffects |
641 | | \brief whether UI elements use hover effects. |
642 | | |
643 | | This property is \c true if UI elements should use hover effects. This is the |
644 | | standard behavior on desktop platforms with a mouse pointer, whereas |
645 | | on touch platforms the overhead of hover event delivery can be avoided. |
646 | | |
647 | | \since 5.8 |
648 | | */ |
649 | | bool QStyleHints::useHoverEffects() const |
650 | 0 | { |
651 | 0 | Q_D(const QStyleHints); |
652 | 0 | return (d->m_uiEffects >= 0 ? |
653 | 0 | d->m_uiEffects : |
654 | 0 | themeableHint(QPlatformTheme::UiEffects, QPlatformIntegration::UiEffects).toInt()) & QPlatformTheme::HoverEffect; |
655 | 0 | } |
656 | | |
657 | | void QStyleHints::setUseHoverEffects(bool useHoverEffects) |
658 | 0 | { |
659 | 0 | Q_D(QStyleHints); |
660 | 0 | if (d->m_uiEffects >= 0 && useHoverEffects == bool(d->m_uiEffects & QPlatformTheme::HoverEffect)) |
661 | 0 | return; |
662 | 0 | if (d->m_uiEffects == -1) |
663 | 0 | d->m_uiEffects = 0; |
664 | 0 | if (useHoverEffects) |
665 | 0 | d->m_uiEffects |= QPlatformTheme::HoverEffect; |
666 | 0 | else |
667 | 0 | d->m_uiEffects &= ~QPlatformTheme::HoverEffect; |
668 | 0 | emit useHoverEffectsChanged(useHoverEffects); |
669 | 0 | } |
670 | | |
671 | | /*! |
672 | | \property QStyleHints::wheelScrollLines |
673 | | \brief Number of lines to scroll by default for each wheel click. |
674 | | |
675 | | \since 5.9 |
676 | | */ |
677 | | int QStyleHints::wheelScrollLines() const |
678 | 0 | { |
679 | 0 | Q_D(const QStyleHints); |
680 | 0 | if (d->m_wheelScrollLines > 0) |
681 | 0 | return d->m_wheelScrollLines; |
682 | 0 | return themeableHint(QPlatformTheme::WheelScrollLines, QPlatformIntegration::WheelScrollLines).toInt(); |
683 | 0 | } |
684 | | |
685 | | /*! |
686 | | Sets the \a wheelScrollLines. |
687 | | \internal |
688 | | \sa wheelScrollLines() |
689 | | \since 5.9 |
690 | | */ |
691 | | void QStyleHints::setWheelScrollLines(int scrollLines) |
692 | 0 | { |
693 | 0 | Q_D(QStyleHints); |
694 | 0 | if (d->m_wheelScrollLines == scrollLines) |
695 | 0 | return; |
696 | 0 | d->m_wheelScrollLines = scrollLines; |
697 | 0 | emit wheelScrollLinesChanged(scrollLines); |
698 | 0 | } |
699 | | |
700 | | /*! |
701 | | Sets the mouse quick selection threshold. |
702 | | \internal |
703 | | \sa mouseQuickSelectionThreshold() |
704 | | \since 5.11 |
705 | | */ |
706 | | void QStyleHints::setMouseQuickSelectionThreshold(int threshold) |
707 | 0 | { |
708 | 0 | Q_D(QStyleHints); |
709 | 0 | if (d->m_mouseQuickSelectionThreshold == threshold) |
710 | 0 | return; |
711 | 0 | d->m_mouseQuickSelectionThreshold = threshold; |
712 | 0 | emit mouseQuickSelectionThresholdChanged(threshold); |
713 | 0 | } |
714 | | |
715 | | /*! |
716 | | \property QStyleHints::mouseQuickSelectionThreshold |
717 | | \brief Quick selection mouse threshold in QLineEdit. |
718 | | |
719 | | This property defines how much the mouse cursor should be moved along the y axis |
720 | | to trigger a quick selection during a normal QLineEdit text selection. |
721 | | |
722 | | If the property value is less than or equal to 0, the quick selection feature is disabled. |
723 | | |
724 | | \since 5.11 |
725 | | */ |
726 | | int QStyleHints::mouseQuickSelectionThreshold() const |
727 | 0 | { |
728 | 0 | Q_D(const QStyleHints); |
729 | 0 | if (d->m_mouseQuickSelectionThreshold >= 0) |
730 | 0 | return d->m_mouseQuickSelectionThreshold; |
731 | 0 | return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt(); |
732 | 0 | } |
733 | | |
734 | | /*! |
735 | | \internal |
736 | | QStyleHintsPrivate::updateColorScheme - set a new color scheme. |
737 | | |
738 | | This function is called by the QPA plugin when the system theme changes. This in |
739 | | turn might be the result of an explicit request of a color scheme via setColorScheme. |
740 | | |
741 | | Set \a colorScheme as the new color scheme of the QStyleHints. |
742 | | The colorSchemeChanged signal will be emitted if present and new color scheme differ. |
743 | | */ |
744 | | void QStyleHintsPrivate::updateColorScheme(Qt::ColorScheme colorScheme) |
745 | 144k | { |
746 | 144k | if (m_colorScheme == colorScheme) |
747 | 144k | return; |
748 | 0 | m_colorScheme = colorScheme; |
749 | 0 | Q_Q(QStyleHints); |
750 | 0 | emit q->colorSchemeChanged(colorScheme); |
751 | 0 | } |
752 | | |
753 | | /*! |
754 | | \internal |
755 | | |
756 | | Helper function that updates the style hints when the theme changes |
757 | | */ |
758 | | void QStyleHintsPrivate::update(const QPlatformTheme *theme) |
759 | 144k | { |
760 | 144k | Q_ASSERT(theme); |
761 | 144k | updateColorScheme(theme->colorScheme()); |
762 | 144k | auto *accessibilityHintsPrivate = QAccessibilityHintsPrivate::get(accessibilityHints()); |
763 | 144k | accessibilityHintsPrivate->updateContrastPreference(theme->contrastPreference()); |
764 | 144k | accessibilityHintsPrivate->updateMotionPreference(theme->motionPreference()); |
765 | 144k | } |
766 | | |
767 | | QAccessibilityHints *QStyleHintsPrivate::accessibilityHints() const |
768 | 144k | { |
769 | 144k | Q_Q(const QStyleHints); |
770 | 144k | if (!m_accessibilityHints) |
771 | 144k | const_cast<QStyleHintsPrivate *>(this)->m_accessibilityHints = new QAccessibilityHints(const_cast<QStyleHints*>(q)); |
772 | 144k | return m_accessibilityHints; |
773 | 144k | } |
774 | | |
775 | | QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q) |
776 | 144k | { |
777 | | Q_ASSERT(q); |
778 | 144k | return q->d_func(); |
779 | 144k | } |
780 | | |
781 | | QT_END_NAMESPACE |
782 | | |
783 | | #include "moc_qstylehints.cpp" |