Fixed searchclients to handle new Google URLs correctly; added GUI
[movie-schedule] / src / ui / optionsdialog.cpp
1 #include "optionsdialog.h"
2 #include "ui_optionsdialog.h"
3 #include "uiutils.h"
4
5 #include <QMaemo5ValueButton>
6 #include <QMaemo5ListPickSelector>
7 #include <QStandardItem>
8 #include <QBoxLayout>
9 #include <QDesktopWidget>
10
11 static QStandardItem *CreateItem(const QString &label)
12 {
13     QStandardItem *item = new QStandardItem(label);
14     item->setTextAlignment(Qt::AlignCenter);
15     item->setEditable(false);
16     return item;
17 }
18
19 OptionsDialog::OptionsDialog(QWidget *parent) :
20     QDialog(parent),
21     ui(new Ui::OptionsDialog),
22     _rotation_model(new QStandardItemModel(0, 1, this)),
23     _rotation_selector(new QMaemo5ListPickSelector())
24 {
25     ui->setupUi(this);
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()));
39     Rotate();
40 }
41
42 OptionsDialog::~OptionsDialog()
43 {
44     delete ui;
45 }
46
47 void OptionsDialog::SetSettings(const Settings &settings)
48 {
49     _settings = settings;
50     int i = 0;
51     switch (_settings.GetOrientationMode()) {
52     case Settings::LANDSCAPE:
53         i = 0;
54         break;
55     case Settings::PORTRAIT:
56         i = 1;
57         break;
58     case Settings::AUTOROTATION:
59         i = 2;
60         break;
61     }
62     _rotation_selector->setCurrentIndex(i);
63 }
64
65 Settings OptionsDialog::GetSettings()
66 {
67     switch (_rotation_selector->currentIndex()) {
68     case 0:
69         _settings.SetOrientationMode(Settings::LANDSCAPE);
70         break;
71     case 1:
72         _settings.SetOrientationMode(Settings::PORTRAIT);
73         break;
74     case 2:
75         _settings.SetOrientationMode(Settings::AUTOROTATION);
76         break;
77     }
78     return _settings;
79 }
80
81 void OptionsDialog::Accept()
82 {
83     emit Accept(GetSettings());
84 }
85
86 void OptionsDialog::Cancel()
87 {
88     emit Cancel(GetSettings());
89 }
90
91 void OptionsDialog::Rotate()
92 {
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);
97     adjustSize();
98 }