Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 1 | #ifndef DIGESTTREESCENE_H |
| 2 | #define DIGESTTREESCENE_H |
| 3 | |
| 4 | #include <QtGui/QGraphicsScene> |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 5 | #include <sync-seq-no.h> |
| 6 | #include <sync-logic.h> |
| 7 | #include <ctime> |
| 8 | #include <QMap> |
| 9 | #include <vector> |
| 10 | #include <tr1/memory> |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 11 | #include <QColor> |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 12 | #include "treelayout.h" |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 13 | |
| 14 | class QGraphicsTextItem; |
| 15 | |
| 16 | class User; |
| 17 | class DisplayUser; |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 18 | |
| 19 | class DigestTreeScene : public QGraphicsScene |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 23 | typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr; |
| 24 | typedef QMap<QString, DisplayUserPtr> Roster; |
| 25 | typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator; |
| 26 | typedef QMapIterator<QString, DisplayUserPtr> RosterIterator; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 27 | static DisplayUserPtr DisplayUserNullPtr; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 28 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 29 | public: |
| 30 | DigestTreeScene(QWidget *parent = 0); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 31 | void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 32 | void msgReceived(QString prefix, QString nick); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 33 | void clearAll(); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 34 | void plot(QString digest); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 35 | private: |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 36 | void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize); |
| 37 | void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 38 | void reDrawNode(DisplayUserPtr p, QColor rimColor); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 39 | private: |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 40 | Roster m_roster; |
| 41 | QGraphicsTextItem *m_rootDigest; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 42 | DisplayUserPtr previouslyUpdatedUser; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 43 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 44 | }; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 45 | |
| 46 | class User |
| 47 | { |
| 48 | public: |
| 49 | User():m_received(time(NULL)) {} |
| 50 | User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {} |
| 51 | void setNick(QString nick) {m_nick = nick;} |
| 52 | void setPrefix(QString prefix) {m_prefix = prefix;} |
| 53 | void setChatroom(QString chatroom) {m_chatroom = chatroom;} |
| 54 | void setSeq(Sync::SeqNo seq) {m_seq = seq;} |
| 55 | void setReceived() {m_received = time(NULL);} |
| 56 | QString getNick() { return m_nick;} |
| 57 | QString getPrefix() { return m_prefix;} |
| 58 | QString getChatroom() { return m_chatroom;} |
| 59 | Sync::SeqNo getSeqNo() { return m_seq;} |
| 60 | time_t getReceived() { return m_received;} |
| 61 | private: |
| 62 | QString m_nick; |
| 63 | QString m_prefix; |
| 64 | QString m_chatroom; |
| 65 | Sync::SeqNo m_seq; |
| 66 | time_t m_received; |
| 67 | }; |
| 68 | |
| 69 | class DisplayUser : public User |
| 70 | { |
| 71 | public: |
| 72 | DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 73 | DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 74 | QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;} |
| 75 | QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;} |
| 76 | QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;} |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 77 | QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;} |
| 78 | QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 79 | void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;} |
| 80 | void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;} |
| 81 | void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;} |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 82 | void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;} |
| 83 | void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 84 | private: |
| 85 | QGraphicsTextItem *m_seqTextItem; |
| 86 | QGraphicsTextItem *m_nickTextItem; |
| 87 | QGraphicsRectItem *m_rimRectItem; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 88 | QGraphicsRectItem *m_innerRectItem; |
| 89 | QGraphicsRectItem *m_nickRectItem; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 92 | #endif |