From 37e9f2688aca7e941c62d438d44b4f7d21284493 Mon Sep 17 00:00:00 2001 From: Sakari Poussa Date: Sun, 8 Aug 2010 10:28:47 +0300 Subject: [PATCH] Initial new score dialogs --- src/main-window.cpp | 9 +++- src/score-dialog.cpp | 128 +++++++++++++++++++++++++++++++++++++++++++------- src/score-dialog.h | 113 ++++++++++++++++++++++++++++++-------------- 3 files changed, 197 insertions(+), 53 deletions(-) diff --git a/src/main-window.cpp b/src/main-window.cpp index 740c1b8..154ba3e 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -467,7 +467,12 @@ void MainWindow::newScore() selectDialog->results(clubName, courseName, date); - ScoreDialog *scoreDialog = new ScoreDialog(this); + ScoreDialog *scoreDialog; + if (conf.userMode == "Basic") + scoreDialog = (ScoreDialog *)new ScoreDialog18(this); + else + scoreDialog = (ScoreDialog *)new ScoreDialogSingle(this); + QString title = "New Score: " + courseName + ", " + date; scoreDialog->setWindowTitle(title); @@ -516,7 +521,7 @@ void MainWindow::editScore() QString date = score->getDate(); - ScoreDialog *scoreDialog = new ScoreDialog(this); + ScoreDialog18 *scoreDialog = new ScoreDialog18(this); scoreDialog->init(course, score); QString title = "Edit Score: " + course->getName() + ", " + date; diff --git a/src/score-dialog.cpp b/src/score-dialog.cpp index 867c373..25a4f28 100644 --- a/src/score-dialog.cpp +++ b/src/score-dialog.cpp @@ -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 &scores) +void ScoreDialog18::results(QVector &scores) { TRACE; for (int i = 0; i < 9; i++) { @@ -431,7 +433,7 @@ void ScoreDialog::results(QVector &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())); +} diff --git a/src/score-dialog.h b/src/score-dialog.h index 80a3d67..380c097 100644 --- a/src/score-dialog.h +++ b/src/score-dialog.h @@ -40,7 +40,6 @@ private: ScoreTableModel *model; }; - class SelectDialog: public QDialog { Q_OBJECT; @@ -51,7 +50,7 @@ public: void results(QString &club, QString &course, QString &date); void init(QList &list); -private slots: + private slots: void next(void); private: @@ -74,55 +73,101 @@ private: QLabel *labelCourse; QPushButton *pushButtonNext; - // Layouts + // Layouts QVBoxLayout *leftLayout; QVBoxLayout *rightLayout; QList clubList; }; +// Base class for multiple score edit dialog class ScoreDialog: public QDialog { - Q_OBJECT + Q_OBJECT; public: - ScoreDialog(QWidget *parent = 0); - ~ScoreDialog(); - void init(Course *course, Score *score = 0); - void results(QVector &scores); - bool validate(void); - -private slots: - void up(void); - void down(void); - void next(void); - void finish(void); + ScoreDialog(QWidget *parent = 0) : QDialog(parent) {}; + + virtual void init(Course *course, Score *score = 0) = 0; + virtual void results(QVector &scores) = 0; private: +}; + +// Class for editing 18 holes in one dialog +class ScoreDialog18: public ScoreDialog +{ + Q_OBJECT; + +public: + ScoreDialog18(QWidget *parent = 0); + ~ScoreDialog18(); + void init(Course *course, Score *score = 0); + void results(QVector &scores); + bool validate(void); - void createTable(QWidget *parent = 0); - void createButton(QWidget *parent = 0); - void createLayout(QWidget *parent = 0); - void setDefaultScore(QTableWidget *table); - void moveToNextCell(QTableWidgetItem *item); - void showNote(QString msg); + private slots: + void up(void); + void down(void); + void next(void); + void finish(void); + +private: + + void createTable(QWidget *parent = 0); + void createButton(QWidget *parent = 0); + void createLayout(QWidget *parent = 0); + void setDefaultScore(QTableWidget *table); + void moveToNextCell(QTableWidgetItem *item); + void showNote(QString msg); - enum { ROWS = 8, COLS = 9 }; - enum { ROW_HOLE = 0, ROW_PAR = 1, ROW_HCP = 2, ROW_SCORE = 3, - ROW_HOLE_2 = 4, ROW_PAR_2 = 5, ROW_HCP_2 = 6, ROW_SCORE_2 = 7}; + enum { ROWS = 8, COLS = 9 }; + enum { ROW_HOLE = 0, ROW_PAR = 1, ROW_HCP = 2, ROW_SCORE = 3, + ROW_HOLE_2 = 4, ROW_PAR_2 = 5, ROW_HCP_2 = 6, ROW_SCORE_2 = 7}; + + void reject(void); + + // Widgets + QTableWidget *table; - void reject(void); + QPushButton *pushButtonFinish; + QPushButton *pushButtonUp; + QPushButton *pushButtonDown; + QPushButton *pushButtonNext; + + // Layouts + QVBoxLayout *leftLayout; + QVBoxLayout *rightLayout; +}; - // Widgets - QTableWidget *table; +// Class for editing single hole in one dialog +class ScoreDialogSingle: public QDialog +{ + Q_OBJECT; - QPushButton *pushButtonFinish; - QPushButton *pushButtonUp; - QPushButton *pushButtonDown; - QPushButton *pushButtonNext; +public: + ScoreDialogSingle(QWidget *parent = 0); + ~ScoreDialogSingle(); - // Layouts - QVBoxLayout *leftLayout; - QVBoxLayout *rightLayout; + void init(Course *course, Score *score = 0); + void results(QVector &scores); + +private: + + void createTable(QWidget *parent = 0); + void createButton(QWidget *parent = 0); + void createLayout(QWidget *parent = 0); + + // Widgets + QTableWidget *table; + + QPushButton *pushButtonFinish; + QPushButton *pushButtonUp; + QPushButton *pushButtonDown; + QPushButton *pushButtonNext; + + // Layouts + QVBoxLayout *leftLayout; + QVBoxLayout *rightLayout; }; #endif -- 1.7.9.5