GPLv2 license
[scorecard] / src / score-dialog.cpp
index 357e688..443bfd2 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * 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>
 
@@ -19,11 +27,13 @@ void SelectDialog::createLayout(QWidget *parent)
 
   QDate today(QDate::currentDate());
   lineEditDate->setText(today.toString("yyyy-MM-dd"));
+  date = new QDateEdit;
 
   connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
 
   leftLayout = new QVBoxLayout;
   leftLayout->addWidget(listClub);
+  //leftLayout->addWidget(date);
   leftLayout->addWidget(lineEditDate);
 
   rightLayout = new QVBoxLayout;
@@ -162,43 +172,47 @@ void ScoreDialog::createButton(QWidget *parent)
   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;
+  QColor fgColor(Qt::white);
+  QColor bgColor(Qt::darkGray);
 
   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->setTextColor(fgColor);
     holeNum->setBackgroundColor(bgColor);
 
-    holeNum->setTextAlignment(Qt::AlignCenter);
-
     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
@@ -228,8 +242,10 @@ void ScoreDialog::up(void)
 {
   QTableWidgetItem *item = table->currentItem();
 
-  if (!item)
+  if (!item) {
+    qWarning() << "ERROR: no current item";
     return;
+  }
 
   int i = (item->text()).toInt();
   QVariant value(i+1);
@@ -277,7 +293,6 @@ void ScoreDialog::moveToNextCell(QTableWidgetItem *item)
     col = 0;
     row = (row == ROW_SCORE_2) ? ROW_SCORE : ROW_SCORE_2;
   }
-  //qDebug() << "new cell: " << row << "/" << col;
   table->setCurrentCell(row, col);
 }