blob: 3720d4b791fb4e665df0c90c2fa58676388d965e [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
Yingdi Yud45777b2014-10-16 23:54:11 -070054 updateNick(QString sessionPrefix, QString nick);
55
56 void
57 messageReceived(QString sessionPrefix);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070058
59 void
60 clearAll();
61
Yingdi Yu0b0a7362014-08-05 16:31:30 -070062 void
Yingdi Yud45777b2014-10-16 23:54:11 -070063 removeNode(const QString sessionPrefix);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070064
65 QStringList
66 getRosterList();
67
Yingdi Yud45777b2014-10-16 23:54:11 -070068 QStringList
69 getRosterPrefixList();
Yingdi Yu0b0a7362014-08-05 16:31:30 -070070
71 void
Yingdi Yud45777b2014-10-16 23:54:11 -070072 plot(QString rootDigest);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070073
74private:
75 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080076 plotEdge(const std::vector<chronochat::TreeLayout::Coordinate>& v, int nodeSize);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070077
78 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080079 plotNode(const std::vector<chronochat::TreeLayout::Coordinate>& v, QString digest, int nodeSize);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070080
81 void
82 reDrawNode(DisplayUserPtr p, QColor rimColor);
83
Yingdi Yu0b0a7362014-08-05 16:31:30 -070084private:
85 Roster m_roster;
Yingdi Yud45777b2014-10-16 23:54:11 -070086
87 QString m_rootDigest;
88 QGraphicsTextItem* m_displayRootDigest;
89
90 DisplayUserPtr m_previouslyUpdatedUser;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070091};
92
93class User
94{
95public:
96 User()
Yingdi Yu0b0a7362014-08-05 16:31:30 -070097 {
98 }
99
Yingdi Yud45777b2014-10-16 23:54:11 -0700100 User(QString n, QString p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700101 : m_nick(n)
102 , m_prefix(p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700103 {
104 }
105
106 void
107 setNick(QString nick)
108 {
109 m_nick = nick;
110 }
111
112 void
113 setPrefix(QString prefix)
114 {
115 m_prefix = prefix;
116 }
117
118 void
Yingdi Yud45777b2014-10-16 23:54:11 -0700119 setSeq(chronosync::SeqNo seq)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700120 {
121 m_seq = seq;
122 }
123
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700124 QString
125 getNick()
126 {
127 return m_nick;
128 }
129
130 QString getPrefix()
131 {
132 return m_prefix;
133 }
134
Yingdi Yud45777b2014-10-16 23:54:11 -0700135 chronosync::SeqNo
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700136 getSeqNo()
137 {
138 return m_seq;
139 }
140
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700141private:
142 QString m_nick;
143 QString m_prefix;
Yingdi Yud45777b2014-10-16 23:54:11 -0700144 chronosync::SeqNo m_seq;
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700145};
146
147class DisplayUser : public User
148{
149public:
150 DisplayUser()
151 : m_seqTextItem(NULL)
152 , m_nickTextItem(NULL)
153 , m_rimRectItem(NULL)
154 {
155 }
156
Yingdi Yud45777b2014-10-16 23:54:11 -0700157 DisplayUser(QString n, QString p)
158 : User(n, p)
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700159 , m_seqTextItem(NULL)
160 , m_nickTextItem(NULL)
161 , m_rimRectItem(NULL)
162 {
163 }
164
165 QGraphicsTextItem*
166 getSeqTextItem()
167 {
168 return m_seqTextItem;
169 }
170
171 QGraphicsTextItem*
172 getNickTextItem()
173 {
174 return m_nickTextItem;
175 }
176
177 QGraphicsRectItem*
178 getRimRectItem()
179 {
180 return m_rimRectItem;
181 }
182
183 QGraphicsRectItem*
184 getInnerRectItem()
185 {
186 return m_innerRectItem;
187 }
188
189 QGraphicsRectItem*
190 getNickRectItem()
191 {
192 return m_nickRectItem;
193 }
194
195 void
196 setSeqTextItem(QGraphicsTextItem* item)
197 {
198 m_seqTextItem = item;
199 }
200
201 void
202 setNickTextItem(QGraphicsTextItem* item)
203 {
204 m_nickTextItem = item;
205 }
206
207 void
208 setRimRectItem(QGraphicsRectItem* item)
209 {
210 m_rimRectItem = item;
211 }
212
213 void
214 setInnerRectItem(QGraphicsRectItem* item)
215 {
216 m_innerRectItem = item;
217 }
218
219 void
220 setNickRectItem(QGraphicsRectItem* item)
221 {
222 m_nickRectItem = item;
223 }
224
225private:
226 QGraphicsTextItem* m_seqTextItem;
227 QGraphicsTextItem* m_nickTextItem;
228 QGraphicsRectItem* m_rimRectItem;
229 QGraphicsRectItem* m_innerRectItem;
230 QGraphicsRectItem* m_nickRectItem;
231};
232
Yingdi Yueb692ac2015-02-10 18:46:18 -0800233} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700234
Yingdi Yueb692ac2015-02-10 18:46:18 -0800235#endif // CHRONOCHAT_DIGEST_TREE_SCENE_HPP