void Ut_MPannableViewport::updateSamePosition() { QGraphicsWidget *mainWidget = new QGraphicsWidget(); QPointF point(0.0, 0.0); subject->setMinimumSize(100, 480); subject->setPreferredSize(100, 480); subject->setMaximumSize(100, 480); mainWidget->setMinimumSize(100, 1000); mainWidget->setPreferredSize(100, 1000); mainWidget->setMaximumSize(100, 1000); subject->setWidget(mainWidget); subject->updatePosition(point); QSignalSpy spy(subject, SIGNAL(positionChanged(QPointF))); subject->updatePosition(point); // Should not have emitted anything since nothing changed QCOMPARE(spy.count(), 0); }
void tst_QGraphicsLayout::moveAndResizeWidgetInWidget() { QFETCH(bool, instantInvalidatePropagation); QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation); QGraphicsScene scene; QGraphicsWidget *widget = new QGraphicsWidget; QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget); layout->setContentsMargins(0,0,0,0); WidgetToTestResizeEvents *innerWidget = new WidgetToTestResizeEvents; QGraphicsLinearLayout *innerLayout = new QGraphicsLinearLayout(innerWidget); innerLayout->setContentsMargins(0,0,0,0); QCOMPARE(widget->maximumSize(), QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); layout->addItem(innerWidget); widget->setMinimumSize(1,1); widget->setPreferredSize(1000,1000); widget->setMaximumSize(2000,2000); widget->resize(widget->preferredSize()); innerWidget->setMinimumSize(1,1); qApp->processEvents(); innerWidget->resizeEventCalled = false; QCOMPARE(widget->size(), QSizeF(1000, 1000)); QCOMPARE(layout->geometry().size(), QSizeF(1000, 1000)); QCOMPARE(innerWidget->size(), QSizeF(1000, 1000)); innerLayout->invalidate(); widget->setMaximumHeight(500); widget->setX(1); qApp->processEvents(); QCOMPARE(widget->size(), QSizeF(1000, 500)); QCOMPARE(innerWidget->size(), QSizeF(1000, 500)); QVERIFY(innerWidget->resizeEventCalled); }
void Ut_MPannableViewport::event() { QEvent *event = new QEvent(QEvent::LayoutRequest); QFETCH(QSizeF, viewportSize); QFETCH(QSizeF, pannedSize); QFETCH(QSizeF, physicsRange); QGraphicsWidget *widget = new QGraphicsWidget(); // Forcing the size of panned widget widget->setMinimumSize(pannedSize); widget->setPreferredSize(pannedSize); widget->setMaximumSize(pannedSize); // Forcing the size of subject subject->setMinimumSize(viewportSize); subject->setPreferredSize(viewportSize); subject->setMaximumSize(viewportSize); subject->setWidget(widget); subject->event(event); qApp->processEvents(); QCOMPARE(subject->physics()->range().size(), physicsRange); }
QGraphicsWidget *MToolBarLayoutPolicy::insertSpacer(int policyIndex) { //Create an item that will expand if necessary QGraphicsWidget *item = new QGraphicsWidget; item->setMaximumWidth(spacesBetween ? -1 : 0); item->setPreferredSize(1,1); //Ugly hack around QTBUG-11134 item->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); MLinearLayoutPolicy::insertItem(policyIndex, item); return item; }
QGraphicsWidget *createSpacer() { QGraphicsWidget *spacer = new QGraphicsWidget(); spacer->hide(); spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); spacer->setMinimumSize(0, 0); spacer->setPreferredSize(0, 0); return spacer; }
static QGraphicsWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0), const QSizeF &preferred = QSize(150.0, 100.0), const QSizeF &maximum = QSizeF(200.0, 100.0), const QString &name = QString()) { QGraphicsWidget *w = new RectWidget; w->setMinimumSize(minimum); w->setPreferredSize(preferred); w->setMaximumSize(maximum); w->setData(0, name); return w; }
ChromeSnippet *ChromeDOM::getSnippet(const QString &docElementId, QGraphicsItem* parent) { Q_UNUSED(parent) ChromeSnippet * snippet = 0; QWebElement doc = m_page->mainFrame()->documentElement(); QWebElement element = doc.findFirst("#" + docElementId); QRect rect = element.geometry(); //TODO: This may not be accurate since final heights may not have been computed at this point!! m_height += rect.height(); // qDebug() << "Snippet: ID: " << docElementId << " Owner Area: " << rect << " Element Rect: " << element.geometry(); if (!rect.isNull()) { QString className = element.attribute("data-GinebraNativeClass", "__NO_CLASS__"); if (className == "__NO_CLASS__") { if (element.attribute("data-GinebraContainer", "false") == "true") { snippet = new WebChromeContainerSnippet(docElementId, m_chrome, element); snippet->setChromeWidget(new ChromeItem(snippet)); } else { snippet = new WebChromeSnippet(docElementId, m_chrome, element); m_renderer->addRenderItem((static_cast<WebChromeSnippet*> (snippet))->item()); } } else { snippet = nativeSnippetForClassName(className, docElementId, element); //TODO: Is the following still needed? QGraphicsWidget * widget = snippet->widget(); //Have snippet determine its own size when in anchor layout. Again, these will not //necessarily be accurate at this point. widget->resize(rect.width(), rect.height()); widget->setPreferredSize(rect.width(), rect.height()); widget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); //Have snippet determine its own location when NOT in anchor layout widget->setPos(rect.x(), rect.y()); } QWebElement parentElem; if (!(parentElem = findChromeParent(element)).isNull()) { snippet->setParentId(parentElem.attribute("id")); } //Set auto-layout attributes snippet->setAnchor(element.attribute("data-GinebraAnchor", "AnchorNone"), false); snippet->setAnchorOffset(element.attribute("data-GinebraAnchorOffset", "0").toInt()); snippet->setInitiallyVisible(element.attribute("data-GinebraVisible", "false") == "true"); snippet->setHidesContent(element.attribute("data-GinebraHidesContent", "false") == "true"); } return snippet; }
void tst_QGraphicsLayout::compressLayoutRequest() { QGraphicsView view; QGraphicsScene scene; TestGraphicsWidget *tw = new TestGraphicsWidget(); scene.addItem(tw); view.show(); QGraphicsLinearLayout *lout = new QGraphicsLinearLayout(tw); for (int i = 0; i < 4; ++i) { QGraphicsWidget *gw = new QGraphicsWidget(tw); gw->setPreferredSize(QSizeF(50, 50)); lout->addItem(gw); } QApplication::processEvents(); QCOMPARE(tw->eventCount(QEvent::LayoutRequest), 1); }
/* * While the pannedWidget is populated, sizePosChanged() signal should be * emitted only once for each actual change in pannedWidget's size. * * See NB#143428 */ void Ut_MPannableViewport::sizePosChangedAfterPopulatingPannedWidget() { QGraphicsWidget *mainWidget = new QGraphicsWidget(); QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); QGraphicsWidget *childWidget; //Settle initial layout position subject->adjustSize(); mainWidget->setLayout(layout); subject->setWidget(mainWidget); QSignalSpy spyRange(subject, SIGNAL(rangeChanged(QRectF))); QSignalSpy spyViewportSize(subject, SIGNAL(viewportSizeChanged(QSizeF))); QSignalSpy spyPosition(subject, SIGNAL(positionChanged(QPointF))); for (int i = 0; i < 30; i++) { childWidget = new QGraphicsWidget; childWidget->setMinimumSize(100, 200); childWidget->setPreferredSize(100, 200); layout->addItem(childWidget); } // Force layout to work. subject->adjustSize(); // Check consecutive signals (if any), are different from each other. // We don't want to send out the very same event twice. for (int i = 1; i < spyRange.size(); i++) { QVERIFY(spyRange.at(i) != spyRange.at(i - 1)); } for (int i = 1; i < spyPosition.size(); i++) { QVERIFY(spyPosition.at(i) != spyPosition.at(i - 1)); } for (int i = 1; i < spyViewportSize.size(); i++) { QVERIFY(spyViewportSize.at(i) != spyViewportSize.at(i - 1)); } }
void tst_QGraphicsLayout::sizeHints() { QGraphicsView view; QGraphicsScene scene; QGraphicsWidget *window = new QGraphicsWidget(); scene.addItem(window); QGraphicsLinearLayout *lout = new QGraphicsLinearLayout(window); lout->setContentsMargins(0,0,0,0); QGraphicsWidget *gw = new QGraphicsWidget(window); gw->setMinimumSize(QSizeF(10,10)); gw->setPreferredSize(QSizeF(100,100)); gw->setMaximumSize(QSizeF(500,500)); lout->addItem(gw); QCOMPARE(lout->effectiveSizeHint(Qt::MinimumSize), gw->effectiveSizeHint(Qt::MinimumSize)); QCOMPARE(lout->effectiveSizeHint(Qt::PreferredSize), gw->effectiveSizeHint(Qt::PreferredSize)); QCOMPARE(lout->effectiveSizeHint(Qt::MaximumSize), gw->effectiveSizeHint(Qt::MaximumSize)); }
void tst_QGraphicsLayout::sizeHintOfHiddenLayout() { QGraphicsScene scene; QGraphicsWidget *window = new QGraphicsWidget(0, Qt::Window); scene.addItem(window); TestLayout *lout = new TestLayout(window); lout->setContentsMargins(1,2,2,1); QGraphicsWidget *w = new QGraphicsWidget; w->setPreferredSize(20, 20); w->setMaximumSize(50, 50); lout->addItem(w); window->setLayout(lout); for (int pass = 0; pass < 3; ++pass) { QCOMPARE(lout->sizeHint(Qt::MinimumSize), QSizeF(3,3)); QCOMPARE(lout->sizeHint(Qt::PreferredSize), QSizeF(23,23)); QCOMPARE(lout->sizeHint(Qt::MaximumSize), QSizeF(53,53)); window->setVisible(pass % 2); } }
void Ut_MPannableViewport::disabledViewportShouldNotAllowWigetToBeBiggerThanViewport() { subject->setVerticalPanningPolicy(MPannableWidget::PanningAlwaysOff); subject->setHorizontalPanningPolicy(MPannableWidget::PanningAlwaysOff); QGraphicsWidget *widget = new QGraphicsWidget(); widget->setPreferredSize(1000,1000); subject->setWidget(widget); // Forcing the size of subject to some value subject->setMinimumSize(QSizeF(500, 300)); subject->setMaximumSize(QSizeF(500, 300)); subject->adjustSize(); QCOMPARE(widget->size(), QSizeF(500,300)); subject->setVerticalPanningPolicy(MPannableWidget::PanningAlwaysOn); subject->setHorizontalPanningPolicy(MPannableWidget::PanningAlwaysOff); }
void Ut_MPannableViewport::testExtendedRange() { QFETCH(qreal, sipHeightExtension); QFETCH(bool, autoRange); QFETCH(qreal, verticalRange); QFETCH(qreal, expectedVerticalRange); QGraphicsScene scene; scene.addItem(subject); const QSizeF viewportSize(100, 100); subject->resize(viewportSize); subject->setMinimumSize(viewportSize); subject->setMaximumSize(viewportSize); subject->setAutoRange(autoRange); QGraphicsWidget *widget = new QGraphicsWidget(); widget->setPreferredSize(1000,1000); subject->setWidget(widget); subject->adjustSize(); subject->layout()->activate(); subject->setRange(QRectF(QPointF(), QSizeF(0, verticalRange))); // Set area occupied by input method area. const QRect imArea(subject->geometry().adjusted(0, (viewportSize.height() - sipHeightExtension), 0, 0).toRect()); subject->d_func()->setInputMethodArea(imArea); const qreal actualVerticalRange = subject->range().height(); // Remove from scene before possible return/fail from QCOMPARE. scene.removeItem(subject); QCOMPARE(actualVerticalRange, expectedVerticalRange); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QGraphicsScene *scene = new QGraphicsScene(); Widget *a = new Widget(Qt::blue, Qt::white, "a"); a->setPreferredSize(100, 100); Widget *b = new Widget(Qt::green, Qt::black, "b"); b->setPreferredSize(100, 100); Widget *c = new Widget(Qt::red, Qt::black, "c"); c->setPreferredSize(100, 100); QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout(); /* //! [adding a corner anchor in two steps] layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop); layout->addAnchor(a, Qt::AnchorLeft, layout, Qt::AnchorLeft); //! [adding a corner anchor in two steps] */ //! [adding a corner anchor] layout->addCornerAnchors(a, Qt::TopLeftCorner, layout, Qt::TopLeftCorner); //! [adding a corner anchor] //! [adding anchors] layout->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight); layout->addAnchor(b, Qt::AnchorTop, a, Qt::AnchorBottom); //! [adding anchors] // Place a third widget below the second. layout->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); /* //! [adding anchors to match sizes in two steps] layout->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft); layout->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight); //! [adding anchors to match sizes in two steps] */ //! [adding anchors to match sizes] layout->addAnchors(b, c, Qt::Horizontal); //! [adding anchors to match sizes] // Anchor the bottom-right corner of the third widget to the bottom-right // corner of the layout. layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner); QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint); w->setPos(20, 20); w->setMinimumSize(100, 100); w->setPreferredSize(320, 240); w->setLayout(layout); w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use")); scene->addItem(w); QGraphicsView *view = new QGraphicsView(); view->setScene(scene); view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout")); view->resize(360, 320); view->show(); return app.exec(); }
void tst_QGraphicsLayout::invalidateAndMove() { // Check that if we set the position of an item and invalidate its layout at the same // time, the widget keeps its correct size QFETCH(bool, instantInvalidatePropagation); QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation); QGraphicsScene scene; QGraphicsWidget *widget = new QGraphicsWidget; new QGraphicsLinearLayout(widget); widget->setMinimumSize(1,1); widget->setPreferredSize(34,34); widget->setMaximumSize(100,100); widget->resize(widget->preferredSize()); scene.addItem(widget); qApp->processEvents(); /* Invalidate and reactivate. The size should not have changed */ widget->layout()->invalidate(); widget->layout()->activate(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setX(1); //Change just the position using setX QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setGeometry(1,1,34,34); //Change just the position using setGeometry QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); widget->layout()->invalidate(); widget->setGeometry(1,1,60,60); //Change just the size using setGeometry QCOMPARE(widget->geometry().size(), QSizeF(60,60)); QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); qApp->processEvents(); QCOMPARE(widget->geometry().size(), QSizeF(60,60)); QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); widget->layout()->invalidate(); widget->setGeometry(0,0,34,34); //Change the size and position using setGeometry QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); qApp->processEvents(); QCOMPARE(widget->geometry().size(), widget->preferredSize()); QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); QGraphicsLayout::setInstantInvalidatePropagation(false); }