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 <mitch.curtis@qt.io>
This commit is contained in:
Friedemann Kleint 2019-10-18 09:07:37 +02:00
parent 5d5a0842dc
commit dff3843d98
64 changed files with 416 additions and 143 deletions

View File

@ -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.",

View File

@ -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

View File

@ -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(')');

View File

@ -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) \

View File

@ -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:

View File

@ -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,

View File

@ -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.",

View File

@ -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

View File

@ -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<QKeySequence> 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<const QShortcutEvent *>(e);
dbg << "QShortcutEvent(" << se->key().toString() << ", id=" << se->shortcutId();

View File

@ -45,7 +45,9 @@
#include <QtGui/qregion.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qstring.h>
#include <QtGui/qkeysequence.h>
#if QT_CONFIG(shortcut)
# include <QtGui/qkeysequence.h>
#endif
#include <QtCore/qcoreevent.h>
#include <QtCore/qvariant.h>
#include <QtCore/qmap.h> // ### 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
{

View File

@ -62,7 +62,10 @@
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qwindowsysteminterface_p.h>
#include "private/qshortcutmap_p.h"
#if QT_CONFIG(shortcut)
# include "private/qshortcutmap_p.h"
#endif
#include <qicon.h>
QT_BEGIN_NAMESPACE
@ -261,7 +264,7 @@ public:
QIcon forcedWindowIcon;
static QList<QObject *> generic_plugin_list;
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
QShortcutMap shortcutMap;
#endif

View File

@ -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<QString *>(result);
switch (d->type) {
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
case QVariant::KeySequence:
*str = (*v_cast<QKeySequence>(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<QKeySequence>(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<QKeySequence *>(result);
switch (d->type) {

View File

@ -53,7 +53,6 @@
#include <QtGui/private/qtguiglobal_p.h>
#include <qobject.h>
#include <private/qobject_p.h>
#include <qkeysequence.h>
#include <qlist.h>
#include <qlocale.h>
#include <qevent.h>

View File

@ -42,8 +42,6 @@
#include <qpa/qplatformtheme.h>
#include "private/qguiapplication_p.h"
#if !defined(QT_NO_SHORTCUT) || defined(Q_CLANG_QDOC)
#include "qdebug.h"
#include <QtCore/qhashfunctions.h>
#ifndef QT_NO_DATASTREAM
@ -1673,9 +1671,6 @@ QDebug operator<<(QDebug dbg, const QKeySequence &p)
}
#endif
#endif // QT_NO_SHORTCUT
/*!
\typedef QKeySequence::DataPtr
\internal

View File

@ -44,11 +44,10 @@
#include <QtCore/qstring.h>
#include <QtCore/qobjectdefs.h>
QT_REQUIRE_CONFIG(shortcut);
QT_BEGIN_NAMESPACE
#if !defined(QT_NO_SHORTCUT) || defined(Q_CLANG_QDOC)
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

View File

@ -56,9 +56,10 @@
#include <algorithm>
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

View File

@ -52,7 +52,9 @@
#include <QtGui/qtguiglobal.h>
#include <QtCore/qpointer.h>
#include <QtGui/QFont>
#include <QtGui/QKeySequence>
#if QT_CONFIG(shortcut)
# include <QtGui/QKeySequence>
#endif
#include <QtGui/QIcon>
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;

View File

@ -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)

View File

@ -51,7 +51,9 @@
#include <QtGui/qtguiglobal.h>
#include <QtCore/QScopedPointer>
#include <QtGui/QKeySequence>
#if QT_CONFIG(shortcut)
# include <QtGui/QKeySequence>
#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<QKeySequence> 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);

View File

@ -52,7 +52,9 @@
//
#include <QtGui/private/qtguiglobal_p.h>
#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

View File

@ -48,8 +48,6 @@
#include <algorithm>
#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

View File

@ -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<QShortcutMapPrivate> d_ptr;
};
#endif // QT_NO_SHORTCUT
QT_END_NAMESPACE
#endif // QSHORTCUTMAP_P_H

View File

@ -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

View File

@ -48,7 +48,9 @@
#include <QDebug>
#include <QtEndian>
#include <QBuffer>
#include <private/qkeysequence_p.h>
#if QT_CONFIG(shortcut)
# include <private/qkeysequence_p.h>
#endif
#include <qpa/qplatformmenu.h>
#include "qdbusplatformmenu_p.h"

View File

@ -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

View File

@ -54,7 +54,9 @@
#include <QtGui/qguiapplication.h>
#include <QtGui/qwindow.h>
#include <QtGui/qevent.h>
#include <QtGui/qkeysequence.h>
#if QT_CONFIG(shortcut)
# include <QtGui/qkeysequence.h>
#endif
#ifdef QT_WIDGETS_LIB
#include <QtWidgets/qwidget.h>

View File

@ -49,7 +49,9 @@
#include <qfontmetrics.h>
#include <qaction.h>
#include <qheaderview.h>
#include <qshortcut.h>
#if QT_CONFIG(shortcut)
# include <qshortcut.h>
#endif
#include <qgridlayout.h>
#if QT_CONFIG(menu)
#include <qmenu.h>
@ -344,7 +346,9 @@ Q_GLOBAL_STATIC(QUrl, lastVisitedDir)
QT_BEGIN_INCLUDE_NAMESPACE
#include <QMetaEnum>
#include <qshortcut.h>
#if QT_CONFIG(shortcut)
# include <qshortcut.h>
#endif
QT_END_INCLUDE_NAMESPACE
/*!

View File

@ -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"

View File

@ -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

View File

@ -46,7 +46,9 @@
#include "qevent.h"
#include "qlist.h"
#include "qstylehints.h"
#include <private/qshortcutmap_p.h>
#if QT_CONFIG(shortcut)
# include <private/qshortcutmap_p.h>
#endif
#include <private/qguiapplication_p.h>
#if QT_CONFIG(menu)
#include <private/qmenu_p.h>

View File

@ -41,7 +41,9 @@
#define QACTION_H
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtGui/qkeysequence.h>
#if QT_CONFIG(shortcut)
# include <QtGui/qkeysequence.h>
#endif
#include <QtCore/qstring.h>
#include <QtWidgets/qwidget.h>
#include <QtCore/qvariant.h>

View File

@ -40,7 +40,6 @@
#include "qshortcut.h"
#include "private/qwidget_p.h"
#ifndef QT_NO_SHORTCUT
#include <qevent.h>
#if QT_CONFIG(whatsthis)
#include <qwhatsthis.h>
@ -676,7 +675,6 @@ bool QShortcut::event(QEvent *e)
}
return QObject::event(e);
}
#endif // QT_NO_SHORTCUT
QT_END_NAMESPACE

View File

@ -44,11 +44,10 @@
#include <QtWidgets/qwidget.h>
#include <QtGui/qkeysequence.h>
QT_REQUIRE_CONFIG(shortcut);
QT_BEGIN_NAMESPACE
#ifndef QT_NO_SHORTCUT
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

View File

@ -53,7 +53,9 @@
#include <QtGui/qregion.h>
#include <QtGui/qbrush.h>
#include <QtGui/qcursor.h>
#include <QtGui/qkeysequence.h>
#if QT_CONFIG(shortcut)
# include <QtGui/qkeysequence.h>
#endif
#ifdef QT_INCLUDE_COMPAT
#include <QtGui/qevent.h>

View File

@ -42,7 +42,9 @@
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtGui/qicon.h>
#include <QtGui/qkeysequence.h>
#if QT_CONFIG(shortcut)
# include <QtGui/qkeysequence.h>
#endif
#include <QtWidgets/qwidget.h>
QT_REQUIRE_CONFIG(abstractbutton);

View File

@ -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"

View File

@ -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);

View File

@ -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<typename Functor>
@ -95,12 +104,14 @@ public:
template<class Obj, typename Func1>
inline typename std::enable_if<!std::is_same<const char*, Func1>::value
&& QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::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 <typename Func1>
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<class Obj, typename Func1>
inline typename std::enable_if<!std::is_same<const char*, Func1>::value
&& QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::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 <typename Func1>
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));

View File

@ -92,7 +92,7 @@
#include <QtGui/qaccessible.h>
#include <QtCore/qmetaobject.h>
#ifndef QT_NO_SHORTCUT
#if QT_CONFIG(shortcut)
#include "private/qapplication_p.h"
#include "private/qshortcutmap_p.h"
#include <qkeysequence.h>

View File

@ -39,7 +39,9 @@
#include <QtCore/QDir>
#include <QtCore/QThread>
#include <QtCore/QSysInfo>
#include <QtGui/QKeySequence>
#if QT_CONFIG(shortcut)
# include <QtGui/QKeySequence>
#endif
#include <QtCore>
#include <QtGui>
@ -1364,6 +1366,7 @@ void tst_QSettings::testVariantTypes()
dt.setOffsetFromUtc(3600);
testVal("key14", dt, QDateTime, DateTime);
#if QT_CONFIG(shortcut)
// We store key sequences as strings instead of binary variant blob, for improved
// readability in the resulting format.
if (format >= QSettings::InvalidFormat) {
@ -1373,6 +1376,7 @@ void tst_QSettings::testVariantTypes()
QKeySequence(Qt::ControlModifier + Qt::Key_F1).toString(QKeySequence::NativeText),
QString, String);
}
#endif // QT_CONFIG(shortcut)
#undef testVal
}

View File

@ -2327,6 +2327,7 @@ void tst_QDataStream::setVersion()
QDataStream latest;
QFETCH(int, vers);
#if QT_CONFIG(shortcut)
/*
Test QKeySequence.
*/
@ -2351,6 +2352,7 @@ void tst_QDataStream::setVersion()
}
QCOMPARE(deadbeef, 0xDEADBEEF);
}
#endif // QT_CONFIG(shortcut)
/*
Test QPalette.

View File

@ -29,6 +29,11 @@ SUBDIRS=\
win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop
!qtConfig(shortcut): SUBDIRS -= \
qkeysequence \
qguimetatype \
qguivariant
!qtHaveModule(widgets): SUBDIRS -= \
qmouseevent_modal \
qtouchevent

View File

@ -181,9 +181,13 @@ template<> struct TestValueFactory<QMetaType::QCursor> {
static QCursor *create() { return new QCursor(Qt::WaitCursor); }
};
#endif
#if QT_CONFIG(shortcut)
template<> struct TestValueFactory<QMetaType::QKeySequence> {
static QKeySequence *create() { return new QKeySequence(QKeySequence::Close); }
};
#endif
template<> struct TestValueFactory<QMetaType::QPen> {
static QPen *create() { return new QPen(Qt::DashDotDotLine); }
};

View File

@ -64,8 +64,10 @@ public:
private slots:
void basicEventDelivery();
#if QT_CONFIG(shortcut)
void modifiers_data();
void modifiers();
#endif
};
tst_QKeyEvent::tst_QKeyEvent()
@ -128,6 +130,8 @@ static QByteArray modifiersTestRowName(const QString &keySequence)
return result;
}
#if QT_CONFIG(shortcut)
void tst_QKeyEvent::modifiers_data()
{
struct Modifier
@ -198,5 +202,7 @@ void tst_QKeyEvent::modifiers()
}
}
#endif // QT_CONFIG(shortcut)
QTEST_MAIN(tst_QKeyEvent)
#include "tst_qkeyevent.moc"

View File

@ -203,11 +203,15 @@ private slots:
void applicationTest();
void mainWindowTest();
void subWindowTest();
#if QT_CONFIG(shortcut)
void buttonTest();
#endif
void scrollBarTest();
void tabTest();
void tabWidgetTest();
#if QT_CONFIG(shortcut)
void menuTest();
#endif
void spinBoxTest();
void doubleSpinBoxTest();
void textEditTest();
@ -234,8 +238,10 @@ private slots:
void dockWidgetTest();
void comboBoxTest();
void accessibleName();
#if QT_CONFIG(shortcut)
void labelTest();
void accelerators();
#endif
void bridgeTest();
protected slots:
@ -1026,6 +1032,8 @@ public Q_SLOTS:
}
};
#if QT_CONFIG(shortcut)
void tst_QAccessibility::buttonTest()
{
QWidget window;
@ -1198,6 +1206,8 @@ void tst_QAccessibility::buttonTest()
// test->release();
}
#endif // QT_CONFIG(shortcut)
void tst_QAccessibility::scrollBarTest()
{
QScrollBar *scrollBar = new QScrollBar(Qt::Horizontal);
@ -1407,6 +1417,8 @@ void tst_QAccessibility::tabWidgetTest()
QTestAccessibility::clearEvents();
}
#if QT_CONFIG(shortcut)
void tst_QAccessibility::menuTest()
{
{
@ -1617,6 +1629,8 @@ void tst_QAccessibility::menuTest()
QTestAccessibility::clearEvents();
}
#endif // QT_CONFIG(shortcut)
void tst_QAccessibility::spinBoxTest()
{
QSpinBox * const spinBox = new QSpinBox();
@ -3629,6 +3643,8 @@ void tst_QAccessibility::comboBoxTest()
QTestAccessibility::clearEvents();
}
#if QT_CONFIG(shortcut)
void tst_QAccessibility::labelTest()
{
QWidget *window = new QWidget;
@ -3729,6 +3745,8 @@ void tst_QAccessibility::accelerators()
QTestAccessibility::clearEvents();
}
#endif // QT_CONFIG(shortcut)
#ifdef QT_SUPPORTS_IACCESSIBLE2
static IUnknown *queryIA2(IAccessible *acc, const IID &iid)
{

View File

@ -91,7 +91,9 @@ private slots:
void checkReason_BackTab();
void checkReason_Popup();
void checkReason_focusWidget();
#if QT_CONFIG(shortcut)
void checkReason_Shortcut();
#endif
void checkReason_ActiveWindow();
private:
@ -250,6 +252,8 @@ QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
#endif
#if QT_CONFIG(shortcut)
void tst_QFocusEvent::checkReason_Shortcut()
{
initWidget();
@ -288,6 +292,8 @@ void tst_QFocusEvent::checkReason_Shortcut()
#endif
}
#endif // QT_CONFIG(shortcut)
void tst_QFocusEvent::checkReason_focusWidget()
{
// This test checks that a widget doesn't loose

View File

@ -96,8 +96,9 @@ private slots:
void task248107_backButton();
void task255350_fieldObjectDestroyed();
void taskQTBUG_25691_fieldObjectDestroyed2();
#if QT_CONFIG(shortcut)
void taskQTBUG_46894_nextButtonShortcut();
#endif
/*
Things that could be added:
@ -2703,6 +2704,8 @@ void tst_QWizard::taskQTBUG_25691_fieldObjectDestroyed2()
::taskQTBUG_25691_fieldObjectDestroyed2();
}
#if QT_CONFIG(shortcut)
void tst_QWizard::taskQTBUG_46894_nextButtonShortcut()
{
for (int i = 0; i < QWizard::NStyles; ++i) {
@ -2717,5 +2720,7 @@ void tst_QWizard::taskQTBUG_46894_nextButtonShortcut()
}
}
#endif // QT_CONFIG(shortcut)
QTEST_MAIN(tst_QWizard)
#include "tst_qwizard.moc"

View File

@ -450,7 +450,9 @@ private slots:
void modality_keyEvents();
void itemIsInFront();
void scenePosChange();
#if QT_CONFIG(shortcut)
void textItem_shortcuts();
#endif
void scroll();
void focusHandling_data();
void focusHandling();
@ -10813,6 +10815,8 @@ void tst_QGraphicsItem::scenePosChange()
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0);
}
#if QT_CONFIG(shortcut)
void tst_QGraphicsItem::textItem_shortcuts()
{
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
@ -10852,6 +10856,8 @@ void tst_QGraphicsItem::textItem_shortcuts()
QTRY_COMPARE(item->textCursor().selectedText(), item->toPlainText());
}
#endif // QT_CONFIG(shortcut)
void tst_QGraphicsItem::scroll()
{
// Create two overlapping rectangles in the scene:

View File

@ -331,8 +331,10 @@ private slots:
void selectColumn_data();
void selectColumn();
#if QT_CONFIG(shortcut)
void selectall_data();
void selectall();
#endif
void visualRect_data();
void visualRect();
@ -1842,6 +1844,8 @@ void tst_QTableView::selectColumn()
QCOMPARE(view.selectionModel()->selectedIndexes().at(i).column(), column);
}
#if QT_CONFIG(shortcut)
void tst_QTableView::selectall_data()
{
QTest::addColumn<int>("rowCount");
@ -1998,6 +2002,8 @@ void tst_QTableView::selectall()
QCOMPARE(view.selectedIndexes().count(), 0);
}
#endif // QT_CONFIG(shortcut)
void tst_QTableView::visualRect_data()
{
QTest::addColumn<int>("rowCount");

View File

@ -22,3 +22,6 @@ SUBDIRS=\
darwin:SUBDIRS -= \ # Uses native recognizers
qgesturerecognizer \
!qtConfig(shortcut): SUBDIRS -= \
qshortcut

View File

@ -57,18 +57,24 @@ private slots:
void setIconText();
void setUnknownFont();
void actionEvent();
#if QT_CONFIG(shortcut)
void setStandardKeys();
void alternateShortcuts();
void enabledVisibleInteraction();
void task200823_tooltip();
#endif
void task229128TriggeredSignalWithoutActiongroup();
void task229128TriggeredSignalWhenInActiongroup();
#if QT_CONFIG(shortcut)
void repeat();
#endif
void setData();
#if QT_CONFIG(shortcut)
void keysequence(); // QTBUG-53381
void disableShortcutsWithBlockedWidgets_data();
void disableShortcutsWithBlockedWidgets();
void shortcutFromKeyEvent(); // QTBUG-48325
#endif
private:
QEvent::Type m_lastEventType;
@ -221,6 +227,8 @@ void tst_QAction::actionEvent()
QCOMPARE(m_lastAction, &a);
}
#if QT_CONFIG(shortcut)
//basic testing of standard keys
void tst_QAction::setStandardKeys()
{
@ -367,6 +375,8 @@ void tst_QAction::task200823_tooltip()
QCOMPARE(action->toolTip(), ref);
}
#endif // QT_CONFIG(shortcut)
void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
{
// test without a group
@ -408,6 +418,8 @@ void tst_QAction::task229128TriggeredSignalWhenInActiongroup()
QCOMPARE(actionSpy.count(), 1);
}
#if QT_CONFIG(shortcut)
void tst_QAction::repeat()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
@ -452,6 +464,8 @@ void tst_QAction::repeat()
QCOMPARE(spy.count(), 2);
}
#endif // QT_CONFIG(shortcut)
void tst_QAction::setData() // QTBUG-62006
{
QAction act(nullptr);
@ -467,6 +481,8 @@ void tst_QAction::setData() // QTBUG-62006
QCOMPARE(spy.count(), 1);
}
#if QT_CONFIG(shortcut)
void tst_QAction::disableShortcutsWithBlockedWidgets_data()
{
QTest::addColumn<Qt::ShortcutContext>("shortcutContext");
@ -556,5 +572,7 @@ void tst_QAction::shortcutFromKeyEvent()
QCOMPARE(testWidget.shortcutOverrideCount, 1);
}
#endif // QT_CONFIG(shortcut)
QTEST_MAIN(tst_QAction)
#include "tst_qaction.moc"

View File

@ -99,7 +99,9 @@ class tst_QFormLayout : public QObject
private slots:
void cleanup();
void rowCount();
#if QT_CONFIG(shortcut)
void buddies();
#endif
void getItemPosition();
void wrapping();
void spacing();
@ -190,6 +192,8 @@ void tst_QFormLayout::rowCount()
//TODO: remove items
}
#if QT_CONFIG(shortcut)
void tst_QFormLayout::buddies()
{
QWidget w;
@ -218,6 +222,8 @@ void tst_QFormLayout::buddies()
//TODO: empty label?
}
#endif // QT_CONFIG(shortcut)
void tst_QFormLayout::getItemPosition()
{
QWidget w;
@ -687,17 +693,21 @@ void tst_QFormLayout::insertRow_QString_QWidget()
layout->insertRow(-5, "&Name:", fld1);
QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
QVERIFY(label1 != 0);
#if QT_CONFIG(shortcut)
QCOMPARE(label1->buddy(), fld1);
#endif
layout->insertRow(0, "&Email:", fld2);
QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
QVERIFY(label2 != 0);
#if QT_CONFIG(shortcut)
QCOMPARE(label2->buddy(), fld2);
#endif
layout->insertRow(5, "&Age:", fld3);
QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
QVERIFY(label3 != 0);
#if QT_CONFIG(shortcut)
QCOMPARE(label3->buddy(), fld3);
#endif
}
void tst_QFormLayout::insertRow_QString_QLayout()
@ -711,21 +721,27 @@ void tst_QFormLayout::insertRow_QString_QLayout()
layout->insertRow(-5, "&Name:", fld1);
QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
QVERIFY(label1 != 0);
#if QT_CONFIG(shortcut)
QVERIFY(!label1->buddy());
#endif
QCOMPARE(layout->rowCount(), 1);
layout->insertRow(0, "&Email:", fld2);
QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
QVERIFY(label2 != 0);
#if QT_CONFIG(shortcut)
QVERIFY(!label2->buddy());
#endif
QCOMPARE(layout->rowCount(), 2);
layout->insertRow(5, "&Age:", fld3);
QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
QVERIFY(label3 != 0);
#if QT_CONFIG(shortcut)
QVERIFY(!label3->buddy());
#endif
QCOMPARE(layout->rowCount(), 3);
}

View File

@ -34,7 +34,9 @@
#include <qapplication.h>
#include <qpainter.h>
#include <qstyleoption.h>
#include <qkeysequence.h>
#if QT_CONFIG(shortcut)
# include <qkeysequence.h>
#endif
#include <qevent.h>
#include <qgridlayout.h>
#include <qabstractbutton.h>
@ -59,7 +61,9 @@ private slots:
void setText();
void setIcon();
#if QT_CONFIG(shortcut)
void setShortcut();
#endif
void animateClick();
@ -68,7 +72,9 @@ private slots:
void isChecked();
void toggled();
void setEnabled();
#if QT_CONFIG(shortcut)
void shortcutEvents();
#endif
void stopRepeatTimer();
void mouseReleased(); // QTBUG-53244
@ -164,8 +170,10 @@ void tst_QAbstractButton::init()
testWidget->setEnabled( true );
testWidget->setDown( false );
testWidget->setAutoRepeat( false );
#if QT_CONFIG(shortcut)
QKeySequence seq;
testWidget->setShortcut( seq );
#endif
toggle_count = 0;
press_count = 0;
@ -336,17 +344,17 @@ void tst_QAbstractButton::setText()
QCOMPARE( testWidget->text(), QString("simple") );
testWidget->setText("&ampersand");
QCOMPARE( testWidget->text(), QString("&ampersand") );
#ifndef Q_OS_MAC // no mneonics on Mac.
#if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN) // no mnemonics on Mac.
QCOMPARE( testWidget->shortcut(), QKeySequence("ALT+A"));
#endif
testWidget->setText("te&st");
QCOMPARE( testWidget->text(), QString("te&st") );
#ifndef Q_OS_MAC // no mneonics on Mac.
#if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN) // no mnemonics on Mac.
QCOMPARE( testWidget->shortcut(), QKeySequence("ALT+S"));
#endif
testWidget->setText("foo");
QCOMPARE( testWidget->text(), QString("foo") );
#ifndef Q_OS_MAC // no mneonics on Mac.
#if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN) // no mnemonics on Mac.
QCOMPARE( testWidget->shortcut(), QKeySequence());
#endif
}
@ -471,6 +479,7 @@ void tst_QAbstractButton::toggled()
testWidget->setCheckable(false);
}
#if QT_CONFIG(shortcut)
void tst_QAbstractButton::setShortcut()
{
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
@ -502,6 +511,7 @@ void tst_QAbstractButton::setShortcut()
// qDebug() << click_count;
}
#endif // QT_CONFIG(shortcut)
void tst_QAbstractButton::animateClick()
{
@ -512,6 +522,8 @@ void tst_QAbstractButton::animateClick()
QTRY_VERIFY( !testWidget->isDown() );
}
#if QT_CONFIG(shortcut)
void tst_QAbstractButton::shortcutEvents()
{
MyButton button;
@ -535,6 +547,8 @@ void tst_QAbstractButton::shortcutEvents()
QCOMPARE(clickedSpy.count(), 3);
}
#endif // QT_CONFIG(shortcut)
void tst_QAbstractButton::stopRepeatTimer()
{
MyButton button;

View File

@ -51,7 +51,9 @@ private slots:
void getSetCheck();
void pressed();
#if QT_CONFIG(shortcut)
void setAccel();
#endif
void isCheckable();
void setDown();
void popupCrash();
@ -133,8 +135,10 @@ void tst_QCommandLinkButton::init()
testWidget->setText("Test");
testWidget->setDescription("Description text.");
testWidget->setEnabled( true );
#if QT_CONFIG(shortcut)
QKeySequence seq;
testWidget->setShortcut( seq );
#endif
resetCounters();
}
@ -327,6 +331,8 @@ void tst_QCommandLinkButton::toggled()
QVERIFY( click_count == 1 );
}
#if QT_CONFIG(shortcut)
/*
If we press an accelerator key we ONLY get a pressed signal and
NOT a released or clicked signal.
@ -355,6 +361,8 @@ void tst_QCommandLinkButton::setAccel()
QTest::qWait(200);
}
#endif // QT_CONFIG(shortcut)
void tst_QCommandLinkButton::animateClick()
{
QVERIFY( !testWidget->isDown() );

View File

@ -166,7 +166,9 @@ private slots:
void doubleDot();
#if QT_CONFIG(shortcut)
void undoRedo();
#endif
void valueFromTextAndValidate_data();
void valueFromTextAndValidate();
@ -1025,6 +1027,8 @@ void tst_QDoubleSpinBox::doubleDot()
QCOMPARE(spin.lineEdit()->cursorPosition(), 2);
}
#if QT_CONFIG(shortcut)
void tst_QDoubleSpinBox::undoRedo()
{
//test undo/redo feature (in conjunction with the "undoRedoEnabled" property)
@ -1073,6 +1077,8 @@ void tst_QDoubleSpinBox::undoRedo()
QVERIFY(!spin.lineEdit()->isRedoAvailable());
}
#endif // QT_CONFIG(shortcut)
struct task199226_DoubleSpinBox : public QDoubleSpinBox
{
task199226_DoubleSpinBox(QWidget *parent = 0) : QDoubleSpinBox(parent) {}

View File

@ -68,7 +68,7 @@ private Q_SLOTS:
void setText_data();
void setText();
void setTextFormat();
#ifndef Q_OS_MAC
#if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN)
void setBuddy();
#endif
void setNum();
@ -88,8 +88,10 @@ private Q_SLOTS:
void unicodeText_data();
void unicodeText();
#if QT_CONFIG(shortcut)
void mnemonic_data();
void mnemonic();
#endif
void selection();
#ifndef QT_NO_CONTEXTMENU
@ -116,6 +118,7 @@ void tst_QLabel::getSetCheck()
obj1.setWordWrap(true);
QCOMPARE(true, obj1.wordWrap());
#if QT_CONFIG(shortcut)
// QWidget * QLabel::buddy()
// void QLabel::setBuddy(QWidget *)
QWidget *var2 = new QWidget();
@ -124,6 +127,7 @@ void tst_QLabel::getSetCheck()
obj1.setBuddy((QWidget *)0);
QCOMPARE((QWidget *)0, obj1.buddy());
delete var2;
#endif // QT_CONFIG(shortcut)
// QMovie * QLabel::movie()
// void QLabel::setMovie(QMovie *)
@ -153,7 +157,9 @@ void tst_QLabel::cleanupTestCase()
void tst_QLabel::init()
{
testWidget->setTextFormat( Qt::AutoText );
# if QT_CONFIG(shortcut)
testWidget->setBuddy( 0 );
#endif
testWidget->setIndent( 0 );
testWidget->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
testWidget->setScaledContents( false );
@ -169,7 +175,7 @@ void tst_QLabel::cleanup()
}
// Set buddy doesn't make much sense on OS X
#ifndef Q_OS_MAC
#if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN)
void tst_QLabel::setBuddy()
{
testWidget->hide();
@ -204,7 +210,7 @@ void tst_QLabel::setBuddy()
delete test_box;
}
#endif
#endif // QT_CONFIG(shortcut) && !Q_OS_DARWIN
void tst_QLabel::setText_data()
{
@ -469,6 +475,8 @@ void tst_QLabel::unicodeText()
testWidget->show();
}
#if QT_CONFIG(shortcut)
void tst_QLabel::mnemonic_data()
{
QTest::addColumn<QString>("text");
@ -513,6 +521,8 @@ void tst_QLabel::mnemonic()
QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor);
}
#endif // QT_CONFIG(shortcut)
void tst_QLabel::selection()
{
QLabel label;

View File

@ -56,7 +56,9 @@
#include <qsortfilterproxymodel.h>
#include <qdebug.h>
#include <qscreen.h>
#include <qshortcut.h>
#if QT_CONFIG(shortcut)
# include <qshortcut.h>
#endif
#include "qcommonstyle.h"
#include "qstyleoption.h"
@ -135,9 +137,11 @@ private slots:
void clearInputMask();
#if QT_CONFIG(shortcut)
void keypress_inputMask_data();
void keypress_inputMask();
void keypress_inputMethod_inputMask();
#endif
void inputMaskAndValidator_data();
void inputMaskAndValidator();
@ -219,7 +223,7 @@ private slots:
void setSelection_data();
void setSelection();
#ifndef QT_NO_CLIPBOARD
#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void cut();
void cutWithoutSelection();
#endif
@ -299,8 +303,10 @@ private slots:
void shouldShowPlaceholderText();
void QTBUG1266_setInputMaskEmittingTextEdited();
#if QT_CONFIG(shortcut)
void shortcutOverrideOnReadonlyLineEdit_data();
void shortcutOverrideOnReadonlyLineEdit();
#endif
void QTBUG59957_clearButtonLeftmostAction();
void QTBUG_60319_setInputMaskCheckImSurroundingText();
void testQuickSelectionWithMouse();
@ -319,7 +325,9 @@ private:
void psKeyClick(QWidget *target, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
void psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
bool unselectingWithLeftOrRightChangesCursorPosition();
#if QT_CONFIG(shortcut)
void addKeySequenceStandardKey(QTestEventList &keys, QKeySequence::StandardKey);
#endif
QLineEdit *ensureTestWidget();
bool validInput;
@ -715,6 +723,8 @@ void tst_QLineEdit::clearInputMask()
QCOMPARE(testWidget->inputMask(), QString());
}
#if QT_CONFIG(shortcut)
void tst_QLineEdit::keypress_inputMask_data()
{
QTest::addColumn<QString>("mask");
@ -832,6 +842,8 @@ void tst_QLineEdit::keypress_inputMethod_inputMask()
QCOMPARE(testWidget->text(), QStringLiteral("EE.EE.EE"));
}
#endif // QT_CONFIG(shortcut)
void tst_QLineEdit::hasAcceptableInputMask_data()
{
QTest::addColumn<QString>("optionalMask");
@ -1986,6 +1998,8 @@ void tst_QLineEdit::psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardMo
keys.addKeyClick(key, pressState);
}
#if QT_CONFIG(shortcut)
void tst_QLineEdit::addKeySequenceStandardKey(QTestEventList &keys, QKeySequence::StandardKey key)
{
QKeySequence keyseq = QKeySequence(key);
@ -1993,6 +2007,8 @@ void tst_QLineEdit::addKeySequenceStandardKey(QTestEventList &keys, QKeySequence
keys.addKeyClick( Qt::Key( keyseq[i] & ~Qt::KeyboardModifierMask), Qt::KeyboardModifier(keyseq[i] & Qt::KeyboardModifierMask) );
}
#endif // QT_CONFIG(shortcut)
void tst_QLineEdit::cursorPosition()
{
QLineEdit *testWidget = ensureTestWidget();
@ -3023,7 +3039,7 @@ void tst_QLineEdit::setSelection()
QCOMPARE(testWidget->cursorPosition(), expectedCursor);
}
#ifndef QT_NO_CLIPBOARD
#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_QLineEdit::cut()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
@ -3124,7 +3140,7 @@ void tst_QLineEdit::cutWithoutSelection()
QCOMPARE(clipboard->text(), origText.left(selectionLength));
}
#endif // !QT_NO_CLIPBOARD
#endif // QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
class InputMaskValidator : public QValidator
{
@ -3969,7 +3985,9 @@ void tst_QLineEdit::taskQTBUG_7395_readOnlyShortcut()
le.setReadOnly(true);
QAction action(QString::fromLatin1("hello"), &le);
#if QT_CONFIG(shortcut)
action.setShortcut(QString::fromLatin1("p"));
#endif
QSignalSpy spy(&action, SIGNAL(triggered()));
le.addAction(&action);
@ -4704,6 +4722,8 @@ void tst_QLineEdit::QTBUG1266_setInputMaskEmittingTextEdited()
QCOMPARE(spy.count(), 0);
}
#if QT_CONFIG(shortcut)
void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit_data()
{
QTest::addColumn<QKeySequence>("keySequence");
@ -4763,6 +4783,8 @@ void tst_QLineEdit::shortcutOverrideOnReadonlyLineEdit()
QCOMPARE(spy.count(), activationCount);
}
#endif // QT_CONFIG(shortcut)
void tst_QLineEdit::QTBUG59957_clearButtonLeftmostAction()
{
#ifndef QT_BUILD_INTERNAL

View File

@ -481,7 +481,7 @@ void tst_QMenu::overrideMenuAction()
// On Mac and Windows CE, we need to create native key events to test menu
// action activation, so skip this part of the test.
#if !defined(Q_OS_DARWIN)
#if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN)
QAction *aQuit = new QAction("Quit", &w);
aQuit->setShortcut(QKeySequence("Ctrl+X"));
m->addAction(aQuit);
@ -499,7 +499,7 @@ void tst_QMenu::overrideMenuAction()
//test if the menu still pops out
QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier);
QTRY_VERIFY(m->isVisible());
#endif
#endif // QT_CONFIG(shortcut) && !Q_OS_DARWIN
delete aFileMenu;
@ -1706,10 +1706,13 @@ void tst_QMenu::QTBUG_61039_menu_shortcuts()
QSKIP("Window activation is not supported");
QAction *actionKamen = new QAction("Action Kamen");
#if QT_CONFIG(shortcut)
actionKamen->setShortcut(QKeySequence(QLatin1String("K")));
#endif
QAction *actionJoe = new QAction("Action Joe");
#if QT_CONFIG(shortcut)
actionJoe->setShortcut(QKeySequence(QLatin1String("Ctrl+J")));
#endif
QMenu menu;
menu.addAction(actionKamen);

View File

@ -232,19 +232,25 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb, bool forceNonNative) {
connect(mb, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*)));
QMenu *menu = mb->addMenu(QStringLiteral("&accel"));
QAction *action = menu->addAction(QStringLiteral("menu1") );
#if QT_CONFIG(shortcut)
action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A));
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A));
#endif
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*)));
result.menus << menu;
result.actions << action;
menu = mb->addMenu(QStringLiteral("accel1"));
action = menu->addAction(QStringLiteral("&Open...") );
#if QT_CONFIG(shortcut)
action->setShortcut(Qt::Key_O);
#endif
result.actions << action;
action = menu->addAction(QStringLiteral("action"));
#if QT_CONFIG(shortcut)
action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Z));
#endif
result.actions << action;
result.menus << menu;
@ -283,7 +289,9 @@ QAction *tst_QMenuBar::createCharacterAction(QMenu *menu, char lowerAscii)
QAction *action = menu->addAction(text);
action->setObjectName(text);
action->setData(QVariant(int(lowerAscii)));
#if QT_CONFIG(shortcut)
action->setShortcut(Qt::CTRL + (lowerAscii - 'a' + Qt::Key_A));
#endif
connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered()));
return action;
}
@ -318,7 +326,9 @@ TestMenu tst_QMenuBar::initComplexMenuBar(QMenuBar *mb)
QAction *action = mb->addAction(QStringLiteral("M&enu 3"));
action->setData(QVariant(3));
#if QT_CONFIG(shortcut)
action->setShortcut(Qt::ALT + Qt::Key_J);
#endif
connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered()));
result.actions << action;
@ -1422,7 +1432,9 @@ void tst_QMenuBar::taskQTBUG4965_escapeEaten()
menubar.setNativeMenuBar(false);
QMenu menu("menu1");
QAction *first = menubar.addMenu(&menu);
#if QT_CONFIG(shortcut)
menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC"));
#endif
centerOnScreen(&menubar);
menubar.show();
QApplication::setActiveWindow(&menubar);

View File

@ -53,7 +53,9 @@ private slots:
void getSetCheck();
void autoRepeat();
void pressed();
#if QT_CONFIG(shortcut)
void setAccel();
#endif
void isCheckable();
void setDown();
void popupCrash();
@ -65,7 +67,9 @@ private slots:
void defaultAndAutoDefault();
void sizeHint_data();
void sizeHint();
#if QT_CONFIG(shortcut)
void taskQTBUG_20191_shortcutWithKeypadModifer();
#endif
void emitReleasedAfterChange();
protected slots:
@ -125,8 +129,10 @@ void tst_QPushButton::init()
testWidget->setDown( false );
testWidget->setText("Test");
testWidget->setEnabled( true );
#if QT_CONFIG(shortcut)
QKeySequence seq;
testWidget->setShortcut( seq );
#endif
resetCounters();
}
@ -318,6 +324,8 @@ void tst_QPushButton::toggled()
QVERIFY( click_count == 1 );
}
#if QT_CONFIG(shortcut)
/*
If we press an accelerator key we ONLY get a pressed signal and
NOT a released or clicked signal.
@ -349,6 +357,8 @@ void tst_QPushButton::setAccel()
QTRY_VERIFY( !testWidget->isDown() );
}
#endif // QT_CONFIG(shortcut)
void tst_QPushButton::animateClick()
{
QVERIFY( !testWidget->isDown() );
@ -571,6 +581,8 @@ void tst_QPushButton::sizeHint()
}
}
#if QT_CONFIG(shortcut)
void tst_QPushButton::taskQTBUG_20191_shortcutWithKeypadModifer()
{
// setup a dialog with two buttons
@ -617,6 +629,8 @@ void tst_QPushButton::taskQTBUG_20191_shortcutWithKeypadModifer()
QCOMPARE(spy2.count(), 1);
}
#endif // QT_CONFIG(shortcut)
void tst_QPushButton::emitReleasedAfterChange()
{
QPushButton *button1 = new QPushButton("A");

View File

@ -44,12 +44,16 @@ public:
virtual ~tst_QRadioButton(){};
private slots:
#if QT_CONFIG(shortcut)
void task190739_focus();
#endif
void minimumSizeHint();
private:
};
#if QT_CONFIG(shortcut)
void tst_QRadioButton::task190739_focus()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
@ -84,6 +88,7 @@ void tst_QRadioButton::task190739_focus()
QVERIFY(!radio1.hasFocus());
}
#endif // QT_CONFIG(shortcut)
void tst_QRadioButton::minimumSizeHint()
{

View File

@ -47,7 +47,9 @@
#include <QLocale>
#include <QDoubleSpinBox>
#include <QVBoxLayout>
#include <QKeySequence>
#if QT_CONFIG(shortcut)
# include <QKeySequence>
#endif
#include <QStackedWidget>
#include <QDebug>
#include <QStyleOptionSpinBox>
@ -173,7 +175,10 @@ private slots:
void removeAll();
void startWithDash();
#if QT_CONFIG(shortcut)
void undoRedo();
#endif
void specialValue();
void textFromValue();
@ -1024,6 +1029,8 @@ void tst_QSpinBox::startWithDash()
QCOMPARE(spin.text(), QString("0"));
}
#if QT_CONFIG(shortcut)
void tst_QSpinBox::undoRedo()
{
//test undo/redo feature (in conjunction with the "undoRedoEnabled" property)
@ -1076,6 +1083,8 @@ void tst_QSpinBox::undoRedo()
QVERIFY(!spin.lineEdit()->isRedoAvailable());
}
#endif // QT_CONFIG(shortcut)
void tst_QSpinBox::specialValue()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))

View File

@ -40,7 +40,9 @@
#include <qwidgetaction.h>
#include <qtoolbutton.h>
#include <qlineedit.h>
#include <qkeysequence.h>
#if QT_CONFIG(shortcut)
# include <qkeysequence.h>
#endif
#include <qmenu.h>
#include <qlabel.h>
#include <private/qtoolbarextension_p.h>

View File

@ -47,6 +47,9 @@ SUBDIRS=\
qtoolbox \
qtoolbutton \
!qtConfig(shortcut): SUBDIRS -= \
qkeysequenceedit
# The following tests depend on private API:
!qtConfig(private_tests): SUBDIRS -= \
qabstractspinbox \