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); |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 38 | QStringList getRosterList(); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 39 | |
| 40 | signals: |
| 41 | void replot(); |
Zhenkai Zhu | 25e33e5 | 2012-09-28 13:00:07 -0700 | [diff] [blame] | 42 | void rosterChanged(QStringList); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 43 | |
| 44 | private slots: |
| 45 | void emitReplot(); |
| 46 | |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 47 | private: |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 48 | void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize); |
| 49 | void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 50 | void reDrawNode(DisplayUserPtr p, QColor rimColor); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 51 | private: |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 52 | Roster m_roster; |
| 53 | QGraphicsTextItem *m_rootDigest; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 54 | DisplayUserPtr previouslyUpdatedUser; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 55 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 56 | }; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 57 | |
| 58 | class User |
| 59 | { |
| 60 | public: |
| 61 | User():m_received(time(NULL)) {} |
| 62 | User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {} |
| 63 | void setNick(QString nick) {m_nick = nick;} |
| 64 | void setPrefix(QString prefix) {m_prefix = prefix;} |
| 65 | void setChatroom(QString chatroom) {m_chatroom = chatroom;} |
| 66 | void setSeq(Sync::SeqNo seq) {m_seq = seq;} |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 67 | void setReceived(time_t t) {m_received = t;} |
Zhenkai Zhu | e95c64a | 2012-09-27 21:46:44 -0700 | [diff] [blame] | 68 | void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 69 | QString getNick() { return m_nick;} |
| 70 | QString getPrefix() { return m_prefix;} |
| 71 | QString getChatroom() { return m_chatroom;} |
Zhenkai Zhu | e95c64a | 2012-09-27 21:46:44 -0700 | [diff] [blame] | 72 | QString getOriginPrefix() { return m_originPrefix;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 73 | Sync::SeqNo getSeqNo() { return m_seq;} |
| 74 | time_t getReceived() { return m_received;} |
| 75 | private: |
| 76 | QString m_nick; |
| 77 | QString m_prefix; |
| 78 | QString m_chatroom; |
Zhenkai Zhu | e95c64a | 2012-09-27 21:46:44 -0700 | [diff] [blame] | 79 | QString m_originPrefix; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 80 | Sync::SeqNo m_seq; |
| 81 | time_t m_received; |
| 82 | }; |
| 83 | |
| 84 | class DisplayUser : public User |
| 85 | { |
| 86 | public: |
| 87 | DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 88 | DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 89 | QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;} |
| 90 | QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;} |
| 91 | QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;} |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 92 | QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;} |
| 93 | QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 94 | void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;} |
| 95 | void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;} |
| 96 | void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;} |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 97 | void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;} |
| 98 | void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 99 | private: |
| 100 | QGraphicsTextItem *m_seqTextItem; |
| 101 | QGraphicsTextItem *m_nickTextItem; |
| 102 | QGraphicsRectItem *m_rimRectItem; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 103 | QGraphicsRectItem *m_innerRectItem; |
| 104 | QGraphicsRectItem *m_nickRectItem; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 107 | #endif |