Fixes to speed alarm and poi alerts. Added flicker effect. Some new fields to text...
[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 #include "buttonbox.h"
27
28 UnitSelector::UnitSelector(QWidget* parent): QDialog(parent)
29 {
30     setWindowTitle(tr("Set unit"));
31
32     unit_ = Settings::instance().value("unit", "km").toString();
33
34     QHBoxLayout* layout = new QHBoxLayout;
35
36     selector_ = new ButtonSelector(tr("Unit"));
37
38     selector_->addItem(tr("Kilometers"), "km");
39     selector_->addItem(tr("Miles"), "mile");
40
41     if(unit_ == "mile")
42     {
43         selector_->setCurrentIndex(1);
44     }
45
46     layout->addWidget(selector_, Qt::AlignLeft);
47
48     ButtonBox* buttons = new ButtonBox;
49     connect(buttons->addButton(tr("Save"), QDialogButtonBox::AcceptRole), SIGNAL(clicked(bool)), this, SLOT(saveUnit()));
50
51     layout->addWidget(buttons);
52
53     setLayout(layout);
54 }
55
56 void UnitSelector::saveUnit()
57 {
58     QString value = selector_->value().toString();
59
60     if(value == unit_)
61     {
62         hide();
63         return;
64     }
65
66     Settings::instance().setValue("unit", value);
67     unit_ = value;
68     hide();
69     emit unitChanged();
70 }