Increase heap size on Symbian.
[dorian] / widgets / dyalog.cpp
1 #include <QtGui>
2
3 #include "dyalog.h"
4 #include "trace.h"
5
6 #ifdef Q_OS_SYMBIAN
7 #include "flickcharm.h"
8 #endif
9
10 Dyalog::Dyalog(QWidget *parent, bool showButtons_):
11     QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
12                     Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint),
13     showButtons(showButtons_)
14 {
15     setAttribute(Qt::WA_DeleteOnClose);
16
17     scroller = new QScrollArea(this);
18
19 #if defined(Q_WS_MAEMO_5)
20     scroller->setProperty("FingerScrollable", true);
21     scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
22 #elif defined(Q_OS_SYMBIAN)
23     FlickCharm *charm = new FlickCharm(this);
24     charm->activateOn(scroller);
25 #else
26     scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
27 #endif
28     scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
29     scroller->setFrameStyle(QFrame::NoFrame);
30
31     content = new QWidget(scroller);
32     contentLayout = new QVBoxLayout(content);
33     contentLayout->setMargin(0);
34     content->setLayout(contentLayout);
35
36     QBoxLayout *boxLayout;
37     QRect screenGeometry = QApplication::desktop()->screenGeometry();
38     if (screenGeometry.width() < screenGeometry.height()) {
39 #ifndef Q_OS_SYMBIAN
40         if (showButtons) {
41             buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
42         }
43 #endif
44         boxLayout = new QVBoxLayout(this);
45     } else {
46 #ifndef Q_OS_SYMBIAN
47         if (showButtons) {
48             buttonBox = new QDialogButtonBox(Qt::Vertical, this);
49         }
50 #endif
51         boxLayout = new QHBoxLayout(this);
52     }
53     boxLayout->addWidget(scroller);
54 #ifndef Q_OS_SYMBIAN
55     if (showButtons) {
56         boxLayout->addWidget(buttonBox);
57     }
58 #endif
59     setLayout(boxLayout);
60
61     scroller->setWidget(content);
62     content->show();
63     scroller->setWidgetResizable(true);
64
65 #if defined(Q_OS_SYMBIAN)
66     QAction *closeAction = new QAction(tr("Back"), this);
67     closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
68     connect(closeAction, SIGNAL(triggered()), this, SLOT(reject()));
69     addAction(closeAction);
70     leftSoftKey = 0;
71     menuBar = 0;
72 #endif // Q_OS_SYMBIAN
73 }
74
75 void Dyalog::addWidget(QWidget *widget)
76 {
77     contentLayout->addWidget(widget);
78 }
79
80 void Dyalog::addStretch(int stretch)
81 {
82     contentLayout->addStretch(stretch);
83 }
84
85 void Dyalog::addButton(const QString &label, QObject *receiver,
86                        const char *slot, QDialogButtonBox::ButtonRole role)
87 {
88     TRACE;
89     if (!showButtons) {
90         qDebug() << "Ignored: showButtons is false";
91         return;
92     }
93 #ifdef Q_OS_SYMBIAN
94     Q_UNUSED(role);
95 #if 0
96     if (!leftSoftKey) {
97         qDebug() << "Adding left soft key";
98         leftSoftKey = new QAction(label, this);
99         leftSoftKey->setSoftKeyRole(QAction::PositiveSoftKey);
100         connect(leftSoftKey, SIGNAL(triggered()), receiver, slot);
101         addAction(leftSoftKey);
102     } else {
103 #endif
104         if (!menuBar) {
105             qDebug() << "Creating menu bar";
106             menuBar = new QMenuBar(this);
107             menuBar->addAction(leftSoftKey);
108         }
109         qDebug() << "Adding to menu bar";
110         QAction *action = new QAction(label, this);
111         connect(action, SIGNAL(triggered()), receiver, slot);
112         menuBar->addAction(action);
113 #if 0
114     }
115 #endif
116 #else
117     QPushButton *button = new QPushButton(label, this);
118     connect(button, SIGNAL(clicked()), receiver, slot);
119     buttonBox->addButton(button, role);
120 #endif // Q_OS_SYMBIAN
121 }
122
123 #ifdef Q_OS_SYMBIAN
124
125 void Dyalog::show()
126 {
127     foreach (QWidget *w, QApplication::allWidgets()) {
128         w->setContextMenuPolicy(Qt::NoContextMenu);
129     }
130     showMaximized();
131 }
132
133 int Dyalog::exec()
134 {
135     show();
136     return QDialog::exec();
137 }
138
139 #endif // Q_OS_SYMBIAN