blob: 51847dc87eedf799cca07628d246cd66b0d6d5ff [file] [log] [blame]
Yingdi Yu0b0a7362014-08-05 16:31:30 -07001/* -*- 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
12#ifndef CHRONOS_DIGEST_TREE_SCENE_HPP
13#define CHRONOS_DIGEST_TREE_SCENE_HPP
14
15#include <QtGui/QGraphicsScene>
16#include <QColor>
17#include <QMap>
18
19#ifndef Q_MOC_RUN
20#include "tree-layout.hpp"
Yingdi Yud45777b2014-10-16 23:54:11 -070021#include "chat-dialog-backend.hpp"
22#include <Leaf.hpp>
Yingdi Yu0b0a7362014-08-05 16:31:30 -070023#include <ctime>
24#include <vector>
25#include <boost/shared_ptr.hpp>
26#endif
27
28const int FRESHNESS = 60;
29
30class QGraphicsTextItem;
31
32namespace chronos {
33
34class User;
35class DisplayUser;
36typedef boost::shared_ptr<DisplayUser> DisplayUserPtr;
Mengjin Yanaec70742014-08-25 10:37:45 -070037typedef QMap<QString, DisplayUserPtr> Roster;
38typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
39typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
40
Yingdi Yu0b0a7362014-08-05 16:31:30 -070041static DisplayUserPtr DisplayUserNullPtr;
42
Mengjin Yanaec70742014-08-25 10:37:45 -070043
Yingdi Yu0b0a7362014-08-05 16:31:30 -070044class DigestTreeScene : public QGraphicsScene
45{
46 Q_OBJECT
47
Yingdi Yu0b0a7362014-08-05 16:31:30 -070048public:
49 DigestTreeScene(QWidget *parent = 0);
50
51 void
Yingdi Yud45777b2014-10-16 23:54:11 -070052 processSyncUpdate(const std::vector<chronos::NodeInfo>& nodeInfos,
53 const QString& digest);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070054
55 void
Yingdi Yud45777b2014-10-16 23:54:11 -070056 updateNick(QString sessionPrefix, QString nick);
57
58 void
59 messageReceived(QString sessionPrefix);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070060
61 void
62 clearAll();
63
Yingdi Yu0b0a7362014-08-05 16:31:30 -070064 void
Yingdi Yud45777b2014-10-16 23:54:11 -070065 removeNode(const QString sessionPrefix);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070066
67 QStringList
68 getRosterList();
69
Yingdi Yud45777b2014-10-16 23:54:11 -070070 QStringList
71 getRosterPrefixList();
Yingdi Yu0b0a7362014-08-05 16:31:30 -070072
73 void
Yingdi Yud45777b2014-10-16 23:54:11 -070074 plot(QString rootDigest);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070075
76private:
77 void
78 plotEdge(const std::vector<chronos::TreeLayout::Coordinate>& v, int nodeSize);
79
80 void
81 plotNode(const std::vector<chronos::TreeLayout::Coordinate>& v, QString digest, int nodeSize);
82
83 void
84 reDrawNode(DisplayUserPtr p, QColor rimColor);
85
Yingdi Yu0b0a7362014-08-05 16:31:30 -070086private:
87 Roster m_roster;
Yingdi Yud45777b2014-10-16 23:54:11 -070088
89 QString m_rootDigest;
90 QGraphicsTextItem* m_displayRootDigest;
91
92 DisplayUserPtr m_previouslyUpdatedUser;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070093};
94
95class User
96{
97public:
98 User()
Yingdi Yu0b0a7362014-08-05 16:31:30 -070099 {
100 }
101
Yingdi Yud45777b2014-10-16 23:54:11 -0700102 User(QString n, QString p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700103 : m_nick(n)
104 , m_prefix(p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700105 {
106 }
107
108 void
109 setNick(QString nick)
110 {
111 m_nick = nick;
112 }
113
114 void
115 setPrefix(QString prefix)
116 {
117 m_prefix = prefix;
118 }
119
120 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700121 setSeq(chronosync::SeqNo seq)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700122 {
123 m_seq = seq;
124 }
125
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700126 QString
127 getNick()
128 {
129 return m_nick;
130 }
131
132 QString getPrefix()
133 {
134 return m_prefix;
135 }
136
Yingdi Yud45777b2014-10-16 23:54:11 -0700137 chronosync::SeqNo
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700138 getSeqNo()
139 {
140 return m_seq;
141 }
142
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700143private:
144 QString m_nick;
145 QString m_prefix;
Yingdi Yud45777b2014-10-16 23:54:11 -0700146 chronosync::SeqNo m_seq;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700147};
148
149class DisplayUser : public User
150{
151public:
152 DisplayUser()
153 : m_seqTextItem(NULL)
154 , m_nickTextItem(NULL)
155 , m_rimRectItem(NULL)
156 {
157 }
158
Yingdi Yud45777b2014-10-16 23:54:11 -0700159 DisplayUser(QString n, QString p)
160 : User(n, p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700161 , m_seqTextItem(NULL)
162 , m_nickTextItem(NULL)
163 , m_rimRectItem(NULL)
164 {
165 }
166
167 QGraphicsTextItem*
168 getSeqTextItem()
169 {
170 return m_seqTextItem;
171 }
172
173 QGraphicsTextItem*
174 getNickTextItem()
175 {
176 return m_nickTextItem;
177 }
178
179 QGraphicsRectItem*
180 getRimRectItem()
181 {
182 return m_rimRectItem;
183 }
184
185 QGraphicsRectItem*
186 getInnerRectItem()
187 {
188 return m_innerRectItem;
189 }
190
191 QGraphicsRectItem*
192 getNickRectItem()
193 {
194 return m_nickRectItem;
195 }
196
197 void
198 setSeqTextItem(QGraphicsTextItem* item)
199 {
200 m_seqTextItem = item;
201 }
202
203 void
204 setNickTextItem(QGraphicsTextItem* item)
205 {
206 m_nickTextItem = item;
207 }
208
209 void
210 setRimRectItem(QGraphicsRectItem* item)
211 {
212 m_rimRectItem = item;
213 }
214
215 void
216 setInnerRectItem(QGraphicsRectItem* item)
217 {
218 m_innerRectItem = item;
219 }
220
221 void
222 setNickRectItem(QGraphicsRectItem* item)
223 {
224 m_nickRectItem = item;
225 }
226
227private:
228 QGraphicsTextItem* m_seqTextItem;
229 QGraphicsTextItem* m_nickTextItem;
230 QGraphicsRectItem* m_rimRectItem;
231 QGraphicsRectItem* m_innerRectItem;
232 QGraphicsRectItem* m_nickRectItem;
233};
234
235} // namespace chronos
236
237#endif // CHRONOS_DIGEST_TREE_SCENE_HPP