summaryrefslogtreecommitdiffstats
path: root/testapp/main.cpp
blob: 92fe4f3e608126cdbc180f13c68054df2e8f65d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

#include <QApplication>
#include <QListWidget>
#include <QListWidgetItem>
#include <QTabWidget>
#include <QSplitter>
#include <QStackedWidget>
#include <QSignalMapper>
#include <QMainWindow>
#include <QMenuBar>
#include <QActionGroup>

#ifdef Q_WS_MAEMO_5
#  include <QAbstractKineticScroller>
#endif

#include "qscrollareakineticscroller.h"

#include "settingswidget.h"
#include "plotwidget.h"

int main(int argc, char **argv)
{
    QApplication a(argc, argv);

    QListWidget *list = new QListWidget();

    for (int i = 0; i < 1000; ++i)
        new QListWidgetItem(QString("This is a test text %1 %2").arg(i).arg(QString("--------").left(i % 8)), list);

    // remove the old kinetic scroller if any
    QAbstractKineticScroller *oldScroller = list->property("kineticScroller").value<QAbstractKineticScroller *>();
    oldScroller->setEnabled(false);

    // set a new kinetic scroller
    QScrollAreaKineticScroller *newScroller = new QScrollAreaKineticScroller();
    newScroller->setWidget(list);

#if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60) || defined(Q_WS_WINCE)
    bool smallScreen = true;
#else
    bool smallScreen = false;
#endif

    QWidget *settings = new SettingsWidget(newScroller, smallScreen);
    QWidget *plot = new PlotWidget(newScroller);

    if (smallScreen) {
        QMainWindow *top = new QMainWindow();
        QStackedWidget *stack = new QStackedWidget();
        stack->addWidget(list);
        stack->addWidget(settings);
        stack->addWidget(plot);
        top->setCentralWidget(stack);

        QActionGroup *pages = new QActionGroup(top);
        pages->setExclusive(true);
        QSignalMapper *mapper = new QSignalMapper(top);
        QObject::connect(mapper, SIGNAL(mapped(int)), stack, SLOT(setCurrentIndex(int)));

        QAction *a = new QAction(QLatin1String("List"), pages);
        a->setCheckable(true);
        a->setChecked(true);
        mapper->setMapping(a, 0);
        QObject::connect(a, SIGNAL(toggled(bool)), mapper, SLOT(map()));

        a = new QAction(QLatin1String("Config"), pages);
        a->setCheckable(true);
        a->setChecked(false);
        a->setMenuRole(QAction::NoRole);
        mapper->setMapping(a, 1);
        QObject::connect(a, SIGNAL(toggled(bool)), mapper, SLOT(map()));

        a = new QAction(QLatin1String("Plot"), pages);
        a->setCheckable(true);
        a->setChecked(false);
        mapper->setMapping(a, 2);
        QObject::connect(a, SIGNAL(toggled(bool)), mapper, SLOT(map()));

        top->menuBar()->addMenu("Pages")->addActions(pages->actions());
        top->showMaximized();
    } else {
        QSplitter *split = new QSplitter();
        split->addWidget(list);
        split->addWidget(settings);
        split->addWidget(plot);
        split->show();
#if defined(Q_WS_MAC)
        split->raise();
#endif
    }

    return a.exec();
}