+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Kaj Wallin - kaj.wallin@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <QtGui>
+#include "mainwindow.h"
+#include "listviewscreen.h"
+#include "mapviewscreen.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QWidget *widget = new QWidget;
+ setCentralWidget(widget);
+ createViews();
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ infoLabel = new QLabel(tr("Click \"view\", to change between views"),this);
+ infoLabel->setAttribute(Qt::WA_TranslucentBackground, true);
+ mainLayout->addWidget(infoLabel);
+ mainLayout->addWidget(situareViews);
+ widget->setLayout(mainLayout);
+ createMenus();
+
+ setWindowTitle(tr("View"));
+}
+
+MainWindow::~MainWindow()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ delete toListViewAct;
+ delete toMapViewAct;
+ delete situareViews;
+ delete infoLabel;
+}
+
+void MainWindow::createMenus()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ toListViewAct = new QAction(tr("List"), this);
+ connect(toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
+ toMapViewAct = new QAction(tr("Map"), this);
+ connect(toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
+ viewMenu = menuBar()->addMenu(tr("View"));
+ viewMenu->addAction(toListViewAct);
+ viewMenu->addAction(toMapViewAct);
+}
+
+void MainWindow::createViews()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ situareViews = new QStackedWidget;
+ situareViews->addWidget(new ListViewScreen);
+ situareViews->addWidget(new MapViewScreen);
+}
+
+void MainWindow::toListView()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ switchView(0);
+}
+
+void MainWindow::toMapView()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ switchView(1);
+}
+
+void MainWindow::switchView(int nextIndex)
+{
+ qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
+ if (nextIndex < 0 || nextIndex > 1) {
+ qDebug() << tr("Illegal parameter value in MainWindow::switchView");
+ return;
+ }
+ situareViews->setCurrentIndex(nextIndex);
+ infoLabel->setText(tr("Current: %1").arg(situareViews->currentIndex()));
+ switch (situareViews->currentIndex()) {
+ case 0:
+ setWindowTitle(tr("List"));
+ break;
+ case 1:
+ setWindowTitle(tr("Map"));
+ break;
+ default:
+ qDebug() << tr("Illegal switch value in MainWindow::switchView");
+ break;
+ }
+}
+
+int MainWindow::getViewIndex()
+{
+ return situareViews->currentIndex();
+}
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Kaj Wallin - kaj.wallin@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+#include <QWidget>
+#include <QDebug>
+
+class QLabel;
+class QStackedWidget;
+
+/**
+* @Main Window Class
+*
+* @class MainWindow mainwindow.h "src/ui/mainwindow.h"
+*/
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+ /**
+ * @brief Public method to get current index of the view. Used for Unit testing
+ *
+ * @fn getViewIndex
+ */
+ int getViewIndex();
+
+private:
+ /**
+ * @brief Private method to create List and Map views as a stacked widget
+ *
+ * @fn createViews
+ */
+ void createViews();
+ /**
+ * @brief Widget Stack object for the List and Map Views
+ *
+ * @var situareViews
+ */
+ QStackedWidget *situareViews;
+
+ /**
+ * @brief Private method to create the Menu items
+ *
+ * @fn createMenus
+ */
+ void createMenus();
+ QMenu *viewMenu;
+
+ /**
+ * @brief Action item for changing view to List View
+ *
+ * @var toListViewAct
+ */
+ QAction *toListViewAct;
+ /**
+ * @brief Action item for changing view to Map View
+ *
+ * @var toMapViewAct
+ */
+ QAction *toMapViewAct;
+
+ /**
+ * @brief Method used to switch active view.
+ *
+ * @fn switchView
+ * @param int 0 for listview, 1 for mapview
+ */
+ void switchView(int);
+
+ /**
+ * @brief DUMMY LABEL, REMOVE WHEN BOTH VIEWS ARE COMPLETE
+ *
+ * @var infoLabel
+ * @todo REMOVE THIS
+ */
+ QLabel *infoLabel;
+
+
+public slots:
+ /**
+ * @brief Public slot, which initiates toListViewAct action to switch view
+ *
+ * @fn toListView
+ */
+ void toListView();
+ /**
+ * @brief Public slot, which initiates toMapViewAct action to switch view
+ *
+ * @fn toMapView
+ */
+ void toMapView();
+};
+
+#endif // MAINWINDOW_H