static void creatLabel (MLinearLayoutPolicy *policy, QString text, bool addSpacing=false)
{
    MLabel *label = new MLabel (text);
    label->setWordWrap(true);
    label->setObjectName ("AccountSetupPageLabel");
    policy->addItem(label);
    if (addSpacing)
        policy->setItemSpacing(policy->indexOf(label), 5);
}
int main(int argc, char **argv)
{
    MApplication app(argc, argv);
    MTheme::loadCSS("layout_inside_layout.css");
    MApplicationWindow window;
    MApplicationPage page;

    /* Create a MLayout that we set the policies for */
    MLayout *layout = new MLayout;
    MLinearLayoutPolicy *portraitPolicy = new MLinearLayoutPolicy(layout, Qt::Horizontal);
    MLinearLayoutPolicy *landscapePolicy = new MLinearLayoutPolicy(layout, Qt::Horizontal);
    for (int i = 0; i < 3; ++i) {
        MLabel *label = new MLabel(QString("Item %1").arg(i + 1));
        label->setAlignment(Qt::AlignCenter);
        label->setObjectName("item"); //Set CSS name for styling
        portraitPolicy->addItem(label);
        landscapePolicy->addItem(label);
    }
    /* Create a widget to hold the inner layout and to put inside the policy */
    QGraphicsWidget *widget = new QGraphicsWidget;
    /* Create an inner layout.  A QGraphicsGridLayout is used since we don't require
     * multiple policies here, but using a MLayout would also work. */
    QGraphicsGridLayout *innerLayout = new QGraphicsGridLayout(widget);
    for (int i = 0; i < 4; ++i) {
        MLabel *label = new MLabel(QString("Inner Item %1").arg(i + 1));
        label->setAlignment(Qt::AlignCenter);
        label->setObjectName("inneritem"); //Set CSS name for styling
        innerLayout->addItem(label, i / 2, i % 2);
    }
    /* Now add the widget to the landscape policy only, so that the innerLayout is hidden when device is rotated */
    landscapePolicy->addItem(widget);
    layout->setLandscapePolicy(landscapePolicy);
    layout->setPortraitPolicy(portraitPolicy);

    /* Attach the layout to the page */
    page.centralWidget()->setLayout(layout);
    page.appear(&window);
    window.show();
    return app.exec();
}
void ConversationPage::processAttachments(const QMailMessage &message)
{
    if (!message.status() & QMailMessageMetaData::HasAttachments)
        return;

    connect(this, SIGNAL(downloadCompleted()), this, SLOT(saveAttachment()));

    bool oneTimeFlag = true;
    for (uint i = 1; i < message.partCount(); ++i)
    {
        QMailMessagePart sourcePart = message.partAt(i);
        if (!(sourcePart.multipartType() == QMailMessagePartContainer::MultipartNone))
            continue;

        if (oneTimeFlag)
        {
            MSeparator *separator = new MSeparator();
            separator->setObjectName("Separator");
            m_policy->addItem(separator);
            oneTimeFlag = false;
        }

        MStylableWidget *w = new MStylableWidget(this);
        QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Horizontal);
        w->setLayout(layout);
        //% "Attached: "
        MLabel *label = new MLabel(qtTrId("xx_attached"));
        label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        label->setObjectName ("AttachmentText");
        layout->addItem(label);
        MButton *button = new MButton(sourcePart.displayName());
        button->setObjectName ("AttachmentButton");
        button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        layout->addItem(button);

        //% "Download..."
        AttachmentAction *action = new AttachmentAction(qtTrId("xx_download_context_menu"), button, sourcePart);
        connect(action, SIGNAL(triggered()), this, SLOT(openAttachmentDownloadDialog()));

        //% "Open..."
        action = new AttachmentAction(qtTrId("xx_open_context_menu"), button, sourcePart);
        connect(action, SIGNAL(triggered()), this, SLOT(openAttachmentOpenDialog()));
        m_policy->addItem (w);
    }
}
int main(int argc, char **argv)
{
    MApplication app(argc, argv);
    MApplicationWindow window;
    MApplicationPage page;
    MTheme::loadCSS("twocolumns.css");
    /* Create a MLayout that we set the policy for */
    MLayout *layout = new MLayout(page.centralWidget());
    MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(layout, Qt::Horizontal);

    /* Setup first layout with a label and text edit */
    MLayout *nameLayout = new MLayout;
    MLinearLayoutPolicy *namePolicy = new MLinearLayoutPolicy(nameLayout, Qt::Horizontal);
    MLabel *textEditLabel = new MLabel("Name:");
    MTextEdit *textEdit = new MTextEdit(MTextEditModel::MultiLine);
    namePolicy->addItem(textEditLabel);  //Add the label and textedit
    namePolicy->addItem(textEdit);
    textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

    /* Setup second layout with a large label */
    MLayout *labelLayout = new MLayout;
    MLinearLayoutPolicy *labelPolicy = new MLinearLayoutPolicy(labelLayout, Qt::Horizontal);
    MLabel *label = new MLabel("Enter the name of the person who likes to listen to music while sorting their socks!");
    label->setObjectName("nameLabel");
    labelPolicy->addItem(label);
    label->setWordWrap(true);

    /* Add the two layouts to the layout */
    policy->addItem(nameLayout);
    policy->addItem(labelLayout);

    /* Make the two layouts have an equal preferred size, so that they get an equal amount of space */
    nameLayout->setPreferredWidth(1);
    labelLayout->setPreferredWidth(1);

    page.appear(&window);
    window.show();

    return app.exec();
}
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();
}
void ConversationPage::createContent()
{
    MApplicationPage::createContent();
    setContentsMargins(0, 0, 0, 0);
    setPannable(true);

    createActions();
    //% "Mail"
    setTitle(qtTrId("xx_page_title"));

    MLayout *layout = new MLayout(centralWidget());
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setAnimation(0);

    m_policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
    m_policy->setObjectName("VerticalPolicy");
    m_policy->setContentsMargins(0, 0, 0, 0);
    m_policy->setSpacing(0);

    QMailMessage message(m_id);
    //% "From"
    QString body = qtTrId("xx_from") + ": " + message.from().address() + "\n";
    QStringList addresses = QMailAddress::toStringList(message.to());
    //% "To"
    body.append(qtTrId("xx_to") + ": "  + addresses.join("; ") + "\n");
    addresses = QMailAddress::toStringList(message.cc());
    if (addresses.size() > 0)
        //% "Cc"
        body.append(qtTrId("xx_cc" ) + ": " + addresses.join("; ") + "\n");
    addresses = QMailAddress::toStringList(message.bcc());
    if (addresses.size() > 0)
        //% "Bcc"
        body.append(qtTrId("xx_bcc" ) + ": " + addresses.join("; ") + "\n");

    QMailAddress replyTo = message.replyTo();
    if (!replyTo.isNull())
        //% "Reply-To"
        body.append(qtTrId("xx_reply_to") + ": " + replyTo.toString() + "\n");

    //% "Subject"
    body.append(qtTrId("xx_subject") + ": " + message.subject() + "\n");
    //% "Date: %1"
    body.append(qtTrId("xx_date").arg(message.date().toLocalTime().toString(Qt::SystemLocaleShortDate)));
    MLabel *messageBody = new MLabel(body);
    messageBody->setWordWrap(true);
    messageBody->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    messageBody->setObjectName("BodyText");
    m_policy->addItem(messageBody);

    MSeparator *separator = new MSeparator();
    separator->setObjectName("Separator");
    m_policy->addItem(separator);

    messageBody = new MLabel("\n" + Utils::bodyPlainText(&message));
    messageBody->setWordWrap(true);
    messageBody->setObjectName("BodyText");
    messageBody->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    m_policy->addItem (messageBody);
    processAttachments(message);

    centralWidget()->setLayout(layout);
}
// ----------------------------------------------------------------------------
// CReporterSendSelectedDialog::createcontent
// ----------------------------------------------------------------------------
void CReporterSendSelectedDialog::createcontent()
{
    Q_D(CReporterSendSelectedDialog);
    setObjectName("CrashReporterSendSelectedDialog");

    int nbrOfFiles = d_ptr->files.count();
    QString message;

    if (nbrOfFiles == 1) {
        //% "<p>This system has 1 stored crash report. Select reports to send to %1 for analysis or to delete.</p>"
        message = qtTrId("qtn_system_has_1_crash_report_send_to_%s").arg(d->server);

    }
    else {
        //% "<p>This system has %1 stored crash reports. Select reports to send to %2 for analysis or to delete.</p>"
        message = qtTrId("qtn_system_has_%1_crash_reports_send_to_%2").arg(nbrOfFiles).arg(d->server);

    }

    // Create content to be placed on central widget.
    QGraphicsWidget *panel = centralWidget();

    // Create layout and policy.
    MLayout *layout = new MLayout(panel);
    layout->setContentsMargins(0,0,0,0);
    panel->setLayout(layout);
    MLinearLayoutPolicy  *policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
    policy->setObjectName("DialogMainLayout");

    // Create message label and hack it to support wordwrapping
    MLabel *messagelabel = new MLabel(message, panel);
    messagelabel->setWordWrap(true);
    messagelabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    messagelabel->setObjectName("DialogMessageLabel");
    messagelabel->setStyleName("CommonFieldLabelInverted");

    d->list = new MList(panel);
    d->cellCreator = new MContentItemCreator;

    d->list->setCellCreator(d->cellCreator);
    d->model = new CReporterSendFileListModel(d->files);
    d->list->setItemModel(d->model);
    d->list->setSelectionMode(MList::MultiSelection);

    // Add widgets to the layout
    policy->addItem(messagelabel, Qt::AlignLeft | Qt::AlignTop);
    policy->addItem(d->list, Qt::AlignLeft | Qt::AlignTop);

    // Add buttons to button area.
    QSignalMapper *mapper = new QSignalMapper(this);
    //% "Send Selected"
    MButton* dialogButton = new MButton(qtTrId("qtn_send_selected_button"));
    dialogButton->setStyleName("CommonSingleButtonInverted");
    policy->addItem(dialogButton, Qt::AlignCenter);
//    MButtonModel *dialogButton = addButton(qtTrId("qtn_send_selected_button"), M::ActionRole);
    connect(dialogButton, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(dialogButton, static_cast<int>(CReporter::SendSelectedButton));

    //% "Send All"
    dialogButton = new MButton(qtTrId("qtn_send_all_button"));
    dialogButton->setStyleName("CommonSingleButtonInverted");
    policy->addItem(dialogButton, Qt::AlignCenter);
//    dialogButton = addButton(qtTrId("qtn_send_all_button"), M::ActionRole);
    connect(dialogButton, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(dialogButton, static_cast<int>(CReporter::SendAllButton));

    //% "Delete Selected"
    dialogButton = new MButton(qtTrId("qtn_delete_selected_button"));
    dialogButton->setStyleName("CommonSingleButtonInverted");
    policy->addItem(dialogButton, Qt::AlignCenter);
//    dialogButton = addButton(qtTrId("qtn_delete_selected_button"), M::DestructiveRole);
    connect(dialogButton, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(dialogButton, static_cast<int>(CReporter::DeleteSelectedButton));

    connect(mapper, SIGNAL(mapped(int)), SIGNAL(actionPerformed(int)));
    connect(mapper, SIGNAL(mapped(int)), SLOT(accept()));
}
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);
}