Symbian fixes.
[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 #if defined(Q_OS_SYMBIAN)
31     setStyleSheet("QFrame {margin:0; border:0; padding:0}");
32     setStyleSheet("QScrollArea {margin:0; border:0; padding:0}");
33 #endif
34
35     content = new QWidget(scroller);
36     contentLayout = new QVBoxLayout(content);
37     contentLayout->setMargin(0);
38     content->setLayout(contentLayout);
39
40     QBoxLayout *boxLayout;
41     QRect screenGeometry = QApplication::desktop()->screenGeometry();
42     if (screenGeometry.width() < screenGeometry.height()) {
43 #ifndef Q_OS_SYMBIAN
44         if (showButtons) {
45             buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
46         }
47 #endif
48         boxLayout = new QVBoxLayout(this);
49     } else {
50 #ifndef Q_OS_SYMBIAN
51         if (showButtons) {
52             buttonBox = new QDialogButtonBox(Qt::Vertical, this);
53         }
54 #endif
55         boxLayout = new QHBoxLayout(this);
56     }
57     boxLayout->addWidget(scroller);
58 #ifndef Q_OS_SYMBIAN
59     if (showButtons) {
60         boxLayout->addWidget(buttonBox);
61     }
62 #endif
63     setLayout(boxLayout);
64
65     scroller->setWidget(content);
66     content->show();
67     scroller->setWidgetResizable(true);
68
69 #if defined(Q_OS_SYMBIAN)
70     QAction *closeAction = new QAction(tr("Back"), this);
71     closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
72     connect(closeAction, SIGNAL(triggered()), this, SLOT(reject()));
73     addAction(closeAction);
74     leftSoftKey = 0;
75     menuBar = 0;
76 #endif // Q_OS_SYMBIAN
77 }
78
79 void Dyalog::addWidget(QWidget *widget)
80 {
81     contentLayout->addWidget(widget);
82 }
83
84 void Dyalog::addStretch(int stretch)
85 {
86     contentLayout->addStretch(stretch);
87 }
88
89 void Dyalog::addButton(const QString &label, QObject *receiver,
90                        const char *slot, QDialogButtonBox::ButtonRole role)
91 {
92     TRACE;
93     if (!showButtons) {
94         qDebug() << "Ignored: showButtons is false";
95         return;
96     }
97 #ifdef Q_OS_SYMBIAN
98     Q_UNUSED(role);
99     if (!leftSoftKey) {
100         // Add new action as left softkey
101         leftSoftKey = new QAction(label, this);
102         leftSoftKey->setSoftKeyRole(QAction::PositiveSoftKey);
103         connect(leftSoftKey, SIGNAL(triggered()), receiver, slot);
104         addAction(leftSoftKey);
105     } else {
106         if (!menuBar) {
107             // Create menu bar
108             menuBar = new QMenuBar(this);
109             // Add previous LSK to menu bar
110             leftSoftKey->setSoftKeyRole(QAction::NoSoftKey);
111             menuBar->addAction(leftSoftKey);
112         }
113         // Add new action to menu bar
114         QAction *action = new QAction(label, this);
115         connect(action, SIGNAL(triggered()), receiver, slot);
116         menuBar->addAction(action);
117     }
118 #else
119     QPushButton *button = new QPushButton(label, this);
120     connect(button, SIGNAL(clicked()), receiver, slot);
121     buttonBox->addButton(button, role);
122 #endif // Q_OS_SYMBIAN
123 }
124
125 #ifdef Q_OS_SYMBIAN
126
127 void Dyalog::show()
128 {
129     foreach (QWidget *w, QApplication::allWidgets()) {
130         w->setContextMenuPolicy(Qt::NoContextMenu);
131     }
132     showMaximized();
133 }
134
135 int Dyalog::exec()
136 {
137     show();
138     return QDialog::exec();
139 }
140
141 #endif // Q_OS_SYMBIAN