1 #include "optionsdialog.h"
2 #include "ui_optionsdialog.h"
5 #include <QMaemo5ValueButton>
6 #include <QMaemo5ListPickSelector>
7 #include <QStandardItem>
9 #include <QDesktopWidget>
11 static QStandardItem *CreateItem(const QString &label)
13 QStandardItem *item = new QStandardItem(label);
14 item->setTextAlignment(Qt::AlignCenter);
15 item->setEditable(false);
19 OptionsDialog::OptionsDialog(QWidget *parent) :
21 ui(new Ui::OptionsDialog),
22 _rotation_model(new QStandardItemModel(0, 1, this)),
23 _rotation_selector(new QMaemo5ListPickSelector())
26 ui->_button_box->addButton(ui->_done_button, QDialogButtonBox::AcceptRole);
27 connect(ui->_button_box, SIGNAL(accepted()), this, SLOT(Accept()));
28 connect(ui->_button_box, SIGNAL(accepted()), this, SLOT(deleteLater()));
29 connect(ui->_button_box, SIGNAL(rejected()), this, SLOT(Cancel()));
30 connect(ui->_button_box, SIGNAL(rejected()), this, SLOT(deleteLater()));
31 ui->_rotation_combo_box->setValueLayout(QMaemo5ValueButton::ValueBesideText);
32 _rotation_model->appendRow(CreateItem(tr("Landscape")));
33 _rotation_model->appendRow(CreateItem(tr("Portrait")));
34 _rotation_model->appendRow(CreateItem(tr("Automatic Rotation")));
35 _rotation_selector->setModel(_rotation_model);
36 _rotation_selector->setCurrentIndex(0);
37 ui->_rotation_combo_box->setPickSelector(_rotation_selector);
38 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(Rotate()));
42 OptionsDialog::~OptionsDialog()
47 void OptionsDialog::SetSettings(const Settings &settings)
51 switch (_settings.GetOrientationMode()) {
52 case Settings::LANDSCAPE:
55 case Settings::PORTRAIT:
58 case Settings::AUTOROTATION:
62 _rotation_selector->setCurrentIndex(i);
65 Settings OptionsDialog::GetSettings()
67 switch (_rotation_selector->currentIndex()) {
69 _settings.SetOrientationMode(Settings::LANDSCAPE);
72 _settings.SetOrientationMode(Settings::PORTRAIT);
75 _settings.SetOrientationMode(Settings::AUTOROTATION);
81 void OptionsDialog::Accept()
83 emit Accept(GetSettings());
86 void OptionsDialog::Cancel()
88 emit Cancel(GetSettings());
91 void OptionsDialog::Rotate()
93 bool landscape = UiUtils::IsLandscape();
94 ui->_dialog_layout->setDirection(landscape ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
95 ui->_button_box->setOrientation(landscape ? Qt::Vertical : Qt::Horizontal);
96 ui->_rotation_combo_box->setValueLayout(landscape ? QMaemo5ValueButton::ValueBesideText : QMaemo5ValueButton::ValueUnderText);