- Refactor: score and course UI widget management into common files
[scorecard] / src / course-dialog.cpp
index 5abbd7b..9010ef1 100644 (file)
 
 #include "course-dialog.h"
 #include "score-common.h"
+#include "table-model.h"
 
+////////////////////////////////////////////////////////////////////////////////
+// CourseWindow based on QMainWindow
+////////////////////////////////////////////////////////////////////////////////
+CourseWindow::CourseWindow(QWidget *parent) : QMainWindow(parent)
+{
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
+
+    QAction *editAction = new QAction(tr("Edit"), this);
+    connect(editAction, SIGNAL(triggered()), parent, SLOT(editCourse()));
+    menuBar()->addAction(editAction);
+
+    QAction *delAction = new QAction(tr("Delete"), this);
+    connect(delAction, SIGNAL(triggered()), parent, SLOT(deleteCourse()));
+    menuBar()->addAction(delAction);
+
+    model = new CourseTableModel;
+    
+    QTableView * table = new QTableView;
+    table->showGrid();
+    table->setSelectionMode(QAbstractItemView::NoSelection);
+    table->setStyleSheet(ScoreStyle::style());
+    table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+    table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
+    table->horizontalHeader()->hide();
+    table->setModel(model);
+    
+    QWidget *central = new QWidget(this);
+    setCentralWidget(central);
+    
+    QVBoxLayout *layout = new QVBoxLayout;
+    layout->addWidget(table);
+    
+    central->setLayout(layout);
+}
+
+void CourseWindow::setup(Course *course)
+{
+    QString title = QString("Course: %1, Par - %2").arg(course->getName()).arg(course->getTotal(Total));
+    setWindowTitle(title);
+
+    model->set(course);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// CourseSelectDialog based on QDialog
+////////////////////////////////////////////////////////////////////////////////
 CourseSelectDialog::CourseSelectDialog(QWidget *parent) : QDialog(parent)
 {
   QWidget *centralWidget = new QWidget(this);
@@ -79,9 +128,8 @@ void CourseSelectDialog::next(void)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+// CourseDialog based on QDialog
 ////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
 CourseDialog::CourseDialog(QWidget *parent) : QDialog(parent)
 {
   resize(800, 400);