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 | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame^] | 42 | void rosterChanged(); |
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 | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 68 | QString getNick() { return m_nick;} |
| 69 | QString getPrefix() { return m_prefix;} |
| 70 | QString getChatroom() { return m_chatroom;} |
| 71 | Sync::SeqNo getSeqNo() { return m_seq;} |
| 72 | time_t getReceived() { return m_received;} |
| 73 | private: |
| 74 | QString m_nick; |
| 75 | QString m_prefix; |
| 76 | QString m_chatroom; |
| 77 | Sync::SeqNo m_seq; |
| 78 | time_t m_received; |
| 79 | }; |
| 80 | |
| 81 | class DisplayUser : public User |
| 82 | { |
| 83 | public: |
| 84 | DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 85 | DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 86 | QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;} |
| 87 | QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;} |
| 88 | QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;} |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 89 | QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;} |
| 90 | QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 91 | void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;} |
| 92 | void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;} |
| 93 | void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;} |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 94 | void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;} |
| 95 | void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;} |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 96 | private: |
| 97 | QGraphicsTextItem *m_seqTextItem; |
| 98 | QGraphicsTextItem *m_nickTextItem; |
| 99 | QGraphicsRectItem *m_rimRectItem; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 100 | QGraphicsRectItem *m_innerRectItem; |
| 101 | QGraphicsRectItem *m_nickRectItem; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 104 | #endif |