2 * This file is part of jSpeed.
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.
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.
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/>.
19 #include <QtCore/QDir>
20 #include <QtCore/QDebug>
21 #include <QtGui/QLineEdit>
22 #include <QtGui/QLabel>
23 #include <QtGui/QHBoxLayout>
24 #include <QtGui/QVBoxLayout>
25 #include <QtGui/QPushButton>
26 #include <QtGui/QDialogButtonBox>
27 #include <QtGui/QCheckBox>
28 #include <QtGui/QIntValidator>
30 #include "speedalarmsettings.h"
31 #include "speedalarm.h"
34 #include "fileselector.h"
35 #include "poialerts.h"
36 #include "soundselector.h"
37 #include "buttonbox.h"
40 SpeedAlarmSettings::SpeedAlarmSettings(QWidget* parent): QDialog(parent)
42 setWindowTitle(tr("Speed alarm"));
44 speedLabel_ = new QLabel;
45 speed_ = new QLineEdit;
46 speed_->setValidator(new QIntValidator(0, 999, this));
48 QPushButton* current = new QPushButton(tr("Current"));
49 connect(current, SIGNAL(clicked(bool)), this, SLOT(loadCurrentSpeed()));
51 QHBoxLayout* speedLayout = new QHBoxLayout;
52 speedLayout->addWidget(speedLabel_);
53 speedLayout->addWidget(speed_);
54 speedLayout->addWidget(current);
56 soundSelector_ = new SoundSelector;
58 enabled_ = new QCheckBox(tr("Enabled"));
59 enabled_->setChecked(Settings::instance().value("alarm_enabled", false).toBool());
61 ButtonBox* buttons = new ButtonBox;
62 connect(buttons->addButton(tr("Save"), QDialogButtonBox::AcceptRole), SIGNAL(clicked(bool)), this, SLOT(saveSettings()));
64 QHBoxLayout* layout = new QHBoxLayout;
65 QVBoxLayout* left = new QVBoxLayout;
67 left->addLayout(speedLayout);
68 left->addLayout(soundSelector_);
69 left->addWidget(enabled_);
70 layout->addLayout(left, Qt::AlignLeft);
71 layout->addWidget(buttons);
77 void SpeedAlarmSettings::loadData()
79 speedLabel_->setText(tr("Speed threshold (%1)").arg(Odometer::getSpeedUnit()));
80 int speedValue = round(Settings::instance().value("alarm_threshold", 100).toDouble() * Odometer::getUnitMultiplier());
81 speed_->setText(QString::number(static_cast<int>(speedValue)));
83 QString selected = Settings::instance().value("alarm_sound", "").toString();
84 soundSelector_->load();
85 soundSelector_->setValue(selected);
88 void SpeedAlarmSettings::loadCurrentSpeed()
90 double speed = round(Odometer::instance().getLatestFix().speed);
91 speed_->setText(QString::number(static_cast<int>(speed)));
94 void SpeedAlarmSettings::saveSettings()
96 double kmSpeed = speed_->text().toInt() / Odometer::getUnitMultiplier();
98 Settings::instance().setValue("alarm_threshold", kmSpeed);
99 Settings::instance().setValue("alarm_enabled", enabled_->isChecked());
100 Settings::instance().setValue("alarm_sound", soundSelector_->value());
102 SpeedAlarm::instance().loadConfig();
107 void SpeedAlarmSettings::setVisible(bool visible)
114 QDialog::setVisible(visible);