src/messageLog.h

changeset 794
c254ddc6618b
parent 789
4b7306f52bb5
child 844
11587d419d2f
equal deleted inserted replaced
793:ceb1b1aaf7db 794:c254ddc6618b
23 #include "basics.h" 23 #include "basics.h"
24 24
25 class GLRenderer; 25 class GLRenderer;
26 class QTimer; 26 class QTimer;
27 27
28 //! 28 //
29 //! \brief Manages the list of messages at the top-left of the renderer. 29 // The message manager is an object which keeps track of messages that appear
30 //! 30 // on the renderer's screen. Each line is contained in a separate object which
31 //! The message manager is an object which keeps track of messages that appear 31 // contains the text, expiry time and alpha. The message manager is doubly
32 //! on the renderer's screen. Each line is contained in a separate object which 32 // linked to its corresponding renderer.
33 //! contains the text, expiry time and alpha. The message manager is doubly 33 //
34 //! linked to its corresponding renderer. 34 // Message manager calls its tick() function regularly to update the messages,
35 //! 35 // where each line's expiry is checked for. Lines begin to fade out when nearing
36 //! Message manager calls its \c tick() function regularly to update the messages, 36 // their expiry. If the message manager's lines change, the renderer undergoes
37 //! where each line's expiry is checked for. Lines begin to fade out when nearing 37 // repainting.
38 //! their expiry. If the message manager's lines change, the renderer undergoes 38 //
39 //! repainting.
40 //!
41 class MessageManager : public QObject 39 class MessageManager : public QObject
42 { 40 {
43 Q_OBJECT 41 Q_OBJECT
44 PROPERTY (public, GLRenderer*, renderer, setRenderer, STOCK_WRITE) 42 PROPERTY (public, GLRenderer*, renderer, setRenderer, STOCK_WRITE)
45 43
46 public: 44 public:
47 //! \class MessageManager::Line 45 // A single line of the message log.
48 //! A single line of the message log. 46 class Line
49 class Line 47 {
50 { 48 public:
51 public: 49 // Constructs a line with the given \c text
52 //! Constructs a line with the given \c text 50 Line (QString text);
53 Line (QString text);
54 51
55 //! Check this line's expiry and update alpha accordingly. 52 // Check this line's expiry and update alpha accordingly. @changed
56 //! \c changed is updated to whether the line has somehow 53 // is updated to whether the line has somehow changed since the
57 //! changed since the last update. 54 // last update.
58 //! \returns true if the line is to still stick around, false 55 //
59 //! \returns if it expired. 56 // Returns true if the line is to still stick around, false if it
60 bool update (bool& changed); 57 // expired.
58 bool update (bool& changed);
61 59
62 QString text; 60 QString text;
63 float alpha; 61 float alpha;
64 QDateTime expiry; 62 QDateTime expiry;
65 }; 63 };
66 64
67 //! Constructs the message manager. 65 // Constructs the message manager.
68 explicit MessageManager (QObject* parent = null); 66 explicit MessageManager (QObject* parent = null);
69 67
70 //! Adds a line with the given \c text to the message manager. 68 // Adds a line with the given \c text to the message manager.
71 void addLine (QString line); 69 void addLine (QString line);
72 70
73 //! \returns all active lines in the message manager. 71 // Returns all active lines in the message manager.
74 const QList<Line>& getLines() const; 72 const QList<Line>& getLines() const;
75 73
76 private: 74 private:
77 QList<Line> m_lines; 75 QList<Line> m_lines;
78 QTimer* m_ticker; 76 QTimer* m_ticker;
79 77
80 private slots: 78 private slots:
81 //! Ticks the manager. This is called by the timer to update 79 void tick();
82 //! the messages.
83 void tick();
84 }; 80 };

mercurial