Use Home Club setting in new score dialog
authorSakari Poussa <spoussa@gmail.com>
Fri, 28 May 2010 00:22:16 +0000 (03:22 +0300)
committerSakari Poussa <spoussa@gmail.com>
Fri, 28 May 2010 00:22:16 +0000 (03:22 +0300)
src/data.cpp
src/data.h
src/main-window.cpp
src/main-window.h
src/score-common.h
src/score-dialog.cpp
src/score-dialog.h
src/table-model.cpp

index 19e52f0..120f317 100644 (file)
@@ -330,18 +330,21 @@ void Course::dump() {
 Club::Club(const QXmlAttributes &attrs, bool readOnly) 
   : m_readOnly(readOnly)
 {
+    m_homeClub = false;
     name = attrs.value("name");
 }
 
 Club::Club(const QDomElement node, bool readOnly) 
   : m_readOnly(readOnly)
 {
+    m_homeClub = false;
     name = node.attribute("name", "");
 }
 
 Club::Club(QString &name, bool readOnly)
   : m_readOnly(readOnly)
 {
+    m_homeClub = false;
     this->name = name;
 }
 
index 01d01ef..c05c6c3 100644 (file)
@@ -108,11 +108,14 @@ public:
     Course *getCourse(const QString &courseName);
     bool isEmpty();
     bool isReadOnly();
+    void setHomeClub(bool value) { m_homeClub = value; }
+    bool isHomeClub() { return m_homeClub; }
 
     QList <Course *> getCourseList() { return courseList; } // HACK: fixme
 
 private:
     bool m_readOnly;
+    bool m_homeClub;
     QList <Course *> courseList;
     QString name;
 };
index c3c3f01..93c5f08 100644 (file)
@@ -141,37 +141,52 @@ void MainWindow::flushReadOnlyItems()
     }
 }
 
+void MainWindow::markHomeClub()
+{
+    TRACE;
+    QListIterator<Club *> i(clubList);
+    Club *c;
+
+    while (i.hasNext()) {
+        c = i.next();
+        if (c->getName() == conf.homeClub)
+            c->setHomeClub(true);
+        else
+            c->setHomeClub(false);
+    }
+}
 
 MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
 {
-  resize(800, 480);
+    resize(800, 480);
 
 #ifdef Q_WS_MAEMO_5
-  setAttribute(Qt::WA_Maemo5StackedWindow);
+    setAttribute(Qt::WA_Maemo5StackedWindow);
 #endif
 
-  loadSettings();
+    loadSettings();
 
-  centralWidget = new QWidget(this);
+    centralWidget = new QWidget(this);
 
-  setCentralWidget(centralWidget);
+    setCentralWidget(centralWidget);
 
-  loadScoreFile(scoreFile, scoreList);
-  if (conf.defaultCourses == "Yes")
-      loadClubFile(masterFile, clubList, true);
-  loadClubFile(clubFile, clubList);
+    loadScoreFile(scoreFile, scoreList);
+    if (conf.defaultCourses == "Yes")
+        loadClubFile(masterFile, clubList, true);
+    loadClubFile(clubFile, clubList);
+    markHomeClub();
 
-  // Sort the scores based on dates
-  qSort(scoreList.begin(), scoreList.end(), dateMoreThan); 
-  createActions();
-  createMenus();
+    // Sort the scores based on dates
+    qSort(scoreList.begin(), scoreList.end(), dateMoreThan); 
+    createActions();
+    createMenus();
 
-  createListView(scoreList, clubList);
+    createListView(scoreList, clubList);
 
-  createLayoutList(centralWidget);
+    createLayoutList(centralWidget);
 
-  scoreWindow = new ScoreWindow(this);
-  courseWindow = new CourseWindow(this);
+    scoreWindow = new ScoreWindow(this);
+    courseWindow = new CourseWindow(this);
 }
 
 void MainWindow::loadSettings(void)
@@ -660,8 +675,6 @@ void MainWindow::viewSettings()
         QString newValue = conf.defaultCourses.toString();
         saveSettings();
 
-        qDebug() << "Settings:" << oldValue << "->" << newValue;
-
         // Reload club list, or drop r/o courses from list
         if (oldValue == "Yes" && newValue == "No") {
             flushReadOnlyItems();
@@ -673,6 +686,7 @@ void MainWindow::viewSettings()
             courseListModel->update(clubList);
             list->update();
         }
+        markHomeClub();
     }
 }
 
index b4ff965..bd39659 100644 (file)
@@ -68,6 +68,7 @@ private:
   Score * currentScore();
   Score * findScore(QString & clubName, QString & courseName);
   void flushReadOnlyItems();
+  void markHomeClub();
                                
   void showNote(QString msg);
   void getStat(QTextEdit *);
index a2dad65..52dc8c6 100644 (file)
@@ -42,7 +42,7 @@ class ScoreColor
     static QColor doubleBogey() { return Qt::red;                  }
     static QColor bad()         { return Qt::red;                  }
     static QColor subTotal()    { return Qt::white;                }
-    static QColor total()       { return Qt::magenta;              }
+    static QColor total()       { return Qt::white;                }
 }; 
 
 static QString statStyleSheet("QTableView {color : white;}");
index faa8d82..29b018c 100644 (file)
@@ -72,121 +72,128 @@ void ScoreWindow::setup(Score *score, Course *course)
 ////////////////////////////////////////////////////////////////////////////////
 SelectDialog::SelectDialog(QWidget *parent) : QDialog(parent)
 {
-  resize(800, 350);
+    resize(800, 350);
 
-  QWidget *centralWidget = new QWidget(this);
-  createLayout(centralWidget);
+    QWidget *centralWidget = new QWidget(this);
+    createLayout(centralWidget);
 
-  setWindowTitle(tr("ScoreCard: Select Course and Date"));
+    setWindowTitle(tr("ScoreCard: Select Course and Date"));
 }
 
 void SelectDialog::createLayout(QWidget *parent)
 {
-  listClub = new QListWidget(parent);
-  pushButtonNext = new QPushButton(tr("Next"));
+    listWidgetClub = new QListWidget(parent);
+    pushButtonNext = new QPushButton(tr("Next"));
 
-  connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
+    connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
 
-  QDialogButtonBox * buttonBox = new QDialogButtonBox(Qt::Vertical);
-  buttonBox->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
+    QDialogButtonBox * buttonBox = new QDialogButtonBox(Qt::Vertical);
+    buttonBox->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
 
-  leftLayout = new QVBoxLayout;
-  leftLayout->addWidget(listClub);
+    leftLayout = new QVBoxLayout;
+    leftLayout->addWidget(listWidgetClub);
 
 #ifdef Q_WS_MAEMO_5
-  dateButton = new QMaemo5ValueButton();
-  dateButton->setValueLayout(QMaemo5ValueButton::ValueUnderText);
-  dateButton->setPickSelector(new QMaemo5DatePickSelector());
-  dateButton->setText(QString::fromUtf8("Date"));
-  leftLayout->addWidget(dateButton);
+    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);
+    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();
-  rightLayout->addWidget(buttonBox);
+    rightLayout = new QVBoxLayout;
+    rightLayout->addStretch();
+    rightLayout->addWidget(buttonBox);
 
-  QHBoxLayout *mainLayout = new QHBoxLayout(parent);
-  mainLayout->addLayout(leftLayout);
-  mainLayout->addLayout(rightLayout);
+    QHBoxLayout *mainLayout = new QHBoxLayout(parent);
+    mainLayout->addLayout(leftLayout);
+    mainLayout->addLayout(rightLayout);
 
-  setLayout(mainLayout);
+    setLayout(mainLayout);
 }
 
 void SelectDialog::init(QList<Club *> &list)
 {
-  clubList = list;
-
-  QListIterator<Club *> i(clubList);
-  int index = 0;
+    TRACE;
+    clubList = list;
 
-  while (i.hasNext()) {
-    Club *club = i.next();
+    QListIterator<Club *> i(clubList);
+    int index = 0;
+    bool markedFlag = false;
 
-    QList<Course *> courseList = club->getCourseList();
+    while (i.hasNext()) {
+        Club *club = i.next();
 
-    QListIterator<Course *> j(courseList);
-    while (j.hasNext()) {
-      Course *course = j.next();
+        QList<Course *> courseList = club->getCourseList();
 
-      QListWidgetItem *newItem = new QListWidgetItem;
+        QListIterator<Course *> j(courseList);
+        while (j.hasNext()) {
+            Course *course = j.next();
 
-      QString entry = club->getName() + ", " + course->getName();
+            QListWidgetItem *newItem = new QListWidgetItem;
+            
+            QString entry = club->getName() + ", " + course->getName();
 
-      newItem->setText(entry);
-      listClub->insertItem(index, newItem);
+            newItem->setText(entry);
+            listWidgetClub->insertItem(index, newItem);
 
-      index++;
+            if (!markedFlag & club->isHomeClub()) {
+                listWidgetClub->setCurrentRow(index);
+                // Mark the 1st course of the home club the selection
+                markedFlag = true;
+            }
+            index++;
+        }
     }
-  }
 }
 
 void SelectDialog::results(QString &club, 
                           QString &course, 
                           QString &date)
 {  
-  QListWidgetItem *current = listClub->currentItem();
+    QListWidgetItem *current = listWidgetClub->currentItem();
 
-  if (current) {
-    QString tmp = current->text();
+    if (current) {
+        QString tmp = current->text();
 
-    QStringList stringList = tmp.split(", ");
-    club = stringList[0];
-    course = stringList[1];
+        QStringList stringList = tmp.split(", ");
+        club = stringList[0];
+        course = stringList[1];
 #ifdef Q_WS_MAEMO_5
-    QMaemo5DatePickSelector *sel = (QMaemo5DatePickSelector *)dateButton->pickSelector();
-    QDate d = sel->currentDate();
-    // TODO: change to QDate
-    date = d.toString(Qt::ISODate);
+        QMaemo5DatePickSelector *sel = (QMaemo5DatePickSelector *)dateButton->pickSelector();
+        QDate d = sel->currentDate();
+        // TODO: change to QDate
+        date = d.toString(Qt::ISODate);
 #else
-    date = lineEditDate->text();
+        date = lineEditDate->text();
 #endif
-  }
+    }
 }
 
 bool SelectDialog::validate(void)
 {
-  return true;
+    return true;
 }
 
 void SelectDialog::next(void)
 {
-  if (validate())
-    done(1);
-  else {
-    qDebug() << "SelectDialog: invalid data, cancel or correct";
-  }
+    if (validate())
+        done(1);
+    else {
+        qDebug() << "SelectDialog: invalid data, cancel or correct";
+    }
 }
 
 void SelectDialog::reject(void)
 {
-  done(0);
+    done(0);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -329,82 +336,82 @@ void ScoreDialog::init(Course *course, Score *score)
 // Set default score to par if not set
 void ScoreDialog::setDefaultScore(QTableWidget *table)
 {
-  int row = table->currentRow();
-  int col = table->currentColumn();
+    int row = table->currentRow();
+    int col = table->currentColumn();
   
-  if (row == ROW_SCORE)
-    row = ROW_PAR;
-  else if (row == ROW_SCORE_2)
-    row = ROW_PAR_2;
-  else {
-    qDebug() << "ERROR: unknown row in default score";
-    return;
-  }
-  QTableWidgetItem *par = table->item(row, col);
-  QTableWidgetItem *score = table->item(row + 2, col);
-
-  if (par && score && score->text() == "") {
-    QVariant value(par->text());
-    score->setData(Qt::DisplayRole, value);
-  }
+    if (row == ROW_SCORE)
+        row = ROW_PAR;
+    else if (row == ROW_SCORE_2)
+        row = ROW_PAR_2;
+    else {
+        qDebug() << "ERROR: unknown row in default score";
+        return;
+    }
+    QTableWidgetItem *par = table->item(row, col);
+    QTableWidgetItem *score = table->item(row + 2, col);
+
+    if (par && score && score->text() == "") {
+        QVariant value(par->text());
+        score->setData(Qt::DisplayRole, value);
+    }
 }
 
 void ScoreDialog::up(void)
 {
-  QTableWidgetItem *item = table->currentItem();
+    QTableWidgetItem *item = table->currentItem();
 
-  if (!item) {
-    qWarning() << "ERROR: no current item";
-    return;
-  }
+    if (!item) {
+        qWarning() << "ERROR: no current item";
+        return;
+    }
 
-  int i = (item->text()).toInt();
-  QVariant value(i+1);
-  item->setData(Qt::DisplayRole, value);
+    int i = (item->text()).toInt();
+    QVariant value(i+1);
+    item->setData(Qt::DisplayRole, value);
 }
 
 void ScoreDialog::down(void)
 {
-  QTableWidgetItem *item = table->currentItem();
+    QTableWidgetItem *item = table->currentItem();
 
-  if (!item)
-    return;
+    if (!item)
+        return;
 
-  int i = (item->text()).toInt();
-  QVariant value(i-1);
-  item->setData(Qt::DisplayRole, value);
+    int i = (item->text()).toInt();
+    QVariant value(i-1);
+    item->setData(Qt::DisplayRole, value);
 }
 
 void ScoreDialog::next(void)
 {
-  if (table) {
-    QTableWidgetItem *item = table->currentItem();
-    moveToNextCell(item);
-    setDefaultScore(table);
-  }
+    if (table) {
+        QTableWidgetItem *item = table->currentItem();
+        moveToNextCell(item);
+        setDefaultScore(table);
+    }
 }
 
 void ScoreDialog::moveToNextCell(QTableWidgetItem *item)
 {
-  if (!item)
-    return;
+    if (!item)
+        return;
 
-  QTableWidget *table = item->tableWidget();
+    QTableWidget *table = item->tableWidget();
 
-  if (!table)
-    return;
+    if (!table)
+        return;
 
-  int row = table->currentRow();
-  int col = table->currentColumn();
+    int row = table->currentRow();
+    int col = table->currentColumn();
 
-  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);
+    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)
@@ -424,20 +431,20 @@ void ScoreDialog::results(QVector<QString> &scores)
 
 bool ScoreDialog::validate(void)
 {
-  for (int i=0; i<9; i++) {
-    QTableWidgetItem *frontItem = table->item(ROW_SCORE, i);
-    QTableWidgetItem *backItem = table->item(ROW_SCORE_2, i);
+    for (int i=0; i<9; i++) {
+        QTableWidgetItem *frontItem = table->item(ROW_SCORE, i);
+        QTableWidgetItem *backItem = table->item(ROW_SCORE_2, i);
     
-    if (!frontItem || !backItem)
-      return false;
+        if (!frontItem || !backItem)
+            return false;
     
-    QString str1 = frontItem->text();
-    QString str2 = backItem->text();
+        QString str1 = frontItem->text();
+        QString str2 = backItem->text();
     
-    if (str1.isEmpty() || str2.isEmpty())
-      return false;
-  }
-  return true;
+        if (str1.isEmpty() || str2.isEmpty())
+            return false;
+    }
+    return true;
 }
 
 void ScoreDialog::finish(void)
@@ -451,7 +458,7 @@ void ScoreDialog::finish(void)
 
 void ScoreDialog::reject(void)
 {
-  done(0);
+    done(0);
 }
 
 void ScoreDialog::showNote(QString msg)
index 2e35bfb..80a3d67 100644 (file)
@@ -63,7 +63,7 @@ private:
     void createLayout(QWidget *parent = 0);
 
     // Widgets
-    QListWidget  *listClub;
+    QListWidget  *listWidgetClub;
 #ifdef Q_WS_MAEMO_5
     QMaemo5ValueButton *dateButton;
 #else
index 43a0afd..562dd62 100644 (file)
@@ -124,7 +124,12 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
   //
   if (role == Qt::FontRole) {
       QFont font;
-      font.setPointSize(fontSize);
+      if (col == (COLS+1) && row == ROW_SCORE_2) {
+          font.setBold(true);
+          font.setPointSize(fontSize+4);
+      }
+      else 
+          font.setPointSize(fontSize);
       if (row == ROW_HOLE || row == ROW_HOLE_2) {
           font.setBold(true);
       }