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