+/*
+ * 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 <QInputContext>
#include "score-dialog.h"
+#include "score-common.h"
SelectDialog::SelectDialog(QWidget *parent) : QDialog(parent)
{
void SelectDialog::createLayout(QWidget *parent)
{
- labelClub = new QLabel(tr("Club"));
- labelCourse = new QLabel(tr("Course"));
listClub = new QListWidget(parent);
- lineEditDate = new QLineEdit;
pushButtonNext = new QPushButton(tr("Next"));
- QDate today(QDate::currentDate());
- lineEditDate->setText(today.toString("yyyy-MM-dd"));
-
connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
leftLayout = new QVBoxLayout;
leftLayout->addWidget(listClub);
+
+#ifdef Q_WS_MAEMO_5
+ dateButton = new QMaemo5ValueButton();
+ dateButton->setValueLayout(QMaemo5ValueButton::ValueUnderText);
+ dateButton->setPickSelector(new QMaemo5DatePickSelector());
+ dateButton->setText(QString::fromUtf8("Date"));
+ leftLayout->addWidget(dateButton);
+#else
+ QDate today(QDate::currentDate());
+ lineEditDate = new QLineEdit;
+ lineEditDate->setText(today.toString("yyyy-MM-dd"));
+ date = new QDateEdit;
+ leftLayout->addWidget(date);
leftLayout->addWidget(lineEditDate);
+#endif
rightLayout = new QVBoxLayout;
rightLayout->addStretch();
QStringList stringList = tmp.split(",");
club = stringList[0];
course = stringList[1];
- date = lineEditDate->text();
+#ifdef Q_WS_MAEMO_5
+ QMaemo5DatePickSelector *sel = (QMaemo5DatePickSelector *)dateButton->pickSelector();
+ QDate d = sel->currentDate();
+ // TODO: change to QDate
+ date = d.toString(Qt::ISODate);
+#else
+ date = lineEditDate->text();
+#endif
}
}
QHBoxLayout *mainLayout = new QHBoxLayout(parent);
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
-
setLayout(mainLayout);
}
table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
table->horizontalHeader()->hide();
+ table->setStyleSheet(ScoreColor::styleSheet());
+
QStringList headers;
headers << "" << "Par" << "HCP" << "Score" << "" << "Par" << "HCP" << "Score";
table->setVerticalHeaderLabels(headers);
-
- //connect(table, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(itemChanged(QTableWidgetItem *)));
- //connect(table, SIGNAL(itemPressed(QTableWidgetItem *)), this, SLOT(itemChanged(QTableWidgetItem *)));
}
void ScoreDialog::createButton(QWidget *parent)
{
- pushButtonFinish = new QPushButton(tr("Finish"));
- connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
-
pushButtonUp = new QPushButton(tr("+"));
connect(pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
pushButtonNext = new QPushButton(tr("Next"));
connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
+
+ pushButtonFinish = new QPushButton(tr("Finish"));
+ connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
}
-void ScoreDialog::init(Course *course)
+void ScoreDialog::init(Course *course, Score *score)
{
- QTableWidgetItem *par, *hcp, *score;
+ QTableWidgetItem *par, *hcp, *scoreItem, *holeNum;
for (int i = 0; i < 18; i++) {
par = new QTableWidgetItem(course->getPar(i));
hcp = new QTableWidgetItem(course->getHcp(i));
- score = new QTableWidgetItem("");
- //score->setInputMask("9");
+ if (score)
+ scoreItem = new QTableWidgetItem(score->getScore(i));
+ else
+ scoreItem = new QTableWidgetItem("");
+ holeNum = new QTableWidgetItem(QString::number(i+1));
- QTableWidgetItem *holeNum = new QTableWidgetItem(QString::number(i+1));
- QColor bgColor(Qt::gray);
- holeNum->setBackgroundColor(bgColor);
-
- holeNum->setTextAlignment(Qt::AlignCenter);
+ holeNum->setBackgroundColor(ScoreColor::holeBg());
par->setTextAlignment(Qt::AlignCenter);
hcp->setTextAlignment(Qt::AlignCenter);
- score->setTextAlignment(Qt::AlignCenter);
+ scoreItem->setTextAlignment(Qt::AlignCenter);
+ holeNum->setTextAlignment(Qt::AlignCenter);
if (i < 9) {
table->setItem(ROW_HOLE, i, holeNum);
table->setItem(ROW_PAR, i, par);
table->setItem(ROW_HCP, i, hcp);
- table->setItem(ROW_SCORE, i, score);
+ table->setItem(ROW_SCORE, i, scoreItem);
}
else {
table->setItem(ROW_HOLE_2, i-9, holeNum);
table->setItem(ROW_PAR_2, i-9, par);
table->setItem(ROW_HCP_2, i-9, hcp);
- table->setItem(ROW_SCORE_2, i-9, score);
+ table->setItem(ROW_SCORE_2, i-9, scoreItem);
}
}
// Set focus to 1st cell
table->setCurrentCell(ROW_SCORE, 0);
- setDefaultScore(table);
+ if (!score)
+ setDefaultScore(table);
}
// Set default score to par if not set
}
}
-void ScoreDialog::moveToNextCell(QTableWidgetItem *item)
+void ScoreDialog::up(void)
{
- if (!item)
+ QTableWidgetItem *item = table->currentItem();
+
+ if (!item) {
+ qWarning() << "ERROR: no current item";
return;
+ }
- QTableWidget *table = item->tableWidget();
+ int i = (item->text()).toInt();
+ QVariant value(i+1);
+ item->setData(Qt::DisplayRole, value);
+}
- if (!table)
- return;
+void ScoreDialog::down(void)
+{
+ QTableWidgetItem *item = table->currentItem();
- int row = table->currentRow();
- int col = table->currentColumn();
+ if (!item)
+ return;
- if (col < (COLS-1)) {
- col++;
- }
- else if (col == (COLS-1)) {
- col = 0;
- row = (row == ROW_SCORE_2) ? ROW_SCORE : ROW_SCORE_2;
- }
- //qDebug() << "new cell: " << row << "/" << col;
- table->setCurrentCell(row, col);
+ int i = (item->text()).toInt();
+ QVariant value(i-1);
+ item->setData(Qt::DisplayRole, value);
}
void ScoreDialog::next(void)
}
}
-void ScoreDialog::up(void)
+void ScoreDialog::moveToNextCell(QTableWidgetItem *item)
{
- QTableWidgetItem *item = table->currentItem();
-
if (!item)
return;
- int i = (item->text()).toInt();
- QVariant value(i+1);
- item->setData(Qt::DisplayRole, value);
-}
-
-void ScoreDialog::down(void)
-{
- QTableWidgetItem *item = table->currentItem();
+ QTableWidget *table = item->tableWidget();
- if (!item)
+ if (!table)
return;
- int i = (item->text()).toInt();
- QVariant value(i-1);
- item->setData(Qt::DisplayRole, value);
-}
+ int row = table->currentRow();
+ int col = table->currentColumn();
-void ScoreDialog::itemChanged(QTableWidgetItem *item)
-{
+ if (col < (COLS-1)) {
+ col++;
+ }
+ else if (col == (COLS-1)) {
+ col = 0;
+ row = (row == ROW_SCORE_2) ? ROW_SCORE : ROW_SCORE_2;
+ }
+ table->setCurrentCell(row, col);
}
void ScoreDialog::results(QVector<QString> &scores)