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 "mediaplayer.h"
37 #include "soundselector.h"
38 #include "buttonbox.h"
41 SpeedAlarmSettings::SpeedAlarmSettings(QWidget* parent): QDialog(parent)
43 setWindowTitle(tr("Speed alarm"));
45 speedLabel_ = new QLabel;
46 speed_ = new QLineEdit;
47 speed_->setValidator(new QIntValidator(0, 999, this));
49 QPushButton* current = new QPushButton(tr("Current"));
50 connect(current, SIGNAL(clicked(bool)), this, SLOT(loadCurrentSpeed()));
52 QHBoxLayout* speedLayout = new QHBoxLayout;
53 speedLayout->addWidget(speedLabel_);
54 speedLayout->addWidget(speed_);
55 speedLayout->addWidget(current);
57 soundSelector_ = new SoundSelector;
59 enabled_ = new QCheckBox(tr("Enabled"));
60 enabled_->setChecked(Settings::instance().value("alarm_enabled", false).toBool());
62 ButtonBox* buttons = new ButtonBox;
63 buttons->addButton(tr("Save"), this, SLOT(saveSettings()), QDialogButtonBox::AcceptRole);
65 QHBoxLayout* layout = new QHBoxLayout;
66 QVBoxLayout* left = new QVBoxLayout;
68 left->addLayout(speedLayout);
69 left->addWidget(soundSelector_);
70 left->addWidget(enabled_);
71 layout->addLayout(left, Qt::AlignLeft);
72 layout->addWidget(buttons);
78 void SpeedAlarmSettings::loadData()
80 speedLabel_->setText(tr("Speed threshold (%1)").arg(Odometer::getSpeedUnit()));
81 int speedValue = round(Settings::instance().value("alarm_threshold", 100).toDouble() * Odometer::getUnitMultiplier());
82 speed_->setText(QString::number(static_cast<int>(speedValue)));
84 QString selected = Settings::instance().value("alarm_sound", "").toString();
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);