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