2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** 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
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** 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-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-29 09:28:13 +00:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QMainWindow>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qevent.h>
|
|
|
|
#include <qaction.h>
|
|
|
|
#include <qmenu.h>
|
Expose QPA API under qpa/*
The main reasons for doing this are:
1. _qpa.h end up in the master QtGui include file. QtGui is meant for
userland applications. qpa code is neither binary nor source compatible.
Inadvertant use of QPA api makes the user code binary-incompatible.
2. syncqt creates forwarding headers for non-private header files. This
gives people the impression that this is public API.
As discussed on the mailing list, even though QPA api is internal and subject
to change, it needs to treated differently from private headers since they
will be used by in-qtbase and out-of-qtbase plugins.
This commit does the following:
1. The _qpa in QPA header files is dropped.
2. syncqt now treats any file with qplatform prefix as a special file and
moves it to qpa/ directory. The recommended way of using QPA API in plugins
is: #include <qpa/qplatformfoo.h>. This allows the user include QPA API
from multiple modules (for example, qplatformfoo might be in QtPrintSupport)
3. The user needs to explicitly add QT += <module>-private to get access to
the qpa api.
4. Creates compat headers for the olden style qplatformfoo_qpa.h and QPlatformFoo
includes.
This commit does not change the cpp filenames. This requires a more careful
merging of existing non qpa cpp files and existing cpp files on a case by
case basis. This can be done at anytime.
The following files are not renamed as part of this changed but will be fixed
as part of a future change:
src/gui/kernel/qgenericpluginfactory_qpa.h
src/gui/kernel/qgenericplugin_qpa.h
src/gui/kernel/qwindowsysteminterface_qpa.h
files were renamed using
for x in `find . -name "qplatform*_qpa.h"`; do git mv $x "${x/_qpa.h/.h}"; done
for x in `find . -name "qplatform*_qpa_p.h"`; do git mv $x "${x/_qpa_p.h/_p.h}"; done
includes were renamed using script
for file in `find . -name "*.h" -or -name "*.cpp" -or -name "*.mm"`; do
sed -i -e 's,.*#.*include.*<\(Qt.*/\)\?\(QPlatform.*\)>,#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.*"\(Qt.*/\)\?\(QPlatform.*\)",#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.* "\(qplatform.*\)_qpa.h",#include <qpa/\L\1.h>,g' \
-e 's,.*#.*include.*"\(qplatform.*\)_qpa_p.h",#include <qpa/\L\1_p.h>,g' \
-e 's,.*#.*include.*<\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)>,#include <qpa/\2\3>,g' \
-e 's,.*#.*include.*"\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)",#include <qpa/\2\3>,g' \
$file
done
Change-Id: I04a350314a45746e3911f54b3b21ad03315afb67
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
2012-04-26 23:33:35 +00:00
|
|
|
#include <qpa/qplatformtheme.h>
|
2019-10-11 13:21:54 +00:00
|
|
|
#include <qpa/qplatformintegration.h>
|
2012-02-21 14:36:01 +00:00
|
|
|
#include <private/qguiapplication_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class tst_QAction : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
tst_QAction();
|
|
|
|
|
|
|
|
void updateState(QActionEvent *e);
|
|
|
|
|
|
|
|
private slots:
|
2015-06-11 10:08:30 +00:00
|
|
|
void init();
|
|
|
|
void cleanup();
|
2014-11-17 17:35:52 +00:00
|
|
|
void setUnknownFont();
|
2011-04-27 10:05:43 +00:00
|
|
|
void actionEvent();
|
2019-10-18 07:07:37 +00:00
|
|
|
#if QT_CONFIG(shortcut)
|
2011-04-27 10:05:43 +00:00
|
|
|
void alternateShortcuts();
|
|
|
|
void enabledVisibleInteraction();
|
2019-10-18 07:07:37 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
void task229128TriggeredSignalWhenInActiongroup();
|
2019-10-18 07:07:37 +00:00
|
|
|
#if QT_CONFIG(shortcut)
|
2015-06-25 16:09:27 +00:00
|
|
|
void repeat();
|
2017-06-16 08:54:53 +00:00
|
|
|
void keysequence(); // QTBUG-53381
|
2017-07-29 09:28:13 +00:00
|
|
|
void disableShortcutsWithBlockedWidgets_data();
|
|
|
|
void disableShortcutsWithBlockedWidgets();
|
2018-04-17 14:45:09 +00:00
|
|
|
void shortcutFromKeyEvent(); // QTBUG-48325
|
2019-10-18 07:07:37 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
2019-06-20 13:00:51 +00:00
|
|
|
QEvent::Type m_lastEventType;
|
2015-06-11 10:08:30 +00:00
|
|
|
const int m_keyboardScheme;
|
2019-06-19 11:00:11 +00:00
|
|
|
QGuiAction *m_lastAction;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2015-06-11 10:08:30 +00:00
|
|
|
tst_QAction::tst_QAction()
|
|
|
|
: m_keyboardScheme(QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QAction::init()
|
|
|
|
{
|
2019-06-20 13:00:51 +00:00
|
|
|
m_lastEventType = QEvent::None;
|
2015-06-11 10:08:30 +00:00
|
|
|
m_lastAction = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QAction::cleanup()
|
|
|
|
{
|
|
|
|
QVERIFY(QApplication::topLevelWidgets().isEmpty());
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class MyWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-06-11 10:08:30 +00:00
|
|
|
explicit MyWidget(tst_QAction *tst, QWidget *parent = nullptr) : QWidget(parent), m_test(tst)
|
|
|
|
{ setWindowTitle(QTest::currentTestFunction()); }
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
protected:
|
2015-06-11 10:08:30 +00:00
|
|
|
void actionEvent(QActionEvent *e) override { m_test->updateState(e); }
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
2015-06-11 10:08:30 +00:00
|
|
|
tst_QAction *m_test;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2014-11-17 17:35:52 +00:00
|
|
|
void tst_QAction::setUnknownFont() // QTBUG-42728
|
|
|
|
{
|
2019-06-20 13:00:51 +00:00
|
|
|
QAction action(nullptr);
|
2014-11-17 17:35:52 +00:00
|
|
|
QFont font("DoesNotExist", 11);
|
|
|
|
action.setFont(font);
|
|
|
|
|
|
|
|
QMenu menu;
|
|
|
|
menu.addAction(&action); // should not crash
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void tst_QAction::updateState(QActionEvent *e)
|
|
|
|
{
|
|
|
|
if (!e) {
|
2019-06-20 13:00:51 +00:00
|
|
|
m_lastEventType = QEvent::None;
|
|
|
|
m_lastAction = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2019-06-20 13:00:51 +00:00
|
|
|
m_lastEventType = e->type();
|
2011-04-27 10:05:43 +00:00
|
|
|
m_lastAction = e->action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QAction::actionEvent()
|
|
|
|
{
|
2019-06-20 13:00:51 +00:00
|
|
|
QAction a(nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
a.setText("action text");
|
|
|
|
|
|
|
|
// add action
|
2015-06-11 10:08:30 +00:00
|
|
|
MyWidget testWidget(this);
|
|
|
|
testWidget.show();
|
|
|
|
QApplication::setActiveWindow(&testWidget);
|
|
|
|
testWidget.addAction(&a);
|
2011-04-27 10:05:43 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2019-06-20 13:00:51 +00:00
|
|
|
QCOMPARE(m_lastEventType, QEvent::ActionAdded);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(m_lastAction, &a);
|
|
|
|
|
|
|
|
// change action
|
|
|
|
a.setText("new action text");
|
|
|
|
qApp->processEvents();
|
|
|
|
|
2019-06-20 13:00:51 +00:00
|
|
|
QCOMPARE(m_lastEventType, QEvent::ActionChanged);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(m_lastAction, &a);
|
|
|
|
|
|
|
|
// remove action
|
2015-06-11 10:08:30 +00:00
|
|
|
testWidget.removeAction(&a);
|
2011-04-27 10:05:43 +00:00
|
|
|
qApp->processEvents();
|
|
|
|
|
2019-06-20 13:00:51 +00:00
|
|
|
QCOMPARE(m_lastEventType, QEvent::ActionRemoved);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(m_lastAction, &a);
|
|
|
|
}
|
|
|
|
|
2019-10-18 07:07:37 +00:00
|
|
|
#if QT_CONFIG(shortcut)
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QAction::alternateShortcuts()
|
|
|
|
{
|
|
|
|
//test the alternate shortcuts (by adding more than 1 shortcut)
|
|
|
|
|
2015-06-11 10:08:30 +00:00
|
|
|
MyWidget testWidget(this);
|
|
|
|
testWidget.show();
|
|
|
|
QApplication::setActiveWindow(&testWidget);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
2015-06-11 10:08:30 +00:00
|
|
|
QAction act(&testWidget);
|
|
|
|
testWidget.addAction(&act);
|
2011-04-27 10:05:43 +00:00
|
|
|
QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A");
|
|
|
|
act.setShortcuts(shlist);
|
|
|
|
|
2019-06-20 13:00:51 +00:00
|
|
|
QSignalSpy spy(&act, &QAction::triggered);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
act.setAutoRepeat(true);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spy.count(), 1); //act should have been triggered
|
|
|
|
|
|
|
|
act.setAutoRepeat(false);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spy.count(), 2); //act should have been triggered a 2nd time
|
|
|
|
|
|
|
|
//end of the scope of the action, it will be destroyed and removed from wid
|
|
|
|
//This action should also unregister its shortcuts
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//this tests a crash (if the action did not unregister its alternate shortcuts)
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 08:54:53 +00:00
|
|
|
void tst_QAction::keysequence()
|
|
|
|
{
|
|
|
|
MyWidget testWidget(this);
|
|
|
|
testWidget.show();
|
|
|
|
QApplication::setActiveWindow(&testWidget);
|
|
|
|
|
|
|
|
{
|
|
|
|
QAction act(&testWidget);
|
|
|
|
testWidget.addAction(&act);
|
|
|
|
|
|
|
|
QKeySequence ks(QKeySequence::SelectAll);
|
|
|
|
|
|
|
|
act.setShortcut(ks);
|
|
|
|
|
|
|
|
QSignalSpy spy(&act, &QAction::triggered);
|
|
|
|
|
|
|
|
act.setAutoRepeat(true);
|
|
|
|
QTest::keySequence(&testWidget, ks);
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(spy.count(), 1); // act should have been triggered
|
|
|
|
|
|
|
|
act.setAutoRepeat(false);
|
|
|
|
QTest::keySequence(&testWidget, ks);
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(spy.count(), 2); //act should have been triggered a 2nd time
|
|
|
|
|
|
|
|
// end of the scope of the action, it will be destroyed and removed from widget
|
|
|
|
// This action should also unregister its shortcuts
|
|
|
|
}
|
|
|
|
|
|
|
|
// this tests a crash (if the action did not unregister its alternate shortcuts)
|
|
|
|
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QAction::enabledVisibleInteraction()
|
|
|
|
{
|
2015-06-11 10:08:30 +00:00
|
|
|
MyWidget testWidget(this);
|
|
|
|
testWidget.show();
|
|
|
|
QApplication::setActiveWindow(&testWidget);
|
|
|
|
|
2019-06-20 13:00:51 +00:00
|
|
|
QAction act(nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
// check defaults
|
|
|
|
QVERIFY(act.isEnabled());
|
|
|
|
QVERIFY(act.isVisible());
|
|
|
|
|
|
|
|
// !visible => !enabled
|
|
|
|
act.setVisible(false);
|
|
|
|
QVERIFY(!act.isEnabled());
|
|
|
|
act.setVisible(true);
|
|
|
|
QVERIFY(act.isEnabled());
|
|
|
|
act.setEnabled(false);
|
|
|
|
QVERIFY(act.isVisible());
|
|
|
|
|
|
|
|
// check if shortcut is disabled if not visible
|
2015-06-11 10:08:30 +00:00
|
|
|
testWidget.addAction(&act);
|
2011-04-27 10:05:43 +00:00
|
|
|
act.setShortcut(QKeySequence("Ctrl+T"));
|
|
|
|
QSignalSpy spy(&act, SIGNAL(triggered()));
|
|
|
|
act.setEnabled(true);
|
|
|
|
act.setVisible(false);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyClick(&testWidget, Qt::Key_T, Qt::ControlModifier);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spy.count(), 0); //act is not visible, so don't trigger
|
|
|
|
act.setVisible(false);
|
|
|
|
act.setEnabled(true);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyClick(&testWidget, Qt::Key_T, Qt::ControlModifier);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spy.count(), 0); //act is not visible, so don't trigger
|
|
|
|
act.setVisible(true);
|
|
|
|
act.setEnabled(true);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyClick(&testWidget, Qt::Key_T, Qt::ControlModifier);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spy.count(), 1); //act is visible and enabled, so trigger
|
|
|
|
}
|
|
|
|
|
2019-10-18 07:07:37 +00:00
|
|
|
#endif // QT_CONFIG(shortcut)
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QAction::task229128TriggeredSignalWhenInActiongroup()
|
|
|
|
{
|
2019-06-20 13:00:51 +00:00
|
|
|
QActionGroup ag(nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
QAction *action = new QAction("Test", &ag);
|
|
|
|
QAction *checkedAction = new QAction("Test 2", &ag);
|
|
|
|
ag.addAction(action);
|
|
|
|
action->setCheckable(true);
|
|
|
|
ag.addAction(checkedAction);
|
|
|
|
checkedAction->setCheckable(true);
|
|
|
|
checkedAction->setChecked(true);
|
|
|
|
|
2019-06-20 13:00:51 +00:00
|
|
|
QSignalSpy actionSpy(checkedAction, QOverload<bool>::of(&QAction::triggered));
|
|
|
|
QSignalSpy actionGroupSpy(&ag, QOverload<QAction*>::of(&QActionGroup::triggered));
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(actionGroupSpy.count(), 0);
|
|
|
|
QCOMPARE(actionSpy.count(), 0);
|
|
|
|
checkedAction->trigger();
|
|
|
|
// check that both the group and the action have emitted the signal
|
|
|
|
QCOMPARE(actionGroupSpy.count(), 1);
|
|
|
|
QCOMPARE(actionSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2019-10-18 07:07:37 +00:00
|
|
|
#if QT_CONFIG(shortcut)
|
|
|
|
|
2015-06-25 16:09:27 +00:00
|
|
|
void tst_QAction::repeat()
|
|
|
|
{
|
2019-10-11 13:21:54 +00:00
|
|
|
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
|
|
|
|
QSKIP("Wayland: This fails. Figure out why.");
|
|
|
|
|
2015-06-11 10:08:30 +00:00
|
|
|
MyWidget testWidget(this);
|
|
|
|
testWidget.show();
|
|
|
|
QApplication::setActiveWindow(&testWidget);
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&testWidget));
|
|
|
|
|
|
|
|
QAction act(&testWidget);
|
|
|
|
testWidget.addAction(&act);
|
2015-06-25 16:09:27 +00:00
|
|
|
act.setShortcut(QKeySequence(Qt::Key_F));
|
|
|
|
QSignalSpy spy(&act, SIGNAL(triggered()));
|
|
|
|
|
|
|
|
act.setAutoRepeat(true);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyPress(&testWidget, Qt::Key_F);
|
|
|
|
QTest::keyRelease(&testWidget, Qt::Key_F);
|
2015-06-25 16:09:27 +00:00
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
spy.clear();
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyPress(&testWidget, Qt::Key_F);
|
2015-06-25 16:09:27 +00:00
|
|
|
// repeat event
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::simulateEvent(&testWidget, true, Qt::Key_F, Qt::NoModifier, QString("f"), true);
|
|
|
|
QTest::simulateEvent(&testWidget, true, Qt::Key_F, Qt::NoModifier, QString("f"), true);
|
|
|
|
QTest::keyRelease(&testWidget, Qt::Key_F);
|
2015-06-25 16:09:27 +00:00
|
|
|
QCOMPARE(spy.count(), 3);
|
|
|
|
|
|
|
|
spy.clear();
|
|
|
|
act.setAutoRepeat(false);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyPress(&testWidget, Qt::Key_F);
|
|
|
|
QTest::simulateEvent(&testWidget, true, Qt::Key_F, Qt::NoModifier, QString("f"), true);
|
|
|
|
QTest::simulateEvent(&testWidget, true, Qt::Key_F, Qt::NoModifier, QString("f"), true);
|
|
|
|
QTest::keyRelease(&testWidget, Qt::Key_F);
|
2015-06-25 16:09:27 +00:00
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
spy.clear();
|
|
|
|
act.setAutoRepeat(true);
|
2015-06-11 10:08:30 +00:00
|
|
|
QTest::keyPress(&testWidget, Qt::Key_F);
|
|
|
|
QTest::simulateEvent(&testWidget, true, Qt::Key_F, Qt::NoModifier, QString("f"), true);
|
|
|
|
QTest::keyRelease(&testWidget, Qt::Key_F);
|
2015-06-25 16:09:27 +00:00
|
|
|
QCOMPARE(spy.count(), 2);
|
|
|
|
}
|
|
|
|
|
2017-07-29 09:28:13 +00:00
|
|
|
void tst_QAction::disableShortcutsWithBlockedWidgets_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::ShortcutContext>("shortcutContext");
|
|
|
|
QTest::addColumn<Qt::WindowModality>("windowModality");
|
|
|
|
|
|
|
|
QTest::newRow("application modal dialog should block window shortcut.")
|
|
|
|
<< Qt::WindowShortcut << Qt::ApplicationModal;
|
|
|
|
|
|
|
|
QTest::newRow("application modal dialog should block application shortcut.")
|
|
|
|
<< Qt::ApplicationShortcut << Qt::ApplicationModal;
|
|
|
|
|
|
|
|
QTest::newRow("window modal dialog should block application shortcut.")
|
|
|
|
<< Qt::ApplicationShortcut << Qt::WindowModal;
|
|
|
|
|
|
|
|
QTest::newRow("window modal dialog should block window shortcut.")
|
|
|
|
<< Qt::WindowShortcut << Qt::WindowModal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QAction::disableShortcutsWithBlockedWidgets()
|
|
|
|
{
|
2019-10-11 13:21:54 +00:00
|
|
|
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
|
|
|
|
QSKIP("Window activation is not supported");
|
|
|
|
|
2017-07-29 09:28:13 +00:00
|
|
|
QMainWindow window;
|
|
|
|
|
|
|
|
QFETCH(Qt::ShortcutContext, shortcutContext);
|
|
|
|
QAction action(&window);
|
|
|
|
window.addAction(&action);
|
|
|
|
action.setShortcut(QKeySequence(Qt::Key_1));
|
|
|
|
action.setShortcutContext(shortcutContext);
|
|
|
|
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
|
|
|
|
QDialog dialog(&window);
|
|
|
|
QFETCH(Qt::WindowModality, windowModality);
|
|
|
|
dialog.setWindowModality(windowModality);
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
|
|
|
|
|
|
|
QApplication::setActiveWindow(&window);
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&window));
|
|
|
|
|
|
|
|
QSignalSpy spy(&action, &QAction::triggered);
|
|
|
|
QTest::keyPress(&window, Qt::Key_1);
|
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:45:09 +00:00
|
|
|
class ShortcutOverrideWidget : public QWidget
|
|
|
|
{
|
|
|
|
public:
|
2019-06-20 13:00:51 +00:00
|
|
|
using QWidget::QWidget;
|
|
|
|
int shortcutOverrideCount = 0;
|
2018-04-17 14:45:09 +00:00
|
|
|
protected:
|
2019-06-20 13:00:51 +00:00
|
|
|
bool event(QEvent *e) override
|
2018-04-17 14:45:09 +00:00
|
|
|
{
|
|
|
|
if (e->type() == QEvent::ShortcutOverride)
|
|
|
|
++shortcutOverrideCount;
|
|
|
|
return QWidget::event(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that a key press event sent with sendEvent() still gets handled as a possible
|
|
|
|
// ShortcutOverride event first before passing it on as a normal KeyEvent.
|
|
|
|
void tst_QAction::shortcutFromKeyEvent()
|
|
|
|
{
|
2019-10-11 13:21:54 +00:00
|
|
|
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
|
|
|
|
QSKIP("Wayland: This fails. Figure out why.");
|
|
|
|
|
2018-04-17 14:45:09 +00:00
|
|
|
ShortcutOverrideWidget testWidget;
|
|
|
|
QAction action;
|
|
|
|
action.setShortcut(Qt::Key_1);
|
|
|
|
testWidget.addAction(&action);
|
|
|
|
testWidget.show();
|
|
|
|
QSignalSpy spy(&action, &QAction::triggered);
|
|
|
|
QVERIFY(spy.isValid());
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&testWidget));
|
|
|
|
QCOMPARE(testWidget.shortcutOverrideCount, 0);
|
|
|
|
|
|
|
|
// Don't use the QTest::keyPress approach as this will take the
|
|
|
|
// shortcut route for us
|
|
|
|
QKeyEvent e(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier);
|
|
|
|
QApplication::sendEvent(&testWidget, &e);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QCOMPARE(testWidget.shortcutOverrideCount, 1);
|
|
|
|
}
|
|
|
|
|
2019-10-18 07:07:37 +00:00
|
|
|
#endif // QT_CONFIG(shortcut)
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QTEST_MAIN(tst_QAction)
|
|
|
|
#include "tst_qaction.moc"
|