Added zpos attribute to all elements. Changed architecture to allow detailscreen...
[jspeed] / src / unitselector.cpp
1 /*
2  * This file is part of jSpeed.
3  *
4  * jSpeed is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * jSpeed is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with jSpeed.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #include <QtCore/QString>
20 #include <QtGui/QHBoxLayout>
21 #include <QtGui/QPushButton>
22 #include <QtGui/QDialogButtonBox>
23 #include "unitselector.h"
24 #include "buttonselector.h"
25 #include "settings.h"
26
27 UnitSelector::UnitSelector(QWidget* parent): QDialog(parent)
28 {
29     setWindowTitle(tr("Set unit"));
30
31     unit_ = Settings::instance().value("unit", "km").toString();
32
33     QHBoxLayout* layout = new QHBoxLayout;
34
35     selector_ = new ButtonSelector(tr("Unit"));
36
37     selector_->addItem(tr("Kilometers"), "km");
38     selector_->addItem(tr("Miles"), "mile");
39
40     if(unit_ == "mile")
41     {
42         selector_->setCurrentIndex(1);
43     }
44
45     layout->addWidget(selector_, Qt::AlignLeft);
46
47     QPushButton* button = new QPushButton(tr("Save"));
48     connect(button, SIGNAL(clicked(bool)), this, SLOT(saveUnit()));
49     QDialogButtonBox* buttons = new QDialogButtonBox;
50     buttons->setCenterButtons(false);
51     buttons->addButton(button, QDialogButtonBox::AcceptRole);
52
53     layout->addWidget(buttons);
54
55     setLayout(layout);
56 }
57
58 void UnitSelector::saveUnit()
59 {
60     QString value = selector_->value().toString();
61
62     if(value == unit_)
63     {
64         hide();
65         return;
66     }
67
68     Settings::instance().setValue("unit", value);
69     unit_ = value;
70     hide();
71     emit unitChanged();
72 }