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