1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the test suite of the Qt Toolkit. |
7 ** This file is part of the test suite of the Qt Toolkit. |
8 ** |
8 ** |
2854 |
2856 |
2855 // Make sure the item got polish event. |
2857 // Make sure the item got polish event. |
2856 QVERIFY(widget->events.contains(QEvent::Polish)); |
2858 QVERIFY(widget->events.contains(QEvent::Polish)); |
2857 } |
2859 } |
2858 |
2860 |
|
2861 void tst_QGraphicsWidget::initialShow() |
|
2862 { |
|
2863 class MyGraphicsWidget : public QGraphicsWidget |
|
2864 { public: |
|
2865 MyGraphicsWidget() : repaints(0) {} |
|
2866 int repaints; |
|
2867 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } |
|
2868 void polishEvent() { update(); } |
|
2869 }; |
|
2870 |
|
2871 QGraphicsScene scene; |
|
2872 MyGraphicsWidget *widget = new MyGraphicsWidget; |
|
2873 |
|
2874 QGraphicsView view(&scene); |
|
2875 view.show(); |
|
2876 QTest::qWaitForWindowShown(&view); |
|
2877 |
|
2878 QTest::qWait(100); |
|
2879 scene.addItem(widget); |
|
2880 QTest::qWait(100); |
|
2881 |
|
2882 QCOMPARE(widget->repaints, 1); |
|
2883 } |
|
2884 |
|
2885 void tst_QGraphicsWidget::initialShow2() |
|
2886 { |
|
2887 class MyGraphicsWidget : public QGraphicsWidget |
|
2888 { public: |
|
2889 MyGraphicsWidget() : repaints(0) {} |
|
2890 int repaints; |
|
2891 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } |
|
2892 void polishEvent() { update(); } |
|
2893 }; |
|
2894 |
|
2895 // Don't let paint events triggered by the windowing system |
|
2896 // influence our test case. We're only interested in knowing |
|
2897 // whether a QGraphicsWidget generates an additional repaint |
|
2898 // on the inital show. Hence create a dummy scenario to find out |
|
2899 // how many repaints we should expect. |
|
2900 QGraphicsScene dummyScene(0, 0, 200, 200); |
|
2901 dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100)); |
|
2902 |
|
2903 QGraphicsView *dummyView = new QGraphicsView(&dummyScene); |
|
2904 dummyView->setWindowFlags(Qt::X11BypassWindowManagerHint); |
|
2905 EventSpy paintSpy(dummyView->viewport(), QEvent::Paint); |
|
2906 dummyView->show(); |
|
2907 QTest::qWaitForWindowShown(dummyView); |
|
2908 const int expectedRepaintCount = paintSpy.count(); |
|
2909 delete dummyView; |
|
2910 dummyView = 0; |
|
2911 QTest::qWait(200); |
|
2912 |
|
2913 MyGraphicsWidget *widget = new MyGraphicsWidget; |
|
2914 widget->resize(100, 100); |
|
2915 |
|
2916 QGraphicsScene scene(0, 0, 200, 200); |
|
2917 scene.addItem(widget); |
|
2918 |
|
2919 QGraphicsView view(&scene); |
|
2920 view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
|
2921 view.show(); |
|
2922 QTest::qWaitForWindowShown(&view); |
|
2923 |
|
2924 QCOMPARE(widget->repaints, expectedRepaintCount); |
|
2925 } |
|
2926 |
2859 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
2927 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
2860 { |
2928 { |
2861 QGraphicsScene scene; |
2929 QGraphicsScene scene; |
2862 QGraphicsWidget* parent1 = new QGraphicsWidget; |
2930 QGraphicsWidget* parent1 = new QGraphicsWidget; |
2863 QGraphicsWidget* child1_0 = new QGraphicsWidget; |
2931 QGraphicsWidget* child1_0 = new QGraphicsWidget; |