From dff3843d98d52e2c32fea07371f91117de0667e9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 18 Oct 2019 09:07:37 +0200 Subject: QShortcut: Properly port to the new configure system Move the feature to corelib so that the QMetaType enumeration values can be properly excluded and there is no need for a dummy class. Use QT_REQUIRE_CONFIG in the headers of classes to be disabled. Add headers/source files in the .pro file depending on the configure feature in libraries and tests. Add the necessary exclusions and use QT_CONFIG. Task-number: QTBUG-76493 Change-Id: I02499ebee1a3d6d9a1e5afd02517beed5f4536b7 Reviewed-by: Mitch Curtis --- src/corelib/configure.json | 6 +++ src/corelib/global/qconfig-bootstrapped.h | 1 + src/corelib/io/qsettings.cpp | 5 +- src/corelib/kernel/qmetatype.h | 9 +++- src/corelib/kernel/qvariant.cpp | 19 ++++++-- src/corelib/kernel/qvariant.h | 2 + src/gui/configure.json | 6 --- src/gui/kernel/kernel.pri | 15 ++++-- src/gui/kernel/qevent.cpp | 10 ++-- src/gui/kernel/qevent.h | 12 +++-- src/gui/kernel/qguiapplication_p.h | 7 ++- src/gui/kernel/qguivariant.cpp | 10 ++-- src/gui/kernel/qkeymapper_p.h | 1 - src/gui/kernel/qkeysequence.cpp | 5 -- src/gui/kernel/qkeysequence.h | 16 +------ src/gui/kernel/qkeysequence_p.h | 4 +- src/gui/kernel/qplatformmenu.h | 6 ++- src/gui/kernel/qplatformtheme.cpp | 8 ++-- src/gui/kernel/qplatformtheme.h | 8 +++- src/gui/kernel/qplatformtheme_p.h | 6 ++- src/gui/kernel/qshortcutmap.cpp | 4 -- src/gui/kernel/qshortcutmap_p.h | 6 +-- src/gui/kernel/qwindowsysteminterface.cpp | 4 +- .../themes/genericunix/dbusmenu/qdbusmenutypes.cpp | 4 +- .../genericunix/dbusmenu/qdbusplatformmenu_p.h | 4 +- src/testlib/qtestkeyboard.h | 4 +- src/widgets/dialogs/qfiledialog.cpp | 8 +++- src/widgets/dialogs/qprogressdialog.cpp | 4 +- src/widgets/kernel/kernel.pri | 9 ++-- src/widgets/kernel/qaction.cpp | 4 +- src/widgets/kernel/qaction.h | 4 +- src/widgets/kernel/qshortcut.cpp | 2 - src/widgets/kernel/qshortcut.h | 7 +-- src/widgets/kernel/qwidget.h | 4 +- src/widgets/widgets/qabstractbutton.h | 4 +- src/widgets/widgets/qlineedit.cpp | 2 +- src/widgets/widgets/qmenu.cpp | 26 +++++++---- src/widgets/widgets/qmenu.h | 54 ++++++++++++++-------- src/widgets/widgets/qwidgettextcontrol.cpp | 2 +- 39 files changed, 189 insertions(+), 123 deletions(-) (limited to 'src') diff --git a/src/corelib/configure.json b/src/corelib/configure.json index b4b7c4eec3..1c3e874c04 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -826,6 +826,12 @@ ], "output": [ "publicFeature", "feature" ] }, + "shortcut": { + "label": "QShortcut", + "purpose": "Provides keyboard accelerators and shortcuts.", + "section": "Kernel", + "output": [ "publicFeature", "feature" ] + }, "systemsemaphore": { "label": "QSystemSemaphore", "purpose": "Provides a general counting system semaphore.", diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index e9383ca68b..da3a1a005f 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -110,6 +110,7 @@ # define QT_FEATURE_renameat2 -1 #endif #define QT_FEATURE_sharedmemory -1 +#define QT_FEATURE_shortcut -1 #define QT_FEATURE_signaling_nan -1 #define QT_FEATURE_slog2 -1 #ifdef __GLIBC_PREREQ diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index fc7122d904..e485310e86 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -420,7 +420,10 @@ QString QSettingsPrivate::variantToString(const QVariant &v) case QVariant::UInt: case QVariant::Bool: case QVariant::Double: - case QVariant::KeySequence: { +#if QT_CONFIG(shortcut) + case QVariant::KeySequence: +#endif + { result = v.toString(); if (result.contains(QChar::Null)) result = QLatin1String("@String(") + result + QLatin1Char(')'); diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 94a32cec02..d04f327223 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -151,6 +151,13 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId(); F(QVariantHash, 28, QVariantHash) \ F(QByteArrayList, 49, QByteArrayList) \ +#if QT_CONFIG(shortcut) +#define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F)\ + F(QKeySequence, 75, QKeySequence) +#else +#define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F) +#endif + #define QT_FOR_EACH_STATIC_GUI_CLASS(F)\ F(QFont, 64, QFont) \ F(QPixmap, 65, QPixmap) \ @@ -163,7 +170,7 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId(); F(QRegion, 72, QRegion) \ F(QBitmap, 73, QBitmap) \ F(QCursor, 74, QCursor) \ - F(QKeySequence, 75, QKeySequence) \ + QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F) \ F(QPen, 76, QPen) \ F(QTextLength, 77, QTextLength) \ F(QTextFormat, 78, QTextFormat) \ diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 705cae6cf4..449adf0bab 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -2469,7 +2469,9 @@ static const ushort mapIdFromQt3ToCurrent[MapFromThreeCount] = QVariant::DateTime, QVariant::ByteArray, QVariant::BitArray, +#if QT_CONFIG(shortcut) QVariant::KeySequence, +#endif QVariant::Pen, QVariant::LongLong, QVariant::ULongLong, @@ -2574,7 +2576,11 @@ void QVariant::save(QDataStream &s) const typeId += 97; } else if (typeId == QMetaType::QSizePolicy) { typeId = 75; +#if QT_CONFIG(shortcut) } else if (typeId >= QMetaType::QKeySequence && typeId <= QMetaType::QQuaternion) { +#else + } else if (typeId >= QMetaType::QPen && typeId <= QMetaType::QQuaternion) { +#endif // and as a result these types received lower ids too typeId +=1; } else if (typeId == QMetaType::QPolygonF) { @@ -3647,9 +3653,11 @@ bool QVariant::canConvert(int targetTypeId) const if (currentType > int(QMetaType::QUuid) || targetTypeId > int(QMetaType::QUuid)) { switch (uint(targetTypeId)) { case QVariant::Int: +#if QT_CONFIG(shortcut) if (currentType == QVariant::KeySequence) return true; Q_FALLTHROUGH(); +#endif case QVariant::UInt: case QVariant::LongLong: case QVariant::ULongLong: @@ -3672,11 +3680,16 @@ bool QVariant::canConvert(int targetTypeId) const return currentType == QVariant::Color || currentType == QMetaType::Nullptr || ((QMetaType::typeFlags(currentType) & QMetaType::IsEnumeration) && QMetaType::metaObjectForType(currentType)); case QVariant::String: - return currentType == QVariant::KeySequence || currentType == QVariant::Font - || currentType == QVariant::Color || currentType == QMetaType::Nullptr - || ((QMetaType::typeFlags(currentType) & QMetaType::IsEnumeration) && QMetaType::metaObjectForType(currentType)); + return currentType == QVariant::Font + || currentType == QVariant::Color || currentType == QMetaType::Nullptr +#if QT_CONFIG(shortcut) + || currentType == QVariant::KeySequence +#endif + || ((QMetaType::typeFlags(currentType) & QMetaType::IsEnumeration) && QMetaType::metaObjectForType(currentType)); +#if QT_CONFIG(shortcut) case QVariant::KeySequence: return currentType == QVariant::String || currentType == QVariant::Int; +#endif case QVariant::Font: return currentType == QVariant::String; case QVariant::Color: diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 86c7414704..331adea4e7 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -184,7 +184,9 @@ class Q_CORE_EXPORT QVariant Region = QMetaType::QRegion, Bitmap = QMetaType::QBitmap, Cursor = QMetaType::QCursor, +#if QT_CONFIG(shortcut) KeySequence = QMetaType::QKeySequence, +#endif Pen = QMetaType::QPen, TextLength = QMetaType::QTextLength, TextFormat = QMetaType::QTextFormat, diff --git a/src/gui/configure.json b/src/gui/configure.json index 39b8d0c2b8..90d0c8c134 100644 --- a/src/gui/configure.json +++ b/src/gui/configure.json @@ -1637,12 +1637,6 @@ "condition": "features.imageformat_xpm", "output": [ "publicFeature", "feature" ] }, - "shortcut": { - "label": "QShortcut", - "purpose": "Provides keyboard accelerators and shortcuts.", - "section": "Kernel", - "output": [ "publicFeature", "feature" ] - }, "action": { "label": "QAction", "purpose": "Provides widget actions.", diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 9c80f1e2cc..237a1c0a3f 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -48,11 +48,8 @@ HEADERS += \ kernel/qinputmethod.h \ kernel/qinputmethod_p.h \ kernel/qinternalmimedata_p.h \ - kernel/qkeysequence.h \ - kernel/qkeysequence_p.h \ kernel/qkeymapper_p.h \ kernel/qpalette.h \ - kernel/qshortcutmap_p.h \ kernel/qsessionmanager.h \ kernel/qsessionmanager_p.h \ kernel/qwindowdefs.h \ @@ -108,12 +105,10 @@ SOURCES += \ kernel/qevent.cpp \ kernel/qinputmethod.cpp \ kernel/qinternalmimedata.cpp \ - kernel/qkeysequence.cpp \ kernel/qkeymapper.cpp \ kernel/qpalette.cpp \ kernel/qguivariant.cpp \ kernel/qscreen.cpp \ - kernel/qshortcutmap.cpp \ kernel/qstylehints.cpp \ kernel/qtouchdevice.cpp \ kernel/qplatformsharedgraphicscache.cpp \ @@ -160,4 +155,14 @@ qtConfig(opengl) { kernel/qopenglwindow.cpp } +qtConfig(shortcut) { + HEADERS += \ + kernel/qshortcutmap_p.h \ + kernel/qkeysequence.h \ + kernel/qkeysequence_p.h + SOURCES += \ + kernel/qshortcutmap.cpp \ + kernel/qkeysequence.cpp +} + win32:HEADERS+=kernel/qwindowdefs_win.h diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index f2f083c277..54502bc6a3 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1224,7 +1224,7 @@ Qt::KeyboardModifiers QKeyEvent::modifiers() const return QInputEvent::modifiers(); } -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) /*! \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const \since 4.2 @@ -1240,7 +1240,7 @@ bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const const QList bindings = QKeySequence::keyBindings(matchKey); return bindings.contains(QKeySequence(searchkey)); } -#endif // QT_NO_SHORTCUT +#endif // QT_CONFIG(shortcut) /*! @@ -3581,7 +3581,7 @@ QToolBarChangeEvent::~QToolBarChangeEvent() #endif // QT_NO_TOOLBAR -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) /*! Constructs a shortcut event for the given \a key press, @@ -3602,7 +3602,7 @@ QShortcutEvent::~QShortcutEvent() { } -#endif // QT_NO_SHORTCUT +#endif // QT_CONFIG(shortcut) #ifndef QT_NO_DEBUG_STREAM @@ -3956,7 +3956,7 @@ QT_WARNING_POP dbg << ')'; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QEvent::Shortcut: { const QShortcutEvent *se = static_cast(e); dbg << "QShortcutEvent(" << se->key().toString() << ", id=" << se->shortcutId(); diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 8a0e42f592..28aa78a420 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -45,7 +45,9 @@ #include #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #include #include #include // ### Qt 6: Remove @@ -375,7 +377,7 @@ public: ~QKeyEvent(); int key() const { return k; } -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) bool matches(QKeySequence::StandardKey key) const; #endif Qt::KeyboardModifiers modifiers() const; @@ -792,7 +794,7 @@ private: }; #endif -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) class Q_GUI_EXPORT QShortcutEvent : public QEvent { public: @@ -827,10 +829,10 @@ private: Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *); #endif -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? e->matches(key) : false);} inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);} -#endif // QT_NO_SHORTCUT +#endif // QT_CONFIG(shortcut) class Q_GUI_EXPORT QPointingDeviceUniqueId { diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index e28607bad6..73d137619e 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -62,7 +62,10 @@ #include #include -#include "private/qshortcutmap_p.h" +#if QT_CONFIG(shortcut) +# include "private/qshortcutmap_p.h" +#endif + #include QT_BEGIN_NAMESPACE @@ -261,7 +264,7 @@ public: QIcon forcedWindowIcon; static QList generic_plugin_list; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) QShortcutMap shortcutMap; #endif diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index edca8d9423..2d6d12cc21 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -44,7 +44,9 @@ #include "qcursor.h" #include "qfont.h" #include "qimage.h" -#include "qkeysequence.h" +#if QT_CONFIG(shortcut) +# include "qkeysequence.h" +#endif #include "qtransform.h" #include "qmatrix.h" #include "qpalette.h" @@ -188,7 +190,7 @@ static bool convert(const QVariant::Private *d, int t, case QVariant::String: { QString *str = static_cast(result); switch (d->type) { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QVariant::KeySequence: *str = (*v_cast(d)).toString(QKeySequence::NativeText); return true; @@ -238,7 +240,7 @@ static bool convert(const QVariant::Private *d, int t, return true; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QVariant::Int: if (d->type == QVariant::KeySequence) { const QKeySequence &seq = *v_cast(d); @@ -277,7 +279,7 @@ static bool convert(const QVariant::Private *d, int t, return true; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QVariant::KeySequence: { QKeySequence *seq = static_cast(result); switch (d->type) { diff --git a/src/gui/kernel/qkeymapper_p.h b/src/gui/kernel/qkeymapper_p.h index 8364557020..fd53747fdd 100644 --- a/src/gui/kernel/qkeymapper_p.h +++ b/src/gui/kernel/qkeymapper_p.h @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index 2a86b340af..25766467eb 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -42,8 +42,6 @@ #include #include "private/qguiapplication_p.h" -#if !defined(QT_NO_SHORTCUT) || defined(Q_CLANG_QDOC) - #include "qdebug.h" #include #ifndef QT_NO_DATASTREAM @@ -1673,9 +1671,6 @@ QDebug operator<<(QDebug dbg, const QKeySequence &p) } #endif -#endif // QT_NO_SHORTCUT - - /*! \typedef QKeySequence::DataPtr \internal diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h index 3dcbbe5941..68f256c37a 100644 --- a/src/gui/kernel/qkeysequence.h +++ b/src/gui/kernel/qkeysequence.h @@ -44,10 +44,9 @@ #include #include -QT_BEGIN_NAMESPACE - +QT_REQUIRE_CONFIG(shortcut); -#if !defined(QT_NO_SHORTCUT) || defined(Q_CLANG_QDOC) +QT_BEGIN_NAMESPACE class QKeySequence; @@ -227,17 +226,6 @@ Q_DECLARE_SHARED(QKeySequence) Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &); #endif -#else - -class Q_GUI_EXPORT QKeySequence -{ -public: - QKeySequence() {} - QKeySequence(int) {} -}; - -#endif // QT_NO_SHORTCUT - QT_END_NAMESPACE #endif // QKEYSEQUENCE_H diff --git a/src/gui/kernel/qkeysequence_p.h b/src/gui/kernel/qkeysequence_p.h index fbcab5d34e..8c59505561 100644 --- a/src/gui/kernel/qkeysequence_p.h +++ b/src/gui/kernel/qkeysequence_p.h @@ -56,9 +56,10 @@ #include +QT_REQUIRE_CONFIG(shortcut); + QT_BEGIN_NAMESPACE -#ifndef QT_NO_SHORTCUT struct QKeyBinding { QKeySequence::StandardKey standardKey; @@ -87,7 +88,6 @@ public: Q_GUI_EXPORT static QString keyName(int key, QKeySequence::SequenceFormat format); static int decodeString(QString accel, QKeySequence::SequenceFormat format); }; -#endif // QT_NO_SHORTCUT QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h index 28c29a704c..8e470aefd3 100644 --- a/src/gui/kernel/qplatformmenu.h +++ b/src/gui/kernel/qplatformmenu.h @@ -52,7 +52,9 @@ #include #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #include QT_BEGIN_NAMESPACE @@ -85,7 +87,7 @@ public: virtual void setRole(MenuRole role) = 0; virtual void setCheckable(bool checkable) = 0; virtual void setChecked(bool isChecked) = 0; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) virtual void setShortcut(const QKeySequence& shortcut) = 0; #endif virtual void setEnabled(bool enabled) = 0; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index f906f808d8..ff6f32de10 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -167,7 +167,7 @@ QT_BEGIN_NAMESPACE */ -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) // Table of key bindings. It must be sorted on key sequence: // The integer value of VK_KEY | Modifier Keys (e.g., VK_META, and etc.) // A priority of 1 indicates that this is the primary key binding when multiple are defined. @@ -623,7 +623,7 @@ static inline int maybeSwapShortcut(int shortcut) } #endif -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) // mixed-mode predicate: all of these overloads are actually needed (but not all for every compiler) struct ByStandardKey { typedef bool result_type; @@ -688,6 +688,7 @@ QString QPlatformTheme::standardButtonText(int button) const return QPlatformTheme::defaultStandardButtonText(button); } +#if QT_CONFIG(shortcut) /*! Returns the mnemonic that should be used for a standard \a button. @@ -700,6 +701,7 @@ QKeySequence QPlatformTheme::standardButtonShortcut(int button) const Q_UNUSED(button) return QKeySequence(); } +#endif // QT_CONFIG(shortcut) QString QPlatformTheme::defaultStandardButtonText(int button) { @@ -784,7 +786,7 @@ unsigned QPlatformThemePrivate::currentKeyPlatforms() { const uint keyboardScheme = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt(); unsigned result = 1u << keyboardScheme; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) if (keyboardScheme == QPlatformTheme::KdeKeyboardScheme || keyboardScheme == QPlatformTheme::GnomeKeyboardScheme || keyboardScheme == QPlatformTheme::CdeKeyboardScheme) diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 356c4ea3ea..7b88af954c 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -51,7 +51,9 @@ #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif QT_BEGIN_NAMESPACE @@ -312,12 +314,14 @@ public: QPlatformTheme::IconOptions iconOptions = nullptr) const; virtual QIconEngine *createIconEngine(const QString &iconName) const; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) virtual QList keyBindings(QKeySequence::StandardKey key) const; #endif virtual QString standardButtonText(int button) const; +#if QT_CONFIG(shortcut) virtual QKeySequence standardButtonShortcut(int button) const; +#endif static QVariant defaultThemeHint(ThemeHint hint); static QString defaultStandardButtonText(int button); diff --git a/src/gui/kernel/qplatformtheme_p.h b/src/gui/kernel/qplatformtheme_p.h index 73deb890bb..2c16fec141 100644 --- a/src/gui/kernel/qplatformtheme_p.h +++ b/src/gui/kernel/qplatformtheme_p.h @@ -52,7 +52,9 @@ // #include -#include "private/qkeysequence_p.h" +#if QT_CONFIG(shortcut) +# include "private/qkeysequence_p.h" +#endif QT_BEGIN_NAMESPACE @@ -67,7 +69,7 @@ public: void initializeSystemPalette(); -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) static const QKeyBinding keyBindings[]; static const uint numberOfKeyBindings; #endif diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index 0395c1db38..b5cd342138 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -48,8 +48,6 @@ #include -#ifndef QT_NO_SHORTCUT - QT_BEGIN_NAMESPACE // To enable verbose output uncomment below @@ -714,5 +712,3 @@ void QShortcutMap::dumpMap() const #endif QT_END_NAMESPACE - -#endif // QT_NO_SHORTCUT diff --git a/src/gui/kernel/qshortcutmap_p.h b/src/gui/kernel/qshortcutmap_p.h index 8fc68229fb..aa3dd969f0 100644 --- a/src/gui/kernel/qshortcutmap_p.h +++ b/src/gui/kernel/qshortcutmap_p.h @@ -56,9 +56,9 @@ #include "QtCore/qvector.h" #include "QtCore/qscopedpointer.h" -QT_BEGIN_NAMESPACE +QT_REQUIRE_CONFIG(shortcut); -#ifndef QT_NO_SHORTCUT +QT_BEGIN_NAMESPACE // To enable dump output uncomment below //#define Dump_QShortcutMap @@ -106,8 +106,6 @@ private: QScopedPointer d_ptr; }; -#endif // QT_NO_SHORTCUT - QT_END_NAMESPACE #endif // QSHORTCUTMAP_P_H diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 5f61853a6d..5ae8013b82 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -434,7 +434,7 @@ void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, ulong t bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestamp, int keyCode, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text, bool autorepeat, ushort count) { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) if (!window) window = QGuiApplication::focusWindow(); @@ -1238,7 +1238,7 @@ Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt:: Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text = QString(), bool autorep = false, ushort count = 1) { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) // FIXME: This method should not allow targeting a specific object, but should // instead forward the event to a window, which then takes care of normal event diff --git a/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenutypes.cpp b/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenutypes.cpp index 82a13d2fa0..a3c9746869 100644 --- a/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenutypes.cpp +++ b/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenutypes.cpp @@ -48,7 +48,9 @@ #include #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #include #include "qdbusplatformmenu_p.h" diff --git a/src/platformsupport/themes/genericunix/dbusmenu/qdbusplatformmenu_p.h b/src/platformsupport/themes/genericunix/dbusmenu/qdbusplatformmenu_p.h index 8a31f82fb0..aa0f303416 100644 --- a/src/platformsupport/themes/genericunix/dbusmenu/qdbusplatformmenu_p.h +++ b/src/platformsupport/themes/genericunix/dbusmenu/qdbusplatformmenu_p.h @@ -96,7 +96,7 @@ public: void setChecked(bool isChecked) override; bool hasExclusiveGroup() const { return m_hasExclusiveGroup; } void setHasExclusiveGroup(bool hasExclusiveGroup) override; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) QKeySequence shortcut() const { return m_shortcut; } void setShortcut(const QKeySequence& shortcut) override; #endif @@ -123,7 +123,9 @@ private: bool m_hasExclusiveGroup : 1; short /*unused*/ : 6; short m_dbusID : 16; +#if QT_CONFIG(shortcut) QKeySequence m_shortcut; +#endif }; class QDBusPlatformMenu : public QPlatformMenu diff --git a/src/testlib/qtestkeyboard.h b/src/testlib/qtestkeyboard.h index e8a7e0d5f5..1882c858c1 100644 --- a/src/testlib/qtestkeyboard.h +++ b/src/testlib/qtestkeyboard.h @@ -54,7 +54,9 @@ #include #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #ifdef QT_WIDGETS_LIB #include diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index a1b9003c1c..65434c96f9 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -49,7 +49,9 @@ #include #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #include #if QT_CONFIG(menu) #include @@ -344,7 +346,9 @@ Q_GLOBAL_STATIC(QUrl, lastVisitedDir) QT_BEGIN_INCLUDE_NAMESPACE #include -#include +#if QT_CONFIG(shortcut) +# include +#endif QT_END_INCLUDE_NAMESPACE /*! diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index e1a6bce5b1..20f89e132a 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -39,7 +39,9 @@ #include "qprogressdialog.h" -#include "qshortcut.h" +#if QT_CONFIG(shortcut) +# include "qshortcut.h" +#endif #include "qpainter.h" #include "qdrawutil.h" #include "qlabel.h" diff --git a/src/widgets/kernel/kernel.pri b/src/widgets/kernel/kernel.pri index 693af7eb80..8115741b6e 100644 --- a/src/widgets/kernel/kernel.pri +++ b/src/widgets/kernel/kernel.pri @@ -20,8 +20,7 @@ HEADERS += \ kernel/qlayout_p.h \ kernel/qlayoutengine_p.h \ kernel/qlayoutitem.h \ - kernel/qshortcut.h \ - kernel/qsizepolicy.h \ + kernel/qsizepolicy.h \ kernel/qstackedlayout.h \ kernel/qwidget.h \ kernel/qwidget_p.h \ @@ -47,7 +46,6 @@ SOURCES += \ kernel/qlayout.cpp \ kernel/qlayoutengine.cpp \ kernel/qlayoutitem.cpp \ - kernel/qshortcut.cpp \ kernel/qsizepolicy.cpp \ kernel/qstackedlayout.cpp \ kernel/qwidget.cpp \ @@ -77,6 +75,11 @@ qtConfig(formlayout) { SOURCES += kernel/qformlayout.cpp } +qtConfig(shortcut) { + HEADERS += kernel/qshortcut.h + SOURCES += kernel/qshortcut.cpp +} + qtConfig(tooltip) { HEADERS += kernel/qtooltip.h SOURCES += kernel/qtooltip.cpp diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp index 19ad65692b..e69474cc47 100644 --- a/src/widgets/kernel/qaction.cpp +++ b/src/widgets/kernel/qaction.cpp @@ -46,7 +46,9 @@ #include "qevent.h" #include "qlist.h" #include "qstylehints.h" -#include +#if QT_CONFIG(shortcut) +# include +#endif #include #if QT_CONFIG(menu) #include diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction.h index f7693f4dde..d232b8d205 100644 --- a/src/widgets/kernel/qaction.h +++ b/src/widgets/kernel/qaction.h @@ -41,7 +41,9 @@ #define QACTION_H #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #include #include #include diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index eec65c8625..49440ad383 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -40,7 +40,6 @@ #include "qshortcut.h" #include "private/qwidget_p.h" -#ifndef QT_NO_SHORTCUT #include #if QT_CONFIG(whatsthis) #include @@ -676,7 +675,6 @@ bool QShortcut::event(QEvent *e) } return QObject::event(e); } -#endif // QT_NO_SHORTCUT QT_END_NAMESPACE diff --git a/src/widgets/kernel/qshortcut.h b/src/widgets/kernel/qshortcut.h index 6dcf4971b2..6334788bce 100644 --- a/src/widgets/kernel/qshortcut.h +++ b/src/widgets/kernel/qshortcut.h @@ -44,10 +44,9 @@ #include #include -QT_BEGIN_NAMESPACE - +QT_REQUIRE_CONFIG(shortcut); -#ifndef QT_NO_SHORTCUT +QT_BEGIN_NAMESPACE class QShortcutPrivate; class Q_WIDGETS_EXPORT QShortcut : public QObject @@ -94,8 +93,6 @@ protected: bool event(QEvent *e) override; }; -#endif // QT_NO_SHORTCUT - QT_END_NAMESPACE #endif // QSHORTCUT_H diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index 83a6e6d4b3..86f937c4c6 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -53,7 +53,9 @@ #include #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #ifdef QT_INCLUDE_COMPAT #include diff --git a/src/widgets/widgets/qabstractbutton.h b/src/widgets/widgets/qabstractbutton.h index e8dee142f2..c6f6e4c546 100644 --- a/src/widgets/widgets/qabstractbutton.h +++ b/src/widgets/widgets/qabstractbutton.h @@ -42,7 +42,9 @@ #include #include -#include +#if QT_CONFIG(shortcut) +# include +#endif #include QT_REQUIRE_CONFIG(abstractbutton); diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index fb67936768..a5499c8ce8 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -78,7 +78,7 @@ #endif #include "private/qstylesheetstyle_p.h" -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include "qkeysequence.h" diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 51b458f03a..8f03889db6 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -403,7 +403,9 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const //calculate size QFontMetrics qfm = q->fontMetrics(); bool previousWasSeparator = true; // this is true to allow removing the leading separators +#if QT_CONFIG(shortcut) const bool contextMenu = isContextMenu(); +#endif for(int i = 0; i <= lastVisibleAction; i++) { QAction *action = actions.at(i); const bool isSection = action->isSeparator() && (!action->text().isEmpty() || !action->icon().isNull()); @@ -434,12 +436,12 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const if (t != -1) { tabWidth = qMax(int(tabWidth), qfm.horizontalAdvance(s.mid(t+1))); s = s.left(t); - #ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) } else if (action->isShortcutVisibleInContextMenu() || !contextMenu) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) tabWidth = qMax(int(tabWidth), qfm.horizontalAdvance(seq.toString(QKeySequence::NativeText))); - #endif +#endif } sz.setWidth(fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, s).width()); sz.setHeight(qMax(fm.height(), qfm.height())); @@ -1767,12 +1769,14 @@ QAction *QMenu::addAction(const QIcon &icon, const QString &text) \sa QWidget::addAction() */ -QAction *QMenu::addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut) +QAction *QMenu::addAction(const QString &text, const QObject *receiver, const char* member +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut +#endif + ) { QAction *action = new QAction(text, this); -#ifdef QT_NO_SHORTCUT - Q_UNUSED(shortcut); -#else +#if QT_CONFIG(shortcut) action->setShortcut(shortcut); #endif QObject::connect(action, SIGNAL(triggered(bool)), receiver, member); @@ -1860,12 +1864,14 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch \sa QWidget::addAction() */ QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, - const char* member, const QKeySequence &shortcut) + const char* member +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut +#endif + ) { QAction *action = new QAction(icon, text, this); -#ifdef QT_NO_SHORTCUT - Q_UNUSED(shortcut); -#else +#if QT_CONFIG(shortcut) action->setShortcut(shortcut); #endif QObject::connect(action, SIGNAL(triggered(bool)), receiver, member); diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index 84ab9e027a..35d5a865ff 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -78,8 +78,17 @@ public: using QWidget::addAction; QAction *addAction(const QString &text); QAction *addAction(const QIcon &icon, const QString &text); - QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); - QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); + + QAction *addAction(const QString &text, const QObject *receiver, const char* member +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut = {} +#endif + ); + QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut = {} +#endif + ); #ifdef Q_CLANG_QDOC template @@ -95,12 +104,14 @@ public: template inline typename std::enable_if::value && QtPrivate::IsPointerToTypeDerivedFromQObject::Value, QAction *>::type - addAction(const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) + addAction(const QString &text, const Obj *object, Func1 slot +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut = {} +#endif + ) { QAction *result = addAction(text); -#ifdef QT_NO_SHORTCUT - Q_UNUSED(shortcut) -#else +#if QT_CONFIG(shortcut) result->setShortcut(shortcut); #endif connect(result, &QAction::triggered, object, std::move(slot)); @@ -108,12 +119,14 @@ public: } // addAction(QString): Connect to a functor or function pointer (without context) template - inline QAction *addAction(const QString &text, Func1 slot, const QKeySequence &shortcut = 0) + inline QAction *addAction(const QString &text, Func1 slot +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut = {} +#endif + ) { QAction *result = addAction(text); -#ifdef QT_NO_SHORTCUT - Q_UNUSED(shortcut) -#else +#if QT_CONFIG(shortcut) result->setShortcut(shortcut); #endif connect(result, &QAction::triggered, std::move(slot)); @@ -123,12 +136,15 @@ public: template inline typename std::enable_if::value && QtPrivate::IsPointerToTypeDerivedFromQObject::Value, QAction *>::type - addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) + addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut = {} +#endif + ) + { QAction *result = addAction(actionIcon, text); -#ifdef QT_NO_SHORTCUT - Q_UNUSED(shortcut) -#else +#if QT_CONFIG(shortcut) result->setShortcut(shortcut); #endif connect(result, &QAction::triggered, object, std::move(slot)); @@ -136,12 +152,14 @@ public: } // addAction(QIcon, QString): Connect to a functor or function pointer (without context) template - inline QAction *addAction(const QIcon &actionIcon, const QString &text, Func1 slot, const QKeySequence &shortcut = 0) + inline QAction *addAction(const QIcon &actionIcon, const QString &text, Func1 slot +#if QT_CONFIG(shortcut) + , const QKeySequence &shortcut = {} +#endif + ) { QAction *result = addAction(actionIcon, text); -#ifdef QT_NO_SHORTCUT - Q_UNUSED(shortcut) -#else +#if QT_CONFIG(shortcut) result->setShortcut(shortcut); #endif connect(result, &QAction::triggered, std::move(slot)); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index dce18f9100..be4abf1ae2 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -92,7 +92,7 @@ #include #include -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include -- cgit v1.2.3