blob: 7266ecbed887de007dff707dbec1cd3ed9938469 [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
22#include <sync-seq-no.h>
23#include <sync-logic.h>
24#include <ctime>
25#include <vector>
26#include <tr1/memory>
27#endif
28
29const int FRESHNESS = 60;
30
31class QGraphicsTextItem;
32
33class User;
34class DisplayUser;
35typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr;
36static DisplayUserPtr DisplayUserNullPtr;
37
38class DigestTreeScene : public QGraphicsScene
39{
40 Q_OBJECT
41
42typedef QMap<QString, DisplayUserPtr> Roster;
43typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
44typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
45
46public:
47 DigestTreeScene(QWidget *parent = 0);
48 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
49 void msgReceived(QString prefix, QString nick);
50 void clearAll();
51 bool removeNode(const QString prefix);
52 void plot(QString digest);
53 QStringList getRosterList();
54 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
55 QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;}
56
57signals:
58 void replot();
59 void rosterChanged(QStringList);
60
61private slots:
62 void emitReplot();
63
64private:
65 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
66 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
67 void reDrawNode(DisplayUserPtr p, QColor rimColor);
68private:
69 Roster m_roster;
70 QGraphicsTextItem *m_rootDigest;
71 DisplayUserPtr previouslyUpdatedUser;
72 QString m_currentPrefix;
73
74};
75
76class User
77{
78public:
79 User():m_received(time(NULL)) {}
80 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
81 void setNick(QString nick) {m_nick = nick;}
82 void setPrefix(QString prefix) {m_prefix = prefix;}
83 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
84 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
85 void setReceived(time_t t) {m_received = t;}
86 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
87 QString getNick() { return m_nick;}
88 QString getPrefix() { return m_prefix;}
89 QString getChatroom() { return m_chatroom;}
90 QString getOriginPrefix() { return m_originPrefix;}
91 Sync::SeqNo getSeqNo() { return m_seq;}
92 time_t getReceived() { return m_received;}
93private:
94 QString m_nick;
95 QString m_prefix;
96 QString m_chatroom;
97 QString m_originPrefix;
98 Sync::SeqNo m_seq;
99 time_t m_received;
100};
101
102class DisplayUser : public User
103{
104public:
105 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
106 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
107 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
108 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
109 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
110 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
111 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
112 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
113 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
114 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
115 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
116 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
117private:
118 QGraphicsTextItem *m_seqTextItem;
119 QGraphicsTextItem *m_nickTextItem;
120 QGraphicsRectItem *m_rimRectItem;
121 QGraphicsRectItem *m_innerRectItem;
122 QGraphicsRectItem *m_nickRectItem;
123};
124
125#endif