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