1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 - 2018 Teemu 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 #pragma once |
|
20 #include <QObject> |
|
21 #include <QDate> |
|
22 #include "main.h" |
|
23 #include "basics.h" |
|
24 |
|
25 class GLRenderer; |
|
26 class QTimer; |
|
27 |
|
28 // |
|
29 // The message manager is an object which keeps track of messages that appear |
|
30 // on the renderer's screen. Each line is contained in a separate object which |
|
31 // contains the text, expiry time and alpha. The message manager is doubly |
|
32 // linked to its corresponding renderer. |
|
33 // |
|
34 // Message manager calls its tick() function regularly to update the messages, |
|
35 // where each line's expiry is checked for. Lines begin to fade out when nearing |
|
36 // their expiry. If the message manager's lines change, the renderer undergoes |
|
37 // repainting. |
|
38 // |
|
39 class MessageManager : public QObject |
|
40 { |
|
41 Q_OBJECT |
|
42 |
|
43 public: |
|
44 // A single line of the message log. |
|
45 class Line |
|
46 { |
|
47 public: |
|
48 // Constructs a line with the given \c text |
|
49 Line (QString text); |
|
50 |
|
51 // Check this line's expiry and update alpha accordingly. @changed |
|
52 // is updated to whether the line has somehow changed since the |
|
53 // last update. |
|
54 // |
|
55 // Returns true if the line is to still stick around, false if it |
|
56 // expired. |
|
57 bool update (bool& changed); |
|
58 |
|
59 QString text; |
|
60 float alpha; |
|
61 QDateTime expiry; |
|
62 }; |
|
63 |
|
64 // Constructs the message manager. |
|
65 explicit MessageManager(QObject* parent = nullptr); |
|
66 |
|
67 // Adds a line with the given \c text to the message manager. |
|
68 void addLine (QString line); |
|
69 |
|
70 // Returns all active lines in the message manager. |
|
71 const QList<Line>& getLines() const; |
|
72 |
|
73 signals: |
|
74 void changed(); |
|
75 |
|
76 private: |
|
77 QList<Line> m_lines; |
|
78 QTimer* m_ticker; |
|
79 |
|
80 private slots: |
|
81 void tick(); |
|
82 }; |
|