blob: c239a4928ad22277bdef87a757883619366387d9 [file] [log] [blame]
Yingdi Yu42f66462013-10-31 17:38:22 -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 DIGESTTREESCENE_H
13#define DIGESTTREESCENE_H
14
15#include "treelayout.h"
16
17#include <QtGui/QGraphicsScene>
18#include <QColor>
19#include <QMap>
20
21#ifndef Q_MOC_RUN
Yingdi Yua524a262014-02-11 22:54:11 -080022#include <ndn-cpp-dev/util/scheduler.hpp>
Yingdi Yu42f66462013-10-31 17:38:22 -070023#include <sync-seq-no.h>
24#include <sync-logic.h>
25#include <ctime>
26#include <vector>
Alexander Afanasyev4f04c552013-11-07 15:30:05 -080027#include <boost/shared_ptr.hpp>
Yingdi Yu42f66462013-10-31 17:38:22 -070028#endif
29
30const int FRESHNESS = 60;
31
32class QGraphicsTextItem;
33
34class User;
35class DisplayUser;
Alexander Afanasyev4f04c552013-11-07 15:30:05 -080036typedef boost::shared_ptr<DisplayUser> DisplayUserPtr;
Yingdi Yu42f66462013-10-31 17:38:22 -070037static DisplayUserPtr DisplayUserNullPtr;
38
39class DigestTreeScene : public QGraphicsScene
40{
41 Q_OBJECT
42
43typedef QMap<QString, DisplayUserPtr> Roster;
44typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
45typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
46
47public:
Yingdi Yua524a262014-02-11 22:54:11 -080048 DigestTreeScene(ndn::shared_ptr<boost::asio::io_service> ioService,
49 QWidget *parent = 0);
Yingdi Yu42f66462013-10-31 17:38:22 -070050 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
51 void msgReceived(QString prefix, QString nick);
52 void clearAll();
53 bool removeNode(const QString prefix);
54 void plot(QString digest);
55 QStringList getRosterList();
56 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
57 QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;}
58
59signals:
60 void replot();
61 void rosterChanged(QStringList);
62
63private slots:
64 void emitReplot();
65
66private:
67 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
68 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
69 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Yingdi Yua524a262014-02-11 22:54:11 -080070
Yingdi Yu42f66462013-10-31 17:38:22 -070071private:
72 Roster m_roster;
73 QGraphicsTextItem *m_rootDigest;
74 DisplayUserPtr previouslyUpdatedUser;
75 QString m_currentPrefix;
Yingdi Yua524a262014-02-11 22:54:11 -080076 ndn::Scheduler m_scheduler;
Yingdi Yu42f66462013-10-31 17:38:22 -070077};
78
79class User
80{
81public:
82 User():m_received(time(NULL)) {}
83 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
84 void setNick(QString nick) {m_nick = nick;}
85 void setPrefix(QString prefix) {m_prefix = prefix;}
86 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
87 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
88 void setReceived(time_t t) {m_received = t;}
89 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
90 QString getNick() { return m_nick;}
91 QString getPrefix() { return m_prefix;}
92 QString getChatroom() { return m_chatroom;}
93 QString getOriginPrefix() { return m_originPrefix;}
94 Sync::SeqNo getSeqNo() { return m_seq;}
95 time_t getReceived() { return m_received;}
96private:
97 QString m_nick;
98 QString m_prefix;
99 QString m_chatroom;
100 QString m_originPrefix;
101 Sync::SeqNo m_seq;
102 time_t m_received;
103};
104
105class DisplayUser : public User
106{
107public:
108 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
109 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
110 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
111 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
112 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
113 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
114 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
115 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
116 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
117 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
118 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
119 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
120private:
121 QGraphicsTextItem *m_seqTextItem;
122 QGraphicsTextItem *m_nickTextItem;
123 QGraphicsRectItem *m_rimRectItem;
124 QGraphicsRectItem *m_innerRectItem;
125 QGraphicsRectItem *m_nickRectItem;
126};
127
128#endif