From 495032429b400b44fdcc585585a5c7220c572c68 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Tue, 20 Apr 2010 13:30:17 +0200 Subject: Fixes keyboard shortcuts for QGraphicsTextItem. The event ShortcutOverride was not handled by QGraphicsTextItem. Autotest included. Task-number: QTBUG-7333 Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsitem.cpp | 3 ++ tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 38 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 9759b39..20ea262 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -10086,6 +10086,9 @@ bool QGraphicsTextItem::sceneEvent(QEvent *event) #endif //QT_NO_IM } break; + case QEvent::ShortcutOverride: + dd->sendControlEvent(event); + return true; default: break; } 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 #include #include +#include #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 -- cgit v0.12