Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplatformtheme.cpp
Go to the documentation of this file.
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
5
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
21QT_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 MenuSelectionWraps (bool) Determines whether menu selection wraps. That is, whether key navigation moves
126 the selection to the first menu item again after the last menu item has been
127 reached, and vice versa.
128 This enum value was added in Qt 6.10.
129
130 \value TouchDoubleTapDistance (int) The maximum distance in logical pixels which a touchpoint can travel
131 between taps in order for the tap sequence to be handled as a double tap.
132 The default value is double the MouseDoubleClickDistance, or 10 logical pixels
133 if that is not specified.
134
135 \value ShowShortcutsInContextMenus (bool) Whether to display shortcut key sequences in context menus.
136
137 \value InteractiveResizeAcrossScreens (bool) Whether using the whole virtual geometry of all the screens
138 as basis for the resize.
139 This enum value has been added in Qt 6.2.
140
141 \value ShowDirectoriesFirst (bool) Whether directories should be shown
142 first (before files) in file dialogs.
143 This enum value was added in Qt 6.3.
144
145 \value PreselectFirstFileInDirectory (bool) Whether the first file in a directory
146 should be automatically selected when a file dialog opens.
147 This enum value was added in Qt 6.3.
148
149 \value ButtonPressKeys (QList<Qt::Key>) A list of keys that can be used to press buttons via keyboard input.
150
151 \value SetFocusOnTouchRelease (bool) Whether focus objects (line edits etc) should receive
152 input focus after a touch/mouse release.
153 This enum value has been added in Qt 6.5.
154
155 \value MouseCursorTheme (QString) Name of the mouse cursor theme.
156 This enum value has been added in Qt 6.5.
157
158 \value MouseCursorSize (QSize) Size of the mouse cursor.
159 This enum value has been added in Qt 6.5.
160
161 \value ScrollSingleStepDistance (int) The distance in logical pixels that scrollable
162 controls should scroll in response to a single step (e.g. scroll-bar arrow click,
163 mouse wheel line).
164
165 \sa themeHint(), QStyle::pixelMetric()
166*/
167
168
169#if QT_CONFIG(shortcut)
170// Table of key bindings. It must be sorted on key sequence:
171// The integer value of VK_KEY | Modifier Keys (e.g., VK_META, and etc.)
172// A priority of 1 indicates that this is the primary key binding when multiple are defined.
173
174enum KeyPlatform {
175 KB_Win = (1 << QPlatformTheme::WindowsKeyboardScheme),
176 KB_Mac = (1 << QPlatformTheme::MacKeyboardScheme),
177 KB_X11 = (1 << QPlatformTheme::X11KeyboardScheme),
178 KB_KDE = (1 << QPlatformTheme::KdeKeyboardScheme),
179 KB_Gnome = (1 << QPlatformTheme::GnomeKeyboardScheme),
180 KB_CDE = (1 << QPlatformTheme::CdeKeyboardScheme),
181 KB_All = 0xffff
182};
183
184const QKeyBinding QPlatformThemePrivate::keyBindings[] = {
185 // StandardKey Priority Key Sequence Platforms
186 {QKeySequence::HelpContents, 1, Qt::CTRL | Qt::Key_Question, KB_Mac},
187 {QKeySequence::HelpContents, 0, Qt::Key_F1, KB_Win | KB_X11},
188 {QKeySequence::HelpContents, 0, Qt::Key_Help, KB_All},
189 {QKeySequence::WhatsThis, 1, Qt::SHIFT | Qt::Key_F1, KB_All},
190 {QKeySequence::Open, 1, Qt::CTRL | Qt::Key_O, KB_All},
191 {QKeySequence::Open, 0, Qt::Key_Open, KB_All},
192 {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_F4, KB_Mac},
193 {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_F4, KB_Win},
194 {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_W, KB_Mac},
195 {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_W, KB_Win | KB_X11},
196 {QKeySequence::Close, 0, Qt::Key_Close, KB_All},
197 {QKeySequence::Save, 1, Qt::CTRL | Qt::Key_S, KB_All},
198 {QKeySequence::Save, 0, Qt::Key_Save, KB_All},
199 {QKeySequence::New, 1, Qt::CTRL | Qt::Key_N, KB_All},
200 {QKeySequence::New, 0, Qt::Key_New, KB_All},
201 {QKeySequence::Delete, 0, Qt::CTRL | Qt::Key_D, KB_X11}, //emacs (line edit only)
202 {QKeySequence::Delete, 1, Qt::Key_Delete, KB_All},
203 {QKeySequence::Delete, 0, Qt::META | Qt::Key_D, KB_Mac},
204 {QKeySequence::Cut, 1, Qt::CTRL | Qt::Key_X, KB_All},
205 {QKeySequence::Cut, 0, Qt::SHIFT | Qt::Key_Delete, KB_Win | KB_X11}, //## Check if this should work on mac
206 {QKeySequence::Cut, 0, Qt::Key_F20, KB_X11}, //Cut on sun keyboards
207 {QKeySequence::Cut, 0, Qt::META | Qt::Key_K, KB_Mac},
208 {QKeySequence::Cut, 0, Qt::Key_Cut, KB_All},
209 {QKeySequence::Copy, 0, Qt::CTRL | Qt::Key_Insert, KB_X11 | KB_Win},
210 {QKeySequence::Copy, 1, Qt::CTRL | Qt::Key_C, KB_All},
211 {QKeySequence::Copy, 0, Qt::Key_F16, KB_X11}, //Copy on sun keyboards
212 {QKeySequence::Copy, 0, Qt::Key_Copy, KB_All},
213 {QKeySequence::Paste, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Insert, KB_X11},
214 {QKeySequence::Paste, 1, Qt::CTRL | Qt::Key_V, KB_All},
215 {QKeySequence::Paste, 0, Qt::SHIFT | Qt::Key_Insert, KB_Win | KB_X11},
216 {QKeySequence::Paste, 0, Qt::Key_F18, KB_X11}, //Paste on sun keyboards
217 {QKeySequence::Paste, 0, Qt::META | Qt::Key_Y, KB_Mac},
218 {QKeySequence::Paste, 0, Qt::Key_Paste, KB_All},
219 {QKeySequence::Undo, 0, Qt::ALT | Qt::Key_Backspace, KB_Win},
220 {QKeySequence::Undo, 1, Qt::CTRL | Qt::Key_Z, KB_All},
221 {QKeySequence::Undo, 0, Qt::Key_F14, KB_X11}, //Undo on sun keyboards
222 {QKeySequence::Undo, 0, Qt::Key_Undo, KB_All},
223 {QKeySequence::Redo, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Backspace,KB_Win},
224 {QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, KB_Mac},
225 {QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, KB_Win | KB_X11},
226 {QKeySequence::Redo, 1, Qt::CTRL | Qt::Key_Y, KB_Win},
227 {QKeySequence::Redo, 0, Qt::Key_Redo, KB_All},
228 {QKeySequence::Back, 1, Qt::ALT | Qt::Key_Left, KB_Win | KB_X11},
229 {QKeySequence::Back, 0, Qt::CTRL | Qt::Key_Left, KB_Mac},
230 {QKeySequence::Back, 1, Qt::CTRL | Qt::Key_BracketLeft, KB_Mac},
231 {QKeySequence::Back, 0, Qt::Key_Backspace, KB_Win},
232 {QKeySequence::Back, 0, Qt::Key_Back, KB_All},
233 {QKeySequence::Forward, 1, Qt::ALT | Qt::Key_Right, KB_Win | KB_X11},
234 {QKeySequence::Forward, 0, Qt::CTRL | Qt::Key_Right, KB_Mac},
235 {QKeySequence::Forward, 1, Qt::CTRL | Qt::Key_BracketRight, KB_Mac},
236 {QKeySequence::Forward, 0, Qt::SHIFT | Qt::Key_Backspace, KB_Win},
237 {QKeySequence::Forward, 0, Qt::Key_Forward, KB_All},
238 {QKeySequence::Refresh, 1, Qt::CTRL | Qt::Key_R, KB_Gnome | KB_Mac},
239 {QKeySequence::Refresh, 0, Qt::Key_F5, KB_Win | KB_X11},
240 {QKeySequence::Refresh, 0, Qt::Key_Refresh, KB_All},
241 {QKeySequence::ZoomIn, 1, Qt::CTRL | Qt::Key_Plus, KB_All},
242 {QKeySequence::ZoomIn, 0, Qt::Key_ZoomIn, KB_All},
243 {QKeySequence::ZoomOut, 1, Qt::CTRL | Qt::Key_Minus, KB_All},
244 {QKeySequence::ZoomOut, 0, Qt::Key_ZoomOut, KB_All},
245 {QKeySequence::Print, 1, Qt::CTRL | Qt::Key_P, KB_All},
246 {QKeySequence::AddTab, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_N, KB_KDE},
247 {QKeySequence::AddTab, 0, Qt::CTRL | Qt::Key_T, KB_All},
248 {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_F6, KB_Win},
249 {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Tab, KB_Mac}, //different priority from above
250 {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_Tab, KB_Win | KB_X11},
251 {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_BraceRight, KB_Mac},
252 {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Comma, KB_KDE},
253 {QKeySequence::NextChild, 0, Qt::Key_Forward, KB_All},
254 {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_F6, KB_Win},
255 {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, KB_Mac },//different priority from above
256 {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, KB_Win | KB_X11},
257 {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::Key_BraceLeft, KB_Mac},
258 {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::Key_Period, KB_KDE},
259 {QKeySequence::PreviousChild, 0, Qt::Key_Back, KB_All},
260 {QKeySequence::Find, 0, Qt::CTRL | Qt::Key_F, KB_All},
261 {QKeySequence::Find, 0, Qt::Key_Find, KB_All},
262 {QKeySequence::FindNext, 0, Qt::CTRL | Qt::Key_G, KB_Win},
263 {QKeySequence::FindNext, 1, Qt::CTRL | Qt::Key_G, KB_Gnome | KB_Mac},
264 {QKeySequence::FindNext, 1, Qt::Key_F3, KB_Win},
265 {QKeySequence::FindNext, 0, Qt::Key_F3, KB_X11},
266 {QKeySequence::FindPrevious, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_G, KB_Win},
267 {QKeySequence::FindPrevious, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_G, KB_Gnome | KB_Mac},
268 {QKeySequence::FindPrevious, 1, Qt::SHIFT | Qt::Key_F3, KB_Win},
269 {QKeySequence::FindPrevious, 0, Qt::SHIFT | Qt::Key_F3, KB_X11},
270 {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_R, KB_KDE},
271 {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, KB_Gnome},
272 {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, KB_Win},
273 {QKeySequence::SelectAll, 1, Qt::CTRL | Qt::Key_A, KB_All},
274 {QKeySequence::Bold, 1, Qt::CTRL | Qt::Key_B, KB_All},
275 {QKeySequence::Italic, 0, Qt::CTRL | Qt::Key_I, KB_All},
276 {QKeySequence::Underline, 1, Qt::CTRL | Qt::Key_U, KB_All},
277 {QKeySequence::MoveToNextChar, 1, Qt::Key_Right, KB_All},
278 {QKeySequence::MoveToNextChar, 0, Qt::META | Qt::Key_F, KB_Mac},
279 {QKeySequence::MoveToPreviousChar, 1, Qt::Key_Left, KB_All},
280 {QKeySequence::MoveToPreviousChar, 0, Qt::META | Qt::Key_B, KB_Mac},
281 {QKeySequence::MoveToNextWord, 0, Qt::ALT | Qt::Key_Right, KB_Mac},
282 {QKeySequence::MoveToNextWord, 0, Qt::CTRL | Qt::Key_Right, KB_Win | KB_X11},
283 {QKeySequence::MoveToPreviousWord, 0, Qt::ALT | Qt::Key_Left, KB_Mac},
284 {QKeySequence::MoveToPreviousWord, 0, Qt::CTRL | Qt::Key_Left, KB_Win | KB_X11},
285 {QKeySequence::MoveToNextLine, 1, Qt::Key_Down, KB_All},
286 {QKeySequence::MoveToNextLine, 0, Qt::META | Qt::Key_N, KB_Mac},
287 {QKeySequence::MoveToPreviousLine, 1, Qt::Key_Up, KB_All},
288 {QKeySequence::MoveToPreviousLine, 0, Qt::META | Qt::Key_P, KB_Mac},
289 {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_PageDown, KB_Mac},
290 {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_Down, KB_Mac},
291 {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_V, KB_Mac},
292 {QKeySequence::MoveToNextPage, 0, Qt::ALT | Qt::Key_PageDown, KB_Mac },
293 {QKeySequence::MoveToNextPage, 1, Qt::Key_PageDown, KB_All},
294 {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_PageUp, KB_Mac},
295 {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_Up, KB_Mac},
296 {QKeySequence::MoveToPreviousPage, 0, Qt::ALT | Qt::Key_PageUp, KB_Mac },
297 {QKeySequence::MoveToPreviousPage, 1, Qt::Key_PageUp, KB_All},
298 {QKeySequence::MoveToStartOfLine, 0, Qt::META | Qt::Key_Left, KB_Mac},
299 {QKeySequence::MoveToStartOfLine, 0, Qt::CTRL | Qt::Key_Left, KB_Mac },
300 {QKeySequence::MoveToStartOfLine, 0, Qt::Key_Home, KB_Win | KB_X11},
301 {QKeySequence::MoveToEndOfLine, 0, Qt::META | Qt::Key_Right, KB_Mac},
302 {QKeySequence::MoveToEndOfLine, 0, Qt::CTRL | Qt::Key_Right, KB_Mac },
303 {QKeySequence::MoveToEndOfLine, 0, Qt::Key_End, KB_Win | KB_X11},
304 {QKeySequence::MoveToEndOfLine, 0, Qt::CTRL | Qt::Key_E, KB_X11},
305 {QKeySequence::MoveToStartOfBlock, 0, Qt::META | Qt::Key_A, KB_Mac},
306 {QKeySequence::MoveToStartOfBlock, 1, Qt::ALT | Qt::Key_Up, KB_Mac}, //mac only
307 {QKeySequence::MoveToEndOfBlock, 0, Qt::META | Qt::Key_E, KB_Mac},
308 {QKeySequence::MoveToEndOfBlock, 1, Qt::ALT | Qt::Key_Down, KB_Mac}, //mac only
309 {QKeySequence::MoveToStartOfDocument, 1, Qt::CTRL | Qt::Key_Up, KB_Mac},
310 {QKeySequence::MoveToStartOfDocument, 0, Qt::CTRL | Qt::Key_Home, KB_Win | KB_X11},
311 {QKeySequence::MoveToStartOfDocument, 0, Qt::Key_Home, KB_Mac},
312 {QKeySequence::MoveToEndOfDocument, 1, Qt::CTRL | Qt::Key_Down, KB_Mac},
313 {QKeySequence::MoveToEndOfDocument, 0, Qt::CTRL | Qt::Key_End, KB_Win | KB_X11},
314 {QKeySequence::MoveToEndOfDocument, 0, Qt::Key_End, KB_Mac},
315 {QKeySequence::SelectNextChar, 0, Qt::SHIFT | Qt::Key_Right, KB_All},
316 {QKeySequence::SelectPreviousChar, 0, Qt::SHIFT | Qt::Key_Left, KB_All},
317 {QKeySequence::SelectNextWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Right, KB_Mac},
318 {QKeySequence::SelectNextWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, KB_Win | KB_X11},
319 {QKeySequence::SelectPreviousWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Left, KB_Mac},
320 {QKeySequence::SelectPreviousWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, KB_Win | KB_X11},
321 {QKeySequence::SelectNextLine, 0, Qt::SHIFT | Qt::Key_Down, KB_All},
322 {QKeySequence::SelectPreviousLine, 0, Qt::SHIFT | Qt::Key_Up, KB_All},
323 {QKeySequence::SelectNextPage, 0, Qt::SHIFT | Qt::Key_PageDown, KB_All},
324 {QKeySequence::SelectPreviousPage, 0, Qt::SHIFT | Qt::Key_PageUp, KB_All},
325 {QKeySequence::SelectStartOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Left, KB_Mac},
326 {QKeySequence::SelectStartOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, KB_Mac },
327 {QKeySequence::SelectStartOfLine, 0, Qt::SHIFT | Qt::Key_Home, KB_Win | KB_X11},
328 {QKeySequence::SelectEndOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Right, KB_Mac},
329 {QKeySequence::SelectEndOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, KB_Mac },
330 {QKeySequence::SelectEndOfLine, 0, Qt::SHIFT | Qt::Key_End, KB_Win | KB_X11},
331 {QKeySequence::SelectStartOfBlock, 1, Qt::ALT | Qt::SHIFT | Qt::Key_Up, KB_Mac}, //mac only
332 {QKeySequence::SelectStartOfBlock, 0, Qt::META | Qt::SHIFT | Qt::Key_A, KB_Mac},
333 {QKeySequence::SelectEndOfBlock, 1, Qt::ALT | Qt::SHIFT | Qt::Key_Down, KB_Mac}, //mac only
334 {QKeySequence::SelectEndOfBlock, 0, Qt::META | Qt::SHIFT | Qt::Key_E, KB_Mac},
335 {QKeySequence::SelectStartOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Up, KB_Mac},
336 {QKeySequence::SelectStartOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Home, KB_Win | KB_X11},
337 {QKeySequence::SelectStartOfDocument, 0, Qt::SHIFT | Qt::Key_Home, KB_Mac},
338 {QKeySequence::SelectEndOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Down, KB_Mac},
339 {QKeySequence::SelectEndOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_End, KB_Win | KB_X11},
340 {QKeySequence::SelectEndOfDocument, 0, Qt::SHIFT | Qt::Key_End, KB_Mac},
341 {QKeySequence::DeleteStartOfWord, 0, Qt::ALT | Qt::Key_Backspace, KB_Mac},
342 {QKeySequence::DeleteStartOfWord, 0, Qt::CTRL | Qt::Key_Backspace, KB_X11 | KB_Win},
343 {QKeySequence::DeleteEndOfWord, 0, Qt::ALT | Qt::Key_Delete, KB_Mac},
344 {QKeySequence::DeleteEndOfWord, 0, Qt::CTRL | Qt::Key_Delete, KB_X11 | KB_Win},
345 {QKeySequence::DeleteEndOfLine, 0, Qt::CTRL | Qt::Key_K, KB_X11}, //emacs (line edit only)
346 {QKeySequence::InsertParagraphSeparator,0, Qt::Key_Enter, KB_All},
347 {QKeySequence::InsertParagraphSeparator,0, Qt::Key_Return, KB_All},
348 {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_Enter, KB_Mac},
349 {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_Return, KB_Mac},
350 {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Enter, KB_All},
351 {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Return, KB_All},
352 {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_O, KB_Mac},
353 {QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, KB_All},
354 {QKeySequence::SaveAs, 0, Qt::SHIFT | Qt::Key_Save, KB_All},
355 {QKeySequence::Preferences, 0, Qt::CTRL | Qt::Key_Comma, KB_Mac},
356 {QKeySequence::Preferences, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Comma, KB_KDE},
357 {QKeySequence::Preferences, 0, Qt::Key_Settings, KB_All},
358 {QKeySequence::Quit, 0, Qt::CTRL | Qt::Key_Q, KB_X11 | KB_Gnome | KB_KDE | KB_Mac},
359 {QKeySequence::Quit, 0, Qt::Key_Exit, KB_All},
360 {QKeySequence::FullScreen, 1, Qt::META | Qt::CTRL | Qt::Key_F, KB_Mac},
361 {QKeySequence::FullScreen, 0, Qt::ALT | Qt::Key_Enter, KB_Win},
362 {QKeySequence::FullScreen, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_F, KB_KDE},
363 {QKeySequence::FullScreen, 1, Qt::Key_F11, KB_Win | KB_Gnome | KB_KDE},
364 {QKeySequence::Deselect, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_A, KB_X11},
365 {QKeySequence::DeleteCompleteLine, 0, Qt::CTRL | Qt::Key_U, KB_X11},
366 {QKeySequence::Backspace, 1, Qt::Key_Backspace, KB_Mac},
367 {QKeySequence::Backspace, 0, Qt::META | Qt::Key_H, KB_Mac},
368 {QKeySequence::Cancel, 0, Qt::Key_Escape, KB_All},
369 {QKeySequence::Cancel, 0, Qt::CTRL | Qt::Key_Period, KB_Mac},
370 {QKeySequence::Cancel, 0, Qt::Key_Cancel, KB_All}
371};
372
373const uint QPlatformThemePrivate::numberOfKeyBindings = sizeof(QPlatformThemePrivate::keyBindings)/(sizeof(QKeyBinding));
374#endif
375
376QPlatformThemePrivate::QPlatformThemePrivate()
377 : systemPalette(nullptr)
378{ }
379
380QPlatformThemePrivate::~QPlatformThemePrivate()
381{
382 if (systemPalette)
383 delete systemPalette;
384}
385
386Q_GUI_EXPORT QPalette qt_fusionPalette()
387{
388 auto theme = QGuiApplicationPrivate::platformTheme();
389 const bool darkAppearance = theme
390 ? theme->colorScheme() == Qt::ColorScheme::Dark
391 : false;
392 const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black;
393 const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239);
394 const QColor light = backGround.lighter(150);
395 const QColor mid = (backGround.darker(130));
396 const QColor midLight = mid.lighter(110);
397 const QColor base = darkAppearance ? backGround.darker(140) : Qt::white;
398 const QColor disabledBase(backGround);
399 const QColor dark = backGround.darker(150);
400 const QColor darkDisabled = QColor(209, 209, 209).darker(110);
401 const QColor text = darkAppearance ? windowText : Qt::black;
402 const QColor highlight = QColor(48, 140, 198);
403 const QColor hightlightedText = darkAppearance ? windowText : Qt::white;
404 const QColor disabledText = darkAppearance ? QColor(130, 130, 130) : QColor(190, 190, 190);
405 const QColor button = backGround;
406 const QColor shadow = dark.darker(135);
407 const QColor disabledShadow = shadow.lighter(150);
408 const QColor disabledHighlight(145, 145, 145);
409 QColor placeholder = text;
410 placeholder.setAlpha(128);
411
412 QPalette fusionPalette(windowText, backGround, light, dark, mid, text, base);
413 fusionPalette.setBrush(QPalette::Midlight, midLight);
414 fusionPalette.setBrush(QPalette::Button, button);
415 fusionPalette.setBrush(QPalette::Shadow, shadow);
416 fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText);
417
418 fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText);
419 fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText);
420 fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText);
421 fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase);
422 fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
423 fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow);
424
425 fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, highlight);
426 fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, highlight);
427 fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, disabledHighlight);
428
429 fusionPalette.setBrush(QPalette::Active, QPalette::Accent, highlight);
430 fusionPalette.setBrush(QPalette::Inactive, QPalette::Accent, highlight);
431 fusionPalette.setBrush(QPalette::Disabled, QPalette::Accent, disabledHighlight);
432
433 fusionPalette.setBrush(QPalette::PlaceholderText, placeholder);
434
435 // Use a more legible light blue on dark backgrounds than the default Qt::blue.
436 if (darkAppearance)
437 fusionPalette.setBrush(QPalette::Link, highlight);
438
439 return fusionPalette;
440}
441
442void QPlatformThemePrivate::initializeSystemPalette()
443{
444 Q_ASSERT(!systemPalette);
445 systemPalette = new QPalette(qt_fusionPalette());
446}
447
448QPlatformTheme::QPlatformTheme()
449 : d_ptr(new QPlatformThemePrivate)
450{
451
452}
453
454QPlatformTheme::QPlatformTheme(QPlatformThemePrivate *priv)
455 : d_ptr(priv)
456{ }
457
458QPlatformTheme::~QPlatformTheme()
459{
460
461}
462
463bool QPlatformTheme::usePlatformNativeDialog(DialogType type) const
464{
465 Q_UNUSED(type);
466 return false;
467}
468
469QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType type) const
470{
471 Q_UNUSED(type);
472 return nullptr;
473}
474
475Qt::ColorScheme QPlatformTheme::colorScheme() const
476{
477 return Qt::ColorScheme::Unknown;
478}
479
480void QPlatformTheme::requestColorScheme(Qt::ColorScheme scheme)
481{
482 Q_UNUSED(scheme);
483 Q_D(QPlatformTheme);
484 if (d->systemPalette) {
485 delete d->systemPalette;
486 d->systemPalette = nullptr;
487 }
488}
489
490Qt::ContrastPreference QPlatformTheme::contrastPreference() const
491{
492 return Qt::ContrastPreference::NoPreference;
493}
494
495/*!
496 \internal
497 \brief Return a color palette for type \a type.
498
499 When relying on system color palette keep in mind that it is
500 lazily initialized and cached. If it needs to be updated
501 (i.e. due to ColorScheme changes), it's up to the caller
502 to take care of it. See \c requestColorScheme.
503*/
504const QPalette *QPlatformTheme::palette(Palette type) const
505{
506 Q_D(const QPlatformTheme);
507 if (type == QPlatformTheme::SystemPalette) {
508 if (!d->systemPalette)
509 const_cast<QPlatformTheme *>(this)->d_ptr->initializeSystemPalette();
510 return d->systemPalette;
511 }
512 return nullptr;
513}
514
515const QFont *QPlatformTheme::font(Font type) const
516{
517 Q_UNUSED(type);
518 return nullptr;
519}
520
521/*!
522 \brief Return a pixmap for \a standardPixmap, at the given \a size.
523
524 The implementation should not take system DPR into account, and
525 always return a pixmap with a DPR of 1. It's up to the consumer
526 to account for DPR and request a pixmap of the right size.
527*/
528QPixmap QPlatformTheme::standardPixmap(StandardPixmap standardPixmap, const QSizeF &size) const
529{
530 Q_UNUSED(standardPixmap);
531 Q_UNUSED(size);
532 // TODO Should return QCommonStyle pixmaps?
533 return QPixmap();
534}
535
536/*!
537 \brief Return an icon for \a fileInfo, observing \a iconOptions.
538
539 This function is queried by QFileIconProvider and similar classes to obtain
540 an icon for a file. If it does not return a non-null icon, fileIconPixmap()
541 is queried for a specific size.
542
543 \since 5.8
544*/
545
546QIcon QPlatformTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const
547{
548 Q_UNUSED(fileInfo);
549 Q_UNUSED(iconOptions);
550 // TODO Should return QCommonStyle pixmaps?
551 return QIcon();
552}
553
554QVariant QPlatformTheme::themeHint(ThemeHint hint) const
555{
556 // For theme hints which mirror platform integration style hints, query
557 // the platform integration. The base QPlatformIntegration::styleHint()
558 // function will in turn query QPlatformTheme::defaultThemeHint() if there
559 // is no custom value.
560 switch (hint) {
561 case QPlatformTheme::CursorFlashTime:
562 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::CursorFlashTime);
563 case QPlatformTheme::KeyboardInputInterval:
564 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::KeyboardInputInterval);
565 case QPlatformTheme::KeyboardAutoRepeatRate:
566 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::KeyboardAutoRepeatRate);
567 case QPlatformTheme::MouseDoubleClickInterval:
568 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::MouseDoubleClickInterval);
569 case QPlatformTheme::StartDragDistance:
570 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::StartDragDistance);
571 case QPlatformTheme::StartDragTime:
572 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::StartDragTime);
573 case QPlatformTheme::StartDragVelocity:
574 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::StartDragVelocity);
575 case QPlatformTheme::PasswordMaskDelay:
576 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::PasswordMaskDelay);
577 case QPlatformTheme::PasswordMaskCharacter:
578 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::PasswordMaskCharacter);
579 case QPlatformTheme::MousePressAndHoldInterval:
580 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::MousePressAndHoldInterval);
581 case QPlatformTheme::ItemViewActivateItemOnSingleClick:
582 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ItemViewActivateItemOnSingleClick);
583 case QPlatformTheme::UiEffects:
584 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UiEffects);
585 case QPlatformTheme::ShowShortcutsInContextMenus:
586 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ShowShortcutsInContextMenus);
587 case QPlatformTheme::SetFocusOnTouchRelease:
588 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SetFocusOnTouchRelease);
589 case QPlatformTheme::FlickStartDistance:
590 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickStartDistance);
591 case QPlatformTheme::FlickMaximumVelocity:
592 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickMaximumVelocity);
593 case QPlatformTheme::FlickDeceleration:
594 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickDeceleration);
595 case QPlatformTheme::UnderlineShortcut:
596 return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UnderlineShortcut);
597 default:
598 return QPlatformTheme::defaultThemeHint(hint);
599 }
600}
601
602QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
603{
604 switch (hint) {
605 case QPlatformTheme::CursorFlashTime:
606 return QVariant(1000);
607 case QPlatformTheme::KeyboardInputInterval:
608 return QVariant(400);
609 case QPlatformTheme::KeyboardAutoRepeatRate:
610 return QVariant(30);
611 case QPlatformTheme::MouseDoubleClickInterval:
612 return QVariant(400);
613 case QPlatformTheme::StartDragDistance:
614 return QVariant(10);
615 case QPlatformTheme::StartDragTime:
616 return QVariant(500);
617 case QPlatformTheme::PasswordMaskDelay:
618 return QVariant(int(0));
619 case QPlatformTheme::PasswordMaskCharacter:
620 return QVariant(QChar(u'\x25CF'));
621 case QPlatformTheme::StartDragVelocity:
622 return QVariant(int(0)); // no limit
623 case QPlatformTheme::UseFullScreenForPopupMenu:
624 return QVariant(false);
625 case QPlatformTheme::WindowAutoPlacement:
626 return QVariant(false);
627 case QPlatformTheme::DialogButtonBoxLayout:
628 return QVariant(int(0));
629 case QPlatformTheme::DialogButtonBoxButtonsHaveIcons:
630 return QVariant(false);
631 case QPlatformTheme::ItemViewActivateItemOnSingleClick:
632 return QVariant(false);
633 case QPlatformTheme::ToolButtonStyle:
634 return QVariant(int(Qt::ToolButtonIconOnly));
635 case QPlatformTheme::ToolBarIconSize:
636 return QVariant(int(0));
637 case QPlatformTheme::SystemIconThemeName:
638 case QPlatformTheme::SystemIconFallbackThemeName:
639 return QVariant(QString());
640 case QPlatformTheme::IconThemeSearchPaths:
641 return QVariant(QStringList());
642 case QPlatformTheme::IconFallbackSearchPaths:
643 return QVariant(QStringList());
644 case QPlatformTheme::StyleNames:
645 return QVariant(QStringList());
646 case QPlatformTheme::ShowShortcutsInContextMenus:
647 return QVariant(true);
648 case TextCursorWidth:
649 return QVariant(1);
650 case DropShadow:
651 return QVariant(false);
652 case MaximumScrollBarDragDistance:
653 return QVariant(-1);
654 case KeyboardScheme:
655 return QVariant(int(WindowsKeyboardScheme));
656 case UiEffects:
657 return QVariant(int(0));
658 case SpellCheckUnderlineStyle:
659 return QVariant(int(QTextCharFormat::WaveUnderline));
660 case TabFocusBehavior:
661 return QVariant(int(Qt::TabFocusAllControls));
662 case IconPixmapSizes:
663 return QVariant::fromValue(QList<int>());
664 case DialogSnapToDefaultButton:
665 case ContextMenuOnMouseRelease:
666 return QVariant(false);
667 case MousePressAndHoldInterval:
668 return QVariant(800);
669 case MouseDoubleClickDistance:
670 {
671 bool ok = false;
672 const int dist = qEnvironmentVariableIntValue("QT_DBL_CLICK_DIST", &ok);
673 return QVariant(ok ? dist : 5);
674 }
675 case WheelScrollLines:
676 return QVariant(3);
677 case TouchDoubleTapDistance:
678 {
679 bool ok = false;
680 int dist = qEnvironmentVariableIntValue("QT_DBL_TAP_DIST", &ok);
681 if (!ok)
682 dist = defaultThemeHint(MouseDoubleClickDistance).toInt(&ok) * 2;
683 return QVariant(ok ? dist : 10);
684 }
685 case MouseQuickSelectionThreshold:
686 return QVariant(10);
687 case InteractiveResizeAcrossScreens:
688 return true;
689 case ShowDirectoriesFirst:
690 return true;
691 case PreselectFirstFileInDirectory:
692 return false;
693 case ButtonPressKeys:
694 return QVariant::fromValue(QList<Qt::Key>({ Qt::Key_Space, Qt::Key_Select }));
695 case SetFocusOnTouchRelease:
696 return false;
697 case FlickStartDistance:
698 return QVariant(15);
699 case FlickMaximumVelocity:
700 return QVariant(2500);
701 case FlickDeceleration:
702 return QVariant(1500);
703 case MenuBarFocusOnAltPressRelease:
704 return false;
705 case MouseCursorTheme:
706 return QVariant(QString());
707 case MouseCursorSize:
708 return QVariant(QSize(16, 16));
709 case UnderlineShortcut:
710 return true;
711 case ShowIconsInMenus:
712 return true;
713 case PreferFileIconFromTheme:
714 return false;
715 case MenuSelectionWraps:
716 return true;
717 case ScrollSingleStepDistance:
718 return 20;
719 }
720
721 return QVariant();
722}
723
724QPlatformMenuItem *QPlatformTheme::createPlatformMenuItem() const
725{
726 return nullptr;
727}
728
729QPlatformMenu *QPlatformTheme::createPlatformMenu() const
730{
731 return nullptr;
732}
733
734QPlatformMenuBar *QPlatformTheme::createPlatformMenuBar() const
735{
736 return nullptr;
737}
738
739#ifndef QT_NO_SYSTEMTRAYICON
740/*!
741 Factory function for QSystemTrayIcon. This function will return 0 if the platform
742 integration does not support creating any system tray icon.
743*/
744QPlatformSystemTrayIcon *QPlatformTheme::createPlatformSystemTrayIcon() const
745{
746 return nullptr;
747}
748#endif
749
750/*!
751 Factory function for the QIconEngine used by QIcon::fromTheme(). By default this
752 function returns a QIconLoaderEngine, but subclasses can reimplement it to
753 provide their own.
754
755 It is especially useful to benefit from some platform specific facilities or
756 optimizations like an inter-process cache in systems mostly built with Qt.
757
758 \since 5.1
759*/
760QIconEngine *QPlatformTheme::createIconEngine(const QString &iconName) const
761{
762 return new QIconLoaderEngine(iconName);
763}
764
765#if QT_CONFIG(shortcut)
766// mixed-mode predicate: all of these overloads are actually needed (but not all for every compiler)
767struct ByStandardKey {
768 typedef bool result_type;
769
770 bool operator()(QKeySequence::StandardKey lhs, QKeySequence::StandardKey rhs) const
771 { return lhs < rhs; }
772
773 bool operator()(const QKeyBinding& lhs, const QKeyBinding& rhs) const
774 { return operator()(lhs.standardKey, rhs.standardKey); }
775
776 bool operator()(QKeySequence::StandardKey lhs, const QKeyBinding& rhs) const
777 { return operator()(lhs, rhs.standardKey); }
778
779 bool operator()(const QKeyBinding& lhs, QKeySequence::StandardKey rhs) const
780 { return operator()(lhs.standardKey, rhs); }
781};
782
783/*!
784 Returns the key sequence that should be used for a standard action.
785
786 \since 5.2
787 */
788QList<QKeySequence> QPlatformTheme::keyBindings(QKeySequence::StandardKey key) const
789{
790 const uint platform = QPlatformThemePrivate::currentKeyPlatforms();
791 QList <QKeySequence> list;
792
793 std::pair<const QKeyBinding *, const QKeyBinding *> range =
794 std::equal_range(QPlatformThemePrivate::keyBindings,
795 QPlatformThemePrivate::keyBindings + QPlatformThemePrivate::numberOfKeyBindings,
796 key, ByStandardKey());
797
798 for (const QKeyBinding *it = range.first; it < range.second; ++it) {
799 if (!(it->platform & platform))
800 continue;
801
802 uint shortcut = it->shortcut.toCombined();
803
804 if (it->priority > 0)
805 list.prepend(QKeySequence(shortcut));
806 else
807 list.append(QKeySequence(shortcut));
808 }
809
810 return list;
811}
812#endif
813
814/*!
815 Returns the text of a standard \a button.
816
817 \since 5.3
818 \sa QPlatformDialogHelper::StandardButton
819 */
820
821QString QPlatformTheme::standardButtonText(int button) const
822{
823 return QPlatformTheme::defaultStandardButtonText(button);
824}
825
826#if QT_CONFIG(shortcut)
827/*!
828 Returns the mnemonic that should be used for a standard \a button.
829
830 \since 5.9
831 \sa QPlatformDialogHelper::StandardButton
832 */
833
834QKeySequence QPlatformTheme::standardButtonShortcut(int button) const
835{
836 Q_UNUSED(button);
837 return QKeySequence();
838}
839#endif // QT_CONFIG(shortcut)
840
841QString QPlatformTheme::defaultStandardButtonText(int button)
842{
843 switch (button) {
844 case QPlatformDialogHelper::Ok:
845 return QCoreApplication::translate("QPlatformTheme", "OK");
846 case QPlatformDialogHelper::Save:
847 return QCoreApplication::translate("QPlatformTheme", "Save");
848 case QPlatformDialogHelper::SaveAll:
849 return QCoreApplication::translate("QPlatformTheme", "Save All");
850 case QPlatformDialogHelper::Open:
851 return QCoreApplication::translate("QPlatformTheme", "Open");
852 case QPlatformDialogHelper::Yes:
853 return QCoreApplication::translate("QPlatformTheme", "&Yes");
854 case QPlatformDialogHelper::YesToAll:
855 return QCoreApplication::translate("QPlatformTheme", "Yes to &All");
856 case QPlatformDialogHelper::No:
857 return QCoreApplication::translate("QPlatformTheme", "&No");
858 case QPlatformDialogHelper::NoToAll:
859 return QCoreApplication::translate("QPlatformTheme", "N&o to All");
860 case QPlatformDialogHelper::Abort:
861 return QCoreApplication::translate("QPlatformTheme", "Abort");
862 case QPlatformDialogHelper::Retry:
863 return QCoreApplication::translate("QPlatformTheme", "Retry");
864 case QPlatformDialogHelper::Ignore:
865 return QCoreApplication::translate("QPlatformTheme", "Ignore");
866 case QPlatformDialogHelper::Close:
867 return QCoreApplication::translate("QPlatformTheme", "Close");
868 case QPlatformDialogHelper::Cancel:
869 return QCoreApplication::translate("QPlatformTheme", "Cancel");
870 case QPlatformDialogHelper::Discard:
871 return QCoreApplication::translate("QPlatformTheme", "Discard");
872 case QPlatformDialogHelper::Help:
873 return QCoreApplication::translate("QPlatformTheme", "Help");
874 case QPlatformDialogHelper::Apply:
875 return QCoreApplication::translate("QPlatformTheme", "Apply");
876 case QPlatformDialogHelper::Reset:
877 return QCoreApplication::translate("QPlatformTheme", "Reset");
878 case QPlatformDialogHelper::RestoreDefaults:
879 return QCoreApplication::translate("QPlatformTheme", "Restore Defaults");
880 default:
881 break;
882 }
883 return QString();
884}
885
886QString QPlatformTheme::removeMnemonics(const QString &original)
887{
888 const auto mnemonicInParentheses = [](QStringView text) {
889 /* Format of mnemonics to remove is /\‍(&[^&]\‍)/ but accept full-width
890 forms of ( and ) as equivalent, for cross-platform compatibility with
891 MS (and consequent behavior of translators, see QTBUG-110829).
892 */
893 Q_ASSERT(text.size() == 4); // Caller's responsibility.
894 constexpr QChar wideOpen = u'\uff08', wideClose = u'\uff09';
895 if (!text.startsWith(u'(') && !text.startsWith(wideOpen))
896 return false;
897 if (text[1] != u'&' || text[2] == u'&')
898 return false;
899 return text.endsWith(u')') || text.endsWith(wideClose);
900 };
901 QString returnText(original.size(), u'\0');
902 int finalDest = 0;
903 QStringView text(original);
904 while (!text.isEmpty()) {
905 if (text.startsWith(u'&')) {
906 text = text.sliced(1);
907 if (text.isEmpty())
908 break;
909 } else if (text.size() >= 4 && mnemonicInParentheses(text.first(4))) {
910 // Advance over the matched mnemonic:
911 text = text.sliced(4);
912 // Also strip any leading space before it:
913 while (finalDest > 0 && returnText.at(finalDest - 1).isSpace())
914 --finalDest;
915 continue;
916 }
917 returnText[finalDest] = text.front();
918 text = text.sliced(1);
919 ++finalDest;
920 }
921 returnText.truncate(finalDest);
922 return returnText;
923}
924
925unsigned QPlatformThemePrivate::currentKeyPlatforms()
926{
927 const uint keyboardScheme = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt();
928 unsigned result = 1u << keyboardScheme;
929#if QT_CONFIG(shortcut)
930 if (keyboardScheme == QPlatformTheme::KdeKeyboardScheme
931 || keyboardScheme == QPlatformTheme::GnomeKeyboardScheme
932 || keyboardScheme == QPlatformTheme::CdeKeyboardScheme)
933 result |= KB_X11;
934#endif
935 return result;
936}
937
938QString QPlatformTheme::name() const
939{
940 return d_func()->name;
941}
942
943QT_END_NAMESPACE
944
945#include "moc_qplatformtheme.cpp"
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19