bd3965922ada8ee4b6fc275eea7b1b462ad7ce10
[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   void markHomeClub();
72                                
73   void showNote(QString msg);
74   void getStat(QTextEdit *);
75
76   void viewScore(Score * score, Course * course);
77   void viewCourse(Course * course);
78
79   QList<Score *> scoreList;
80   QList<Club *> clubList;
81
82   ScoreTableModel *scoreTableModel;
83   ScoreListModel *scoreListModel;
84   CourseListModel *courseListModel;
85
86   QItemSelectionModel *selectionModel;
87
88   QListView *list;
89
90   // Layouts
91   QWidget *centralWidget;
92
93   // Menus
94   QMenu *menu;
95
96   // Settings
97   QSettings settings;
98   AppSettings conf;
99
100   // Actions
101   QAction *newScoreAction;
102   QAction *newCourseAction;
103   QAction *statAction;
104   QAction *settingsAction;
105
106   QActionGroup *filterGroup;
107   QAction *listScoreAction;
108   QAction *listCourseAction;
109
110   void createMenus();
111   void createActions();
112
113   // Windows
114   ScoreWindow *scoreWindow;
115   CourseWindow *courseWindow;
116 };