main.cpp 3.89 KB
Newer Older
LE BRETON Come's avatar
LE BRETON Come committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Version: $Id$
//
//

// Commentary:
//
//

// Change Log:
//
//

// Code:

#include  <QtWidgets>
#include <dtkWidgets>

#include <dtkCore/dtkCoreParameter>
#include <dtkWidgets/dtkWidgetsParameter>
20
#include <dtkWidgets/dtkWidgetsParameterFactory>
LE BRETON Come's avatar
LE BRETON Come committed
21 22 23 24 25 26 27 28 29 30 31 32 33

// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////

int main(int argc, char **argv)
{
    dtk::widgets::initialize("");

    QApplication application(argc, argv);

    QMainWindow *window = new QMainWindow;

LE BRETON Come's avatar
LE BRETON Come committed
34
    dtk::d_real real_parameter = 5.;
LE BRETON Come's avatar
LE BRETON Come committed
35
    real_parameter.setDocumentation("A real parameter.");
SZPYRKA Jean-Luc's avatar
SZPYRKA Jean-Luc committed
36
    real_parameter.setDecimals(3);
LE BRETON Come's avatar
LE BRETON Come committed
37

38
    dtkWidgetsParameter *first_real_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBox");
SZPYRKA Jean-Luc's avatar
SZPYRKA Jean-Luc committed
39
    dtkWidgetsParameter *second_real_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterScientificSpinBox");
LE BRETON Come's avatar
LE BRETON Come committed
40

41 42
    real_parameter.connect([=] (QVariant v) {
                               double value = v.value<dtk::d_real>().value();
43
                               qInfo() << "real_parameter (dbl)=" << value;
44 45
                           });

SZPYRKA Jean-Luc's avatar
SZPYRKA Jean-Luc committed
46
    dtk::d_real scientific_parameter = 8.654321;
47 48 49 50 51 52
    scientific_parameter.setDocumentation("A real parameter.");
    scientific_parameter.setDecimals(6);

    dtkWidgetsParameter *scientific_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&scientific_parameter, "dtkWidgetsParameterScientificSpinBox");
    scientific_parameter.connect([=] (QVariant v) {
                               double value = v.value<dtk::d_real>().value();
SZPYRKA Jean-Luc's avatar
SZPYRKA Jean-Luc committed
53
                               printf("scientific_parameter(XXX) = %.12f\n", value);
54
                           });
55

56 57 58 59 60
    QList<QString> available_strings;
    available_strings.append("FirstString");
    available_strings.append("SecondString");
    available_strings.append("ThirdString");

LE BRETON Come's avatar
LE BRETON Come committed
61
    dtk::d_inliststring inliststring_parameter("listofstrings", available_strings);
62
    inliststring_parameter.setDocumentation("A inliststring parameter.");
LE BRETON Come's avatar
LE BRETON Come committed
63 64

    inliststring_parameter.setValue(QString("SecondString"));
65
    dtkWidgetsParameter *inliststring_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&inliststring_parameter, "dtkWidgetsParameterStringListComboBox");
66

67 68 69 70 71 72
    inliststring_parameter.connect([=] (QVariant v) {
                               QString value = v.value<dtk::d_inliststring>().value();
                               qInfo() << "inliststring_parameter =" << value;
                           });


LE BRETON Come's avatar
LE BRETON Come committed
73 74

    dtk::d_bool bool_parameter = true;
75
    dtkWidgetsParameter *bool_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&bool_parameter, "dtkWidgetsParameterBoolCheckBox");
LE BRETON Come's avatar
LE BRETON Come committed
76

77 78 79 80 81
    bool_parameter.connect([=] (QVariant v) {
                               bool value = v.value<dtk::d_bool>().value();
                               qInfo() << "bool_parameter =" << value;
                           });

82
    QVBoxLayout *central_layout = new QVBoxLayout;
83 84 85 86 87 88 89 90 91 92 93
    QFrame *frame = new QFrame();
    frame->setFrameStyle(QFrame::Box | QFrame::Raised);
    central_layout->addWidget(frame);

    QVBoxLayout *real_layout = new QVBoxLayout;
    frame->setLayout(real_layout);
    real_layout->addWidget(first_real_parameter_widget);
    real_layout->addWidget(second_real_parameter_widget);

    central_layout->addWidget(new QSplitter);
    central_layout->addWidget(scientific_parameter_widget);
94 95
    central_layout->addWidget(new QSplitter);
    central_layout->addWidget(inliststring_parameter_widget);
LE BRETON Come's avatar
LE BRETON Come committed
96 97
    central_layout->addWidget(new QSplitter);
    central_layout->addWidget(bool_parameter_widget);
98 99 100 101 102

    QWidget *central_widget = new QWidget;
    central_widget->setLayout(central_layout);

    window->setCentralWidget(central_widget);
LE BRETON Come's avatar
LE BRETON Come committed
103 104 105 106 107 108 109 110 111

    window->show();
    window->raise();

    return application.exec();
}

//
// main.cpp ends here