blob: 6ac6b1cd08459db4825466bb41934b588c5b75ef [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
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070012#ifndef DIGEST_TREE_SCENE_H
13#define DIGEST_TREE_SCENE_H
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070014
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070015#include <QtGui/QGraphicsScene>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070016#include <QColor>
17#include <QMap>
18
19#ifndef Q_MOC_RUN
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070020#include "tree-layout.h"
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070021#include <sync-seq-no.h>
22#include <sync-logic.h>
23#include <ctime>
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070024#include <vector>
Alexander Afanasyev4a979312013-11-07 15:30:05 -080025#include <boost/shared_ptr.hpp>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070026#endif
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070027
Zhenkai Zhuc61dbc22012-10-08 11:36:37 -070028const int FRESHNESS = 60;
Zhenkai Zhu86df7412012-09-27 16:30:20 -070029
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070030class QGraphicsTextItem;
31
32class User;
33class DisplayUser;
Alexander Afanasyev4a979312013-11-07 15:30:05 -080034typedef boost::shared_ptr<DisplayUser> DisplayUserPtr;
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070035static DisplayUserPtr DisplayUserNullPtr;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070036
37class DigestTreeScene : public QGraphicsScene
38{
39 Q_OBJECT
40
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070041typedef QMap<QString, DisplayUserPtr> Roster;
42typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
43typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
44
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070045public:
Yingdi Yu348f5ea2014-03-01 14:47:25 -080046 DigestTreeScene(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070047 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070048 void msgReceived(QString prefix, QString nick);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070049 void clearAll();
Zhenkai Zhu591e8c32012-09-26 11:57:50 -070050 bool removeNode(const QString prefix);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070051 void plot(QString digest);
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070052 QStringList getRosterList();
Zhenkai Zhu716fe852012-10-08 18:27:55 -070053 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070054 QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070055
56signals:
57 void replot();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070058 void rosterChanged(QStringList);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070059
60private slots:
61 void emitReplot();
62
Zhenkai Zhu82a62752012-06-04 17:11:04 -070063private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070064 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
65 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070066 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Yingdi Yu3a014852014-02-11 22:54:11 -080067
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 Zhuf474a0a2012-05-30 15:06:29 -070073};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070074
75class User
76{
77public:
78 User():m_received(time(NULL)) {}
79 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
80 void setNick(QString nick) {m_nick = nick;}
81 void setPrefix(QString prefix) {m_prefix = prefix;}
82 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
83 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070084 void setReceived(time_t t) {m_received = t;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070085 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070086 QString getNick() { return m_nick;}
87 QString getPrefix() { return m_prefix;}
88 QString getChatroom() { return m_chatroom;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070089 QString getOriginPrefix() { return m_originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070090 Sync::SeqNo getSeqNo() { return m_seq;}
91 time_t getReceived() { return m_received;}
92private:
93 QString m_nick;
94 QString m_prefix;
95 QString m_chatroom;
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070096 QString m_originPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070097 Sync::SeqNo m_seq;
98 time_t m_received;
99};
100
101class DisplayUser : public User
102{
103public:
104 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
105 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
106 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
107 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
108 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700109 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
110 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700111 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
112 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
113 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700114 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
115 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700116private:
117 QGraphicsTextItem *m_seqTextItem;
118 QGraphicsTextItem *m_nickTextItem;
119 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700120 QGraphicsRectItem *m_innerRectItem;
121 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700122};
123
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -0700124#endif // DIGEST_TREE_SCENE_H