b4ff9657c7bb4802d9fcb308d450d0794a5b61f0
[scorecard] / src / main-window.h
1 /*
2  * Copyright (C) 2009 Sakari Poussa
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 2.
7  */
8
9 #include <QMainWindow>
10 #include <QTableView>
11 #include <QListView>
12 #include <QPushButton>
13 #include <QTextEdit>
14 #include <QVBoxLayout>
15 #include <QItemSelectionModel>
16 #include <QList>
17 #include <QLabel>
18 #include <QActionGroup>
19 #include <QXmlDefaultHandler>
20 #include <QSettings>
21
22 #include "data.h"
23 #include "score-common.h"
24 #include "score-dialog.h"
25 #include "course-dialog.h"
26 #include "table-model.h"
27 #include "list-model.h"
28
29 class MainWindow : public QMainWindow
30 {
31   Q_OBJECT
32
33 public:
34   MainWindow(QMainWindow *parent = 0);
35   void createLayoutTable(QWidget *parent = 0);
36   void createLayoutList(QWidget *parent = 0);
37   void createListView(QList<Score *> &, QList <Club *> &);
38   void updateTitleBar(QString & msg);
39   void loadScoreFile(QString &fileName, QList<Score *> &scoreList);
40   void loadClubFile(QString &fileName, QList<Club *> &clubList, bool readOnly = false);
41   void saveScoreFile(QString &fileName, QList<Score *> &scoreList);
42   void saveClubFile(QString &fileName, QList<Club *> &clubList);
43
44 signals:
45   void dataChanged();
46
47 private slots:
48   void clickedList(const QModelIndex &index);
49
50   void newScore();
51   void deleteScore();
52   void editScore();
53   void newCourse();
54   void deleteCourse();
55   void editCourse();
56   void viewStatistics();
57   void viewSettings();
58   void listScores();
59   void listCourses();
60
61 private:
62
63   void loadSettings(void);
64   void saveSettings(void);
65   Club * findClub(QString &name);
66   Course * findCourse(const QString &clubName, const QString &courseName);
67   Course * currentCourse();
68   Score * currentScore();
69   Score * findScore(QString & clubName, QString & courseName);
70   void flushReadOnlyItems();
71                                
72   void showNote(QString msg);
73   void getStat(QTextEdit *);
74
75   void viewScore(Score * score, Course * course);
76   void viewCourse(Course * course);
77
78   QList<Score *> scoreList;
79   QList<Club *> clubList;
80
81   ScoreTableModel *scoreTableModel;
82   ScoreListModel *scoreListModel;
83   CourseListModel *courseListModel;
84
85   QItemSelectionModel *selectionModel;
86
87   QListView *list;
88
89   // Layouts
90   QWidget *centralWidget;
91
92   // Menus
93   QMenu *menu;
94
95   // Settings
96   QSettings settings;
97   AppSettings conf;
98
99   // Actions
100   QAction *newScoreAction;
101   QAction *newCourseAction;
102   QAction *statAction;
103   QAction *settingsAction;
104
105   QActionGroup *filterGroup;
106   QAction *listScoreAction;
107   QAction *listCourseAction;
108
109   void createMenus();
110   void createActions();
111
112   // Windows
113   ScoreWindow *scoreWindow;
114   CourseWindow *courseWindow;
115 };