void tst_qdeclarativelayoutitem::test_resizing() { //Create Layout (must be done in C++) QGraphicsView view; QGraphicsScene scene; QGraphicsWidget *widget = new QGraphicsWidget(); QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(); widget->setLayout(layout); scene.addItem(widget); view.setScene(&scene); //Add the QML snippet into the layout QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/layoutItem.qml")); QDeclarativeLayoutItem* obj = static_cast<QDeclarativeLayoutItem*>(c.create()); QVERIFY(obj); QCOMPARE(obj->minimumSize(), QSizeF(100,100)); QCOMPARE(obj->preferredSize(), QSizeF(200,200)); QCOMPARE(obj->maximumSize(), QSizeF(300,300)); layout->addItem(obj); layout->setContentsMargins(0,0,0,0); widget->setContentsMargins(0,0,0,0); view.show(); QVERIFY(obj!= 0); widget->setGeometry(QRectF(0,0, 400,400)); QCOMPARE(obj->width(), 300.0); QCOMPARE(obj->height(), 300.0); widget->setGeometry(QRectF(0,0, 300,300)); QCOMPARE(obj->width(), 300.0); QCOMPARE(obj->height(), 300.0); widget->setGeometry(QRectF(0,0, 200,200)); QCOMPARE(obj->width(), 200.0); QCOMPARE(obj->height(), 200.0); widget->setGeometry(QRectF(0,0, 100,100)); QCOMPARE(obj->width(), 100.0); QCOMPARE(obj->height(), 100.0); widget->setGeometry(QRectF(0,0, 40,40)); QCOMPARE(obj->width(), 100.0); QCOMPARE(obj->height(), 100.0); widget->setGeometry(QRectF(0,0, 412,112)); QCOMPARE(obj->width(), 300.0); QCOMPARE(obj->height(), 112.0); }
void ScreenShotPage::createContent() { TemplatePage::createContent(); QGraphicsWidget *panel = centralWidget(); panel->setContentsMargins(0,0,0,0); setContentsMargins(0,0,0,0); layout = new MLayout(panel); layoutPolicy = new MLinearLayoutPolicy(layout, Qt::Vertical); layoutPolicy->setSpacing(0); layoutPolicy->setContentsMargins(0,0,0,0); layout->setPortraitPolicy(layoutPolicy); layout->setLandscapePolicy(layoutPolicy); MLayout * elementsLayout = new MLayout; MLinearLayoutPolicy* elementsPolicyL = new MLinearLayoutPolicy(elementsLayout,Qt::Vertical); elementsLayout->setLandscapePolicy(elementsPolicyL); elementsPolicyL->setSpacing(0); elementsPolicyL->setContentsMargins(0, 0, 0, 0); MLinearLayoutPolicy* elementsPolicyP = new MLinearLayoutPolicy(elementsLayout,Qt::Vertical); elementsLayout->setLandscapePolicy(elementsPolicyP); elementsPolicyP->setSpacing(0); elementsPolicyP->setContentsMargins(0, 0, 0, 0); label1 = new MLabel ("Take a screenshot"); label1->setObjectName("label1"); label1->setStyleName(inv("CommonApplicationHeader")); elementsPolicyL->addItem(label1); elementsPolicyP->addItem(label1); labelDescription = new MLabel (); labelDescription->setObjectName("descriptionLabel"); labelDescription->setWordWrap(true); labelDescription->setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); labelDescription->setStyleName(inv("CommonBodyText")); elementsPolicyL->addItem(labelDescription); elementsPolicyP->addItem(labelDescription); QGraphicsGridLayout * gridSecs = new QGraphicsGridLayout(); entrySeconds = new MTextEdit(MTextEditModel::SingleLine,""); entrySeconds->setObjectName("secondsTextEntry"); entrySeconds->setMaxLength(2); entrySeconds->setStyleName(inv("CommonSingleInputField")); entrySeconds->setContentType(M::NumberContentType); entrySeconds->setText("8"); entrySeconds->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); MLabel * secsLabel = new MLabel(); secsLabel->setObjectName("secsLabel"); secsLabel->setText("seconds"); secsLabel->setStyleName(inv("CommonSingleTitle")); gridSecs->addItem(entrySeconds, 0 , 0 , Qt::AlignVCenter); gridSecs->addItem(secsLabel, 0 , 1, Qt::AlignVCenter); elementsPolicyL->addItem(gridSecs); elementsPolicyP->addItem(gridSecs); buttonScreenshot = new MButton("Take it!"); buttonScreenshot->setObjectName("screenshotButton"); buttonScreenshot->setStyleName(inv("CommonSingleButton")); elementsPolicyL->addItem(buttonScreenshot); elementsPolicyP->addItem(buttonScreenshot); connect(buttonScreenshot, SIGNAL(clicked()), this, SLOT(screenshotDelay())); elementsPolicyL->addStretch(); elementsPolicyP->addStretch(); layoutPolicy->addItem(elementsLayout); retranslateUi(); }