summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicswidget
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-05-13 08:26:31 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-05-13 08:26:31 (GMT)
commitf9afc51f96b2b09d8be7fcd9bf080d1144643273 (patch)
tree9cfaefbd6f58d3bb47ab3be564bd74df0ff65ccb /tests/auto/qgraphicswidget
parent5cbaaa1a8baf14b66efe89fe967a3e966dac659c (diff)
parent03415f5db33ee1d8af15b924f84b547a9ed8020b (diff)
downloadQt-f9afc51f96b2b09d8be7fcd9bf080d1144643273.zip
Qt-f9afc51f96b2b09d8be7fcd9bf080d1144643273.tar.gz
Qt-f9afc51f96b2b09d8be7fcd9bf080d1144643273.tar.bz2
Merge commit 'origin/4.5'
Diffstat (limited to 'tests/auto/qgraphicswidget')
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index 56737c3..343aac6 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -50,6 +50,7 @@
#include <qcleanlooksstyle.h>
#include <qlineedit.h>
#include <qboxlayout.h>
+#include <qaction.h>
#include "../../shared/util.h"
@@ -155,6 +156,7 @@ private slots:
// Task fixes
void task236127_bspTreeIndexFails();
void task243004_setStyleCrash();
+ void task250119_shortcutContext();
};
@@ -2212,6 +2214,89 @@ void tst_QGraphicsWidget::task243004_setStyleCrash()
delete item2;
}
+class GraphicsWidget_task250119 : public QGraphicsWidget
+{
+public:
+ GraphicsWidget_task250119()
+ : shortcutEvents(0)
+ {
+ setFocusPolicy(Qt::StrongFocus);
+ resize(100, 100);
+ }
+
+ int shortcutEvents;
+
+private:
+ bool event(QEvent *event)
+ {
+ if (event->type() == QEvent::Shortcut)
+ shortcutEvents++;
+ return QGraphicsWidget::event(event);
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ if (hasFocus()) {
+ painter->setPen(QPen(Qt::black, 0, Qt::DashLine));
+ painter->drawRect(rect());
+ }
+ painter->setPen(QPen(Qt::black, 0, Qt::SolidLine));
+ painter->fillRect(rect().adjusted(2, 2, -2, -2), Qt::yellow);
+ painter->drawRect(rect().adjusted(2, 2, -2, -2));
+ }
+};
+
+void tst_QGraphicsWidget::task250119_shortcutContext()
+{
+ QGraphicsScene scene;
+ QGraphicsView view;
+ view.setScene(&scene);
+ view.show();
+ QTest::qWait(100);
+
+
+ // *** Event: ***
+
+ GraphicsWidget_task250119 w_event;
+ scene.addItem(&w_event);
+
+ const int id = w_event.grabShortcut(Qt::Key_A, Qt::WidgetWithChildrenShortcut);
+ w_event.setShortcutEnabled(id, true);
+
+ w_event.setFocus();
+ QTest::keyPress(&view, Qt::Key_A);
+ QCOMPARE(w_event.shortcutEvents, 1);
+
+ w_event.clearFocus();
+ QTest::keyPress(&view, Qt::Key_A);
+ QCOMPARE(w_event.shortcutEvents, 1);
+
+ scene.removeItem(&w_event);
+
+
+ // *** Signal: ***
+
+ GraphicsWidget_task250119 w_signal;
+ scene.addItem(&w_signal);
+
+ QAction action(0);
+ action.setShortcut(Qt::Key_B);
+ action.setShortcutContext(Qt::WidgetWithChildrenShortcut);
+ QSignalSpy spy(&action, SIGNAL(triggered()));
+
+ w_signal.addAction(&action);
+
+ w_signal.setFocus();
+ QTest::keyPress(&view, Qt::Key_B);
+ QCOMPARE(spy.count(), 1);
+
+ w_signal.clearFocus();
+ QTest::keyPress(&view, Qt::Key_B);
+ QCOMPARE(spy.count(), 1);
+
+ scene.removeItem(&w_signal);
+}
+
QTEST_MAIN(tst_QGraphicsWidget)
#include "tst_qgraphicswidget.moc"