Initial new score dialogs
[scorecard] / src / score-dialog.cpp
index 867c373..25a4f28 100644 (file)
@@ -18,6 +18,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 // ScoreWindow based on QMainWindow
+// Usage: view scorecard 
 ////////////////////////////////////////////////////////////////////////////////
 ScoreWindow::ScoreWindow(QWidget *parent) : QMainWindow(parent)
 {
@@ -66,9 +67,9 @@ void ScoreWindow::setup(Score *score, Course *course)
     model->set(score, course);
 }
 
-
 ////////////////////////////////////////////////////////////////////////////////
 // SelectDialog based on QDialog
+// Usage: select course and date for entering score
 ////////////////////////////////////////////////////////////////////////////////
 SelectDialog::SelectDialog(QWidget *parent) : QDialog(parent)
 {
@@ -198,8 +199,9 @@ void SelectDialog::reject(void)
 
 ////////////////////////////////////////////////////////////////////////////////
 // ScoreDialog based on QDialog
+// Usage: edit scorecard data
 ////////////////////////////////////////////////////////////////////////////////
-ScoreDialog::ScoreDialog(QWidget *parent) : QDialog(parent)
+ScoreDialog18::ScoreDialog18(QWidget *parent) : ScoreDialog(parent)
 {
     TRACE;
     resize(800, 400);
@@ -215,7 +217,7 @@ ScoreDialog::ScoreDialog(QWidget *parent) : QDialog(parent)
     createLayout(centralWidget);
 }
 
-ScoreDialog::~ScoreDialog()
+ScoreDialog18::~ScoreDialog18()
 {
     //if (centralWidget)
     //  delete centralWidget;
@@ -229,7 +231,7 @@ ScoreDialog::~ScoreDialog()
         delete table;
 }
 
-void ScoreDialog::createLayout(QWidget *parent)
+void ScoreDialog18::createLayout(QWidget *parent)
 {
     TRACE;
     leftLayout = new QVBoxLayout;
@@ -254,7 +256,7 @@ void ScoreDialog::createLayout(QWidget *parent)
     setLayout(mainLayout);
 }
 
-void ScoreDialog::createTable(QWidget *parent)
+void ScoreDialog18::createTable(QWidget *parent)
 {
     TRACE;
     table = new QTableWidget(ROWS, COLS, parent);
@@ -270,7 +272,7 @@ void ScoreDialog::createTable(QWidget *parent)
     table->setVerticalHeaderLabels(headers);
 }
 
-void ScoreDialog::createButton(QWidget *parent)
+void ScoreDialog18::createButton(QWidget *parent)
 {
     TRACE;
     Q_UNUSED(parent);
@@ -287,7 +289,7 @@ void ScoreDialog::createButton(QWidget *parent)
     connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
 }
 
-void ScoreDialog::init(Course *course, Score *score)
+void ScoreDialog18::init(Course *course, Score *score)
 {
     TRACE;
     QTableWidgetItem *par, *hcp, *scoreItem, *holeNum;
@@ -336,7 +338,7 @@ void ScoreDialog::init(Course *course, Score *score)
 }
 
 // Set default score to par if not set
-void ScoreDialog::setDefaultScore(QTableWidget *table)
+void ScoreDialog18::setDefaultScore(QTableWidget *table)
 {
     int row = table->currentRow();
     int col = table->currentColumn();
@@ -358,7 +360,7 @@ void ScoreDialog::setDefaultScore(QTableWidget *table)
     }
 }
 
-void ScoreDialog::up(void)
+void ScoreDialog18::up(void)
 {
     QTableWidgetItem *item = table->currentItem();
 
@@ -372,7 +374,7 @@ void ScoreDialog::up(void)
     item->setData(Qt::DisplayRole, value);
 }
 
-void ScoreDialog::down(void)
+void ScoreDialog18::down(void)
 {
     QTableWidgetItem *item = table->currentItem();
 
@@ -384,7 +386,7 @@ void ScoreDialog::down(void)
     item->setData(Qt::DisplayRole, value);
 }
 
-void ScoreDialog::next(void)
+void ScoreDialog18::next(void)
 {
     if (table) {
         QTableWidgetItem *item = table->currentItem();
@@ -393,7 +395,7 @@ void ScoreDialog::next(void)
     }
 }
 
-void ScoreDialog::moveToNextCell(QTableWidgetItem *item)
+void ScoreDialog18::moveToNextCell(QTableWidgetItem *item)
 {
     if (!item)
         return;
@@ -416,7 +418,7 @@ void ScoreDialog::moveToNextCell(QTableWidgetItem *item)
     table->setCurrentCell(row, col);
 }
 
-void ScoreDialog::results(QVector<QString> &scores)
+void ScoreDialog18::results(QVector<QString> &scores)
 {
     TRACE;
     for (int i = 0; i < 9; i++) {
@@ -431,7 +433,7 @@ void ScoreDialog::results(QVector<QString> &scores)
     }
 }
 
-bool ScoreDialog::validate(void)
+bool ScoreDialog18::validate(void)
 {
     for (int i=0; i<9; i++) {
         QTableWidgetItem *frontItem = table->item(ROW_SCORE, i);
@@ -449,7 +451,7 @@ bool ScoreDialog::validate(void)
     return true;
 }
 
-void ScoreDialog::finish(void)
+void ScoreDialog18::finish(void)
 {
     if (validate())
         done(1);
@@ -458,12 +460,12 @@ void ScoreDialog::finish(void)
     }
 }
 
-void ScoreDialog::reject(void)
+void ScoreDialog18::reject(void)
 {
     done(0);
 }
 
-void ScoreDialog::showNote(QString msg)
+void ScoreDialog18::showNote(QString msg)
 {
 #ifdef Q_WS_MAEMO_5
     QMaemo5InformationBox::information(this, 
@@ -471,3 +473,95 @@ void ScoreDialog::showNote(QString msg)
                                        QMaemo5InformationBox::DefaultTimeout);
 #endif
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// ScoreDialogSingle based on QDialog
+// Usage: edit scorecard data for single hole
+////////////////////////////////////////////////////////////////////////////////
+ScoreDialogSingle::ScoreDialogSingle(QWidget *parent) : QDialog(parent)
+{
+    TRACE;
+    resize(800, 400);
+    QFont font;
+    font.setPointSize(fontSize);
+    setFont(font);
+
+    QWidget *centralWidget = new QWidget(this);
+
+    createTable();
+    createButton();
+    
+    createLayout(centralWidget);
+}
+
+ScoreDialogSingle::~ScoreDialogSingle()
+{
+    //if (centralWidget)
+    //  delete centralWidget;
+    if (leftLayout)
+        delete leftLayout;
+    if (rightLayout)
+        delete rightLayout;
+    //if (mainLayout)
+    //  delete mainLayout;
+    if (table)
+        delete table;
+}
+
+void ScoreDialogSingle::createLayout(QWidget *parent)
+{
+    TRACE;
+    leftLayout = new QVBoxLayout;
+    leftLayout->addWidget(table);
+
+    QDialogButtonBox * buttonBoxUp = new QDialogButtonBox(Qt::Vertical);
+    buttonBoxUp->addButton(pushButtonUp, QDialogButtonBox::ActionRole);
+    buttonBoxUp->addButton(pushButtonDown, QDialogButtonBox::ActionRole);
+    buttonBoxUp->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
+
+    QDialogButtonBox * buttonBoxDown = new QDialogButtonBox(Qt::Vertical);
+    buttonBoxDown->addButton(pushButtonFinish, QDialogButtonBox::ActionRole);
+
+    rightLayout = new QVBoxLayout;
+    rightLayout->addWidget(buttonBoxUp);
+    rightLayout->addStretch();
+    rightLayout->addWidget(buttonBoxDown);
+
+    QHBoxLayout *mainLayout = new QHBoxLayout(parent);
+    mainLayout->addLayout(leftLayout);
+    mainLayout->addLayout(rightLayout);
+    setLayout(mainLayout);
+}
+
+void ScoreDialogSingle::createTable(QWidget *parent)
+{
+    TRACE;
+    table = new QTableWidget(5, 5, parent);
+
+    table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+    table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
+    table->horizontalHeader()->hide();
+
+    table->setStyleSheet(defaultStyleSheet);
+
+    QStringList headers;
+    headers << "" << "Par" << "HCP" << "Score" << "" << "Par" << "HCP" << "Score";
+    table->setVerticalHeaderLabels(headers);
+}
+
+void ScoreDialogSingle::createButton(QWidget *parent)
+{
+    TRACE;
+    Q_UNUSED(parent);
+    pushButtonUp = new QPushButton(tr("+"));
+    connect(pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
+    
+    pushButtonDown = new QPushButton(tr("-"));
+    connect(pushButtonDown, SIGNAL(clicked()), this, SLOT(down()));
+  
+    pushButtonNext = new QPushButton(tr("Next"));
+    connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
+
+    pushButtonFinish = new QPushButton(tr("Finish"));
+    connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
+}