blob: 0e6952826ae66de9fd6a77b9f77aa802db2b194c [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
Yingdi Yueb692ac2015-02-10 18:46:18 -080012#ifndef CHRONOCHAT_DIGEST_TREE_SCENE_HPP
13#define CHRONOCHAT_DIGEST_TREE_SCENE_HPP
Yingdi Yu0b0a7362014-08-05 16:31:30 -070014
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"
Yingdi Yu0b0a7362014-08-05 16:31:30 -070022#include <ctime>
23#include <vector>
Yingdi Yu0b0a7362014-08-05 16:31:30 -070024#endif
25
26const int FRESHNESS = 60;
27
28class QGraphicsTextItem;
29
Yingdi Yueb692ac2015-02-10 18:46:18 -080030namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070031
32class User;
33class DisplayUser;
Yingdi Yu1cc45d92015-02-09 14:19:54 -080034typedef std::shared_ptr<DisplayUser> DisplayUserPtr;
Mengjin Yanaec70742014-08-25 10:37:45 -070035typedef QMap<QString, DisplayUserPtr> Roster;
36typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
37typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
38
Yingdi Yu0b0a7362014-08-05 16:31:30 -070039static DisplayUserPtr DisplayUserNullPtr;
40
Mengjin Yanaec70742014-08-25 10:37:45 -070041
Yingdi Yu0b0a7362014-08-05 16:31:30 -070042class DigestTreeScene : public QGraphicsScene
43{
44 Q_OBJECT
45
Yingdi Yu0b0a7362014-08-05 16:31:30 -070046public:
47 DigestTreeScene(QWidget *parent = 0);
48
49 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080050 processSyncUpdate(const std::vector<chronochat::NodeInfo>& nodeInfos,
Yingdi Yud45777b2014-10-16 23:54:11 -070051 const QString& digest);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070052
53 void
Qiuhan Ding7a4e7ef2015-02-03 20:25:50 -080054 updateNode(QString sessionPrefix, QString nick, uint64_t seqNo);
55
56 void
Yingdi Yud45777b2014-10-16 23:54:11 -070057 updateNick(QString sessionPrefix, QString nick);
58
59 void
60 messageReceived(QString sessionPrefix);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070061
62 void
63 clearAll();
64
Yingdi Yu0b0a7362014-08-05 16:31:30 -070065 void
Yingdi Yud45777b2014-10-16 23:54:11 -070066 removeNode(const QString sessionPrefix);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070067
68 QStringList
69 getRosterList();
70
Yingdi Yud45777b2014-10-16 23:54:11 -070071 QStringList
72 getRosterPrefixList();
Yingdi Yu0b0a7362014-08-05 16:31:30 -070073
74 void
Yingdi Yud45777b2014-10-16 23:54:11 -070075 plot(QString rootDigest);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070076
77private:
78 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080079 plotEdge(const std::vector<chronochat::TreeLayout::Coordinate>& v, int nodeSize);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070080
81 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080082 plotNode(const std::vector<chronochat::TreeLayout::Coordinate>& v, QString digest, int nodeSize);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070083
84 void
85 reDrawNode(DisplayUserPtr p, QColor rimColor);
86
Yingdi Yu0b0a7362014-08-05 16:31:30 -070087private:
88 Roster m_roster;
Yingdi Yud45777b2014-10-16 23:54:11 -070089
90 QString m_rootDigest;
91 QGraphicsTextItem* m_displayRootDigest;
92
93 DisplayUserPtr m_previouslyUpdatedUser;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070094};
95
96class User
97{
98public:
99 User()
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700100 {
101 }
102
Yingdi Yud45777b2014-10-16 23:54:11 -0700103 User(QString n, QString p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700104 : m_nick(n)
105 , m_prefix(p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700106 {
107 }
108
109 void
110 setNick(QString nick)
111 {
112 m_nick = nick;
113 }
114
115 void
116 setPrefix(QString prefix)
117 {
118 m_prefix = prefix;
119 }
120
121 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700122 setSeq(chronosync::SeqNo seq)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700123 {
124 m_seq = seq;
125 }
126
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700127 QString
128 getNick()
129 {
130 return m_nick;
131 }
132
133 QString getPrefix()
134 {
135 return m_prefix;
136 }
137
Yingdi Yud45777b2014-10-16 23:54:11 -0700138 chronosync::SeqNo
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700139 getSeqNo()
140 {
141 return m_seq;
142 }
143
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700144private:
145 QString m_nick;
146 QString m_prefix;
Yingdi Yud45777b2014-10-16 23:54:11 -0700147 chronosync::SeqNo m_seq;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700148};
149
150class DisplayUser : public User
151{
152public:
153 DisplayUser()
154 : m_seqTextItem(NULL)
155 , m_nickTextItem(NULL)
156 , m_rimRectItem(NULL)
157 {
158 }
159
Yingdi Yud45777b2014-10-16 23:54:11 -0700160 DisplayUser(QString n, QString p)
161 : User(n, p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700162 , m_seqTextItem(NULL)
163 , m_nickTextItem(NULL)
164 , m_rimRectItem(NULL)
165 {
166 }
167
168 QGraphicsTextItem*
169 getSeqTextItem()
170 {
171 return m_seqTextItem;
172 }
173
174 QGraphicsTextItem*
175 getNickTextItem()
176 {
177 return m_nickTextItem;
178 }
179
180 QGraphicsRectItem*
181 getRimRectItem()
182 {
183 return m_rimRectItem;
184 }
185
186 QGraphicsRectItem*
187 getInnerRectItem()
188 {
189 return m_innerRectItem;
190 }
191
192 QGraphicsRectItem*
193 getNickRectItem()
194 {
195 return m_nickRectItem;
196 }
197
198 void
199 setSeqTextItem(QGraphicsTextItem* item)
200 {
201 m_seqTextItem = item;
202 }
203
204 void
205 setNickTextItem(QGraphicsTextItem* item)
206 {
207 m_nickTextItem = item;
208 }
209
210 void
211 setRimRectItem(QGraphicsRectItem* item)
212 {
213 m_rimRectItem = item;
214 }
215
216 void
217 setInnerRectItem(QGraphicsRectItem* item)
218 {
219 m_innerRectItem = item;
220 }
221
222 void
223 setNickRectItem(QGraphicsRectItem* item)
224 {
225 m_nickRectItem = item;
226 }
227
228private:
229 QGraphicsTextItem* m_seqTextItem;
230 QGraphicsTextItem* m_nickTextItem;
231 QGraphicsRectItem* m_rimRectItem;
232 QGraphicsRectItem* m_innerRectItem;
233 QGraphicsRectItem* m_nickRectItem;
234};
235
Yingdi Yueb692ac2015-02-10 18:46:18 -0800236} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700237
Yingdi Yueb692ac2015-02-10 18:46:18 -0800238#endif // CHRONOCHAT_DIGEST_TREE_SCENE_HPP