29 FadeTime = 500 |
29 FadeTime = 500 |
30 }; |
30 }; |
31 |
31 |
32 // ------------------------------------------------------------------------------------------------- |
32 // ------------------------------------------------------------------------------------------------- |
33 // |
33 // |
34 MessageManager::MessageManager (QObject* parent) : |
34 MessageManager::MessageManager(QObject* parent) : |
35 QObject (parent) |
35 QObject(parent) |
36 { |
36 { |
37 m_ticker = new QTimer; |
37 m_ticker = new QTimer; |
38 m_ticker->start (100); |
38 m_ticker->start(100); |
39 connect (m_ticker, SIGNAL (timeout()), this, SLOT (tick())); |
39 connect(m_ticker, SIGNAL(timeout()), this, SLOT(tick())); |
40 } |
40 } |
41 |
41 |
42 // ------------------------------------------------------------------------------------------------- |
42 // ------------------------------------------------------------------------------------------------- |
43 // |
43 // |
44 MessageManager::Line::Line (QString text) : |
44 MessageManager::Line::Line(QString text) : |
45 text (text), |
45 text(text), |
46 alpha (1.0f), |
46 alpha(1.0f), |
47 expiry (QDateTime::currentDateTime().addMSecs (ExpireTime)) {} |
47 expiry(QDateTime::currentDateTime().addMSecs(ExpireTime)) {} |
48 |
48 |
49 // ------------------------------------------------------------------------------------------------- |
49 // ------------------------------------------------------------------------------------------------- |
50 // |
50 // |
51 bool MessageManager::Line::update (bool& changed) |
51 bool MessageManager::Line::update(bool& changed) |
52 { |
52 { |
53 changed = false; |
53 changed = false; |
54 QDateTime now = QDateTime::currentDateTime(); |
54 QDateTime now = QDateTime::currentDateTime(); |
55 int msec = now.msecsTo (expiry); |
55 int msec = now.msecsTo(expiry); |
56 |
56 |
57 if (now >= expiry) |
57 if (now >= expiry) |
58 { |
58 { |
59 // Message line has expired |
59 // Message line has expired |
60 changed = true; |
60 changed = true; |
62 } |
62 } |
63 |
63 |
64 if (msec <= FadeTime) |
64 if (msec <= FadeTime) |
65 { |
65 { |
66 // Message line has not expired but is fading out |
66 // Message line has not expired but is fading out |
67 alpha = ( (float) msec) / FadeTime; |
67 alpha = ((float) msec) / FadeTime; |
68 changed = true; |
68 changed = true; |
69 } |
69 } |
70 |
70 |
71 return true; |
71 return true; |
72 } |
72 } |
73 |
73 |
74 // ------------------------------------------------------------------------------------------------- |
74 // ------------------------------------------------------------------------------------------------- |
75 // |
75 // |
76 // Add a line to the message manager. |
76 // Add a line to the message manager. |
77 // |
77 // |
78 void MessageManager::addLine (QString line) |
78 void MessageManager::addLine(QString line) |
79 { |
79 { |
80 // If there's too many entries, pop the excess out |
80 // If there's too many entries, pop the excess out |
81 while (m_lines.size() >= MaxMessages) |
81 while (m_lines.size() >= MaxMessages) |
82 m_lines.removeFirst(); |
82 m_lines.removeFirst(); |
83 |
83 |
84 m_lines << Line (line); |
84 m_lines << Line(line); |
85 |
85 |
86 // Update the renderer view |
86 // Update the renderer view |
87 if (renderer()) |
87 if (renderer()) |
88 renderer()->update(); |
88 renderer()->update(); |
89 } |
89 } |
124 GLRenderer* MessageManager::renderer() const |
124 GLRenderer* MessageManager::renderer() const |
125 { |
125 { |
126 return m_renderer; |
126 return m_renderer; |
127 } |
127 } |
128 |
128 |
129 void MessageManager::setRenderer (GLRenderer* renderer) |
129 void MessageManager::setRenderer(GLRenderer* renderer) |
130 { |
130 { |
131 m_renderer = renderer; |
131 m_renderer = renderer; |
132 } |
132 } |
133 |
133 |
134 // ============================================================================= |
134 // ============================================================================= |
135 // |
135 // |
136 void printToLog (const QString& msg) |
136 void printToLog(const QString& msg) |
137 { |
137 { |
138 for (QString& a : msg.split ("\n", QString::SkipEmptyParts)) |
138 for (QString& a : msg.split("\n", QString::SkipEmptyParts)) |
139 { |
139 { |
140 if (g_win) |
140 if (g_win) |
141 g_win->addMessage (a); |
141 g_win->addMessage(a); |
142 |
142 |
143 // Also print it to stdout |
143 // Also print it to stdout |
144 fprint (stdout, "%1\n", a); |
144 fprint(stdout, "%1\n", a); |
145 } |
145 } |
146 } |
146 } |