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 {
9     scroller = new QScrollArea(this);
10
11 #ifdef Q_WS_MAEMO_5
12     scroller->setProperty("FingerScrollable", true);
13     scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
14 #else
15     scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
16 #endif
17     scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
18     scroller->setFrameStyle(QFrame::NoFrame);
19
20     content = new QWidget(scroller);
21     contentLayout = new QVBoxLayout(content);
22     contentLayout->setMargin(0);
23     content->setLayout(contentLayout);
24
25     QBoxLayout *boxLayout;
26     QRect screenGeometry = QApplication::desktop()->screenGeometry();
27     if (screenGeometry.width() < screenGeometry.height()) {
28         buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
29         boxLayout = new QVBoxLayout(this);
30     } else {
31         buttonBox = new QDialogButtonBox(Qt::Vertical, this);
32         boxLayout = new QHBoxLayout(this);
33     }
34     boxLayout->addWidget(scroller);
35     if (showButtons) {
36         boxLayout->addWidget(buttonBox);
37     } else {
38         buttonBox->hide();
39     }
40     setLayout(boxLayout);
41
42     scroller->setWidget(content);
43     content->show();
44     scroller->setWidgetResizable(true);
45
46 #ifdef Q_OS_SYMBIAN
47     QAction *closeAction = new QAction(tr("Close"), this);
48     closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
49     connect(closeAction, SIGNAL(triggered()), this, SLOT(reject()));
50     addAction(closeAction);
51 #endif // Q_OS_SYMBIAN
52 }
53
54 void Dyalog::addWidget(QWidget *widget)
55 {
56     contentLayout->addWidget(widget);
57 }
58
59 void Dyalog::addStretch(int stretch)
60 {
61     contentLayout->addStretch(stretch);
62 }
63
64 void Dyalog::addButton(QPushButton *button, QDialogButtonBox::ButtonRole role)
65 {
66     buttonBox->addButton(button, role);
67 }
68
69 QPushButton *Dyalog::addButton(QDialogButtonBox::StandardButton button)
70 {
71     return buttonBox->addButton(button);
72 }