1 /* |
1 /* |
2 * LDForge: LDraw parts authoring CAD |
2 * LDForge: LDraw parts authoring CAD |
3 * Copyright (C) 2013 Santeri Piippo |
3 * Copyright (C) 2013 Santeri Piippo |
4 * |
4 * |
5 * This program is free software: you can redistribute it and/or modify |
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 |
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 |
7 * the Free Software Foundation, either version 3 of the License, or |
8 * (at your option) any later version. |
8 * (at your option) any later version. |
9 * |
9 * |
10 * This program is distributed in the hope that it will be useful, |
10 * This program is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. |
13 * GNU General Public License for more details. |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
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/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
|
19 #include <QTimer> |
|
20 #include <QDate> |
19 #include "messagelog.h" |
21 #include "messagelog.h" |
20 #include "gldraw.h" |
22 #include "gldraw.h" |
21 #include "gui.h" |
23 #include "gui.h" |
22 #include <QTimer> |
24 #include "build/moc_messagelog.cpp" |
23 #include <QDate> |
|
24 |
25 |
25 static const unsigned int g_maxMessages = 5; |
26 static const unsigned int g_maxMessages = 5; |
26 static const int g_expiry = 5; |
27 static const int g_expiry = 5; |
27 static const int g_fadeTime = 500; // msecs |
28 static const int g_fadeTime = 500; // msecs |
28 |
29 |
44 |
45 |
45 // ============================================================================= |
46 // ============================================================================= |
46 // Check this line's expiry and update alpha accordingly. Returns true if the |
47 // Check this line's expiry and update alpha accordingly. Returns true if the |
47 // line is to still stick around, false if it expired. 'changed' is updated to |
48 // line is to still stick around, false if it expired. 'changed' is updated to |
48 // whether the line has somehow changed since the last update. |
49 // whether the line has somehow changed since the last update. |
|
50 // ----------------------------------------------------------------------------- |
49 bool MessageManager::Line::update (bool& changed) { |
51 bool MessageManager::Line::update (bool& changed) { |
50 changed = false; |
52 changed = false; |
51 QDateTime now = QDateTime::currentDateTime(); |
53 QDateTime now = QDateTime::currentDateTime(); |
52 int msec = now.msecsTo (expiry); |
54 int msec = now.msecsTo (expiry); |
53 |
55 |
65 |
67 |
66 return true; |
68 return true; |
67 } |
69 } |
68 |
70 |
69 // ============================================================================= |
71 // ============================================================================= |
|
72 // Add a line to the message manager. |
70 // ----------------------------------------------------------------------------- |
73 // ----------------------------------------------------------------------------- |
71 // Add a line to the message manager. |
|
72 void MessageManager::addLine (str line) { |
74 void MessageManager::addLine (str line) { |
73 // If there's too many entries, pop the excess out |
75 // If there's too many entries, pop the excess out |
74 while (m_lines.size() >= g_maxMessages) |
76 while (m_lines.size() >= g_maxMessages) |
75 m_lines.erase (0); |
77 m_lines.erase (0); |
76 |
78 |
80 if (renderer()) |
82 if (renderer()) |
81 renderer()->update(); |
83 renderer()->update(); |
82 } |
84 } |
83 |
85 |
84 // ============================================================================= |
86 // ============================================================================= |
85 // ----------------------------------------------------------------------------- |
|
86 // Shortcut |
|
87 MessageManager& MessageManager::operator<< (str line) { |
|
88 addLine (line); |
|
89 return *this; |
|
90 } |
|
91 |
|
92 // ============================================================================= |
|
93 // ----------------------------------------------------------------------------- |
|
94 // Ticks the message manager. All lines are ticked and the renderer scene is |
87 // Ticks the message manager. All lines are ticked and the renderer scene is |
95 // redrawn if something changed. |
88 // redrawn if something changed. |
|
89 // ----------------------------------------------------------------------------- |
96 void MessageManager::tick() { |
90 void MessageManager::tick() { |
97 if (m_lines.size() == 0) |
91 if (m_lines.size() == 0) |
98 return; |
92 return; |
99 |
93 |
100 bool changed = false; |
94 bool changed = false; |
112 renderer()->update(); |
106 renderer()->update(); |
113 } |
107 } |
114 |
108 |
115 // ============================================================================= |
109 // ============================================================================= |
116 // ----------------------------------------------------------------------------- |
110 // ----------------------------------------------------------------------------- |
117 // C++11-for loop support |
111 const List<MessageManager::Line>& MessageManager::getLines() const { |
118 MessageManager::c_it MessageManager::begin() const { |
112 return m_lines; |
119 return m_lines.begin(); |
|
120 } |
113 } |
121 |
114 |
122 // ============================================================================= |
115 // ============================================================================= |
123 // ----------------------------------------------------------------------------- |
|
124 MessageManager::c_it MessageManager::end() const { |
|
125 return m_lines.end(); |
|
126 } |
|
127 |
|
128 // ============================================================================= |
|
129 // ----------------------------------------------------------------------------- |
|
130 // log() interface - format the argument list and add the resulting string to |
116 // log() interface - format the argument list and add the resulting string to |
131 // the main message manager. |
117 // the main message manager. |
|
118 // ----------------------------------------------------------------------------- |
132 void DoLog (std::initializer_list<StringFormatArg> args) { |
119 void DoLog (std::initializer_list<StringFormatArg> args) { |
133 const str msg = DoFormat (args); |
120 const str msg = DoFormat (args); |
134 g_win->addMessage (msg); |
121 g_win->addMessage (msg); |
135 |
122 |
136 // Also print it to stdout |
123 // Also print it to stdout |
137 print ("%1\n", msg); |
124 print ("%1\n", msg); |
138 } |
125 } |
139 |
|
140 #include "build/moc_messagelog.cpp" |
|