void Ut_MGridLayoutPolicy::testLayoutInLayoutRefresh() { m_policy->setSpacing(0); m_mockLayout->activate(); QGraphicsWidget *widget = new QGraphicsWidget; MLayout *layout = new MLayout(widget); layout->setContentsMargins(0,0,0,0); MGridLayoutPolicy *policy = new MGridLayoutPolicy(layout); m_policy->addItem(widget,0,0); QGraphicsWidget *leftSpacerWithWidget = new QGraphicsWidget; policy->addItem(leftSpacerWithWidget, 0, 0); policy->addItem(m_mockItem100, 0, 1); policy->addItem(new QGraphicsWidget, 0, 2); policy->addItem(m_mockItem200, 0, 3); m_form->resize(400,200); qApp->processEvents(); qApp->processEvents(); QCOMPARE(m_mockItem100->geometry(), QRectF(50,0,100,100)); QCOMPARE(m_mockItem200->geometry(), QRectF(200,0,200,200)); leftSpacerWithWidget->setMaximumWidth(0); qApp->processEvents(); QCOMPARE(m_mockItem100->geometry(), QRectF(0,0,100,100)); QCOMPARE(m_mockItem200->geometry(), QRectF(200,0,200,200)); }
void Ut_MGridLayoutPolicy::testDeletingLayout() { MLayout *layout = new MLayout; MGridLayoutPolicy *policy = new MGridLayoutPolicy(layout); policy->addItem(m_mockItem100, 0, 0); delete policy; delete layout; qApp->processEvents(); }
MLayout *Layout2Columns::layout(const QList<QGraphicsLayoutItem*> &child_list) { int column = 0; int row = 0; MLayout *realFormLayout = new MLayout(); MGridLayoutPolicy *formGridLayoutPolicy = new MGridLayoutPolicy(realFormLayout); foreach(QGraphicsLayoutItem *item, child_list) { formGridLayoutPolicy->addItem(item, row, column); column++; if (column > 1) { column = 0; row++; } }
void LanguagePage::createContent() { MApplicationPage::createContent(); QGraphicsWidget *panel = centralWidget(); MLayout *layout = new MLayout(panel); MGridLayoutPolicy *policy = new MGridLayoutPolicy(layout); comboBoxLanguage = new MComboBox; policy->addItem(comboBoxLanguage, 1, 1); comboBoxLcTime = new MComboBox; comboBoxLcTimeFormat24h = new MComboBox; comboBoxLcCollate = new MComboBox; comboBoxLcNumeric = new MComboBox; comboBoxLcMonetary = new MComboBox; labelHaveGconf = new MLabel; labelHaveIcu = new MLabel; labelExampleNumber = new MLabel; labelExampleDateTime = new MLabel; labelExampleWeekNumber = new MLabel; labelExampleCurrency = new MLabel; labelExampleTranslation1 = new MLabel; labelExampleTranslation2 = new MLabel; labelExampleTranslation3 = new MLabel; labelLtrTest = new MLabel; labelRtlTest = new MLabel; labelLtrTestRich = new MLabel; labelRtlTestRich = new MLabel; labelFontTest = new MLabel; labelFontTest->setWordWrap(true); policy->addItem(comboBoxLcTime, 2, 1); policy->addItem(comboBoxLcTimeFormat24h, 3, 1); policy->addItem(comboBoxLcCollate, 4, 1); policy->addItem(comboBoxLcNumeric, 5, 1); policy->addItem(comboBoxLcMonetary, 6, 1); policy->addItem(labelHaveGconf, 7, 1); policy->addItem(labelHaveIcu, 8, 1); policy->addItem(labelExampleNumber, 9, 1); policy->addItem(labelExampleDateTime, 10, 1); policy->addItem(labelExampleWeekNumber, 11, 1); policy->addItem(labelExampleCurrency, 12, 1); policy->addItem(labelExampleTranslation1, 13, 1); policy->addItem(labelExampleTranslation2, 14, 1); policy->addItem(labelExampleTranslation3, 15, 1); policy->addItem(labelLtrTest, 16, 1); policy->addItem(labelRtlTest, 17, 1); policy->addItem(labelLtrTestRich, 18, 1); policy->addItem(labelRtlTestRich, 19, 1); policy->addItem(labelFontTest, 20, 1); retranslateUi(); }
void Ut_MGridLayoutPolicy::testHeightForWidthInSubLayout() { QFETCH(bool, useMLayout); QFETCH(bool, useInnerMLayout); QFETCH(bool, putInnerWidgetInWidget); QGraphicsWidget *form = new QGraphicsWidget; MGridLayoutPolicy *mpolicy = NULL; QGraphicsGridLayout *qlayout = NULL; if (useMLayout) { MLayout *mlayout = new MLayout(form); mlayout->setContentsMargins(0, 0, 0, 0); mpolicy = new MGridLayoutPolicy(mlayout); mpolicy->setSpacing(0); } else { qlayout = new QGraphicsGridLayout(form); qlayout->setContentsMargins(0, 0, 0, 0); qlayout->setSpacing(0); } QGraphicsWidget *topSpacer = createSpacer(); QGraphicsWidget *leftSpacer = createSpacer(); QGraphicsWidget *rightSpacer = createSpacer(); leftSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); rightSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); QGraphicsWidget *square = new SquareWidget; QGraphicsLayout *innerLayout = NULL; if (useInnerMLayout) { innerLayout = new MLayout(); MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(static_cast<MLayout *>(innerLayout), Qt::Horizontal); policy->addItem(square); } else { innerLayout = new QGraphicsLinearLayout(Qt::Horizontal); static_cast<QGraphicsLinearLayout *>(innerLayout)->addItem(square); } innerLayout->setContentsMargins(0,0,0,0); QGraphicsLayoutItem *innerItem; if (putInnerWidgetInWidget) { QGraphicsWidget *innerWidget = new QGraphicsWidget; innerWidget->setLayout(innerLayout); innerItem = innerWidget; } else { innerItem = innerLayout; } if (useMLayout) { mpolicy->addItem(topSpacer, 0, 1); mpolicy->addItem(leftSpacer, 1, 0); mpolicy->addItem(rightSpacer, 1, 2); mpolicy->addItem(innerItem, 1, 1); } else { qlayout->addItem(topSpacer, 0, 1); qlayout->addItem(leftSpacer, 1, 0); qlayout->addItem(rightSpacer, 1, 2); qlayout->addItem(innerItem, 1, 1); } QCOMPARE(form->preferredSize(), QSizeF(500,500)); QCOMPARE(form->effectiveSizeHint(Qt::PreferredSize, QSizeF(100,-1)), QSizeF(100,100)); delete form; }
void LanguagePage::createContent() { MApplicationPage::createContent(); pannableViewport()->setAcceptGesturesFromAnyDirection(true); setStyleName(inv("CommonApplicationPage")); QGraphicsWidget *panel = centralWidget(); panel->setObjectName("panel"); MLayout *layout = new MLayout(panel); MGridLayoutPolicy *policy = new MGridLayoutPolicy(layout); policy->setContentsMargins(0, 0, 0, 0); policy->setSpacing(0); comboBoxLanguage = new MComboBox; comboBoxLanguage->setObjectName("comboBoxLanguage"); comboBoxLanguage->setStyleName(inv("CommonComboBox")); policy->addItem(comboBoxLanguage, 1, 1); comboBoxLcTime = new MComboBox; comboBoxLcTime->setObjectName("comboBoxLcTime"); comboBoxLcTime->setStyleName(inv("CommonComboBox")); comboBoxLcTimeFormat24h = new MComboBox; comboBoxLcTimeFormat24h->setObjectName("comboBoxLcTimeFormat24h"); comboBoxLcTimeFormat24h->setStyleName(inv("CommonComboBox")); comboBoxLcCollate = new MComboBox; comboBoxLcCollate->setObjectName("comboBoxLcCollate"); comboBoxLcCollate->setStyleName(inv("CommonComboBox")); comboBoxLcNumeric = new MComboBox; comboBoxLcNumeric->setObjectName("comboBoxLcNumeric"); comboBoxLcNumeric->setStyleName(inv("CommonComboBox")); comboBoxLcMonetary = new MComboBox; comboBoxLcMonetary->setObjectName("comboBoxLcMonetary"); comboBoxLcMonetary->setStyleName(inv("CommonComboBox")); labelHaveGconf = new MLabel; labelHaveGconf->setObjectName("labelHaveGconf"); labelHaveGconf->setStyleName(inv("CommonBodyText")); labelHaveGconf->setWordWrap(true); labelHaveIcu = new MLabel; labelHaveIcu->setObjectName("labelHaveIcu"); labelHaveIcu->setStyleName(inv("CommonBodyText")); labelHaveIcu->setWordWrap(true); labelExampleNumber = new MLabel; labelExampleNumber->setObjectName("labelExampleNumber"); labelExampleNumber->setStyleName(inv("CommonBodyText")); labelExampleNumber->setWordWrap(true); labelExampleDateTime = new MLabel; labelExampleDateTime->setObjectName("labelExampleDateTime"); labelExampleDateTime->setStyleName(inv("CommonBodyText")); labelExampleDateTime->setWordWrap(true); labelExampleWeekNumber = new MLabel; labelExampleWeekNumber->setObjectName("labelExampleWeekNumber"); labelExampleWeekNumber->setStyleName(inv("CommonBodyText")); labelExampleWeekNumber->setWordWrap(true); labelExampleCurrency = new MLabel; labelExampleCurrency->setObjectName("labelExampleCurrency"); labelExampleCurrency->setStyleName(inv("CommonBodyText")); labelExampleCurrency->setWordWrap(true); labelExampleTranslation1 = new MLabel; labelExampleTranslation1->setObjectName("labelExampleTranslation1"); labelExampleTranslation1->setStyleName(inv("CommonBodyText")); labelExampleTranslation1->setWordWrap(true); labelExampleTranslation2 = new MLabel; labelExampleTranslation2->setObjectName("labelExampleTranslation2"); labelExampleTranslation2->setStyleName(inv("CommonBodyText")); labelExampleTranslation2->setWordWrap(true); labelExampleTranslation3 = new MLabel; labelExampleTranslation3->setObjectName("labelExampleTranslation3"); labelExampleTranslation3->setStyleName(inv("CommonBodyText")); labelExampleTranslation3->setWordWrap(true); labelLtrTest = new MLabel; labelLtrTest->setObjectName("labelLtrTest"); labelLtrTest->setStyleName(inv("CommonBodyText")); labelLtrTest->setWordWrap(true); labelRtlTest = new MLabel; labelRtlTest->setObjectName("labelRtlTest"); labelRtlTest->setStyleName(inv("CommonBodyText")); labelRtlTest->setWordWrap(true); labelLtrTestRich = new MLabel; labelLtrTestRich->setObjectName("labelLtrTestRich"); labelLtrTestRich->setStyleName(inv("CommonBodyText")); labelLtrTestRich->setWordWrap(true); labelRtlTestRich = new MLabel; labelRtlTestRich->setObjectName("labelRtlTestRich"); labelRtlTestRich->setStyleName(inv("CommonBodyText")); labelRtlTestRich->setWordWrap(true); labelFontTest = new MLabel; labelFontTest->setObjectName("labelFontTest"); labelFontTest->setStyleName(inv("CommonBodyText")); labelFontTest->setWordWrap(true); labelFontTest->setWordWrap(true); policy->addItem(comboBoxLcTime, 2, 1); policy->addItem(comboBoxLcTimeFormat24h, 3, 1); policy->addItem(comboBoxLcCollate, 4, 1); policy->addItem(comboBoxLcNumeric, 5, 1); policy->addItem(comboBoxLcMonetary, 6, 1); policy->addItem(labelHaveGconf, 7, 1); policy->addItem(labelHaveIcu, 8, 1); policy->addItem(labelExampleNumber, 9, 1); policy->addItem(labelExampleDateTime, 10, 1); policy->addItem(labelExampleWeekNumber, 11, 1); policy->addItem(labelExampleCurrency, 12, 1); policy->addItem(labelExampleTranslation1, 13, 1); policy->addItem(labelExampleTranslation2, 14, 1); policy->addItem(labelExampleTranslation3, 15, 1); policy->addItem(labelLtrTest, 16, 1); policy->addItem(labelRtlTest, 17, 1); policy->addItem(labelLtrTestRich, 18, 1); policy->addItem(labelRtlTestRich, 19, 1); policy->addItem(labelFontTest, 20, 1); retranslateUi(); }
SwAcctEditPage::SwAcctEditPage(SwClientService *swService, QGraphicsItem *parent) : MApplicationPage(parent), mService(swService), mServiceConfig(mService->getServiceConfig()), mFlickrClicked(false) { int adj = 0; setEscapeMode(MApplicationPageModel::EscapeManualBack); connect(this, SIGNAL(backButtonClicked()), this, SLOT(dismiss())); connect(mService, SIGNAL(CredsStateChanged(SwClientService*,SwClientService::CredsState)), this, SLOT(onCredsStateChanged(SwClientService *, SwClientService::CredsState))); if (!mServiceConfig->isValid()) dismiss(); mParams = mServiceConfig->getConfigParams(); MLayout *layout = new MLayout; MGridLayoutPolicy *policy = new MGridLayoutPolicy(layout); QString link = mServiceConfig->getLink(); MLabel *lblServiceName = new MLabel(); if (!link.isEmpty()) lblServiceName->setText(QString("<a href=\"%1\">%2</a>").arg(link, mServiceConfig->getDisplayName())); else lblServiceName->setText(mServiceConfig->getDisplayName()); lblServiceName->setObjectName("SwAcctEditPageServiceNameLabel"); policy->addItem(lblServiceName, 0, 0, 1, 2, Qt::AlignHCenter); connect(lblServiceName, SIGNAL(linkActivated(QString)), this, SLOT(onLinkClicked(QString))); QString desc = mServiceConfig->getDescription(); if (!desc.isEmpty()) { MLabel *lblServiceDesc = new MLabel(); lblServiceDesc->setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); lblServiceDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //Have to insert a random HTML tag to make word wrap actually work... //Should be able to remove at some point once MTF word wrap works properly lblServiceDesc->setText(QString("<b></b>").append(desc)); lblServiceDesc->setObjectName("SwAcctEditPageServiceDescLabel"); policy->addItem(lblServiceDesc, 1, 0, 1, 2, Qt::AlignLeft); } else { adj -= 1; } //This is *ugly* if (mServiceConfig->getAuthtype() == SwClientServiceConfig::AuthTypeFlickr) { if (!mParams.value(USER_KEY).isEmpty()) { //% "User %1" MLabel *lblUsername = new MLabel(qtTrId("label_flickr_username").arg(mParams.value(USER_KEY))); lblUsername->setObjectName("SwAcctEditPageFlickrUserLabel"); policy->addItem(lblUsername, 2+adj, 0, 1, 2, Qt::AlignHCenter); adj += 1; } mFlickrButton = new MButton(); mFlickrButton->setObjectName("SwAcctEditPageFlickrButton"); policy->addItem(mFlickrButton, 2+adj, 0, 1, 2, Qt::AlignHCenter); connect(mFlickrButton, SIGNAL(clicked()), this, SLOT(onFlickrClicked())); adj += 1; } else { MLabel *lblUsername = new MLabel(); lblUsername->setObjectName("SwAcctEditPageUsernameLabel"); lblUsername->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //% "Username:"******"label_username")); policy->addItem(lblUsername, 2+adj, 0); mEdtUsername = new MTextEdit(MTextEditModel::SingleLine); mEdtUsername->setObjectName("SwAcctEditPageUsernameButton"); mEdtUsername->setText(mParams.value(USER_KEY)); //qDebug() << QString("Set username to %1").arg(mParams.value(USER_KEY)); policy->addItem(mEdtUsername, 2+adj, 1); if (mServiceConfig->getAuthtype() == SwClientServiceConfig::AuthTypePassword) { MLabel *lblPassword = new MLabel(); lblPassword->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //% "Password:"******"label_password")); lblPassword->setObjectName("SwAcctEditPagePasswordLabel"); policy->addItem(lblPassword, 3+adj, 0); mEdtPassword = new MTextEdit(MTextEditModel::SingleLine); mEdtPassword->setText(mParams.value(PASS_KEY)); mEdtPassword->setEchoMode(MTextEditModel::Password); mEdtPassword->setObjectName("SwAcctEditPagePasswordButton"); // qDebug() << QString("Set password to %1").arg(mParams.value(PASS_KEY)); policy->addItem(mEdtPassword, 3+adj, 1); connect(mEdtPassword, SIGNAL(textChanged()), this, SLOT(onLoginChanged())); adj += 1; } } mLblStatus = new MLabel(STATUS_TEXT_UNCONFIGURED); mLblStatus->setObjectName("SwAcctEditPageStatusLabel"); policy->addItem(mLblStatus, 3+adj, 0, 1, 2, Qt::AlignHCenter); onCredsStateChanged(mService, mService->credsState()); MLabel *lblServiceHint = new MLabel(); lblServiceHint->setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); lblServiceHint->setObjectName("SwAcctEditPageServiceHintLabel"); lblServiceHint->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); lblServiceHint->setText(SERVICE_HINT_TEXT.arg(mService->getDisplayName())); policy->addItem(lblServiceHint, 4+adj, 0, 1, 2); //This, also, is *ugly* if (mServiceConfig->getAuthtype() != SwClientServiceConfig::AuthTypeFlickr) { //% "Apply" mBtnApply = new MButton(qtTrId("button_apply")); mBtnApply->setObjectName("SwAcctEditPageApplyButton"); policy->addItem(mBtnApply, 5+adj, 0, 1, 2, Qt::AlignHCenter); //% "Cancel" mBtnCancel = new MButton(qtTrId("button_cancel")); mBtnCancel->setObjectName("SwAcctEditPageCancelButton"); policy->addItem(mBtnCancel, 6+adj, 0, 1, 2, Qt::AlignHCenter); connect(mEdtUsername, SIGNAL(textChanged()), this, SLOT(onLoginChanged())); connect(mBtnApply, SIGNAL(clicked()), this, SLOT(onApplyClicked())); connect(mBtnCancel, SIGNAL(clicked()), this, SLOT(dismiss())); } layout->setPolicy(policy); centralWidget()->setLayout(layout); }
CalculatorWidget::CalculatorWidget() { mValue = 0; //Prevent the layout from changing in right-to-left. //The calculation line will still be reversed however. setLayoutDirection(Qt::LeftToRight); /* Create a MLayout attached to this widget */ MLayout *layout = new MLayout(this); MGridLayoutPolicy *landscapePolicy = new MGridLayoutPolicy(layout); MGridLayoutPolicy *portraitPolicy = new MGridLayoutPolicy(layout); layout->setPortraitPolicy(portraitPolicy); layout->setLandscapePolicy(landscapePolicy); landscapePolicy->setObjectName("calculatorLandscape"); portraitPolicy->setObjectName("calculatorPortrait"); mCalculationLine = new MLabel; mCalculationLine->setObjectName("calculationLine"); mCalculationLine->setAlignment(Qt::AlignRight); QList<CalculatorButton *> buttons; CalculatorButton *button; for (int i = 0; i < 10; i++) { button = new CalculatorButton(CalculatorButton::Button((int)CalculatorButton::Num0 + i), this); if (i == 0) { landscapePolicy->addItem(button, 3, 4); portraitPolicy->addItem(button, 6, 0); } else { landscapePolicy->addItem(button, 2 - (i - 1) / 3, 4 + (i - 1) % 3); portraitPolicy->addItem(button, 5 - (i - 1) / 3, (i - 1) % 3); } } CalculatorButton *buttonC = new CalculatorButton(CalculatorButton::Clear, this); CalculatorButton *buttonBackspace = new CalculatorButton(CalculatorButton::Backspace, this); CalculatorButton *buttonSign = new CalculatorButton(CalculatorButton::Sign, this); CalculatorButton *buttonDecimal = new CalculatorButton(CalculatorButton::Decimal, this); CalculatorButton *buttonReciprocal = new CalculatorButton(CalculatorButton::Reciprocal, this); CalculatorButton *buttonPower = new CalculatorButton(CalculatorButton::Power, this); CalculatorButton *buttonSqrt = new CalculatorButton(CalculatorButton::Sqrt, this); CalculatorButton *buttonPercentage = new CalculatorButton(CalculatorButton::Percentage, this); CalculatorButton *buttonDivide = new CalculatorButton(CalculatorButton::Divide, this); CalculatorButton *buttonMultiply = new CalculatorButton(CalculatorButton::Multiply, this); CalculatorButton *buttonSubtract = new CalculatorButton(CalculatorButton::Subtract, this); CalculatorButton *buttonAdd = new CalculatorButton(CalculatorButton::Add, this); CalculatorButton *buttonEquals = new CalculatorButton(CalculatorButton::Equals, this); buttonEquals->setObjectName("calculatorButtonEquals"); landscapePolicy->addItem(mCalculationLine, 0, 0, 1, 4); landscapePolicy->addItem(buttonC, 1, 0); landscapePolicy->addItem(buttonBackspace, 1, 1); landscapePolicy->addItem(buttonSign, 1, 2); landscapePolicy->addItem(buttonDecimal, 1, 3); landscapePolicy->addItem(buttonReciprocal, 2, 0); landscapePolicy->addItem(buttonPower, 2, 1); landscapePolicy->addItem(buttonSqrt, 2, 2); landscapePolicy->addItem(buttonPercentage, 2, 3); landscapePolicy->addItem(buttonDivide, 3, 0); landscapePolicy->addItem(buttonMultiply, 3, 1); landscapePolicy->addItem(buttonSubtract, 3, 2); landscapePolicy->addItem(buttonAdd, 3, 3); landscapePolicy->addItem(buttonEquals, 3, 5, 1, 2); portraitPolicy->addItem(mCalculationLine, 0, 0, 1, 4); portraitPolicy->addItem(buttonC, 1, 0); portraitPolicy->addItem(buttonBackspace, 1, 1); portraitPolicy->addItem(buttonReciprocal, 1, 2); portraitPolicy->addItem(buttonDivide, 1, 3); portraitPolicy->addItem(buttonPower, 2, 0); portraitPolicy->addItem(buttonSqrt, 2, 1); portraitPolicy->addItem(buttonPercentage, 2, 2); portraitPolicy->addItem(buttonMultiply, 2, 3); portraitPolicy->addItem(buttonSubtract, 3, 3); portraitPolicy->addItem(buttonAdd, 4, 3); portraitPolicy->addItem(buttonEquals, 5, 3, 2, 1); portraitPolicy->addItem(buttonDecimal, 6, 1); portraitPolicy->addItem(buttonSign, 6, 2); setValue(mValue); }