void tst_QFormLayout::layoutAlone()
{
    QWidget w;
    QFormLayout layout;
    layout.setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
    w.setLayout(&layout);
    QLabel label("Here is a strange test case");
    layout.setWidget(0, QFormLayout::LabelRole, &label);
    QHBoxLayout hlay;
    layout.setLayout(1, QFormLayout::LabelRole, &hlay);
    QCOMPARE(layout.count(), 2);
    w.show();
    layout.activate();
    QTest::qWait(500);
}
WorkbenchPage::WorkbenchPage(QWidget* parent):QWidget(parent), uComboBox(0), wSpinBox(0), hSpinBox(0), pLineEdit(0){
    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    setLayout(mainLayout);

    QGroupBox* defaultSizeGroupBox = new QGroupBox(tr("Default Size"), this);
    QFormLayout* defaultSizeLayout = new QFormLayout(defaultSizeGroupBox);
    defaultSizeGroupBox->setLayout(defaultSizeLayout);
    QLabel* uLabel = new QLabel(tr("Unit:"), this);
    QLabel* wLabel = new QLabel(tr("Width:"), this);
    QLabel* hLabel = new QLabel(tr("Height:"), this);
    uComboBox = new QComboBox(this);
    uComboBox->addItem(tr("Pixel"));
    uComboBox->addItem(tr("Millimeter"));
    uComboBox->addItem(tr("Centimeter"));
    uComboBox->addItem(tr("Meter"));
    uComboBox->addItem(tr("Inch"));
    connect(uComboBox, SIGNAL(activated(const QString&)), this, SLOT(setWorkbenchSizeUnitSuffix(const QString&)));
    wSpinBox = new QSpinBox(this);
    hSpinBox = new QSpinBox(this);
    defaultSizeLayout->setWidget(0, QFormLayout::LabelRole, uLabel);
    defaultSizeLayout->setWidget(0, QFormLayout::FieldRole, uComboBox);
    defaultSizeLayout->setWidget(1, QFormLayout::LabelRole, wLabel);
    defaultSizeLayout->setWidget(1, QFormLayout::FieldRole, wSpinBox);
    defaultSizeLayout->setWidget(2, QFormLayout::LabelRole, hLabel);
    defaultSizeLayout->setWidget(2, QFormLayout::FieldRole, hSpinBox);
    
    mainLayout->addWidget(defaultSizeGroupBox);
    
    QGroupBox* autosaveGroupBox = new QGroupBox(tr("Autosave"), this);
    autosaveGroupBox->setCheckable(true);
    QFormLayout* autosaveLayout = new QFormLayout(autosaveGroupBox);
    autosaveGroupBox->setLayout(autosaveLayout);
    QLabel* pLabel = new QLabel(tr("Path:"), this);
    pLineEdit = new QLineEdit(this);
    QToolButton* pToolButton = new QToolButton(this);
    pToolButton->setText(tr("..."));
    connect(pToolButton, SIGNAL(clicked()), this, SLOT(getAutosavePath()));
    QHBoxLayout* pLayout = new QHBoxLayout();
    pLayout->addWidget(pLineEdit);
    pLayout->addWidget(pToolButton);
    autosaveLayout->setWidget(0, QFormLayout::LabelRole, pLabel);
    autosaveLayout->setLayout(0, QFormLayout::FieldRole, pLayout);
//    autosaveLayout->setWidget(0, QFormLayout::FieldRole, pLineEdit);
    
    mainLayout->addWidget(autosaveGroupBox);
}
void tst_QFormLayout::setLayout()
{
    QFormLayout layout;

    QHBoxLayout l1;
    QHBoxLayout l2;
    QHBoxLayout l3;
    QHBoxLayout l4;

    QCOMPARE(layout.count(), 0);
    QCOMPARE(layout.rowCount(), 0);

    layout.setLayout(5, QFormLayout::LabelRole, &l1);
    QCOMPARE(layout.count(), 1);
    QCOMPARE(layout.rowCount(), 6);

    layout.setLayout(3, QFormLayout::FieldRole, &l2);
    layout.setLayout(3, QFormLayout::LabelRole, &l3);
    QCOMPARE(layout.count(), 3);
    QCOMPARE(layout.rowCount(), 6);

    // should be ignored and generate warnings
    layout.setLayout(3, QFormLayout::FieldRole, &l4);
    layout.setLayout(-1, QFormLayout::FieldRole, &l4);
    QCOMPARE(layout.count(), 3);
    QCOMPARE(layout.rowCount(), 6);

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l1, &row, &role);
        QCOMPARE(row, 5);
        QCOMPARE(int(role), int(QFormLayout::LabelRole));
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l2, &row, &role);
        QCOMPARE(row, 3);
        QCOMPARE(int(role), int(QFormLayout::FieldRole));
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l3, &row, &role);
        QCOMPARE(row, 3);
        QCOMPARE(int(role), int(QFormLayout::LabelRole));
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l4, &row, &role);
        QCOMPARE(row, -1);
        QCOMPARE(int(role), -123);
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(0, &row, &role);
        QCOMPARE(row, -1);
        QCOMPARE(int(role), -123);
    }
}
BackgroundWidget::BackgroundWidget(QWidget *parent) :
    QWidget(parent)
{

    this->setWindowTitle("Background");
    this->setWindowIcon(QIcon(":/resources/icons/resources/background.png"));

    zoomInAction = new QAction(QIcon(":/icons/actions/zoom-in.png"), "Zoom In", NULL);
    connect(zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
    zoomOutAction = new QAction(QIcon(":/icons/actions/zoom-out.png"), "Zoom Out", NULL);
    connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut()));
    QAction* openAction = new QAction(QIcon(":/icons/actions/open.png"), "Load from file", NULL);
    connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
    QAction* saveAction = new QAction(QIcon(":/icons/actions/save.png"), "Save to file", NULL);
    connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
    QAction* printAction = new QAction(QIcon(":/icons/actions/print.png"), "Print", NULL);
    connect(printAction, SIGNAL(triggered()), this, SLOT(print()));

    QVBoxLayout* propertiesLayout = new QVBoxLayout();

    QLabel* nameLabel = new QLabel("Name: ");
    QLineEdit* nameEdit = new QLineEdit("bg_0", this);

    QToolBar* toolBar = new QToolBar();
    toolBar->addAction(QIcon(":/icons/actions/accept.png"), "Save Changes");
    toolBar->addAction(openAction);
    toolBar->addAction(saveAction);
    toolBar->addAction(printAction);

    toolBar->addSeparator();
    toolBar->addAction(zoomInAction);
    toolBar->addAction(zoomOutAction);
    toolBar->addSeparator();
    toolBar->addWidget(nameLabel);
    toolBar->addWidget(nameEdit);

    toolBar->setStyleSheet(" QToolBar { height: 18px; width: 18px; icon-size: 18px; } ");

    QCheckBox* smoothCheckBox = new QCheckBox("Smooth", this);
    QCheckBox* transparentCheckBox = new QCheckBox("Transparent", this);
    QCheckBox* preloadCheckBox = new QCheckBox("Preload", this);
    QCheckBox* tilesetCheckBox = new QCheckBox("Tileset", this);

    imageLabel = new QLabel;
    imageLabel->setBackgroundRole(QPalette::Base);
    imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    imageLabel->setScaledContents(true);


    scrollArea = new QScrollArea;
    scrollArea->setBackgroundRole(QPalette::Dark);
    scrollArea->setWidget(imageLabel);
    scrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);

    propertiesLayout->addWidget(smoothCheckBox);
    propertiesLayout->addWidget(transparentCheckBox);
    propertiesLayout->addWidget(preloadCheckBox);
    propertiesLayout->addWidget(tilesetCheckBox);
    QSplitter* horizontalSplitter = new QSplitter(this);
    QWidget* propertiesWidget = new QWidget(this, Qt::WindowTitleHint);
    QFormLayout* propertiesFormLayout = new QFormLayout();
    propertiesFormLayout->setLayout(0, QFormLayout::SpanningRole, propertiesLayout);
    propertiesWidget->setLayout(propertiesFormLayout);

    horizontalSplitter->addWidget(propertiesWidget);
    horizontalSplitter->addWidget(scrollArea);
    horizontalSplitter->setStretchFactor(0, 0);
    horizontalSplitter->setStretchFactor(1, 1);

    QVBoxLayout* verticalLayout = new QVBoxLayout();
    verticalLayout->addWidget(toolBar);
    verticalLayout->addWidget(horizontalSplitter);
    QStatusBar* statusBar = new QStatusBar();
    statusBar->showMessage("Width: 0 | Height: 0 | Memory: 0 B | Zoom: 100%");
    statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
    verticalLayout->addWidget(statusBar);
    verticalLayout->setContentsMargins(2, 2, 2, 2);
    this->setLayout(verticalLayout);
}
    SeExprEdAddDialog::SeExprEdAddDialog(int& count,QWidget* parent)
        :QDialog(parent)
    {
        QVBoxLayout *verticalLayout;
        verticalLayout = new QVBoxLayout();
        verticalLayout->setSpacing(3);
        verticalLayout->setMargin(3);
        setLayout(verticalLayout);
        QHBoxLayout *horizontalLayout = new QHBoxLayout();

        horizontalLayout->addWidget(new QLabel("Variable"));
        // TODO would be nice to unique this over multiple sessions
        variableName = new QLineEdit(QString("$var%1").arg(count++));

        horizontalLayout->addWidget(variableName);
        verticalLayout->addLayout(horizontalLayout);

        tabWidget = new QTabWidget();

        // Curve
        {
            QWidget* curveTab = new QWidget();
            QFormLayout* curveLayout = new QFormLayout(curveTab);
            curveLayout->setWidget(0,QFormLayout::LabelRole,new QLabel("Lookup"));
            curveLookup=new QLineEdit("$u");
            curveLayout->setWidget(0,QFormLayout::FieldRole,curveLookup);
            tabWidget->addTab(curveTab, QString("Curve"));
        }

        // Color Curve
        {
            QWidget* colorCurveTab = new QWidget();
            QFormLayout* colorCurveLayout = new QFormLayout(colorCurveTab);
            colorCurveLayout->setWidget(0,QFormLayout::LabelRole,new QLabel("Lookup"));
            colorCurveLookup=new QLineEdit("$u");
            colorCurveLayout->setWidget(0,QFormLayout::FieldRole,colorCurveLookup);
            tabWidget->addTab(colorCurveTab, QString("Color Curve"));
        }

        // Integer
        {
            QWidget* intTab = new QWidget();
            QFormLayout* intFormLayout = new QFormLayout(intTab);
            intFormLayout->setWidget(0, QFormLayout::LabelRole, new QLabel("Default"));
            intFormLayout->setWidget(1, QFormLayout::LabelRole, new QLabel("Min"));
            intFormLayout->setWidget(2, QFormLayout::LabelRole, new QLabel("Max"));
            intDefault = new QLineEdit("0");
            intFormLayout->setWidget(0, QFormLayout::FieldRole, intDefault);
            intMin = new QLineEdit("0");
            intFormLayout->setWidget(1, QFormLayout::FieldRole, intMin);
            intMax = new QLineEdit("10");
            intFormLayout->setWidget(2, QFormLayout::FieldRole, intMax);
            tabWidget->addTab(intTab, QString("Int"));
        }

        // Float
        {
            QWidget* floatTab = new QWidget();
            QFormLayout* floatFormLayout = new QFormLayout(floatTab);
            floatFormLayout->setWidget(0, QFormLayout::LabelRole, new QLabel("Default"));
            floatFormLayout->setWidget(1, QFormLayout::LabelRole, new QLabel("Min"));
            floatFormLayout->setWidget(2, QFormLayout::LabelRole, new QLabel("Max"));
            floatDefault = new QLineEdit("0");
            floatFormLayout->setWidget(0, QFormLayout::FieldRole, floatDefault);
            floatMin = new QLineEdit("0");
            floatFormLayout->setWidget(1, QFormLayout::FieldRole, floatMin);
            floatMax = new QLineEdit("1");
            floatFormLayout->setWidget(2, QFormLayout::FieldRole, floatMax);

            tabWidget->addTab(floatTab, QString("Float"));
        }

        // Vector
        {
            QWidget* vectorTab = new QWidget();
            QFormLayout* vectorFormLayout = new QFormLayout(vectorTab);
            vectorFormLayout->setWidget(0, QFormLayout::LabelRole, new QLabel("Default"));
            vectorFormLayout->setWidget(1, QFormLayout::LabelRole, new QLabel("Min"));
            vectorFormLayout->setWidget(2, QFormLayout::LabelRole, new QLabel("Max"));
            vectorDefault0 = new QLineEdit("0");
            vectorDefault1 = new QLineEdit("0");
            vectorDefault2 = new QLineEdit("0");
            QHBoxLayout* compLayout=new QHBoxLayout();
            compLayout->addWidget(vectorDefault0);
            compLayout->addWidget(vectorDefault1);
            compLayout->addWidget(vectorDefault2);
            vectorFormLayout->setLayout(0, QFormLayout::FieldRole, compLayout);
            vectorMin = new QLineEdit("0");
            vectorFormLayout->setWidget(1, QFormLayout::FieldRole, vectorMin);
            vectorMax = new QLineEdit("1");
            vectorFormLayout->setWidget(2, QFormLayout::FieldRole, vectorMax);

            tabWidget->addTab(vectorTab, QString("Vector"));
        }

        // Color
        {
            QWidget* colorTab = new QWidget();
            QFormLayout* colorLayout = new QFormLayout(colorTab);
            colorWidget=new QPushButton();
            colorWidget->setFixedWidth(30);
            colorWidget->setFixedWidth(30);
            colorLayout->setWidget(0,QFormLayout::LabelRole,new QLabel("Color"));
            colorLayout->setWidget(0,QFormLayout::FieldRole,colorWidget);
            color=Qt::red;
            QPixmap colorPix(30,30);
            colorPix.fill(color);
            colorWidget->setIcon(QIcon(colorPix));
            tabWidget->addTab(colorTab, QString("Color"));

            connect(colorWidget,SIGNAL(clicked()),this,SLOT(colorChooseClicked()));
        }

        // Color Swatch
        {
            QWidget* swatchTab = new QWidget();
            QFormLayout* swatchLayout = new QFormLayout(swatchTab);
            swatchLookup=new QLineEdit("$u");
            swatchLayout->setWidget(0,QFormLayout::LabelRole,new QLabel("Lookup"));
            swatchLayout->setWidget(0,QFormLayout::FieldRole,swatchLookup);
            rainbowPaletteBtn = new QRadioButton("Rainbow");
            rainbowPaletteBtn->setChecked(true);
            grayPaletteBtn = new QRadioButton("Shades of Gray");
            swatchLayout->setWidget(1,QFormLayout::LabelRole,new QLabel("Colors"));
            swatchLayout->setWidget(1,QFormLayout::FieldRole,rainbowPaletteBtn);
            swatchLayout->setWidget(2,QFormLayout::LabelRole,new QLabel(""));
            swatchLayout->setWidget(2,QFormLayout::FieldRole,grayPaletteBtn);
            tabWidget->addTab(swatchTab, QString("Swatch"));
        }

        // String literal
        {
            QWidget* stringTab = new QWidget();
            QFormLayout* stringLayout = new QFormLayout(stringTab);
            stringTypeWidget=new QComboBox();
            stringTypeWidget->addItem("string");
            stringTypeWidget->addItem("file");
            stringTypeWidget->addItem("directory");
            stringDefaultWidget=new QLineEdit();
            stringNameWidget=new QLineEdit("str1");

            stringLayout->setWidget(0,QFormLayout::LabelRole,new QLabel("String Name"));
            stringLayout->setWidget(0,QFormLayout::FieldRole,stringNameWidget);
            stringLayout->setWidget(1,QFormLayout::LabelRole,new QLabel("String Type"));
            stringLayout->setWidget(1,QFormLayout::FieldRole,stringTypeWidget);
            stringLayout->setWidget(2,QFormLayout::LabelRole,new QLabel("String Default"));
            stringLayout->setWidget(3,QFormLayout::FieldRole,stringDefaultWidget);

            tabWidget->addTab(stringTab, QString("String"));
        }

#ifdef SEEXPR_USE_ANIMLIB
        // Anim Curve
        {
            QWidget* curveTab = new QWidget();
            QFormLayout* curveLayout = new QFormLayout(curveTab);
            curveLayout->setWidget(0,QFormLayout::LabelRole,new QLabel("Lookup"));
            curveLayout->setWidget(1,QFormLayout::LabelRole,new QLabel("Link"));
            animCurveLookup=new QLineEdit("$frame");
            animCurveLink=new QLineEdit("");
            curveLayout->setWidget(0,QFormLayout::FieldRole,animCurveLookup);
            curveLayout->setWidget(1,QFormLayout::FieldRole,animCurveLink);
            tabWidget->addTab(curveTab, QString("AnimCurve"));
        }
#endif

        verticalLayout->addWidget(tabWidget);

        QDialogButtonBox* buttonBox = new QDialogButtonBox();
        buttonBox->setOrientation(Qt::Horizontal);
        buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

        verticalLayout->addWidget(buttonBox);


        QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
        QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

        tabWidget->setCurrentIndex(0);

    }