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