summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-08-26 09:02:33 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-08-26 14:18:45 (GMT)
commitda5033d8b48b24580e3b6faf7b4e2a8fe2cec254 (patch)
tree5870b468e418a29a8269bd462e93e54bb0ee5b7b /tests
parent7e30c92186878beb300a13093c3668ae8a10f2be (diff)
downloadQt-da5033d8b48b24580e3b6faf7b4e2a8fe2cec254.zip
Qt-da5033d8b48b24580e3b6faf7b4e2a8fe2cec254.tar.gz
Qt-da5033d8b48b24580e3b6faf7b4e2a8fe2cec254.tar.bz2
Introduce QGraphicsItem::ItemIsPanel, light-weight window.
ItemIsPanel allows items that act like windows. They can be activated and deactivated just like windows and focus is handled just like with windows. The main difference is that panels are more light-weight. There's less built-in functionality (e.g., clicking a panel doesn't automatically activate nor raise it). This patch also introduces QGraphicsItem::panel(), QGraphicsItem::isPanel(), and QGraphicsItem::isActive(), as well as QGraphicsScene::activePanel(), QGraphicsScene::setActivePanel(). and QGraphicsScene::isActive(). Regular windows (QGraphicsWidgets with Qt::Window set) are also panels, with added functionality. The ItemIsPanel flag is set automatically for windows. Reviewed-by: brad
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp184
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp24
2 files changed, 193 insertions, 15 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index e9154d4..ba27c85 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -287,6 +287,8 @@ private slots:
void focusProxyDeletion();
void negativeZStacksBehindParent();
void setGraphicsEffect();
+ void panel();
+ void addPanelToActiveScene();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -2922,7 +2924,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
int npaints = tester->repaints;
qApp->processEvents();
qApp->processEvents();
- QCOMPARE(tester->events.size(), 2); // enter + move
+ QCOMPARE(tester->events.size(), 3); // activate + enter + move
QCOMPARE(tester->repaints, npaints + 1);
QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove);
@@ -2936,7 +2938,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
qApp->processEvents();
qApp->processEvents();
- QCOMPARE(tester->events.size(), 3);
+ QCOMPARE(tester->events.size(), 4);
QCOMPARE(tester->repaints, npaints + 1);
QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove);
@@ -2950,7 +2952,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
qApp->processEvents();
qApp->processEvents();
- QCOMPARE(tester->events.size(), 4);
+ QCOMPARE(tester->events.size(), 5);
QCOMPARE(tester->repaints, npaints + 2);
QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverLeave);
}
@@ -7764,5 +7766,181 @@ void tst_QGraphicsItem::setGraphicsEffect()
delete anotherItem;
}
+void tst_QGraphicsItem::panel()
+{
+ QGraphicsScene scene;
+
+ QGraphicsRectItem *panel1 = new QGraphicsRectItem;
+ QGraphicsRectItem *panel2 = new QGraphicsRectItem;
+ QGraphicsRectItem *panel3 = new QGraphicsRectItem;
+ QGraphicsRectItem *panel4 = new QGraphicsRectItem;
+ QGraphicsRectItem *notPanel1 = new QGraphicsRectItem;
+ QGraphicsRectItem *notPanel2 = new QGraphicsRectItem;
+ panel1->setFlag(QGraphicsItem::ItemIsPanel);
+ panel2->setFlag(QGraphicsItem::ItemIsPanel);
+ panel3->setFlag(QGraphicsItem::ItemIsPanel);
+ panel4->setFlag(QGraphicsItem::ItemIsPanel);
+ scene.addItem(panel1);
+ scene.addItem(panel2);
+ scene.addItem(panel3);
+ scene.addItem(panel4);
+ scene.addItem(notPanel1);
+ scene.addItem(notPanel2);
+
+ EventSpy spy_activate_panel1(&scene, panel1, QEvent::WindowActivate);
+ EventSpy spy_deactivate_panel1(&scene, panel1, QEvent::WindowDeactivate);
+ EventSpy spy_activate_panel2(&scene, panel2, QEvent::WindowActivate);
+ EventSpy spy_deactivate_panel2(&scene, panel2, QEvent::WindowDeactivate);
+ EventSpy spy_activate_panel3(&scene, panel3, QEvent::WindowActivate);
+ EventSpy spy_deactivate_panel3(&scene, panel3, QEvent::WindowDeactivate);
+ EventSpy spy_activate_panel4(&scene, panel4, QEvent::WindowActivate);
+ EventSpy spy_deactivate_panel4(&scene, panel4, QEvent::WindowDeactivate);
+ EventSpy spy_activate_notPanel1(&scene, notPanel1, QEvent::WindowActivate);
+ EventSpy spy_deactivate_notPanel1(&scene, notPanel1, QEvent::WindowDeactivate);
+ EventSpy spy_activate_notPanel2(&scene, notPanel1, QEvent::WindowActivate);
+ EventSpy spy_deactivate_notPanel2(&scene, notPanel1, QEvent::WindowDeactivate);
+
+ QCOMPARE(spy_activate_panel1.count(), 0);
+ QCOMPARE(spy_deactivate_panel1.count(), 0);
+ QCOMPARE(spy_activate_panel2.count(), 0);
+ QCOMPARE(spy_deactivate_panel2.count(), 0);
+ QCOMPARE(spy_activate_panel3.count(), 0);
+ QCOMPARE(spy_deactivate_panel3.count(), 0);
+ QCOMPARE(spy_activate_panel4.count(), 0);
+ QCOMPARE(spy_deactivate_panel4.count(), 0);
+ QCOMPARE(spy_activate_notPanel1.count(), 0);
+ QCOMPARE(spy_deactivate_notPanel1.count(), 0);
+ QCOMPARE(spy_activate_notPanel2.count(), 0);
+ QCOMPARE(spy_deactivate_notPanel2.count(), 0);
+
+ QVERIFY(!scene.activePanel());
+ QVERIFY(!scene.isActive());
+
+ QEvent activate(QEvent::WindowActivate);
+ QEvent deactivate(QEvent::WindowDeactivate);
+
+ QApplication::sendEvent(&scene, &activate);
+
+ // No previous activation, so the scene is active.
+ QVERIFY(scene.isActive());
+ QVERIFY(!scene.activePanel());
+ QVERIFY(!panel1->isActive());
+ QVERIFY(!panel2->isActive());
+ QVERIFY(!panel3->isActive());
+ QVERIFY(!panel4->isActive());
+ QVERIFY(notPanel1->isActive());
+ QVERIFY(notPanel2->isActive());
+ QCOMPARE(spy_activate_notPanel1.count(), 1);
+ QCOMPARE(spy_activate_notPanel2.count(), 1);
+
+ // Switch to panel1.
+ scene.setActivePanel(panel1);
+ QVERIFY(panel1->isActive());
+ QVERIFY(!panel2->isActive());
+ QVERIFY(!panel3->isActive());
+ QVERIFY(!panel4->isActive());
+ QVERIFY(!notPanel1->isActive());
+ QVERIFY(!notPanel2->isActive());
+ QCOMPARE(spy_deactivate_notPanel1.count(), 1);
+ QCOMPARE(spy_deactivate_notPanel2.count(), 1);
+ QCOMPARE(spy_activate_panel1.count(), 1);
+ QCOMPARE(spy_activate_panel2.count(), 0);
+ QCOMPARE(spy_activate_panel3.count(), 0);
+ QCOMPARE(spy_activate_panel4.count(), 0);
+
+ // Switch back to scene.
+ scene.setActivePanel(0);
+ QVERIFY(!scene.activePanel());
+ QVERIFY(!panel1->isActive());
+ QVERIFY(!panel2->isActive());
+ QVERIFY(!panel3->isActive());
+ QVERIFY(!panel4->isActive());
+ QVERIFY(notPanel1->isActive());
+ QVERIFY(notPanel2->isActive());
+ QCOMPARE(spy_activate_notPanel1.count(), 2);
+ QCOMPARE(spy_activate_notPanel2.count(), 2);
+
+ // Deactivate the scene
+ QApplication::sendEvent(&scene, &deactivate);
+ QVERIFY(!scene.activePanel());
+ QVERIFY(!panel1->isActive());
+ QVERIFY(!panel2->isActive());
+ QVERIFY(!panel3->isActive());
+ QVERIFY(!panel4->isActive());
+ QVERIFY(!notPanel1->isActive());
+ QVERIFY(!notPanel2->isActive());
+ QCOMPARE(spy_deactivate_notPanel1.count(), 2);
+ QCOMPARE(spy_deactivate_notPanel2.count(), 2);
+
+ // Reactivate the scene
+ QApplication::sendEvent(&scene, &activate);
+ QVERIFY(!scene.activePanel());
+ QVERIFY(!panel1->isActive());
+ QVERIFY(!panel2->isActive());
+ QVERIFY(!panel3->isActive());
+ QVERIFY(!panel4->isActive());
+ QVERIFY(notPanel1->isActive());
+ QVERIFY(notPanel2->isActive());
+ QCOMPARE(spy_activate_notPanel1.count(), 3);
+ QCOMPARE(spy_activate_notPanel2.count(), 3);
+
+ // Switch to panel1
+ scene.setActivePanel(panel1);
+ QVERIFY(panel1->isActive());
+ QCOMPARE(spy_deactivate_notPanel1.count(), 3);
+ QCOMPARE(spy_deactivate_notPanel2.count(), 3);
+ QCOMPARE(spy_activate_panel1.count(), 2);
+
+ // Deactivate the scene
+ QApplication::sendEvent(&scene, &deactivate);
+ QVERIFY(!panel1->isActive());
+ QCOMPARE(spy_deactivate_panel1.count(), 2);
+
+ // Reactivate the scene
+ QApplication::sendEvent(&scene, &activate);
+ QVERIFY(panel1->isActive());
+ QCOMPARE(spy_activate_panel1.count(), 3);
+
+ // Deactivate the scene
+ QApplication::sendEvent(&scene, &deactivate);
+ QVERIFY(!panel1->isActive());
+ QVERIFY(!scene.activePanel());
+ scene.setActivePanel(0);
+
+ // Reactivate the scene
+ QApplication::sendEvent(&scene, &activate);
+ QVERIFY(!panel1->isActive());
+}
+
+void tst_QGraphicsItem::addPanelToActiveScene()
+{
+ QGraphicsScene scene;
+ QVERIFY(!scene.isActive());
+
+ QGraphicsRectItem *rect = new QGraphicsRectItem;
+ scene.addItem(rect);
+ QVERIFY(!rect->isActive());
+ scene.removeItem(rect);
+
+ QEvent activate(QEvent::WindowActivate);
+ QEvent deactivate(QEvent::WindowDeactivate);
+
+ QApplication::sendEvent(&scene, &activate);
+ QVERIFY(scene.isActive());
+ scene.addItem(rect);
+ QVERIFY(rect->isActive());
+ scene.removeItem(rect);
+
+ rect->setFlag(QGraphicsItem::ItemIsPanel);
+ scene.addItem(rect);
+ QVERIFY(rect->isActive());
+ QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect);
+
+ QGraphicsRectItem *rect2 = new QGraphicsRectItem;
+ scene.addItem(rect2);
+ QVERIFY(rect->isActive());
+ QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect);
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index 505f9a4..524b756 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -376,7 +376,7 @@ void tst_QGraphicsView::interactive()
view.show();
QTestEventLoop::instance().enterLoop(1);
- QCOMPARE(item->events.size(), 0);
+ QCOMPARE(item->events.size(), 1); // activate
QPoint itemPoint = view.mapFromScene(item->scenePos());
@@ -384,16 +384,16 @@ void tst_QGraphicsView::interactive()
for (int i = 0; i < 100; ++i) {
sendMousePress(view.viewport(), itemPoint);
- QCOMPARE(item->events.size(), i * 5 + 2);
+ QCOMPARE(item->events.size(), i * 5 + 3);
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GrabMouse);
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::GraphicsSceneMousePress);
sendMouseRelease(view.viewport(), itemPoint);
- QCOMPARE(item->events.size(), i * 5 + 4);
+ QCOMPARE(item->events.size(), i * 5 + 5);
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GraphicsSceneMouseRelease);
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::UngrabMouse);
QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint));
QApplication::sendEvent(view.viewport(), &contextEvent);
- QCOMPARE(item->events.size(), i * 5 + 5);
+ QCOMPARE(item->events.size(), i * 5 + 6);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu);
}
@@ -401,14 +401,14 @@ void tst_QGraphicsView::interactive()
for (int i = 0; i < 100; ++i) {
sendMousePress(view.viewport(), itemPoint);
- QCOMPARE(item->events.size(), 500);
+ QCOMPARE(item->events.size(), 501);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu);
sendMouseRelease(view.viewport(), itemPoint);
- QCOMPARE(item->events.size(), 500);
+ QCOMPARE(item->events.size(), 501);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu);
QContextMenuEvent contextEvent(QContextMenuEvent::Mouse, itemPoint, view.mapToGlobal(itemPoint));
QApplication::sendEvent(view.viewport(), &contextEvent);
- QCOMPARE(item->events.size(), 500);
+ QCOMPARE(item->events.size(), 501);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneContextMenu);
}
}
@@ -1872,32 +1872,32 @@ void tst_QGraphicsView::sendEvent()
item->setFocus();
QCOMPARE(scene.focusItem(), (QGraphicsItem *)item);
- QCOMPARE(item->events.size(), 1);
+ QCOMPARE(item->events.size(), 2);
QCOMPARE(item->events.last(), QEvent::FocusIn);
QPoint itemPoint = view.mapFromScene(item->scenePos());
sendMousePress(view.viewport(), itemPoint);
- QCOMPARE(item->events.size(), 3);
+ QCOMPARE(item->events.size(), 4);
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GrabMouse);
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::GraphicsSceneMousePress);
QMouseEvent mouseMoveEvent(QEvent::MouseMove, itemPoint, view.viewport()->mapToGlobal(itemPoint),
Qt::LeftButton, Qt::LeftButton, 0);
QApplication::sendEvent(view.viewport(), &mouseMoveEvent);
- QCOMPARE(item->events.size(), 4);
+ QCOMPARE(item->events.size(), 5);
QCOMPARE(item->events.last(), QEvent::GraphicsSceneMouseMove);
QMouseEvent mouseReleaseEvent(QEvent::MouseButtonRelease, itemPoint,
view.viewport()->mapToGlobal(itemPoint),
Qt::LeftButton, 0, 0);
QApplication::sendEvent(view.viewport(), &mouseReleaseEvent);
- QCOMPARE(item->events.size(), 6);
+ QCOMPARE(item->events.size(), 7);
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::GraphicsSceneMouseRelease);
QCOMPARE(item->events.at(item->events.size() - 1), QEvent::UngrabMouse);
QKeyEvent keyPress(QEvent::KeyPress, Qt::Key_Space, 0);
QApplication::sendEvent(view.viewport(), &keyPress);
- QCOMPARE(item->events.size(), 8);
+ QCOMPARE(item->events.size(), 9);
QCOMPARE(item->events.at(item->events.size() - 2), QEvent::ShortcutOverride);
QCOMPARE(item->events.last(), QEvent::KeyPress);
}