+/*
+ * 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");
loadSettings();
- QWidget *centralWidget = new QWidget(this);
+ centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
// Sort the scores based on dates
qSort(scoreList.begin(), scoreList.end(), dateLessThan);
-
createActions();
createMenus();
createTableView(scoreList, clubList);
- createStatusBar();
+ updateTitleBar();
createLayout(centralWidget);
}
// 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) {
table->showGrid();
+ table->setStyleSheet(ScoreColor::styleSheet());
+
table->setModel(scoreTableModel);
- QItemSelectionModel selectionModel();
table->setSelectionMode(QAbstractItemView::NoSelection);
scoreTableModel->setScore(scoreList);
// 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()
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()));
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())
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
// TODO: does this really work? No mem leaks?
scoreTableModel->setScore(scoreList, score);
- updateStatusBar();
+ updateTitleBar();
}
}
}
{
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);
// 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);