Maemo5 date picker button
[scorecard] / src / main-window.cpp
index e81997a..49d973a 100644 (file)
@@ -1,12 +1,18 @@
+/*
+ * Copyright (C) 2009 Sakari Poussa
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2.
+ */
+
 #include <QtGui>
-#include <QDirModel>
-#include <QListView>
-#include <QStandardItemModel>
 
+#include "score-common.h"
 #include "main-window.h"
 #include "score-dialog.h"
 #include "course-dialog.h"
-#include "xml-parser.h"
+#include "stat-model.h"
 #include "xml-dom-parser.h"
 
 QString appName("scorecard");
@@ -32,7 +38,7 @@ MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
 
   loadSettings();
 
-  QWidget *centralWidget = new QWidget(this);
+  centralWidget = new QWidget(this);
 
   setCentralWidget(centralWidget);
 
@@ -41,12 +47,11 @@ MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
 
   // Sort the scores based on dates
   qSort(scoreList.begin(), scoreList.end(), dateLessThan); 
-
   createActions();
   createMenus();
 
   createTableView(scoreList, clubList);
-  createStatusBar();
+  updateTitleBar();
 
   createLayout(centralWidget);
 }
@@ -62,7 +67,7 @@ void MainWindow::loadSettings(void)
   // TODO: make via user option, automatic will never work
   external = false;
 
-#ifndef Q_WS_HILDON
+#ifndef Q_WS_MAEMO_5
   dataDir = "./" + dataDirName;
 #else
   if (external) {
@@ -122,8 +127,9 @@ void MainWindow::createTableView(QList<Score *> &scoreList, QList <Club *> &club
 
   table->showGrid();
 
+  table->setStyleSheet(ScoreColor::styleSheet());
+
   table->setModel(scoreTableModel);
-  QItemSelectionModel selectionModel();
   table->setSelectionMode(QAbstractItemView::NoSelection);
 
   scoreTableModel->setScore(scoreList);
@@ -132,22 +138,8 @@ void MainWindow::createTableView(QList<Score *> &scoreList, QList <Club *> &club
   // Fill out all the space with the tables
   table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
   table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
-  table->verticalHeader()->setAutoFillBackground(true);
   table->horizontalHeader()->hide();
-}
-
-void MainWindow::createStatusBar()
-{
-#if 0
-  // TODO: use toolbar or buttons. Toolbar seems not to be ready and
-  // requires more work.
-  toolbar = addToolBar(tr("foo"));
-  toolbar->addAction(firstAct);
-  toolbar->addAction(lastAct);
-  toolbar->addAction(prevAct);
-  toolbar->addAction(nextAct);
-#endif
-  updateStatusBar();
+  //table->verticalHeader()->setStyleSheet("color : gray }");
 }
 
 void MainWindow::createActions()
@@ -164,16 +156,8 @@ void MainWindow::createActions()
   editCourseAct = new QAction(tr("Edit Course"), this);
   connect(editCourseAct, SIGNAL(triggered()), this, SLOT(editCourse()));
 
-#if 0
-  viewScoreAct = new QAction(tr("&View Scores"), this);
-  connect(viewScoreAct, SIGNAL(triggered()), this, SLOT(viewScore()));
-
-  viewCourseAct = new QAction(tr("&View Courses"), this);
-  connect(viewCourseAct, SIGNAL(triggered()), this, SLOT(viewCourse()));
-
-  viewStatisticAct = new QAction(tr("&View Statistics"), this);
-  connect(viewStatisticAct, SIGNAL(triggered()), this, SLOT(viewStatistic()));
-#endif
+  statAct = new QAction(tr("Statistics"), this);
+  connect(statAct, SIGNAL(triggered()), this, SLOT(viewStatistics()));
 
   nextAct = new QAction(tr( "   Next   "), this);
   connect(nextAct, SIGNAL(triggered()), this, SLOT(nextButtonClicked()));
@@ -190,19 +174,20 @@ void MainWindow::createActions()
 
 void MainWindow::createMenus()
 {
+#ifdef Q_WS_MAEMO_5
   menu = menuBar()->addMenu("");
-#if 0
-  menu->addAction(viewScoreAct);
-  menu->addAction(viewCourseAct);
-  menu->addAction(viewStatisticAct);
+#else
+  menu = menuBar()->addMenu("Menu");
 #endif
+
   menu->addAction(newScoreAct);
   menu->addAction(newCourseAct);
   menu->addAction(editScoreAct);
   menu->addAction(editCourseAct);
+  menu->addAction(statAct);
 }
 
-void MainWindow::updateStatusBar()
+void MainWindow::updateTitleBar()
 {
   QString title = scoreTableModel->getInfoText();
   if (title.isEmpty())
@@ -214,25 +199,25 @@ void MainWindow::updateStatusBar()
 void MainWindow::firstButtonClicked()
 {
   scoreTableModel->first();
-  updateStatusBar();
+  updateTitleBar();
 }
 
 void MainWindow::lastButtonClicked()
 {
   scoreTableModel->last();
-  updateStatusBar();
+  updateTitleBar();
 }
 
 void MainWindow::nextButtonClicked()
 {
   scoreTableModel->next();
-  updateStatusBar();
+  updateTitleBar();
 }
 
 void MainWindow::prevButtonClicked()
 {
   scoreTableModel->prev();
-  updateStatusBar();
+  updateTitleBar();
 }
 
 // FIXME: dup code from table-model.cpp
@@ -375,7 +360,7 @@ void MainWindow::newScore()
 
       // TODO: does this really work? No mem leaks?
       scoreTableModel->setScore(scoreList, score);
-      updateStatusBar();
+      updateTitleBar();
     }
   }
 }
@@ -384,6 +369,12 @@ void MainWindow::editScore()
 {
   Course *course = scoreTableModel->getCourse();
   Score *score = scoreTableModel->getScore();
+
+  if (!course || !score) {
+    qDebug() << "No score/course to edit";
+    return;
+  }
+
   QString date = score->getDate();
 
   ScoreDialog *scoreDialog = new ScoreDialog(this);
@@ -409,10 +400,51 @@ void MainWindow::editScore()
 
     // TODO: does this really work? No mem leaks?
     scoreTableModel->setScore(scoreList, score);
-    updateStatusBar();
+    updateTitleBar();
   }
 }
 
+void MainWindow::viewStatistics()
+{
+  QMainWindow *win = new QMainWindow(this);
+  QString title = "Statistics";
+  win->setWindowTitle(title);
+
+  StatModel *statModel = new StatModel(clubList, scoreList);
+
+  QTableView *table = new QTableView;
+  table->showGrid();
+  table->setSelectionMode(QAbstractItemView::NoSelection);
+  table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+  table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
+  table->verticalHeader()->setAutoFillBackground(true);
+  table->setModel(statModel);
+
+  QWidget *central = new QWidget(win);
+  win->setCentralWidget(central);
+
+  QPushButton *b1 = new QPushButton("Graphs");
+
+  QVBoxLayout *buttonLayout = new QVBoxLayout;
+  buttonLayout->addWidget(b1);
+
+  QTextEdit *textEdit = new QTextEdit;
+  //getStat(textEdit);
+
+  textEdit->setReadOnly(true);
+
+  QVBoxLayout *infoLayout = new QVBoxLayout;
+  infoLayout->addWidget(table);
+
+  QHBoxLayout *mainLayout = new QHBoxLayout(central);
+  mainLayout->addLayout(infoLayout);
+  //mainLayout->addLayout(buttonLayout);
+
+  central->setLayout(mainLayout);
+
+  win->show();
+}
+
 void MainWindow::loadScoreFile(QString &fileName, QList<Score *> &list)
 {
   ScoreXmlHandler handler(list);