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