Added POI text field. Some tuning to detail screen item position.
[jspeed] / src / mainmenu.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 <QtGui/QPushButton>
20 #include <QtGui/QVBoxLayout>
21 #include <QtGui/QHBoxLayout>
22 #include <QtGui/QMessageBox>
23 #include <QtGui/QLabel>
24 #include <QtGui/QPixmap>
25 #include "mainmenu.h"
26 #include "themeselector.h"
27 #include "unitselector.h"
28 #include "poisettings.h"
29 #include "speedalarmsettings.h"
30
31 MainMenu::MainMenu(QWidget* parent): QDialog(parent), itemCount_(0),
32 currentRow_(0), themeSelector_(0), unitSelector_(0), poiSettings_(0),
33 speedAlarmSettings_(0), aboutDialog_(0)
34 {
35     layout_ = new QVBoxLayout;
36     setLayout(layout_);
37
38     setWindowTitle(tr("Menu"));
39     addAction(tr("Reset trip"), this, SIGNAL(resetTrip()));
40     addAction(tr("Reset all"), this, SLOT(confirmReset()));
41     addAction(tr("Theme"), this, SLOT(selectTheme()));
42     addAction(tr("Options"), this, SLOT(selectUnit()));
43     addAction(tr("Speed camera alerts"), this, SLOT(openPoiAlerts()));
44     addAction(tr("Speed alarm"), this, SLOT(openSpeedAlarm()));
45     addAction(tr("Flip screen"), this, SIGNAL(flip()));
46     addAction(tr("About"), this, SLOT(showAbout()));
47 }
48
49 void MainMenu::selectTheme()
50 {
51     if(!themeSelector_)
52     {
53         themeSelector_ = new ThemeSelector(this);
54         connect(themeSelector_, SIGNAL(themeChanged()), this, SIGNAL(themeChanged()));
55     }
56
57     themeSelector_->show();
58 }
59
60 void MainMenu::openPoiAlerts()
61 {
62     if(!poiSettings_)
63     {
64         poiSettings_ = new PoiSettings(this);
65     }
66
67     poiSettings_->show();
68 }
69
70 void MainMenu::openSpeedAlarm()
71 {
72     if(!speedAlarmSettings_)
73     {
74         speedAlarmSettings_ = new SpeedAlarmSettings(this);
75     }
76
77     speedAlarmSettings_->show();
78 }
79
80 void MainMenu::selectUnit()
81 {
82     if(!unitSelector_)
83     {
84         unitSelector_ = new UnitSelector(this);
85         connect(unitSelector_, SIGNAL(unitChanged()), this, SIGNAL(unitChanged()));
86         connect(unitSelector_, SIGNAL(orientationChanged()), this, SIGNAL(orientationChanged()));
87     }
88
89     unitSelector_->show();
90 }
91
92 void MainMenu::showAbout()
93 {
94     if(!aboutDialog_)
95     {
96         aboutDialog_ = new QDialog(this);
97         aboutDialog_->setWindowTitle(tr("About"));
98
99         QHBoxLayout* mainLayout = new QHBoxLayout;
100         QPixmap pixmap(":/resources/appicon.png");
101         QLabel* image = new QLabel;
102         image->setPixmap(pixmap);
103         mainLayout->addWidget(image, 0, Qt::AlignLeft);
104         mainLayout->addSpacing(15);
105         QLabel* text = new QLabel(QString::fromUtf8("<font size='4'><b>jSpeed</b></font><br>(c) 2010 Jesse Hakanen<br><a href='http://jspeed.garage.maemo.org' style='color:#ffffff'>http://jspeed.garage.maemo.org</a>"));
106         text->setOpenExternalLinks(true);
107         mainLayout->addWidget(text, 10, Qt::AlignLeft);
108
109         aboutDialog_->setLayout(mainLayout);
110     }
111
112     aboutDialog_->show();
113 }
114
115 void MainMenu::confirmReset()
116 {
117     hide();
118
119     QMessageBox::StandardButton result =  QMessageBox::question(this, tr("Reset all"),
120              tr("Are you sure? All recorded data will be lost."),
121              QMessageBox::Yes | QMessageBox::No);
122
123     if(result == QMessageBox::Yes)
124     {
125         emit resetAll();
126     }
127 }
128
129 void MainMenu::addAction(const QString& text,
130                          const QObject* receiver,
131                          const char* member)
132 {
133     if(itemCount_ % 2 == 0 || !currentRow_)
134     {
135         currentRow_ = new QHBoxLayout;
136         layout_->addLayout(currentRow_);
137     }
138
139     QPushButton* button = new QPushButton(text);
140     connect(button, SIGNAL(clicked(bool)), receiver, member);
141     connect(button, SIGNAL(clicked(bool)), this, SLOT(hide()));
142     currentRow_->addWidget(button);
143     itemCount_++;
144 }