Changelog fixed.
[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
29 MainMenu::MainMenu(QWidget* parent): QDialog(parent), itemCount_(0),
30 currentRow_(0), themeSelector_(0), unitSelector_(0), aboutDialog_(0)
31 {
32     layout_ = new QVBoxLayout;
33     setLayout(layout_);
34
35     setWindowTitle(tr("Menu"));
36     addAction(tr("Reset trip"), this, SIGNAL(resetTrip()));
37     addAction(tr("Reset all"), this, SLOT(confirmReset()));
38     addAction(tr("Select theme"), this, SLOT(selectTheme()));
39     addAction(tr("Set unit"), this, SLOT(selectUnit()));
40     addAction(tr("Flip screen"), this, SIGNAL(flip()));
41     addAction(tr("About"), this, SLOT(showAbout()));
42 }
43
44 void MainMenu::selectTheme()
45 {
46     if(!themeSelector_)
47     {
48         themeSelector_ = new ThemeSelector(this);
49         connect(themeSelector_, SIGNAL(themeChanged()), this, SIGNAL(themeChanged()));
50     }
51
52     themeSelector_->show();
53 }
54
55 void MainMenu::selectUnit()
56 {
57     if(!unitSelector_)
58     {
59         unitSelector_ = new UnitSelector(this);
60         connect(unitSelector_, SIGNAL(unitChanged()), this, SIGNAL(unitChanged()));
61     }
62
63     unitSelector_->show();
64 }
65
66 void MainMenu::showAbout()
67 {
68     if(!aboutDialog_)
69     {
70         aboutDialog_ = new QDialog(this);
71         aboutDialog_->setWindowTitle(tr("About"));
72
73         QHBoxLayout* mainLayout = new QHBoxLayout;
74         QPixmap pixmap(":/resources/appicon.png");
75         QLabel* image = new QLabel;
76         image->setPixmap(pixmap);
77         mainLayout->addWidget(image, 0, Qt::AlignLeft);
78         mainLayout->addSpacing(15);
79         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>"));
80         text->setOpenExternalLinks(true);
81         mainLayout->addWidget(text, 10, Qt::AlignLeft);
82
83         aboutDialog_->setLayout(mainLayout);
84     }
85
86     aboutDialog_->show();
87 }
88
89 void MainMenu::confirmReset()
90 {
91     hide();
92
93     QMessageBox::StandardButton result =  QMessageBox::question(this, tr("Reset all"),
94              tr("Are you sure? All recorded data will be lost."),
95              QMessageBox::Yes | QMessageBox::No);
96
97     if(result == QMessageBox::Yes)
98     {
99         emit resetAll();
100     }
101 }
102
103 void MainMenu::addAction(const QString& text,
104                          const QObject* receiver,
105                          const char* member)
106 {
107     if(itemCount_ % 2 == 0 || !currentRow_)
108     {
109         currentRow_ = new QHBoxLayout;
110         layout_->addLayout(currentRow_);
111     }
112
113     QPushButton* button = new QPushButton(text);
114     connect(button, SIGNAL(clicked(bool)), receiver, member);
115     connect(button, SIGNAL(clicked(bool)), this, SLOT(hide()));
116     currentRow_->addWidget(button);
117     itemCount_++;
118 }