QWidget *centralWidget = new QWidget(this);
createLayout(centralWidget);
- setWindowTitle(tr("ScoreCard: Select Club, Course and Date"));
+ setWindowTitle(tr("ScoreCard: Select Course and Date"));
}
void SelectDialog::createLayout(QWidget *parent)
{
- labelClub = new QLabel(tr("Club"));
- labelCourse = new QLabel(tr("Course"));
- comboBoxClub = new QComboBox;
- comboBoxCourse = new QComboBox;
+ listClub = new QListWidget(parent);
lineEditDate = new QLineEdit;
pushButtonNext = new QPushButton(tr("Next"));
QDate today(QDate::currentDate());
lineEditDate->setText(today.toString("yyyy-MM-dd"));
+ date = new QDateEdit;
connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
- connect(comboBoxClub, SIGNAL(activated(int)), this, SLOT(comboBoxClubChanged()));
- connect(comboBoxCourse, SIGNAL(activated(int)), this, SLOT(comboBoxCourseChanged()));
leftLayout = new QVBoxLayout;
- leftLayout->addWidget(comboBoxClub);
- leftLayout->addWidget(comboBoxCourse);
+ leftLayout->addWidget(listClub);
+ //leftLayout->addWidget(date);
leftLayout->addWidget(lineEditDate);
rightLayout = new QVBoxLayout;
while (i.hasNext()) {
Club *club = i.next();
- comboBoxClub->insertItem(index, club->getName());
- index++;
+
+ QList<Course *> courseList = club->getCourseList();
+
+ QListIterator<Course *> j(courseList);
+ while (j.hasNext()) {
+ Course *course = j.next();
+
+ QListWidgetItem *newItem = new QListWidgetItem;
+
+ QString entry = club->getName() + "," + course->getName();
+
+ newItem->setText(entry);
+ listClub->insertItem(index, newItem);
+
+ index++;
+ }
}
- comboBoxCourseUpdate();
}
void SelectDialog::results(QString &club,
QString &course,
QString &date)
{
- club = comboBoxClub->currentText();
- course = comboBoxCourse->currentText();
- date = lineEditDate->text();
-}
+ QListWidgetItem *current = listClub->currentItem();
-void SelectDialog::comboBoxCourseUpdate()
-{
- int index = comboBoxClub->currentIndex();
+ if (current) {
+ QString tmp = current->text();
- Club *club = clubList[index];
- QList<Course *> courseList = club->getCourseList();
-
- comboBoxCourse->clear();
- QListIterator<Course *> i(courseList);
- index = 0;
- while (i.hasNext()) {
- Course *course = i.next();
- comboBoxCourse->insertItem(index, course->getName());
- index++;
+ QStringList stringList = tmp.split(",");
+ club = stringList[0];
+ course = stringList[1];
+ date = lineEditDate->text();
}
}
-void SelectDialog::comboBoxClubChanged()
-{
- comboBoxCourseUpdate();
-}
-
-void SelectDialog::comboBoxCourseChanged()
-{
-}
-
bool SelectDialog::validate(void)
{
return true;
{
resize(800, 400);
- QFont font;
- font.setPointSize(20);
- setFont(font);
-
QWidget *centralWidget = new QWidget(this);
createTable();
createButton();
createLayout(centralWidget);
-
- setWindowTitle(tr("ScoreCard: New Score"));
}
void ScoreDialog::createLayout(QWidget *parent)
rightLayout->addWidget(pushButtonDown);
rightLayout->addWidget(pushButtonNext);
rightLayout->addStretch();
- rightLayout->addWidget(pushButtonFinnish);
+ rightLayout->addWidget(pushButtonFinish);
QHBoxLayout *mainLayout = new QHBoxLayout(parent);
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
-
setLayout(mainLayout);
}
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)
{
- pushButtonFinnish = new QPushButton(tr("Finnish"));
- connect(pushButtonFinnish, SIGNAL(clicked()), this, SLOT(finnish()));
-
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;
+ 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
}
}
-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)
return true;
}
-void ScoreDialog::finnish(void)
+void ScoreDialog::finish(void)
{
if (validate())
done(1);