diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-09-04 10:37:20 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-09-04 13:20:07 (GMT) |
commit | a56acff4789521a7b6a6439dcb88e6d9ba4b7ada (patch) | |
tree | f3fe0a3dbd491a121672f278275690695be17d06 /tests/auto | |
parent | a0b5f9529f3bb7858f4261af98aa13d20ac6c16c (diff) | |
download | Qt-a56acff4789521a7b6a6439dcb88e6d9ba4b7ada.zip Qt-a56acff4789521a7b6a6439dcb88e6d9ba4b7ada.tar.gz Qt-a56acff4789521a7b6a6439dcb88e6d9ba4b7ada.tar.bz2 |
Make sure that top-level windows respect hfw/wfh constraint.
Note that the constraint is only enforced when resizing the window
interactively. Calling setGeometry() will not try to enforce the
constraint.
See the graphicsview/flowlayout example for a "manual test".
Task-number: 257455
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 03054f9..d1193bd 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -157,6 +157,7 @@ private slots: void shortcutsDeletion(); void painterStateProtectionOnWindowFrame(); void ensureClipping(); + void respectHFW(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2543,6 +2544,84 @@ void tst_QGraphicsWidget::ensureClipping() QVERIFY(scene.drawnItems.contains(childitem)); } +class HFWWidget : public QGraphicsWidget +{ +public: + HFWWidget() : QGraphicsWidget(0, Qt::Window) + { + QSizePolicy sp; + sp.setHeightForWidth(true); + setSizePolicy(sp); + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + qreal w = rect().width(); + QRectF box(0, 0, w, 2400/w); + painter->drawRoundRect(box); + painter->drawLine(box.topLeft(), box.bottomRight()); + painter->drawLine(box.bottomLeft(), box.topRight()); + } + +protected: + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const + { + qreal w = constraint.width(); + switch (which) { + case Qt::MinimumSize: + if (w >= 0 && constraint.height() < 0) { + // keep the same area of 60x40 = 2400 + return QSizeF(w, 2400.0/w); + } else { + return QSizeF(10, 10); + } + break; + case Qt::PreferredSize: + return QSizeF(48.989794, 48.989794); + default: + break; + } + return QGraphicsWidget::sizeHint(which, constraint); + } +}; + +void tst_QGraphicsWidget::respectHFW() +{ + QGraphicsScene scene; + HFWWidget *window = new HFWWidget; + scene.addItem(window); + QGraphicsView *view = new QGraphicsView(&scene); + view->resize(400, 400); + view->setSceneRect(-100, -100, 300,300); + + view->show(); + window->setGeometry(0, 0, 70, 70); + + { // here we go - simulate a interactive resize of the window + QTest::qWait(200); + QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner + QTest::qWait(200); + + QTest::mousePress(view->viewport(), Qt::LeftButton, 0, view->mapFromScene(71, 71), 200); + view->grabMouse(); + // move both mouse cursor and set correct event in order to emulate resize + QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200); + QMouseEvent e = QMouseEvent(QEvent::MouseMove, + view->mapFromScene(60, 20), + Qt::NoButton, + Qt::LeftButton, + Qt::NoModifier); + QApplication::sendEvent(view->viewport(), &e); + view->releaseMouse(); + } + QTest::qWait(200); + const QSizeF winSize = window->size(); + qreal minHFW = window->effectiveSizeHint(Qt::MinimumSize, QSizeF(winSize.width(), -1)).height(); + QVERIFY(qAbs(minHFW - winSize.height()) < 1); +} + QTEST_MAIN(tst_QGraphicsWidget) #include "tst_qgraphicswidget.moc" |