9dc64aecde42caf4a07f5081a2a8ed05ab3fd544
[presencevnc] / src / preferences.cpp
1 /*
2     Presence VNC
3     Copyright (C) 2010 Christian Pulvermacher
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 #include <QtGui>
20 #include <QMaemo5ValueButton>
21 #include <QMaemo5ListPickSelector>
22
23 #include "preferences.h"
24
25 Preferences::Preferences(QWidget *parent):
26         QDialog(parent)
27 {
28         setWindowTitle("Preferences");
29
30         QHBoxLayout *layout1 = new QHBoxLayout();
31         QVBoxLayout *layout2 = new QVBoxLayout();
32
33         QMaemo5ValueButton *rotation = new QMaemo5ValueButton(tr("Screen Rotation"), this);
34         rotation_selector = new QMaemo5ListPickSelector(this);
35         QStandardItemModel *model = new QStandardItemModel(0, 1, this);
36         model->appendRow(new QStandardItem(tr("Automatic")));
37         model->appendRow(new QStandardItem(tr("Landscape")));
38         model->appendRow(new QStandardItem(tr("Portrait")));
39         rotation_selector->setModel(model);
40         rotation_selector->setCurrentIndex(settings.value("screen_rotation", 0).toInt());
41         rotation->setPickSelector(rotation_selector);
42         rotation->setValueLayout(QMaemo5ValueButton::ValueBesideText);
43         layout2->addWidget(rotation);
44
45         QMaemo5ValueButton *leftzoom = new QMaemo5ValueButton(tr("Left Zoom Button"), this);
46         leftzoom_selector = new QMaemo5ListPickSelector(this);
47         QStandardItemModel *key_model = new QStandardItemModel(0, 1, this);
48         key_model->appendRow(new QStandardItem(tr("Left Click"))); //0
49         key_model->appendRow(new QStandardItem(tr("Right Click")));//1
50         key_model->appendRow(new QStandardItem(tr("Wheel Up")));//2
51         key_model->appendRow(new QStandardItem(tr("Wheel Down")));//3
52         key_model->appendRow(new QStandardItem(tr("Page Up")));//4
53         key_model->appendRow(new QStandardItem(tr("Page Down")));//5
54         leftzoom_selector->setModel(key_model);
55         leftzoom_selector->setCurrentIndex(settings.value("left_zoom", 0).toInt());
56         leftzoom->setPickSelector(leftzoom_selector);
57         leftzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
58         layout2->addWidget(leftzoom);
59
60         QMaemo5ValueButton *rightzoom = new QMaemo5ValueButton(tr("Right Zoom Button"), this);
61         rightzoom_selector = new QMaemo5ListPickSelector(this);
62         rightzoom_selector->setModel(key_model);
63         rightzoom_selector->setCurrentIndex(settings.value("right_zoom", 1).toInt());
64         rightzoom->setPickSelector(rightzoom_selector);
65         rightzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
66         layout2->addWidget(rightzoom);
67
68         QPushButton *ok = new QPushButton("OK");
69
70         layout1->addLayout(layout2);
71         layout1->addWidget(ok);
72
73         setLayout(layout1);
74
75         connect(ok, SIGNAL(clicked()),
76                 this, SLOT(accept()));
77         connect(this, SIGNAL(accepted()),
78                 this, SLOT(save()));
79 }
80
81 Preferences::~Preferences()
82 {
83
84 }
85
86
87 void Preferences::save()
88 {
89         settings.setValue("screen_rotation", rotation_selector->currentIndex());
90         settings.setValue("left_zoom", leftzoom_selector->currentIndex());
91         settings.setValue("right_zoom", rightzoom_selector->currentIndex());
92
93         settings.sync();
94 }