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