diff options
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/widgets/kernel/kernel.pri | 3 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication_p.h | 3 | ||||
-rw-r--r-- | src/widgets/kernel/qshortcut.h | 133 | ||||
-rw-r--r-- | src/widgets/kernel/qshortcut_widgets.cpp (renamed from src/widgets/kernel/qshortcut.cpp) | 212 |
5 files changed, 16 insertions, 337 deletions
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 8fa3090475..9730b787be 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -334,7 +334,7 @@ qt_extend_target(Widgets CONDITION QT_FEATURE_formlayout qt_extend_target(Widgets CONDITION QT_FEATURE_shortcut SOURCES - kernel/qshortcut.cpp kernel/qshortcut.h + kernel/qshortcut_widgets.cpp ) qt_extend_target(Widgets CONDITION QT_FEATURE_tooltip diff --git a/src/widgets/kernel/kernel.pri b/src/widgets/kernel/kernel.pri index e73617fd19..b9dfdef5ee 100644 --- a/src/widgets/kernel/kernel.pri +++ b/src/widgets/kernel/kernel.pri @@ -71,8 +71,7 @@ qtConfig(formlayout) { } qtConfig(shortcut) { - HEADERS += kernel/qshortcut.h - SOURCES += kernel/qshortcut.cpp + SOURCES += kernel/qshortcut_widgets.cpp } qtConfig(tooltip) { diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index f6e3e861d9..e1e391b13d 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -120,6 +120,9 @@ public: #ifndef QT_NO_ACTION QActionPrivate *createActionPrivate() const override; #endif +#ifndef QT_NO_SHORTCUT + QShortcutPrivate *createShortcutPrivate() const override; +#endif //modality bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const override; diff --git a/src/widgets/kernel/qshortcut.h b/src/widgets/kernel/qshortcut.h deleted file mode 100644 index a519a8696a..0000000000 --- a/src/widgets/kernel/qshortcut.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSHORTCUT_H -#define QSHORTCUT_H - -#include <QtWidgets/qtwidgetsglobal.h> -#include <QtWidgets/qwidget.h> -#include <QtGui/qguishortcut.h> - -QT_REQUIRE_CONFIG(shortcut); - -QT_BEGIN_NAMESPACE - -class QShortcutPrivate; -class Q_WIDGETS_EXPORT QShortcut : public QGuiShortcut -{ - Q_OBJECT - Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis) - Q_DECLARE_PRIVATE(QShortcut) -public: - explicit QShortcut(QWidget *parent); - explicit QShortcut(const QKeySequence& key, QWidget *parent, - const char *member = nullptr, const char *ambiguousMember = nullptr, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); -#ifdef Q_CLANG_QDOC - template<typename Functor> - QShortcut(const QKeySequence &key, QWidget *parent, - Functor functor, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); - template<typename Functor> - QShortcut(const QKeySequence &key, QWidget *parent, - const QObject *context, Functor functor, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); - template<typename Functor, typename FunctorAmbiguous> - QShortcut(const QKeySequence &key, QWidget *parent, - const QObject *context1, Functor functor, - FunctorAmbiguous functorAmbiguous, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); - template<typename Functor, typename FunctorAmbiguous> - QShortcut(const QKeySequence &key, QWidget *parent, - const QObject *context1, Functor functor, - const QObject *context2, FunctorAmbiguous functorAmbiguous, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); -#else - template<typename Func1> - QShortcut(const QKeySequence &key, QWidget *parent, - Func1 slot1, - Qt::ShortcutContext context = Qt::WindowShortcut) - : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) - { - connect(this, &QShortcut::activated, std::move(slot1)); - } - template<class Obj1, typename Func1> - QShortcut(const QKeySequence &key, QWidget *parent, - const Obj1 *object1, Func1 slot1, - Qt::ShortcutContext context = Qt::WindowShortcut, - typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0) - : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) - { - connect(this, &QShortcut::activated, object1, std::move(slot1)); - } - template<class Obj1, typename Func1, typename Func2> - QShortcut(const QKeySequence &key, QWidget *parent, - const Obj1 *object1, Func1 slot1, Func2 slot2, - Qt::ShortcutContext context = Qt::WindowShortcut, - typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0) - : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) - { - connect(this, &QShortcut::activated, object1, std::move(slot1)); - connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2)); - } - template<class Obj1, typename Func1, class Obj2, typename Func2> - QShortcut(const QKeySequence &key, QWidget *parent, - const Obj1 *object1, Func1 slot1, - const Obj2 *object2, Func2 slot2, - Qt::ShortcutContext context = Qt::WindowShortcut, - typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0, - typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj2*>::Value>::type* = 0) - : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context) - { - connect(this, &QShortcut::activated, object1, std::move(slot1)); - connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2)); - } -#endif - ~QShortcut(); - - void setWhatsThis(const QString &text); - QString whatsThis() const; - - inline QWidget *parentWidget() const - { return static_cast<QWidget *>(QObject::parent()); } -}; - -QT_END_NAMESPACE - -#endif // QSHORTCUT_H diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut_widgets.cpp index aad89b6273..9e64376fce 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut_widgets.cpp @@ -38,6 +38,8 @@ ****************************************************************************/ #include "qshortcut.h" +#include "private/qshortcut_p.h" + #include "private/qwidget_p.h" #include <qevent.h> @@ -52,7 +54,6 @@ #endif #include <qapplication.h> #include <private/qapplication_p.h> -#include "private/qguishortcut_p.h" #include <private/qshortcutmap_p.h> #if QT_CONFIG(action) # include <private/qaction_p.h> @@ -326,223 +327,32 @@ static bool correctActionContext(Qt::ShortcutContext context, QAction *a, QWidge } #endif // QT_CONFIG(action) - -/*! - \class QShortcut - \brief The QShortcut class is used to create keyboard shortcuts. - - \ingroup events - \inmodule QtWidgets - - The QShortcut class provides a way of connecting keyboard - shortcuts to Qt's \l{signals and slots} mechanism, so that - objects can be informed when a shortcut is executed. The shortcut - can be set up to contain all the key presses necessary to - describe a keyboard shortcut, including the states of modifier - keys such as \uicontrol Shift, \uicontrol Ctrl, and \uicontrol Alt. - - \target mnemonic - - On certain widgets, using '&' in front of a character will - automatically create a mnemonic (a shortcut) for that character, - e.g. "E&xit" will create the shortcut \uicontrol Alt+X (use '&&' to - display an actual ampersand). The widget might consume and perform - an action on a given shortcut. On X11 the ampersand will not be - shown and the character will be underlined. On Windows, shortcuts - are normally not displayed until the user presses the \uicontrol Alt - key, but this is a setting the user can change. On Mac, shortcuts - are disabled by default. Call \l qt_set_sequence_auto_mnemonic() to - enable them. However, because mnemonic shortcuts do not fit in - with Aqua's guidelines, Qt will not show the shortcut character - underlined. - - For applications that use menus, it may be more convenient to - use the convenience functions provided in the QMenu class to - assign keyboard shortcuts to menu items as they are created. - Alternatively, shortcuts may be associated with other types of - actions in the QAction class. - - The simplest way to create a shortcut for a particular widget is - to construct the shortcut with a key sequence. For example: - - \snippet code/src_gui_kernel_qshortcut.cpp 0 - - When the user types the \l{QKeySequence}{key sequence} - for a given shortcut, the shortcut's activated() signal is - emitted. (In the case of ambiguity, the activatedAmbiguously() - signal is emitted.) A shortcut is "listened for" by Qt's event - loop when the shortcut's parent widget is receiving events. - - A shortcut's key sequence can be set with setKey() and retrieved - with key(). A shortcut can be enabled or disabled with - setEnabled(), and can have "What's This?" help text set with - setWhatsThis(). - - \sa QShortcutEvent, QKeySequence, QAction -*/ - -/*! - \fn QWidget *QShortcut::parentWidget() const - - Returns the shortcut's parent widget. -*/ - -/* - \internal - Private data accessed through d-pointer. -*/ -class QShortcutPrivate : public QGuiShortcutPrivate +class QtWidgetsShortcutPrivate : public QShortcutPrivate { Q_DECLARE_PUBLIC(QShortcut) public: - QShortcutPrivate() = default; + QtWidgetsShortcutPrivate() = default; QShortcutMap::ContextMatcher contextMatcher() const override { return qWidgetShortcutContextMatcher; } bool handleWhatsThis() override; - - QString sc_whatsthis; }; -bool QShortcutPrivate::handleWhatsThis() +bool QtWidgetsShortcutPrivate::handleWhatsThis() { #if QT_CONFIG(whatsthis) - const bool result = QWhatsThis::inWhatsThisMode(); - if (result) + if (QWhatsThis::inWhatsThisMode()) { QWhatsThis::showText(QCursor::pos(), sc_whatsthis); - return result; -#else - return false; + return true; + } #endif + return false; } -/*! - Constructs a QShortcut object for the \a parent widget. Since no - shortcut key sequence is specified, the shortcut will not emit any - signals. - - \sa setKey() -*/ -QShortcut::QShortcut(QWidget *parent) - : QGuiShortcut(*new QShortcutPrivate, parent) -{ -} - -/*! - Constructs a QShortcut object for the \a parent widget. The shortcut - operates on its parent, listening for \l{QShortcutEvent}s that - match the \a key sequence. Depending on the ambiguity of the - event, the shortcut will call the \a member function, or the \a - ambiguousMember function, if the key press was in the shortcut's - \a shortcutContext. -*/ -QShortcut::QShortcut(const QKeySequence &key, QWidget *parent, - const char *member, const char *ambiguousMember, - Qt::ShortcutContext shortcutContext) - : QGuiShortcut(*new QShortcutPrivate, key, parent, member, ambiguousMember, shortcutContext) -{ -} - -/*! - \fn template<typename Functor> - QShortcut(const QKeySequence &key, QWidget *parent, - Functor functor, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); - \since 5.15 - \overload - - This is a QShortcut convenience constructor which connects the shortcut's - \l{QShortcut::activated()}{activated()} signal to the \a functor. -*/ -/*! - \fn template<typename Functor> - QShortcut(const QKeySequence &key, QWidget *parent, - const QObject *context, Functor functor, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); - \since 5.15 - \overload - - This is a QShortcut convenience constructor which connects the shortcut's - \l{QShortcut::activated()}{activated()} signal to the \a functor. - - The \a functor can be a pointer to a member function of the \a context object. - - If the \a context object is destroyed, the \a functor will not be called. -*/ -/*! - \fn template<typename Functor, typename FunctorAmbiguous> - QShortcut(const QKeySequence &key, QWidget *parent, - const QObject *context1, Functor functor, - FunctorAmbiguous functorAmbiguous, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); - \since 5.15 - \overload - - This is a QShortcut convenience constructor which connects the shortcut's - \l{QShortcut::activated()}{activated()} signal to the \a functor and - \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()} - signal to the \a FunctorAmbiguous. - - The \a functor and \a FunctorAmbiguous can be a pointer to a member - function of the \a context object. - - If the \a context object is destroyed, the \a functor and - \a FunctorAmbiguous will not be called. -*/ -/*! - \fn template<typename Functor, typename FunctorAmbiguous> - QShortcut(const QKeySequence &key, QWidget *parent, - const QObject *context1, Functor functor, - const QObject *context2, FunctorAmbiguous functorAmbiguous, - Qt::ShortcutContext shortcutContext = Qt::WindowShortcut); - \since 5.15 - \overload - - This is a QShortcut convenience constructor which connects the shortcut's - \l{QShortcut::activated()}{activated()} signal to the \a functor and - \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()} - signal to the \a FunctorAmbiguous. - - The \a functor can be a pointer to a member function of the - \a context1 object. - The \a FunctorAmbiguous can be a pointer to a member function of the - \a context2 object. - - If the \a context1 object is destroyed, the \a functor will not be called. - If the \a context2 object is destroyed, the \a FunctorAmbiguous - will not be called. -*/ - -/*! - \property QShortcut::whatsThis - \brief the shortcut's "What's This?" help text - - The text will be shown when the application is in "What's - This?" mode and the user types the shortcut key() sequence. - - To set "What's This?" help on a menu item (with or without a - shortcut key), set the help on the item's action. - - By default, this property contains an empty string. - - \sa QWhatsThis::inWhatsThisMode(), QAction::setWhatsThis() -*/ -void QShortcut::setWhatsThis(const QString &text) -{ - Q_D(QShortcut); - d->sc_whatsthis = text; -} - -QString QShortcut::whatsThis() const +QShortcutPrivate *QApplicationPrivate::createShortcutPrivate() const { - Q_D(const QShortcut); - return d->sc_whatsthis; + return new QtWidgetsShortcutPrivate; } -/*! - Destroys the shortcut. -*/ -QShortcut::~QShortcut() = default; - QT_END_NAMESPACE |