diff options
Diffstat (limited to 'src/gui/kernel/qplatformtheme.cpp')
-rw-r--r-- | src/gui/kernel/qplatformtheme.cpp | 152 |
1 files changed, 127 insertions, 25 deletions
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 65f600c338..48978b849a 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -143,6 +143,16 @@ QT_BEGIN_NAMESPACE \value ButtonPressKeys (QList<Qt::Key>) A list of keys that can be used to press buttons via keyboard input. + \value SetFocusOnTouchRelease (bool) Whether focus objects (line edits etc) should receive + input focus after a touch/mouse release. + This enum value has been added in Qt 6.5. + + \value MouseCursorTheme (QString) Name of the mouse cursor theme. + This enum value has been added in Qt 6.5. + + \value MouseCursorSize (QSize) Size of the mouse cursor. + This enum value has been added in Qt 6.5. + \sa themeHint(), QStyle::pixelMetric() */ @@ -315,7 +325,7 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = { {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Enter, KB_All}, {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Return, KB_All}, {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_O, KB_Mac}, - {QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, KB_Gnome | KB_Mac}, + {QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, KB_All}, {QKeySequence::Preferences, 0, Qt::CTRL | Qt::Key_Comma, KB_Mac}, {QKeySequence::Quit, 0, Qt::CTRL | Qt::Key_Q, KB_X11 | KB_Gnome | KB_KDE | KB_Mac}, {QKeySequence::FullScreen, 1, Qt::META | Qt::CTRL | Qt::Key_F, KB_Mac}, @@ -325,6 +335,7 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = { {QKeySequence::FullScreen, 1, Qt::Key_F11, KB_Win | KB_KDE}, {QKeySequence::Deselect, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_A, KB_X11}, {QKeySequence::DeleteCompleteLine, 0, Qt::CTRL | Qt::Key_U, KB_X11}, + {QKeySequence::Backspace, 1, Qt::Key_Backspace, KB_Mac}, {QKeySequence::Backspace, 0, Qt::META | Qt::Key_H, KB_Mac}, {QKeySequence::Cancel, 0, Qt::Key_Escape, KB_All}, {QKeySequence::Cancel, 0, Qt::CTRL | Qt::Key_Period, KB_Mac} @@ -342,7 +353,61 @@ QPlatformThemePrivate::~QPlatformThemePrivate() delete systemPalette; } -Q_GUI_EXPORT QPalette qt_fusionPalette(); +Q_GUI_EXPORT QPalette qt_fusionPalette() +{ + auto theme = QGuiApplicationPrivate::platformTheme(); + const bool darkAppearance = theme + ? theme->colorScheme() == Qt::ColorScheme::Dark + : false; + const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black; + const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239); + const QColor light = backGround.lighter(150); + const QColor mid = (backGround.darker(130)); + const QColor midLight = mid.lighter(110); + const QColor base = darkAppearance ? backGround.darker(140) : Qt::white; + const QColor disabledBase(backGround); + const QColor dark = backGround.darker(150); + const QColor darkDisabled = QColor(209, 209, 209).darker(110); + const QColor text = darkAppearance ? windowText : Qt::black; + const QColor highlight = QColor(48, 140, 198); + const QColor hightlightedText = darkAppearance ? windowText : Qt::white; + const QColor disabledText = darkAppearance ? QColor(130, 130, 130) : QColor(190, 190, 190); + const QColor button = backGround; + const QColor shadow = dark.darker(135); + const QColor disabledShadow = shadow.lighter(150); + const QColor disabledHighlight(145, 145, 145); + QColor placeholder = text; + placeholder.setAlpha(128); + + QPalette fusionPalette(windowText, backGround, light, dark, mid, text, base); + fusionPalette.setBrush(QPalette::Midlight, midLight); + fusionPalette.setBrush(QPalette::Button, button); + fusionPalette.setBrush(QPalette::Shadow, shadow); + fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText); + + fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText); + fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText); + fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText); + fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase); + fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled); + fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow); + + fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, highlight); + fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, highlight); + fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, disabledHighlight); + + fusionPalette.setBrush(QPalette::Active, QPalette::Accent, highlight); + fusionPalette.setBrush(QPalette::Inactive, QPalette::Accent, highlight); + fusionPalette.setBrush(QPalette::Disabled, QPalette::Accent, disabledHighlight); + + fusionPalette.setBrush(QPalette::PlaceholderText, placeholder); + + // Use a more legible light blue on dark backgrounds than the default Qt::blue. + if (darkAppearance) + fusionPalette.setBrush(QPalette::Link, highlight); + + return fusionPalette; +} void QPlatformThemePrivate::initializeSystemPalette() { @@ -377,9 +442,9 @@ QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType typ return nullptr; } -QPlatformTheme::Appearance QPlatformTheme::appearance() const +Qt::ColorScheme QPlatformTheme::colorScheme() const { - return Appearance::Unknown; + return Qt::ColorScheme::Unknown; } const QPalette *QPlatformTheme::palette(Palette type) const @@ -458,6 +523,16 @@ QVariant QPlatformTheme::themeHint(ThemeHint hint) const return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UiEffects); case QPlatformTheme::ShowShortcutsInContextMenus: return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ShowShortcutsInContextMenus); + case QPlatformTheme::SetFocusOnTouchRelease: + return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SetFocusOnTouchRelease); + case QPlatformTheme::FlickStartDistance: + return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickStartDistance); + case QPlatformTheme::FlickMaximumVelocity: + return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickMaximumVelocity); + case QPlatformTheme::FlickDeceleration: + return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickDeceleration); + case QPlatformTheme::UnderlineShortcut: + return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UnderlineShortcut); default: return QPlatformTheme::defaultThemeHint(hint); } @@ -556,7 +631,24 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) return false; case ButtonPressKeys: return QVariant::fromValue(QList<Qt::Key>({ Qt::Key_Space, Qt::Key_Select })); + case SetFocusOnTouchRelease: + return false; + case FlickStartDistance: + return QVariant(15); + case FlickMaximumVelocity: + return QVariant(2500); + case FlickDeceleration: + return QVariant(1500); + case MenuBarFocusOnAltPressRelease: + return false; + case MouseCursorTheme: + return QVariant(QString()); + case MouseCursorSize: + return QVariant(QSize(16, 16)); + case UnderlineShortcut: + return true; } + return QVariant(); } @@ -724,33 +816,38 @@ QString QPlatformTheme::defaultStandardButtonText(int button) QString QPlatformTheme::removeMnemonics(const QString &original) { + const auto mnemonicInParentheses = [](QStringView text) { + /* Format of mnemonics to remove is /\(&[^&]\)/ but accept full-width + forms of ( and ) as equivalent, for cross-platform compatibility with + MS (and consequent behavior of translators, see QTBUG-110829). + */ + Q_ASSERT(text.size() == 4); // Caller's responsibility. + constexpr QChar wideOpen = u'\uff08', wideClose = u'\uff09'; + if (!text.startsWith(u'(') && !text.startsWith(wideOpen)) + return false; + if (text[1] != u'&' || text[2] == u'&') + return false; + return text.endsWith(u')') || text.endsWith(wideClose); + }; QString returnText(original.size(), u'\0'); int finalDest = 0; - int currPos = 0; - int l = original.length(); - while (l) { - if (original.at(currPos) == u'&') { - ++currPos; - --l; - if (l == 0) + QStringView text(original); + while (!text.isEmpty()) { + if (text.startsWith(u'&')) { + text = text.sliced(1); + if (text.isEmpty()) break; - } else if (original.at(currPos) == u'(' && l >= 4 && - original.at(currPos + 1) == u'&' && - original.at(currPos + 2) != u'&' && - original.at(currPos + 3) == u')') { - /* remove mnemonics its format is "\s*(&X)" */ - int n = 0; - while (finalDest > n && returnText.at(finalDest - n - 1).isSpace()) - ++n; - finalDest -= n; - currPos += 4; - l -= 4; + } else if (text.size() >= 4 && mnemonicInParentheses(text.first(4))) { + // Advance over the matched mnemonic: + text = text.sliced(4); + // Also strip any leading space before it: + while (finalDest > 0 && returnText.at(finalDest - 1).isSpace()) + --finalDest; continue; } - returnText[finalDest] = original.at(currPos); - ++currPos; + returnText[finalDest] = text.front(); + text = text.sliced(1); ++finalDest; - --l; } returnText.truncate(finalDest); return returnText; @@ -769,6 +866,11 @@ unsigned QPlatformThemePrivate::currentKeyPlatforms() return result; } +QString QPlatformTheme::name() const +{ + return d_func()->name; +} + QT_END_NAMESPACE #include "moc_qplatformtheme.cpp" |