blob: 7d30bacfc50be9983eafb4033aa09439cf637fba [file] [log] [blame]
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -07001#ifndef DIGESTTREESCENE_H
2#define DIGESTTREESCENE_H
3
4#include <QtGui/QGraphicsScene>
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -07005#include <sync-seq-no.h>
6#include <sync-logic.h>
7#include <ctime>
8#include <QMap>
9#include <vector>
10#include <tr1/memory>
Zhenkai Zhud13acd02012-06-04 15:25:20 -070011#include <QColor>
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070012#include "treelayout.h"
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070013
Zhenkai Zhu86df7412012-09-27 16:30:20 -070014const int FRESHNESS = 120;
15
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070016class QGraphicsTextItem;
17
18class User;
19class DisplayUser;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070020
21class DigestTreeScene : public QGraphicsScene
22{
23 Q_OBJECT
24
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070025typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr;
26typedef QMap<QString, DisplayUserPtr> Roster;
27typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
28typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070029static DisplayUserPtr DisplayUserNullPtr;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070030
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070031public:
32 DigestTreeScene(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070033 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070034 void msgReceived(QString prefix, QString nick);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070035 void clearAll();
Zhenkai Zhu591e8c32012-09-26 11:57:50 -070036 bool removeNode(const QString prefix);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070037 void plot(QString digest);
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070038 QStringList getRosterList();
Zhenkai Zhu86df7412012-09-27 16:30:20 -070039
40signals:
41 void replot();
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070042 void rosterChanged();
Zhenkai Zhu86df7412012-09-27 16:30:20 -070043
44private slots:
45 void emitReplot();
46
Zhenkai Zhu82a62752012-06-04 17:11:04 -070047private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070048 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
49 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070050 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070051private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070052 Roster m_roster;
53 QGraphicsTextItem *m_rootDigest;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070054 DisplayUserPtr previouslyUpdatedUser;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070055
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070056};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070057
58class User
59{
60public:
61 User():m_received(time(NULL)) {}
62 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
63 void setNick(QString nick) {m_nick = nick;}
64 void setPrefix(QString prefix) {m_prefix = prefix;}
65 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
66 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070067 void setReceived(time_t t) {m_received = t;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070068 QString getNick() { return m_nick;}
69 QString getPrefix() { return m_prefix;}
70 QString getChatroom() { return m_chatroom;}
71 Sync::SeqNo getSeqNo() { return m_seq;}
72 time_t getReceived() { return m_received;}
73private:
74 QString m_nick;
75 QString m_prefix;
76 QString m_chatroom;
77 Sync::SeqNo m_seq;
78 time_t m_received;
79};
80
81class DisplayUser : public User
82{
83public:
84 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
85 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
86 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
87 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
88 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070089 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
90 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070091 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
92 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
93 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070094 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
95 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070096private:
97 QGraphicsTextItem *m_seqTextItem;
98 QGraphicsTextItem *m_nickTextItem;
99 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700100 QGraphicsRectItem *m_innerRectItem;
101 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700102};
103
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -0700104#endif