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