1 | /* |
2 | Copyright (C) 2014 by Elvis Angelaccio <elvis.angelaccio@kdemail.net> |
3 | |
4 | This file is part of Kronometer. |
5 | |
6 | Kronometer is free software: you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation, either version 2 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | Kronometer is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with Kronometer. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | |
21 | #ifndef MAINWINDOW_H |
22 | #define MAINWINDOW_H |
23 | |
24 | #include <KXmlGuiWindow> |
25 | |
26 | class KAction; |
27 | class QLabel; |
28 | class QSplitter; |
29 | class QTableView; |
30 | class QSortFilterProxyModel; |
31 | |
32 | class Stopwatch; |
33 | class TimeDisplay; |
34 | class QTextStream; |
35 | class LapModel; |
36 | |
37 | /** |
38 | * @brief Kronometer main window. |
39 | */ |
40 | class MainWindow : public KXmlGuiWindow |
41 | { |
42 | Q_OBJECT |
43 | |
44 | public: |
45 | |
46 | explicit MainWindow(QWidget *parent = nullptr, const QString& file = "" ); |
47 | |
48 | protected: |
49 | |
50 | bool queryClose(); |
51 | |
52 | private slots: |
53 | |
54 | /** |
55 | * Stopwatch running state triggers. |
56 | */ |
57 | void running(); |
58 | |
59 | /** |
60 | * Stopwatch paused state triggers. |
61 | */ |
62 | void paused(); |
63 | |
64 | /** |
65 | * Stopwatch inactive state triggers. |
66 | */ |
67 | void inactive(); |
68 | |
69 | /** |
70 | * Setup the settings dialog. |
71 | */ |
72 | void showSettings(); |
73 | |
74 | /** |
75 | * Write the new settings on filesystem. |
76 | * @param dialogName Ignored argument. |
77 | */ |
78 | void writeSettings(const QString& dialogName); |
79 | |
80 | /** |
81 | * Fix lap dock appereance. |
82 | */ |
83 | void updateLapDock(); |
84 | |
85 | /** |
86 | * Open a new MainWindow instance. |
87 | */ |
88 | void newFile(); |
89 | |
90 | /** |
91 | * Open an existing file in a new MainWindow instance. |
92 | */ |
93 | void openFile(); |
94 | |
95 | /** |
96 | * Save current times on the current file. |
97 | * @returns true if operation was successful |
98 | */ |
99 | bool saveFile(); |
100 | |
101 | /** |
102 | * Save current times on a new file. |
103 | * @returns true if operation was successful |
104 | */ |
105 | bool saveFileAs(); |
106 | |
107 | /** |
108 | * Export current lap times on a file. |
109 | */ |
110 | void exportLapsAs(); |
111 | |
112 | /** |
113 | * Copy current stopwatch time to clipboard. |
114 | */ |
115 | void copyToClipboard(); |
116 | |
117 | private: |
118 | |
119 | Stopwatch *stopwatch; |
120 | TimeDisplay *stopwatchDisplay; |
121 | QSplitter *centralSplitter; |
122 | QTableView *lapView; |
123 | QLabel *statusLabel; |
124 | |
125 | KAction *startAction; |
126 | KAction *pauseAction; |
127 | KAction *resetAction; |
128 | KAction *lapAction; |
129 | KAction *exportAction; |
130 | |
131 | LapModel *lapModel; |
132 | QSortFilterProxyModel *proxyModel; |
133 | |
134 | QString fileName; |
135 | bool unsavedTimes; /** Whether there are unsaved times */ |
136 | |
137 | /** |
138 | * Setup the central widget of the window. |
139 | */ |
140 | void setupCentralWidget(); |
141 | |
142 | /** |
143 | * Setup application status bar. |
144 | */ |
145 | void setupStatusBar(); |
146 | |
147 | /** |
148 | * Setup standard and custom KActions. |
149 | */ |
150 | void setupActions(); |
151 | |
152 | /** |
153 | * Load settings from app Config and apply them to the other objects. |
154 | */ |
155 | void loadSettings(); |
156 | |
157 | /** |
158 | * Set the stopwatch refresh granularity. |
159 | * By default, if all the arguments are false, the stopwatch is refreshed every second. |
160 | * @param tenths Whether to refresh the stopwatch every tenth of second. |
161 | * @param hundredths Whether to refresh the stopwatch every hundredth of second. |
162 | * @param msec Whether to refresh the stopwatch every millisecond. |
163 | */ |
164 | void setupGranularity(bool tenths, bool hundredths, bool msec); |
165 | |
166 | /** |
167 | * Create a file with the current stopwatch time and lap times. |
168 | * @param name The name of the file to be saved. |
169 | * @return true if operation was successful |
170 | */ |
171 | bool saveFileAs(const QString& name); |
172 | |
173 | /** |
174 | * Load the XML save file. If an error occurs, the window is closed. |
175 | * @param name The name of the file with the saved times to be loaded. |
176 | */ |
177 | void openFile(const QString& name); |
178 | |
179 | /** |
180 | * Write the XML save file on the given stream. |
181 | * @param out The stream to be written. |
182 | */ |
183 | void createXmlSaveFile(QTextStream& out); |
184 | |
185 | /** |
186 | * Parse the XML save file from the given DOM document. |
187 | * @param doc The DOM document to be parsed. |
188 | * @return true if doc is a valid Kronometer save file, false otherwise. |
189 | */ |
190 | bool parseXmlSaveFile(const QDomDocument& doc); |
191 | |
192 | /** |
193 | * Export current lap times on a new file. |
194 | * @param name The name of the file to be created. |
195 | * @param mimetype The mimetype of the file to be created. |
196 | */ |
197 | void exportLapsAs(const QString& name, const QString& mimetype); |
198 | |
199 | /** |
200 | * Write the XML laps representation on the given stream. |
201 | * @param out The stream to be written. |
202 | */ |
203 | void exportLapsAsXml(QTextStream& out); |
204 | |
205 | /** |
206 | * Write the CSV laps representation on the given stream. |
207 | * @param out The stream to be written. |
208 | */ |
209 | void exportLapsAsCsv(QTextStream& out); |
210 | |
211 | /** |
212 | * A "comment" message with timestamp, to be used in the created files. |
213 | * @return The string "Created by Kronomer on <timestamp>" |
214 | */ |
215 | QString timestampMessage(); |
216 | |
217 | }; |
218 | |
219 | |
220 | #endif |
221 | |