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