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