358f97e8f0ad3bf393bcd8049d97c74785b00483
[situare] / src / ui / mainwindow.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Henri Lampela - henri.lampela@ixonos.com
6        Kaj Wallin - kaj.wallin@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21  */
22
23 #include <QtGui>
24 #include "mainwindow.h"
25 #include "listviewtab.h"
26 #include "mapviewtab.h"
27
28 MainWindow::MainWindow(QWidget *parent)
29     : QMainWindow(parent)
30 {
31     QWidget *widget = new QWidget;
32     setCentralWidget(widget);
33     createViews();
34     QVBoxLayout *mainLayout = new QVBoxLayout;
35     infoLabel = new QLabel(tr("Click \"view\", to change between views"),this);
36     mainLayout->addWidget(infoLabel);
37     mainLayout->addWidget(situareViews);
38     widget->setLayout(mainLayout);
39     createMenus();
40
41     this->setWindowTitle(tr("View"));
42 }
43
44 MainWindow::~MainWindow()
45 {
46
47 }
48
49 void MainWindow::createMenus()
50 {
51     toListViewAct = new QAction(tr("List"), this);
52     connect(toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
53     toMapViewAct = new QAction(tr("Map"), this);
54     connect(toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
55     viewMenu = menuBar()->addMenu(tr("View"));
56     viewMenu->addAction(toListViewAct);
57     viewMenu->addAction(toMapViewAct);
58 }
59
60 void MainWindow::createViews()
61 {
62     situareViews = new QStackedWidget(this);
63     situareViews->addWidget(new SituareListView(this));
64     situareViews->addWidget(new SituareMapView(this));
65 }
66
67 void MainWindow::toListView()
68 {
69     this->situareViews->setCurrentIndex(0);
70     infoLabel->setText(tr("Current: %1").arg(situareViews->currentIndex()));
71     this->setWindowTitle("List");
72 }
73
74 void MainWindow::toMapView()
75 {
76     this->situareViews->setCurrentIndex(1);
77     infoLabel->setText(tr("Current: %1").arg(situareViews->currentIndex()));
78     this->setWindowTitle("Map");
79 }