| 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 "qplatformtheme.h" |
| 5 | |
| 6 | #include "qplatformtheme_p.h" |
| 7 | |
| 8 | #include <QtCore/QVariant> |
| 9 | #include <QtCore/QStringList> |
| 10 | #include <QtCore/qfileinfo.h> |
| 11 | #include <qicon.h> |
| 12 | #include <qpalette.h> |
| 13 | #include <qtextformat.h> |
| 14 | #include <private/qiconloader_p.h> |
| 15 | #include <private/qguiapplication_p.h> |
| 16 | #include <qpa/qplatformintegration.h> |
| 17 | #include <qpa/qplatformdialoghelper.h> |
| 18 | |
| 19 | #include <algorithm> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | /*! |
| 24 | \class QPlatformTheme |
| 25 | \since 5.0 |
| 26 | \internal |
| 27 | \preliminary |
| 28 | \ingroup qpa |
| 29 | \brief The QPlatformTheme class allows customizing the UI based on themes. |
| 30 | |
| 31 | See the init_platform function in qguiapplication.cpp for the complete |
| 32 | platform initialization process. |
| 33 | */ |
| 34 | |
| 35 | /*! |
| 36 | \enum QPlatformTheme::ThemeHint |
| 37 | |
| 38 | This enum describes the available theme hints. |
| 39 | |
| 40 | \value CursorFlashTime (int) Cursor flash time in ms, overriding |
| 41 | QPlatformIntegration::styleHint. |
| 42 | |
| 43 | \value KeyboardInputInterval (int) Keyboard input interval in ms, overriding |
| 44 | QPlatformIntegration::styleHint. |
| 45 | |
| 46 | \value MouseDoubleClickInterval (int) Mouse double click interval in ms, |
| 47 | overriding QPlatformIntegration::styleHint. |
| 48 | |
| 49 | \value MouseDoubleClickDistance (int) The maximum distance in logical pixels which the mouse can travel |
| 50 | between clicks in order for the click sequence to be handled as a double click. |
| 51 | The default value is 5 logical pixels. |
| 52 | |
| 53 | \value MousePressAndHoldInterval (int) Mouse press and hold interval in ms, |
| 54 | overriding QPlatformIntegration::styleHint. |
| 55 | |
| 56 | \value StartDragDistance (int) Start drag distance, |
| 57 | overriding QPlatformIntegration::styleHint. |
| 58 | |
| 59 | \value StartDragTime (int) Start drag time in ms, |
| 60 | overriding QPlatformIntegration::styleHint. |
| 61 | |
| 62 | \value WheelScrollLines (int) The number of lines to scroll a widget, when the mouse wheel is rotated. |
| 63 | The default value is 3. \sa QApplication::wheelScrollLines() |
| 64 | |
| 65 | \value KeyboardAutoRepeatRate (int) Keyboard auto repeat rate, |
| 66 | overriding QPlatformIntegration::styleHint. |
| 67 | |
| 68 | \value PasswordMaskDelay (int) Pass word mask delay in ms, |
| 69 | overriding QPlatformIntegration::styleHint. |
| 70 | |
| 71 | \value StartDragVelocity (int) Velocity of a drag, |
| 72 | overriding QPlatformIntegration::styleHint. |
| 73 | |
| 74 | \value TextCursorWidth (int) Determines the width of the text cursor. |
| 75 | |
| 76 | \value DropShadow (bool) Determines whether the drop shadow effect for |
| 77 | tooltips or whatsthis is enabled. |
| 78 | |
| 79 | \value MaximumScrollBarDragDistance (int) Determines the value returned by |
| 80 | QStyle::pixelMetric(PM_MaximumDragDistance) |
| 81 | |
| 82 | \value ToolButtonStyle (int) A value representing a Qt::ToolButtonStyle. |
| 83 | |
| 84 | \value ToolBarIconSize Icon size for tool bars. |
| 85 | |
| 86 | \value SystemIconThemeName (QString) Name of the icon theme. |
| 87 | |
| 88 | \value SystemIconFallbackThemeName (QString) Name of the fallback icon theme. |
| 89 | |
| 90 | \value IconThemeSearchPaths (QStringList) Search paths for icons. |
| 91 | |
| 92 | \value ItemViewActivateItemOnSingleClick (bool) Activate items by single click. |
| 93 | |
| 94 | \value StyleNames (QStringList) A list of preferred style names. |
| 95 | |
| 96 | \value WindowAutoPlacement (bool) A boolean value indicating whether Windows |
| 97 | (particularly dialogs) are placed by the system |
| 98 | (see _NET_WM_FULL_PLACEMENT in X11). |
| 99 | |
| 100 | \value DialogButtonBoxLayout (int) An integer representing a |
| 101 | QDialogButtonBox::ButtonLayout value. |
| 102 | |
| 103 | \value DialogButtonBoxButtonsHaveIcons (bool) A boolean value indicating whether |
| 104 | the buttons of a QDialogButtonBox should have icons. |
| 105 | |
| 106 | \value UseFullScreenForPopupMenu (bool) Pop menus can cover the full screen including task bar. |
| 107 | |
| 108 | \value KeyboardScheme (int) An integer value (enum KeyboardSchemes) specifying the |
| 109 | keyboard scheme. |
| 110 | |
| 111 | \value UiEffects (int) A flag value consisting of UiEffect values specifying the enabled UI animations. |
| 112 | |
| 113 | \value SpellCheckUnderlineStyle (int) A QTextCharFormat::UnderlineStyle specifying |
| 114 | the underline style used misspelled words when spell checking. |
| 115 | |
| 116 | \value TabFocusBehavior (int) A Qt::TabFocusBehavior specifying |
| 117 | the behavior of focus change when tab key was pressed. |
| 118 | This enum value was added in Qt 5.5. |
| 119 | |
| 120 | \value DialogSnapToDefaultButton (bool) Whether the mouse should snap to the default button when a dialog |
| 121 | becomes visible. |
| 122 | |
| 123 | \value ContextMenuOnMouseRelease (bool) Whether the context menu should be shown on mouse release. |
| 124 | |
| 125 | \value TouchDoubleTapDistance (int) The maximum distance in logical pixels which a touchpoint can travel |
| 126 | between taps in order for the tap sequence to be handled as a double tap. |
| 127 | The default value is double the MouseDoubleClickDistance, or 10 logical pixels |
| 128 | if that is not specified. |
| 129 | |
| 130 | \value ShowShortcutsInContextMenus (bool) Whether to display shortcut key sequences in context menus. |
| 131 | |
| 132 | \value InteractiveResizeAcrossScreens (bool) Whether using the whole virtual geometry of all the screens |
| 133 | as basis for the resize. |
| 134 | This enum value has been added in Qt 6.2. |
| 135 | |
| 136 | \value ShowDirectoriesFirst (bool) Whether directories should be shown |
| 137 | first (before files) in file dialogs. |
| 138 | This enum value was added in Qt 6.3. |
| 139 | |
| 140 | \value PreselectFirstFileInDirectory (bool) Whether the first file in a directory |
| 141 | should be automatically selected when a file dialog opens. |
| 142 | This enum value was added in Qt 6.3. |
| 143 | |
| 144 | \value ButtonPressKeys (QList<Qt::Key>) A list of keys that can be used to press buttons via keyboard input. |
| 145 | |
| 146 | \value SetFocusOnTouchRelease (bool) Whether focus objects (line edits etc) should receive |
| 147 | input focus after a touch/mouse release. |
| 148 | This enum value has been added in Qt 6.5. |
| 149 | |
| 150 | \value MouseCursorTheme (QString) Name of the mouse cursor theme. |
| 151 | This enum value has been added in Qt 6.5. |
| 152 | |
| 153 | \value MouseCursorSize (QSize) Size of the mouse cursor. |
| 154 | This enum value has been added in Qt 6.5. |
| 155 | |
| 156 | \sa themeHint(), QStyle::pixelMetric() |
| 157 | */ |
| 158 | |
| 159 | |
| 160 | #if QT_CONFIG(shortcut) |
| 161 | // Table of key bindings. It must be sorted on key sequence: |
| 162 | // The integer value of VK_KEY | Modifier Keys (e.g., VK_META, and etc.) |
| 163 | // A priority of 1 indicates that this is the primary key binding when multiple are defined. |
| 164 | |
| 165 | enum KeyPlatform { |
| 166 | KB_Win = (1 << QPlatformTheme::WindowsKeyboardScheme), |
| 167 | KB_Mac = (1 << QPlatformTheme::MacKeyboardScheme), |
| 168 | KB_X11 = (1 << QPlatformTheme::X11KeyboardScheme), |
| 169 | KB_KDE = (1 << QPlatformTheme::KdeKeyboardScheme), |
| 170 | KB_Gnome = (1 << QPlatformTheme::GnomeKeyboardScheme), |
| 171 | KB_CDE = (1 << QPlatformTheme::CdeKeyboardScheme), |
| 172 | KB_All = 0xffff |
| 173 | }; |
| 174 | |
| 175 | const QKeyBinding QPlatformThemePrivate::keyBindings[] = { |
| 176 | // StandardKey Priority Key Sequence Platforms |
| 177 | {.standardKey: QKeySequence::HelpContents, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Question, .platform: KB_Mac}, |
| 178 | {.standardKey: QKeySequence::HelpContents, .priority: 0, .shortcut: Qt::Key_F1, .platform: KB_Win | KB_X11}, |
| 179 | {.standardKey: QKeySequence::WhatsThis, .priority: 1, .shortcut: Qt::SHIFT | Qt::Key_F1, .platform: KB_All}, |
| 180 | {.standardKey: QKeySequence::Open, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_O, .platform: KB_All}, |
| 181 | {.standardKey: QKeySequence::Close, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_F4, .platform: KB_Mac}, |
| 182 | {.standardKey: QKeySequence::Close, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_F4, .platform: KB_Win}, |
| 183 | {.standardKey: QKeySequence::Close, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_W, .platform: KB_Mac}, |
| 184 | {.standardKey: QKeySequence::Close, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_W, .platform: KB_Win | KB_X11}, |
| 185 | {.standardKey: QKeySequence::Save, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_S, .platform: KB_All}, |
| 186 | {.standardKey: QKeySequence::New, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_N, .platform: KB_All}, |
| 187 | {.standardKey: QKeySequence::Delete, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_D, .platform: KB_X11}, //emacs (line edit only) |
| 188 | {.standardKey: QKeySequence::Delete, .priority: 1, .shortcut: Qt::Key_Delete, .platform: KB_All}, |
| 189 | {.standardKey: QKeySequence::Delete, .priority: 0, .shortcut: Qt::META | Qt::Key_D, .platform: KB_Mac}, |
| 190 | {.standardKey: QKeySequence::Cut, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_X, .platform: KB_All}, |
| 191 | {.standardKey: QKeySequence::Cut, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Delete, .platform: KB_Win | KB_X11}, //## Check if this should work on mac |
| 192 | {.standardKey: QKeySequence::Cut, .priority: 0, .shortcut: Qt::Key_F20, .platform: KB_X11}, //Cut on sun keyboards |
| 193 | {.standardKey: QKeySequence::Cut, .priority: 0, .shortcut: Qt::META | Qt::Key_K, .platform: KB_Mac}, |
| 194 | {.standardKey: QKeySequence::Copy, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Insert, .platform: KB_X11 | KB_Win}, |
| 195 | {.standardKey: QKeySequence::Copy, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_C, .platform: KB_All}, |
| 196 | {.standardKey: QKeySequence::Copy, .priority: 0, .shortcut: Qt::Key_F16, .platform: KB_X11}, //Copy on sun keyboards |
| 197 | {.standardKey: QKeySequence::Paste, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Insert, .platform: KB_X11}, |
| 198 | {.standardKey: QKeySequence::Paste, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_V, .platform: KB_All}, |
| 199 | {.standardKey: QKeySequence::Paste, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Insert, .platform: KB_Win | KB_X11}, |
| 200 | {.standardKey: QKeySequence::Paste, .priority: 0, .shortcut: Qt::Key_F18, .platform: KB_X11}, //Paste on sun keyboards |
| 201 | {.standardKey: QKeySequence::Paste, .priority: 0, .shortcut: Qt::META | Qt::Key_Y, .platform: KB_Mac}, |
| 202 | {.standardKey: QKeySequence::Undo, .priority: 0, .shortcut: Qt::ALT | Qt::Key_Backspace, .platform: KB_Win}, |
| 203 | {.standardKey: QKeySequence::Undo, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Z, .platform: KB_All}, |
| 204 | {.standardKey: QKeySequence::Undo, .priority: 0, .shortcut: Qt::Key_F14, .platform: KB_X11}, //Undo on sun keyboards |
| 205 | {.standardKey: QKeySequence::Redo, .priority: 0, .shortcut: Qt::ALT | Qt::SHIFT | Qt::Key_Backspace,.platform: KB_Win}, |
| 206 | {.standardKey: QKeySequence::Redo, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Z, .platform: KB_Mac}, |
| 207 | {.standardKey: QKeySequence::Redo, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Z, .platform: KB_Win | KB_X11}, |
| 208 | {.standardKey: QKeySequence::Redo, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Y, .platform: KB_Win}, |
| 209 | {.standardKey: QKeySequence::Back, .priority: 1, .shortcut: Qt::ALT | Qt::Key_Left, .platform: KB_Win | KB_X11}, |
| 210 | {.standardKey: QKeySequence::Back, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Left, .platform: KB_Mac}, |
| 211 | {.standardKey: QKeySequence::Back, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_BracketLeft, .platform: KB_Mac}, |
| 212 | {.standardKey: QKeySequence::Back, .priority: 0, .shortcut: Qt::Key_Backspace, .platform: KB_Win}, |
| 213 | {.standardKey: QKeySequence::Forward, .priority: 1, .shortcut: Qt::ALT | Qt::Key_Right, .platform: KB_Win | KB_X11}, |
| 214 | {.standardKey: QKeySequence::Forward, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Right, .platform: KB_Mac}, |
| 215 | {.standardKey: QKeySequence::Forward, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_BracketRight, .platform: KB_Mac}, |
| 216 | {.standardKey: QKeySequence::Forward, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Backspace, .platform: KB_Win}, |
| 217 | {.standardKey: QKeySequence::Refresh, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_R, .platform: KB_Gnome | KB_Mac}, |
| 218 | {.standardKey: QKeySequence::Refresh, .priority: 0, .shortcut: Qt::Key_F5, .platform: KB_Win | KB_X11}, |
| 219 | {.standardKey: QKeySequence::ZoomIn, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Plus, .platform: KB_All}, |
| 220 | {.standardKey: QKeySequence::ZoomOut, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Minus, .platform: KB_All}, |
| 221 | {.standardKey: QKeySequence::Print, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_P, .platform: KB_All}, |
| 222 | {.standardKey: QKeySequence::AddTab, .priority: 1, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_N, .platform: KB_KDE}, |
| 223 | {.standardKey: QKeySequence::AddTab, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_T, .platform: KB_All}, |
| 224 | {.standardKey: QKeySequence::NextChild, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_F6, .platform: KB_Win}, |
| 225 | {.standardKey: QKeySequence::NextChild, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Tab, .platform: KB_Mac}, //different priority from above |
| 226 | {.standardKey: QKeySequence::NextChild, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Tab, .platform: KB_Win | KB_X11}, |
| 227 | {.standardKey: QKeySequence::NextChild, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_BraceRight, .platform: KB_Mac}, |
| 228 | {.standardKey: QKeySequence::NextChild, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Comma, .platform: KB_KDE}, |
| 229 | {.standardKey: QKeySequence::NextChild, .priority: 0, .shortcut: Qt::Key_Forward, .platform: KB_All}, |
| 230 | {.standardKey: QKeySequence::PreviousChild, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_F6, .platform: KB_Win}, |
| 231 | {.standardKey: QKeySequence::PreviousChild, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, .platform: KB_Mac },//different priority from above |
| 232 | {.standardKey: QKeySequence::PreviousChild, .priority: 1, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, .platform: KB_Win | KB_X11}, |
| 233 | {.standardKey: QKeySequence::PreviousChild, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_BraceLeft, .platform: KB_Mac}, |
| 234 | {.standardKey: QKeySequence::PreviousChild, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Period, .platform: KB_KDE}, |
| 235 | {.standardKey: QKeySequence::PreviousChild, .priority: 0, .shortcut: Qt::Key_Back, .platform: KB_All}, |
| 236 | {.standardKey: QKeySequence::Find, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_F, .platform: KB_All}, |
| 237 | {.standardKey: QKeySequence::FindNext, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_G, .platform: KB_Win}, |
| 238 | {.standardKey: QKeySequence::FindNext, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_G, .platform: KB_Gnome | KB_Mac}, |
| 239 | {.standardKey: QKeySequence::FindNext, .priority: 1, .shortcut: Qt::Key_F3, .platform: KB_Win}, |
| 240 | {.standardKey: QKeySequence::FindNext, .priority: 0, .shortcut: Qt::Key_F3, .platform: KB_X11}, |
| 241 | {.standardKey: QKeySequence::FindPrevious, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_G, .platform: KB_Win}, |
| 242 | {.standardKey: QKeySequence::FindPrevious, .priority: 1, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_G, .platform: KB_Gnome | KB_Mac}, |
| 243 | {.standardKey: QKeySequence::FindPrevious, .priority: 1, .shortcut: Qt::SHIFT | Qt::Key_F3, .platform: KB_Win}, |
| 244 | {.standardKey: QKeySequence::FindPrevious, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_F3, .platform: KB_X11}, |
| 245 | {.standardKey: QKeySequence::Replace, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_R, .platform: KB_KDE}, |
| 246 | {.standardKey: QKeySequence::Replace, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_H, .platform: KB_Gnome}, |
| 247 | {.standardKey: QKeySequence::Replace, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_H, .platform: KB_Win}, |
| 248 | {.standardKey: QKeySequence::SelectAll, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_A, .platform: KB_All}, |
| 249 | {.standardKey: QKeySequence::Bold, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_B, .platform: KB_All}, |
| 250 | {.standardKey: QKeySequence::Italic, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_I, .platform: KB_All}, |
| 251 | {.standardKey: QKeySequence::Underline, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_U, .platform: KB_All}, |
| 252 | {.standardKey: QKeySequence::MoveToNextChar, .priority: 1, .shortcut: Qt::Key_Right, .platform: KB_All}, |
| 253 | {.standardKey: QKeySequence::MoveToNextChar, .priority: 0, .shortcut: Qt::META | Qt::Key_F, .platform: KB_Mac}, |
| 254 | {.standardKey: QKeySequence::MoveToPreviousChar, .priority: 1, .shortcut: Qt::Key_Left, .platform: KB_All}, |
| 255 | {.standardKey: QKeySequence::MoveToPreviousChar, .priority: 0, .shortcut: Qt::META | Qt::Key_B, .platform: KB_Mac}, |
| 256 | {.standardKey: QKeySequence::MoveToNextWord, .priority: 0, .shortcut: Qt::ALT | Qt::Key_Right, .platform: KB_Mac}, |
| 257 | {.standardKey: QKeySequence::MoveToNextWord, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Right, .platform: KB_Win | KB_X11}, |
| 258 | {.standardKey: QKeySequence::MoveToPreviousWord, .priority: 0, .shortcut: Qt::ALT | Qt::Key_Left, .platform: KB_Mac}, |
| 259 | {.standardKey: QKeySequence::MoveToPreviousWord, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Left, .platform: KB_Win | KB_X11}, |
| 260 | {.standardKey: QKeySequence::MoveToNextLine, .priority: 1, .shortcut: Qt::Key_Down, .platform: KB_All}, |
| 261 | {.standardKey: QKeySequence::MoveToNextLine, .priority: 0, .shortcut: Qt::META | Qt::Key_N, .platform: KB_Mac}, |
| 262 | {.standardKey: QKeySequence::MoveToPreviousLine, .priority: 1, .shortcut: Qt::Key_Up, .platform: KB_All}, |
| 263 | {.standardKey: QKeySequence::MoveToPreviousLine, .priority: 0, .shortcut: Qt::META | Qt::Key_P, .platform: KB_Mac}, |
| 264 | {.standardKey: QKeySequence::MoveToNextPage, .priority: 0, .shortcut: Qt::META | Qt::Key_PageDown, .platform: KB_Mac}, |
| 265 | {.standardKey: QKeySequence::MoveToNextPage, .priority: 0, .shortcut: Qt::META | Qt::Key_Down, .platform: KB_Mac}, |
| 266 | {.standardKey: QKeySequence::MoveToNextPage, .priority: 0, .shortcut: Qt::META | Qt::Key_V, .platform: KB_Mac}, |
| 267 | {.standardKey: QKeySequence::MoveToNextPage, .priority: 0, .shortcut: Qt::ALT | Qt::Key_PageDown, .platform: KB_Mac }, |
| 268 | {.standardKey: QKeySequence::MoveToNextPage, .priority: 1, .shortcut: Qt::Key_PageDown, .platform: KB_All}, |
| 269 | {.standardKey: QKeySequence::MoveToPreviousPage, .priority: 0, .shortcut: Qt::META | Qt::Key_PageUp, .platform: KB_Mac}, |
| 270 | {.standardKey: QKeySequence::MoveToPreviousPage, .priority: 0, .shortcut: Qt::META | Qt::Key_Up, .platform: KB_Mac}, |
| 271 | {.standardKey: QKeySequence::MoveToPreviousPage, .priority: 0, .shortcut: Qt::ALT | Qt::Key_PageUp, .platform: KB_Mac }, |
| 272 | {.standardKey: QKeySequence::MoveToPreviousPage, .priority: 1, .shortcut: Qt::Key_PageUp, .platform: KB_All}, |
| 273 | {.standardKey: QKeySequence::MoveToStartOfLine, .priority: 0, .shortcut: Qt::META | Qt::Key_Left, .platform: KB_Mac}, |
| 274 | {.standardKey: QKeySequence::MoveToStartOfLine, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Left, .platform: KB_Mac }, |
| 275 | {.standardKey: QKeySequence::MoveToStartOfLine, .priority: 0, .shortcut: Qt::Key_Home, .platform: KB_Win | KB_X11}, |
| 276 | {.standardKey: QKeySequence::MoveToEndOfLine, .priority: 0, .shortcut: Qt::META | Qt::Key_Right, .platform: KB_Mac}, |
| 277 | {.standardKey: QKeySequence::MoveToEndOfLine, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Right, .platform: KB_Mac }, |
| 278 | {.standardKey: QKeySequence::MoveToEndOfLine, .priority: 0, .shortcut: Qt::Key_End, .platform: KB_Win | KB_X11}, |
| 279 | {.standardKey: QKeySequence::MoveToEndOfLine, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_E, .platform: KB_X11}, |
| 280 | {.standardKey: QKeySequence::MoveToStartOfBlock, .priority: 0, .shortcut: Qt::META | Qt::Key_A, .platform: KB_Mac}, |
| 281 | {.standardKey: QKeySequence::MoveToStartOfBlock, .priority: 1, .shortcut: Qt::ALT | Qt::Key_Up, .platform: KB_Mac}, //mac only |
| 282 | {.standardKey: QKeySequence::MoveToEndOfBlock, .priority: 0, .shortcut: Qt::META | Qt::Key_E, .platform: KB_Mac}, |
| 283 | {.standardKey: QKeySequence::MoveToEndOfBlock, .priority: 1, .shortcut: Qt::ALT | Qt::Key_Down, .platform: KB_Mac}, //mac only |
| 284 | {.standardKey: QKeySequence::MoveToStartOfDocument, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Up, .platform: KB_Mac}, |
| 285 | {.standardKey: QKeySequence::MoveToStartOfDocument, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Home, .platform: KB_Win | KB_X11}, |
| 286 | {.standardKey: QKeySequence::MoveToStartOfDocument, .priority: 0, .shortcut: Qt::Key_Home, .platform: KB_Mac}, |
| 287 | {.standardKey: QKeySequence::MoveToEndOfDocument, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_Down, .platform: KB_Mac}, |
| 288 | {.standardKey: QKeySequence::MoveToEndOfDocument, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_End, .platform: KB_Win | KB_X11}, |
| 289 | {.standardKey: QKeySequence::MoveToEndOfDocument, .priority: 0, .shortcut: Qt::Key_End, .platform: KB_Mac}, |
| 290 | {.standardKey: QKeySequence::SelectNextChar, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Right, .platform: KB_All}, |
| 291 | {.standardKey: QKeySequence::SelectPreviousChar, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Left, .platform: KB_All}, |
| 292 | {.standardKey: QKeySequence::SelectNextWord, .priority: 0, .shortcut: Qt::ALT | Qt::SHIFT | Qt::Key_Right, .platform: KB_Mac}, |
| 293 | {.standardKey: QKeySequence::SelectNextWord, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Right, .platform: KB_Win | KB_X11}, |
| 294 | {.standardKey: QKeySequence::SelectPreviousWord, .priority: 0, .shortcut: Qt::ALT | Qt::SHIFT | Qt::Key_Left, .platform: KB_Mac}, |
| 295 | {.standardKey: QKeySequence::SelectPreviousWord, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Left, .platform: KB_Win | KB_X11}, |
| 296 | {.standardKey: QKeySequence::SelectNextLine, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Down, .platform: KB_All}, |
| 297 | {.standardKey: QKeySequence::SelectPreviousLine, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Up, .platform: KB_All}, |
| 298 | {.standardKey: QKeySequence::SelectNextPage, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_PageDown, .platform: KB_All}, |
| 299 | {.standardKey: QKeySequence::SelectPreviousPage, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_PageUp, .platform: KB_All}, |
| 300 | {.standardKey: QKeySequence::SelectStartOfLine, .priority: 0, .shortcut: Qt::META | Qt::SHIFT | Qt::Key_Left, .platform: KB_Mac}, |
| 301 | {.standardKey: QKeySequence::SelectStartOfLine, .priority: 1, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Left, .platform: KB_Mac }, |
| 302 | {.standardKey: QKeySequence::SelectStartOfLine, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Home, .platform: KB_Win | KB_X11}, |
| 303 | {.standardKey: QKeySequence::SelectEndOfLine, .priority: 0, .shortcut: Qt::META | Qt::SHIFT | Qt::Key_Right, .platform: KB_Mac}, |
| 304 | {.standardKey: QKeySequence::SelectEndOfLine, .priority: 1, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Right, .platform: KB_Mac }, |
| 305 | {.standardKey: QKeySequence::SelectEndOfLine, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_End, .platform: KB_Win | KB_X11}, |
| 306 | {.standardKey: QKeySequence::SelectStartOfBlock, .priority: 1, .shortcut: Qt::ALT | Qt::SHIFT | Qt::Key_Up, .platform: KB_Mac}, //mac only |
| 307 | {.standardKey: QKeySequence::SelectStartOfBlock, .priority: 0, .shortcut: Qt::META | Qt::SHIFT | Qt::Key_A, .platform: KB_Mac}, |
| 308 | {.standardKey: QKeySequence::SelectEndOfBlock, .priority: 1, .shortcut: Qt::ALT | Qt::SHIFT | Qt::Key_Down, .platform: KB_Mac}, //mac only |
| 309 | {.standardKey: QKeySequence::SelectEndOfBlock, .priority: 0, .shortcut: Qt::META | Qt::SHIFT | Qt::Key_E, .platform: KB_Mac}, |
| 310 | {.standardKey: QKeySequence::SelectStartOfDocument, .priority: 1, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Up, .platform: KB_Mac}, |
| 311 | {.standardKey: QKeySequence::SelectStartOfDocument, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Home, .platform: KB_Win | KB_X11}, |
| 312 | {.standardKey: QKeySequence::SelectStartOfDocument, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Home, .platform: KB_Mac}, |
| 313 | {.standardKey: QKeySequence::SelectEndOfDocument, .priority: 1, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_Down, .platform: KB_Mac}, |
| 314 | {.standardKey: QKeySequence::SelectEndOfDocument, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_End, .platform: KB_Win | KB_X11}, |
| 315 | {.standardKey: QKeySequence::SelectEndOfDocument, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_End, .platform: KB_Mac}, |
| 316 | {.standardKey: QKeySequence::DeleteStartOfWord, .priority: 0, .shortcut: Qt::ALT | Qt::Key_Backspace, .platform: KB_Mac}, |
| 317 | {.standardKey: QKeySequence::DeleteStartOfWord, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Backspace, .platform: KB_X11 | KB_Win}, |
| 318 | {.standardKey: QKeySequence::DeleteEndOfWord, .priority: 0, .shortcut: Qt::ALT | Qt::Key_Delete, .platform: KB_Mac}, |
| 319 | {.standardKey: QKeySequence::DeleteEndOfWord, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Delete, .platform: KB_X11 | KB_Win}, |
| 320 | {.standardKey: QKeySequence::DeleteEndOfLine, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_K, .platform: KB_X11}, //emacs (line edit only) |
| 321 | {.standardKey: QKeySequence::InsertParagraphSeparator,.priority: 0, .shortcut: Qt::Key_Enter, .platform: KB_All}, |
| 322 | {.standardKey: QKeySequence::InsertParagraphSeparator,.priority: 0, .shortcut: Qt::Key_Return, .platform: KB_All}, |
| 323 | {.standardKey: QKeySequence::InsertLineSeparator, .priority: 0, .shortcut: Qt::META | Qt::Key_Enter, .platform: KB_Mac}, |
| 324 | {.standardKey: QKeySequence::InsertLineSeparator, .priority: 0, .shortcut: Qt::META | Qt::Key_Return, .platform: KB_Mac}, |
| 325 | {.standardKey: QKeySequence::InsertLineSeparator, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Enter, .platform: KB_All}, |
| 326 | {.standardKey: QKeySequence::InsertLineSeparator, .priority: 0, .shortcut: Qt::SHIFT | Qt::Key_Return, .platform: KB_All}, |
| 327 | {.standardKey: QKeySequence::InsertLineSeparator, .priority: 0, .shortcut: Qt::META | Qt::Key_O, .platform: KB_Mac}, |
| 328 | {.standardKey: QKeySequence::SaveAs, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_S, .platform: KB_All}, |
| 329 | {.standardKey: QKeySequence::Preferences, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Comma, .platform: KB_Mac}, |
| 330 | {.standardKey: QKeySequence::Quit, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Q, .platform: KB_X11 | KB_Gnome | KB_KDE | KB_Mac}, |
| 331 | {.standardKey: QKeySequence::FullScreen, .priority: 1, .shortcut: Qt::META | Qt::CTRL | Qt::Key_F, .platform: KB_Mac}, |
| 332 | {.standardKey: QKeySequence::FullScreen, .priority: 0, .shortcut: Qt::ALT | Qt::Key_Enter, .platform: KB_Win}, |
| 333 | {.standardKey: QKeySequence::FullScreen, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_F, .platform: KB_KDE}, |
| 334 | {.standardKey: QKeySequence::FullScreen, .priority: 1, .shortcut: Qt::CTRL | Qt::Key_F11, .platform: KB_Gnome}, |
| 335 | {.standardKey: QKeySequence::FullScreen, .priority: 1, .shortcut: Qt::Key_F11, .platform: KB_Win | KB_KDE}, |
| 336 | {.standardKey: QKeySequence::Deselect, .priority: 0, .shortcut: Qt::CTRL | Qt::SHIFT | Qt::Key_A, .platform: KB_X11}, |
| 337 | {.standardKey: QKeySequence::DeleteCompleteLine, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_U, .platform: KB_X11}, |
| 338 | {.standardKey: QKeySequence::Backspace, .priority: 1, .shortcut: Qt::Key_Backspace, .platform: KB_Mac}, |
| 339 | {.standardKey: QKeySequence::Backspace, .priority: 0, .shortcut: Qt::META | Qt::Key_H, .platform: KB_Mac}, |
| 340 | {.standardKey: QKeySequence::Cancel, .priority: 0, .shortcut: Qt::Key_Escape, .platform: KB_All}, |
| 341 | {.standardKey: QKeySequence::Cancel, .priority: 0, .shortcut: Qt::CTRL | Qt::Key_Period, .platform: KB_Mac} |
| 342 | }; |
| 343 | |
| 344 | const uint QPlatformThemePrivate::numberOfKeyBindings = sizeof(QPlatformThemePrivate::keyBindings)/(sizeof(QKeyBinding)); |
| 345 | #endif |
| 346 | |
| 347 | QPlatformThemePrivate::QPlatformThemePrivate() |
| 348 | : systemPalette(nullptr) |
| 349 | { } |
| 350 | |
| 351 | QPlatformThemePrivate::~QPlatformThemePrivate() |
| 352 | { |
| 353 | delete systemPalette; |
| 354 | } |
| 355 | |
| 356 | Q_GUI_EXPORT QPalette qt_fusionPalette() |
| 357 | { |
| 358 | auto theme = QGuiApplicationPrivate::platformTheme(); |
| 359 | const bool darkAppearance = theme |
| 360 | ? theme->colorScheme() == Qt::ColorScheme::Dark |
| 361 | : false; |
| 362 | const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black; |
| 363 | const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239); |
| 364 | const QColor light = backGround.lighter(f: 150); |
| 365 | const QColor mid = (backGround.darker(f: 130)); |
| 366 | const QColor midLight = mid.lighter(f: 110); |
| 367 | const QColor base = darkAppearance ? backGround.darker(f: 140) : Qt::white; |
| 368 | const QColor disabledBase(backGround); |
| 369 | const QColor dark = backGround.darker(f: 150); |
| 370 | const QColor darkDisabled = QColor(209, 209, 209).darker(f: 110); |
| 371 | const QColor text = darkAppearance ? windowText : Qt::black; |
| 372 | const QColor highlight = QColor(48, 140, 198); |
| 373 | const QColor hightlightedText = darkAppearance ? windowText : Qt::white; |
| 374 | const QColor disabledText = darkAppearance ? QColor(130, 130, 130) : QColor(190, 190, 190); |
| 375 | const QColor button = backGround; |
| 376 | const QColor shadow = dark.darker(f: 135); |
| 377 | const QColor disabledShadow = shadow.lighter(f: 150); |
| 378 | const QColor disabledHighlight(145, 145, 145); |
| 379 | QColor placeholder = text; |
| 380 | placeholder.setAlpha(128); |
| 381 | |
| 382 | QPalette fusionPalette(windowText, backGround, light, dark, mid, text, base); |
| 383 | fusionPalette.setBrush(acr: QPalette::Midlight, abrush: midLight); |
| 384 | fusionPalette.setBrush(acr: QPalette::Button, abrush: button); |
| 385 | fusionPalette.setBrush(acr: QPalette::Shadow, abrush: shadow); |
| 386 | fusionPalette.setBrush(acr: QPalette::HighlightedText, abrush: hightlightedText); |
| 387 | |
| 388 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::Text, brush: disabledText); |
| 389 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::WindowText, brush: disabledText); |
| 390 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::ButtonText, brush: disabledText); |
| 391 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::Base, brush: disabledBase); |
| 392 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::Dark, brush: darkDisabled); |
| 393 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::Shadow, brush: disabledShadow); |
| 394 | |
| 395 | fusionPalette.setBrush(cg: QPalette::Active, cr: QPalette::Highlight, brush: highlight); |
| 396 | fusionPalette.setBrush(cg: QPalette::Inactive, cr: QPalette::Highlight, brush: highlight); |
| 397 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::Highlight, brush: disabledHighlight); |
| 398 | |
| 399 | fusionPalette.setBrush(cg: QPalette::Active, cr: QPalette::Accent, brush: highlight); |
| 400 | fusionPalette.setBrush(cg: QPalette::Inactive, cr: QPalette::Accent, brush: highlight); |
| 401 | fusionPalette.setBrush(cg: QPalette::Disabled, cr: QPalette::Accent, brush: disabledHighlight); |
| 402 | |
| 403 | fusionPalette.setBrush(acr: QPalette::PlaceholderText, abrush: placeholder); |
| 404 | |
| 405 | // Use a more legible light blue on dark backgrounds than the default Qt::blue. |
| 406 | if (darkAppearance) |
| 407 | fusionPalette.setBrush(acr: QPalette::Link, abrush: highlight); |
| 408 | |
| 409 | return fusionPalette; |
| 410 | } |
| 411 | |
| 412 | void QPlatformThemePrivate::initializeSystemPalette() |
| 413 | { |
| 414 | Q_ASSERT(!systemPalette); |
| 415 | systemPalette = new QPalette(qt_fusionPalette()); |
| 416 | } |
| 417 | |
| 418 | QPlatformTheme::QPlatformTheme() |
| 419 | : d_ptr(new QPlatformThemePrivate) |
| 420 | { |
| 421 | |
| 422 | } |
| 423 | |
| 424 | QPlatformTheme::QPlatformTheme(QPlatformThemePrivate *priv) |
| 425 | : d_ptr(priv) |
| 426 | { } |
| 427 | |
| 428 | QPlatformTheme::~QPlatformTheme() |
| 429 | { |
| 430 | |
| 431 | } |
| 432 | |
| 433 | bool QPlatformTheme::usePlatformNativeDialog(DialogType type) const |
| 434 | { |
| 435 | Q_UNUSED(type); |
| 436 | return false; |
| 437 | } |
| 438 | |
| 439 | QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType type) const |
| 440 | { |
| 441 | Q_UNUSED(type); |
| 442 | return nullptr; |
| 443 | } |
| 444 | |
| 445 | Qt::ColorScheme QPlatformTheme::colorScheme() const |
| 446 | { |
| 447 | return Qt::ColorScheme::Unknown; |
| 448 | } |
| 449 | |
| 450 | void QPlatformTheme::requestColorScheme(Qt::ColorScheme scheme) |
| 451 | { |
| 452 | Q_UNUSED(scheme); |
| 453 | } |
| 454 | |
| 455 | const QPalette *QPlatformTheme::palette(Palette type) const |
| 456 | { |
| 457 | Q_D(const QPlatformTheme); |
| 458 | if (type == QPlatformTheme::SystemPalette) { |
| 459 | if (!d->systemPalette) |
| 460 | const_cast<QPlatformTheme *>(this)->d_ptr->initializeSystemPalette(); |
| 461 | return d->systemPalette; |
| 462 | } |
| 463 | return nullptr; |
| 464 | } |
| 465 | |
| 466 | const QFont *QPlatformTheme::font(Font type) const |
| 467 | { |
| 468 | Q_UNUSED(type); |
| 469 | return nullptr; |
| 470 | } |
| 471 | |
| 472 | QPixmap QPlatformTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) const |
| 473 | { |
| 474 | Q_UNUSED(sp); |
| 475 | Q_UNUSED(size); |
| 476 | // TODO Should return QCommonStyle pixmaps? |
| 477 | return QPixmap(); |
| 478 | } |
| 479 | |
| 480 | /*! |
| 481 | \brief Return an icon for \a fileInfo, observing \a iconOptions. |
| 482 | |
| 483 | This function is queried by QFileIconProvider and similar classes to obtain |
| 484 | an icon for a file. If it does not return a non-null icon, fileIconPixmap() |
| 485 | is queried for a specific size. |
| 486 | |
| 487 | \since 5.8 |
| 488 | */ |
| 489 | |
| 490 | QIcon QPlatformTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const |
| 491 | { |
| 492 | Q_UNUSED(fileInfo); |
| 493 | Q_UNUSED(iconOptions); |
| 494 | // TODO Should return QCommonStyle pixmaps? |
| 495 | return QIcon(); |
| 496 | } |
| 497 | |
| 498 | QVariant QPlatformTheme::themeHint(ThemeHint hint) const |
| 499 | { |
| 500 | // For theme hints which mirror platform integration style hints, query |
| 501 | // the platform integration. The base QPlatformIntegration::styleHint() |
| 502 | // function will in turn query QPlatformTheme::defaultThemeHint() if there |
| 503 | // is no custom value. |
| 504 | switch (hint) { |
| 505 | case QPlatformTheme::CursorFlashTime: |
| 506 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::CursorFlashTime); |
| 507 | case QPlatformTheme::KeyboardInputInterval: |
| 508 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::KeyboardInputInterval); |
| 509 | case QPlatformTheme::KeyboardAutoRepeatRate: |
| 510 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::KeyboardAutoRepeatRate); |
| 511 | case QPlatformTheme::MouseDoubleClickInterval: |
| 512 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::MouseDoubleClickInterval); |
| 513 | case QPlatformTheme::StartDragDistance: |
| 514 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::StartDragDistance); |
| 515 | case QPlatformTheme::StartDragTime: |
| 516 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::StartDragTime); |
| 517 | case QPlatformTheme::StartDragVelocity: |
| 518 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::StartDragVelocity); |
| 519 | case QPlatformTheme::PasswordMaskDelay: |
| 520 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::PasswordMaskDelay); |
| 521 | case QPlatformTheme::PasswordMaskCharacter: |
| 522 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::PasswordMaskCharacter); |
| 523 | case QPlatformTheme::MousePressAndHoldInterval: |
| 524 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::MousePressAndHoldInterval); |
| 525 | case QPlatformTheme::ItemViewActivateItemOnSingleClick: |
| 526 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::ItemViewActivateItemOnSingleClick); |
| 527 | case QPlatformTheme::UiEffects: |
| 528 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::UiEffects); |
| 529 | case QPlatformTheme::ShowShortcutsInContextMenus: |
| 530 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::ShowShortcutsInContextMenus); |
| 531 | case QPlatformTheme::SetFocusOnTouchRelease: |
| 532 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::SetFocusOnTouchRelease); |
| 533 | case QPlatformTheme::FlickStartDistance: |
| 534 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::FlickStartDistance); |
| 535 | case QPlatformTheme::FlickMaximumVelocity: |
| 536 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::FlickMaximumVelocity); |
| 537 | case QPlatformTheme::FlickDeceleration: |
| 538 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::FlickDeceleration); |
| 539 | case QPlatformTheme::UnderlineShortcut: |
| 540 | return QGuiApplicationPrivate::platformIntegration()->styleHint(hint: QPlatformIntegration::UnderlineShortcut); |
| 541 | default: |
| 542 | return QPlatformTheme::defaultThemeHint(hint); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) |
| 547 | { |
| 548 | switch (hint) { |
| 549 | case QPlatformTheme::CursorFlashTime: |
| 550 | return QVariant(1000); |
| 551 | case QPlatformTheme::KeyboardInputInterval: |
| 552 | return QVariant(400); |
| 553 | case QPlatformTheme::KeyboardAutoRepeatRate: |
| 554 | return QVariant(30); |
| 555 | case QPlatformTheme::MouseDoubleClickInterval: |
| 556 | return QVariant(400); |
| 557 | case QPlatformTheme::StartDragDistance: |
| 558 | return QVariant(10); |
| 559 | case QPlatformTheme::StartDragTime: |
| 560 | return QVariant(500); |
| 561 | case QPlatformTheme::PasswordMaskDelay: |
| 562 | return QVariant(int(0)); |
| 563 | case QPlatformTheme::PasswordMaskCharacter: |
| 564 | return QVariant(QChar(u'\x25CF')); |
| 565 | case QPlatformTheme::StartDragVelocity: |
| 566 | return QVariant(int(0)); // no limit |
| 567 | case QPlatformTheme::UseFullScreenForPopupMenu: |
| 568 | return QVariant(false); |
| 569 | case QPlatformTheme::WindowAutoPlacement: |
| 570 | return QVariant(false); |
| 571 | case QPlatformTheme::DialogButtonBoxLayout: |
| 572 | return QVariant(int(0)); |
| 573 | case QPlatformTheme::DialogButtonBoxButtonsHaveIcons: |
| 574 | return QVariant(false); |
| 575 | case QPlatformTheme::ItemViewActivateItemOnSingleClick: |
| 576 | return QVariant(false); |
| 577 | case QPlatformTheme::ToolButtonStyle: |
| 578 | return QVariant(int(Qt::ToolButtonIconOnly)); |
| 579 | case QPlatformTheme::ToolBarIconSize: |
| 580 | return QVariant(int(0)); |
| 581 | case QPlatformTheme::SystemIconThemeName: |
| 582 | case QPlatformTheme::SystemIconFallbackThemeName: |
| 583 | return QVariant(QString()); |
| 584 | case QPlatformTheme::IconThemeSearchPaths: |
| 585 | return QVariant(QStringList()); |
| 586 | case QPlatformTheme::IconFallbackSearchPaths: |
| 587 | return QVariant(QStringList()); |
| 588 | case QPlatformTheme::StyleNames: |
| 589 | return QVariant(QStringList()); |
| 590 | case QPlatformTheme::ShowShortcutsInContextMenus: |
| 591 | return QVariant(true); |
| 592 | case TextCursorWidth: |
| 593 | return QVariant(1); |
| 594 | case DropShadow: |
| 595 | return QVariant(false); |
| 596 | case MaximumScrollBarDragDistance: |
| 597 | return QVariant(-1); |
| 598 | case KeyboardScheme: |
| 599 | return QVariant(int(WindowsKeyboardScheme)); |
| 600 | case UiEffects: |
| 601 | return QVariant(int(0)); |
| 602 | case SpellCheckUnderlineStyle: |
| 603 | return QVariant(int(QTextCharFormat::WaveUnderline)); |
| 604 | case TabFocusBehavior: |
| 605 | return QVariant(int(Qt::TabFocusAllControls)); |
| 606 | case IconPixmapSizes: |
| 607 | return QVariant::fromValue(value: QList<int>()); |
| 608 | case DialogSnapToDefaultButton: |
| 609 | case ContextMenuOnMouseRelease: |
| 610 | return QVariant(false); |
| 611 | case MousePressAndHoldInterval: |
| 612 | return QVariant(800); |
| 613 | case MouseDoubleClickDistance: |
| 614 | { |
| 615 | bool ok = false; |
| 616 | const int dist = qEnvironmentVariableIntValue(varName: "QT_DBL_CLICK_DIST" , ok: &ok); |
| 617 | return QVariant(ok ? dist : 5); |
| 618 | } |
| 619 | case WheelScrollLines: |
| 620 | return QVariant(3); |
| 621 | case TouchDoubleTapDistance: |
| 622 | { |
| 623 | bool ok = false; |
| 624 | int dist = qEnvironmentVariableIntValue(varName: "QT_DBL_TAP_DIST" , ok: &ok); |
| 625 | if (!ok) |
| 626 | dist = defaultThemeHint(hint: MouseDoubleClickDistance).toInt(ok: &ok) * 2; |
| 627 | return QVariant(ok ? dist : 10); |
| 628 | } |
| 629 | case MouseQuickSelectionThreshold: |
| 630 | return QVariant(10); |
| 631 | case InteractiveResizeAcrossScreens: |
| 632 | return true; |
| 633 | case ShowDirectoriesFirst: |
| 634 | return true; |
| 635 | case PreselectFirstFileInDirectory: |
| 636 | return false; |
| 637 | case ButtonPressKeys: |
| 638 | return QVariant::fromValue(value: QList<Qt::Key>({ Qt::Key_Space, Qt::Key_Select })); |
| 639 | case SetFocusOnTouchRelease: |
| 640 | return false; |
| 641 | case FlickStartDistance: |
| 642 | return QVariant(15); |
| 643 | case FlickMaximumVelocity: |
| 644 | return QVariant(2500); |
| 645 | case FlickDeceleration: |
| 646 | return QVariant(1500); |
| 647 | case MenuBarFocusOnAltPressRelease: |
| 648 | return false; |
| 649 | case MouseCursorTheme: |
| 650 | return QVariant(QString()); |
| 651 | case MouseCursorSize: |
| 652 | return QVariant(QSize(16, 16)); |
| 653 | case UnderlineShortcut: |
| 654 | return true; |
| 655 | case ShowIconsInMenus: |
| 656 | return true; |
| 657 | case PreferFileIconFromTheme: |
| 658 | return false; |
| 659 | } |
| 660 | |
| 661 | return QVariant(); |
| 662 | } |
| 663 | |
| 664 | QPlatformMenuItem *QPlatformTheme::() const |
| 665 | { |
| 666 | return nullptr; |
| 667 | } |
| 668 | |
| 669 | QPlatformMenu *QPlatformTheme::() const |
| 670 | { |
| 671 | return nullptr; |
| 672 | } |
| 673 | |
| 674 | QPlatformMenuBar *QPlatformTheme::() const |
| 675 | { |
| 676 | return nullptr; |
| 677 | } |
| 678 | |
| 679 | #ifndef QT_NO_SYSTEMTRAYICON |
| 680 | /*! |
| 681 | Factory function for QSystemTrayIcon. This function will return 0 if the platform |
| 682 | integration does not support creating any system tray icon. |
| 683 | */ |
| 684 | QPlatformSystemTrayIcon *QPlatformTheme::createPlatformSystemTrayIcon() const |
| 685 | { |
| 686 | return nullptr; |
| 687 | } |
| 688 | #endif |
| 689 | |
| 690 | /*! |
| 691 | Factory function for the QIconEngine used by QIcon::fromTheme(). By default this |
| 692 | function returns a QIconLoaderEngine, but subclasses can reimplement it to |
| 693 | provide their own. |
| 694 | |
| 695 | It is especially useful to benefit from some platform specific facilities or |
| 696 | optimizations like an inter-process cache in systems mostly built with Qt. |
| 697 | |
| 698 | \since 5.1 |
| 699 | */ |
| 700 | QIconEngine *QPlatformTheme::createIconEngine(const QString &iconName) const |
| 701 | { |
| 702 | return new QIconLoaderEngine(iconName); |
| 703 | } |
| 704 | |
| 705 | #if QT_CONFIG(shortcut) |
| 706 | // mixed-mode predicate: all of these overloads are actually needed (but not all for every compiler) |
| 707 | struct ByStandardKey { |
| 708 | typedef bool result_type; |
| 709 | |
| 710 | bool operator()(QKeySequence::StandardKey lhs, QKeySequence::StandardKey rhs) const |
| 711 | { return lhs < rhs; } |
| 712 | |
| 713 | bool operator()(const QKeyBinding& lhs, const QKeyBinding& rhs) const |
| 714 | { return operator()(lhs: lhs.standardKey, rhs: rhs.standardKey); } |
| 715 | |
| 716 | bool operator()(QKeySequence::StandardKey lhs, const QKeyBinding& rhs) const |
| 717 | { return operator()(lhs, rhs: rhs.standardKey); } |
| 718 | |
| 719 | bool operator()(const QKeyBinding& lhs, QKeySequence::StandardKey rhs) const |
| 720 | { return operator()(lhs: lhs.standardKey, rhs); } |
| 721 | }; |
| 722 | |
| 723 | /*! |
| 724 | Returns the key sequence that should be used for a standard action. |
| 725 | |
| 726 | \since 5.2 |
| 727 | */ |
| 728 | QList<QKeySequence> QPlatformTheme::keyBindings(QKeySequence::StandardKey key) const |
| 729 | { |
| 730 | const uint platform = QPlatformThemePrivate::currentKeyPlatforms(); |
| 731 | QList <QKeySequence> list; |
| 732 | |
| 733 | std::pair<const QKeyBinding *, const QKeyBinding *> range = |
| 734 | std::equal_range(first: QPlatformThemePrivate::keyBindings, |
| 735 | last: QPlatformThemePrivate::keyBindings + QPlatformThemePrivate::numberOfKeyBindings, |
| 736 | val: key, comp: ByStandardKey()); |
| 737 | |
| 738 | for (const QKeyBinding *it = range.first; it < range.second; ++it) { |
| 739 | if (!(it->platform & platform)) |
| 740 | continue; |
| 741 | |
| 742 | uint shortcut = it->shortcut.toCombined(); |
| 743 | |
| 744 | if (it->priority > 0) |
| 745 | list.prepend(t: QKeySequence(shortcut)); |
| 746 | else |
| 747 | list.append(t: QKeySequence(shortcut)); |
| 748 | } |
| 749 | |
| 750 | return list; |
| 751 | } |
| 752 | #endif |
| 753 | |
| 754 | /*! |
| 755 | Returns the text of a standard \a button. |
| 756 | |
| 757 | \since 5.3 |
| 758 | \sa QPlatformDialogHelper::StandardButton |
| 759 | */ |
| 760 | |
| 761 | QString QPlatformTheme::standardButtonText(int button) const |
| 762 | { |
| 763 | return QPlatformTheme::defaultStandardButtonText(button); |
| 764 | } |
| 765 | |
| 766 | #if QT_CONFIG(shortcut) |
| 767 | /*! |
| 768 | Returns the mnemonic that should be used for a standard \a button. |
| 769 | |
| 770 | \since 5.9 |
| 771 | \sa QPlatformDialogHelper::StandardButton |
| 772 | */ |
| 773 | |
| 774 | QKeySequence QPlatformTheme::standardButtonShortcut(int button) const |
| 775 | { |
| 776 | Q_UNUSED(button); |
| 777 | return QKeySequence(); |
| 778 | } |
| 779 | #endif // QT_CONFIG(shortcut) |
| 780 | |
| 781 | QString QPlatformTheme::defaultStandardButtonText(int button) |
| 782 | { |
| 783 | switch (button) { |
| 784 | case QPlatformDialogHelper::Ok: |
| 785 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "OK" ); |
| 786 | case QPlatformDialogHelper::Save: |
| 787 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Save" ); |
| 788 | case QPlatformDialogHelper::SaveAll: |
| 789 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Save All" ); |
| 790 | case QPlatformDialogHelper::Open: |
| 791 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Open" ); |
| 792 | case QPlatformDialogHelper::Yes: |
| 793 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "&Yes" ); |
| 794 | case QPlatformDialogHelper::YesToAll: |
| 795 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Yes to &All" ); |
| 796 | case QPlatformDialogHelper::No: |
| 797 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "&No" ); |
| 798 | case QPlatformDialogHelper::NoToAll: |
| 799 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "N&o to All" ); |
| 800 | case QPlatformDialogHelper::Abort: |
| 801 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Abort" ); |
| 802 | case QPlatformDialogHelper::Retry: |
| 803 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Retry" ); |
| 804 | case QPlatformDialogHelper::Ignore: |
| 805 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Ignore" ); |
| 806 | case QPlatformDialogHelper::Close: |
| 807 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Close" ); |
| 808 | case QPlatformDialogHelper::Cancel: |
| 809 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Cancel" ); |
| 810 | case QPlatformDialogHelper::Discard: |
| 811 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Discard" ); |
| 812 | case QPlatformDialogHelper::Help: |
| 813 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Help" ); |
| 814 | case QPlatformDialogHelper::Apply: |
| 815 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Apply" ); |
| 816 | case QPlatformDialogHelper::Reset: |
| 817 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Reset" ); |
| 818 | case QPlatformDialogHelper::RestoreDefaults: |
| 819 | return QCoreApplication::translate(context: "QPlatformTheme" , key: "Restore Defaults" ); |
| 820 | default: |
| 821 | break; |
| 822 | } |
| 823 | return QString(); |
| 824 | } |
| 825 | |
| 826 | QString QPlatformTheme::removeMnemonics(const QString &original) |
| 827 | { |
| 828 | const auto mnemonicInParentheses = [](QStringView text) { |
| 829 | /* Format of mnemonics to remove is /\(&[^&]\)/ but accept full-width |
| 830 | forms of ( and ) as equivalent, for cross-platform compatibility with |
| 831 | MS (and consequent behavior of translators, see QTBUG-110829). |
| 832 | */ |
| 833 | Q_ASSERT(text.size() == 4); // Caller's responsibility. |
| 834 | constexpr QChar wideOpen = u'\uff08', wideClose = u'\uff09'; |
| 835 | if (!text.startsWith(c: u'(') && !text.startsWith(c: wideOpen)) |
| 836 | return false; |
| 837 | if (text[1] != u'&' || text[2] == u'&') |
| 838 | return false; |
| 839 | return text.endsWith(c: u')') || text.endsWith(c: wideClose); |
| 840 | }; |
| 841 | QString returnText(original.size(), u'\0'); |
| 842 | int finalDest = 0; |
| 843 | QStringView text(original); |
| 844 | while (!text.isEmpty()) { |
| 845 | if (text.startsWith(c: u'&')) { |
| 846 | text = text.sliced(pos: 1); |
| 847 | if (text.isEmpty()) |
| 848 | break; |
| 849 | } else if (text.size() >= 4 && mnemonicInParentheses(text.first(n: 4))) { |
| 850 | // Advance over the matched mnemonic: |
| 851 | text = text.sliced(pos: 4); |
| 852 | // Also strip any leading space before it: |
| 853 | while (finalDest > 0 && returnText.at(i: finalDest - 1).isSpace()) |
| 854 | --finalDest; |
| 855 | continue; |
| 856 | } |
| 857 | returnText[finalDest] = text.front(); |
| 858 | text = text.sliced(pos: 1); |
| 859 | ++finalDest; |
| 860 | } |
| 861 | returnText.truncate(pos: finalDest); |
| 862 | return returnText; |
| 863 | } |
| 864 | |
| 865 | unsigned QPlatformThemePrivate::currentKeyPlatforms() |
| 866 | { |
| 867 | const uint keyboardScheme = QGuiApplicationPrivate::platformTheme()->themeHint(hint: QPlatformTheme::KeyboardScheme).toInt(); |
| 868 | unsigned result = 1u << keyboardScheme; |
| 869 | #if QT_CONFIG(shortcut) |
| 870 | if (keyboardScheme == QPlatformTheme::KdeKeyboardScheme |
| 871 | || keyboardScheme == QPlatformTheme::GnomeKeyboardScheme |
| 872 | || keyboardScheme == QPlatformTheme::CdeKeyboardScheme) |
| 873 | result |= KB_X11; |
| 874 | #endif |
| 875 | return result; |
| 876 | } |
| 877 | |
| 878 | QString QPlatformTheme::name() const |
| 879 | { |
| 880 | return d_func()->name; |
| 881 | } |
| 882 | |
| 883 | QT_END_NAMESPACE |
| 884 | |
| 885 | #include "moc_qplatformtheme.cpp" |
| 886 | |