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