|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013, 2014 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #ifndef LDFORGE_MESSAGELOG_H |
|
20 #define LDFORGE_MESSAGELOG_H |
|
21 |
|
22 #include <QObject> |
|
23 #include <QDate> |
|
24 #include "Main.h" |
|
25 #include "Types.h" |
|
26 |
|
27 class GLRenderer; |
|
28 class QTimer; |
|
29 |
|
30 /* The message manager is an object which keeps track of messages that appear |
|
31 * on the renderer's screen. Each line is contained in a separate object which |
|
32 * contains the text, expiry time and alpha. The message manager is doubly |
|
33 * linked to its corresponding renderer. |
|
34 * |
|
35 * Message manager calls its tick() function regularly to update the messages, |
|
36 * where each line's expiry is checked for. Lines begin to fade out when nearing |
|
37 * their expiry. If the message manager's lines change, the renderer undergoes |
|
38 * repainting. |
|
39 */ |
|
40 class MessageManager : public QObject |
|
41 { |
|
42 Q_OBJECT |
|
43 PROPERTY (public, GLRenderer*, Renderer, NO_OPS, STOCK_WRITE) |
|
44 |
|
45 public: |
|
46 // Single line of the message log. |
|
47 class Line |
|
48 { |
|
49 public: |
|
50 Line (QString text); |
|
51 bool update (bool& changed); |
|
52 |
|
53 QString text; |
|
54 float alpha; |
|
55 QDateTime expiry; |
|
56 }; |
|
57 |
|
58 explicit MessageManager (QObject* parent = 0); |
|
59 void addLine (QString line); |
|
60 const QList<Line>& getLines() const; |
|
61 |
|
62 private: |
|
63 QList<Line> m_lines; |
|
64 QTimer* m_ticker; |
|
65 |
|
66 private slots: |
|
67 void tick(); |
|
68 }; |
|
69 |
|
70 #endif // LDFORGE_MESSAGELOG_H |