diff options
author | Yoann Lopes <yoann.lopes@nokia.com> | 2010-04-20 11:30:17 (GMT) |
---|---|---|
committer | Yoann Lopes <yoann.lopes@nokia.com> | 2010-04-20 13:53:34 (GMT) |
commit | 495032429b400b44fdcc585585a5c7220c572c68 (patch) | |
tree | 8870dec5458cc4d0685c530cdc687b9e2aeadf7f /tests | |
parent | 7f207df8cc63762e32803505aaf6e9b320fd6ba5 (diff) | |
download | Qt-495032429b400b44fdcc585585a5c7220c572c68.zip Qt-495032429b400b44fdcc585585a5c7220c572c68.tar.gz Qt-495032429b400b44fdcc585585a5c7220c572c68.tar.bz2 |
Fixes keyboard shortcuts for QGraphicsTextItem.
The event ShortcutOverride was not handled by QGraphicsTextItem.
Autotest included.
Task-number: QTBUG-7333
Reviewed-by: bnilsen
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 03ce45a..e2f7f18 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -62,6 +62,7 @@ #include <QVBoxLayout> #include <QGraphicsEffect> #include <QInputContext> +#include <QPushButton> #include "../../shared/util.h" @@ -426,6 +427,7 @@ private slots: void itemIsInFront(); void scenePosChange(); void updateMicroFocus(); + void textItem_shortcuts(); // task specific tests below me void task141694_textItemEnsureVisible(); @@ -10060,6 +10062,42 @@ void tst_QGraphicsItem::updateMicroFocus() QTRY_COMPARE(ic2.nbUpdates, 0); } +void tst_QGraphicsItem::textItem_shortcuts() +{ + QWidget w; + QVBoxLayout l; + w.setLayout(&l); + QGraphicsScene scene; + QGraphicsView view(&scene); + l.addWidget(&view); + QPushButton b("Push Me"); + l.addWidget(&b); + + QGraphicsTextItem *item = scene.addText("Troll Text"); + item->setFlag(QGraphicsItem::ItemIsFocusable); + item->setTextInteractionFlags(Qt::TextEditorInteraction); + w.show(); + QTest::qWaitForWindowShown(&w); + + item->setFocus(); + QTRY_VERIFY(item->hasFocus()); + QVERIFY(item->textCursor().selectedText().isEmpty()); + + // Shortcut should work (select all) + QTest::keyClick(&view, Qt::Key_A, Qt::ControlModifier); + QTRY_COMPARE(item->textCursor().selectedText(), item->toPlainText()); + QTextCursor tc = item->textCursor(); + tc.clearSelection(); + item->setTextCursor(tc); + QVERIFY(item->textCursor().selectedText().isEmpty()); + + // Shortcut should also work if the text item has the focus and another widget + // has the same shortcut. + b.setShortcut(QKeySequence("CTRL+A")); + QTest::keyClick(&view, Qt::Key_A, Qt::ControlModifier); + QTRY_COMPARE(item->textCursor().selectedText(), item->toPlainText()); +} + void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() { struct Item : public QGraphicsTextItem |