blob: e7600e8647c09350c4ae8b4c86423f1664f0c5c4 [file] [log] [blame]
Yingdi Yu7989eb22013-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
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070012#ifndef DIGESTTREESCENE_H
13#define DIGESTTREESCENE_H
14
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070015#include "treelayout.h"
16
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070017#include <QtGui/QGraphicsScene>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070018#include <QColor>
19#include <QMap>
20
21#ifndef Q_MOC_RUN
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070022#include <sync-seq-no.h>
23#include <sync-logic.h>
24#include <ctime>
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070025#include <vector>
Alexander Afanasyev4a979312013-11-07 15:30:05 -080026#include <boost/shared_ptr.hpp>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070027#endif
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070028
Zhenkai Zhuc61dbc22012-10-08 11:36:37 -070029const int FRESHNESS = 60;
Zhenkai Zhu86df7412012-09-27 16:30:20 -070030
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070031class QGraphicsTextItem;
32
33class User;
34class DisplayUser;
Alexander Afanasyev4a979312013-11-07 15:30:05 -080035typedef boost::shared_ptr<DisplayUser> DisplayUserPtr;
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070036static DisplayUserPtr DisplayUserNullPtr;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070037
38class DigestTreeScene : public QGraphicsScene
39{
40 Q_OBJECT
41
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070042typedef QMap<QString, DisplayUserPtr> Roster;
43typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
44typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
45
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070046public:
47 DigestTreeScene(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070048 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070049 void msgReceived(QString prefix, QString nick);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070050 void clearAll();
Zhenkai Zhu591e8c32012-09-26 11:57:50 -070051 bool removeNode(const QString prefix);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070052 void plot(QString digest);
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070053 QStringList getRosterList();
Zhenkai Zhu716fe852012-10-08 18:27:55 -070054 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070055 QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070056
57signals:
58 void replot();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070059 void rosterChanged(QStringList);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070060
61private slots:
62 void emitReplot();
63
Zhenkai Zhu82a62752012-06-04 17:11:04 -070064private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070065 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
66 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070067 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070068private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070069 Roster m_roster;
70 QGraphicsTextItem *m_rootDigest;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070071 DisplayUserPtr previouslyUpdatedUser;
Zhenkai Zhu716fe852012-10-08 18:27:55 -070072 QString m_currentPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070073
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070074};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070075
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;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070085 void setReceived(time_t t) {m_received = t;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070086 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070087 QString getNick() { return m_nick;}
88 QString getPrefix() { return m_prefix;}
89 QString getChatroom() { return m_chatroom;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070090 QString getOriginPrefix() { return m_originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070091 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;
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070097 QString m_originPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070098 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;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700110 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
111 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700112 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
113 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
114 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700115 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
116 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700117private:
118 QGraphicsTextItem *m_seqTextItem;
119 QGraphicsTextItem *m_nickTextItem;
120 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700121 QGraphicsRectItem *m_innerRectItem;
122 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700123};
124
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -0700125#endif