blob: 33a4973514f8f1c22edc96f101d4054100c63581 [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 Zhu25e33e52012-09-28 13:00:07 -070042 void rosterChanged(QStringList);
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 Zhue95c64a2012-09-27 21:46:44 -070068 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070069 QString getNick() { return m_nick;}
70 QString getPrefix() { return m_prefix;}
71 QString getChatroom() { return m_chatroom;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070072 QString getOriginPrefix() { return m_originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070073 Sync::SeqNo getSeqNo() { return m_seq;}
74 time_t getReceived() { return m_received;}
75private:
76 QString m_nick;
77 QString m_prefix;
78 QString m_chatroom;
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070079 QString m_originPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070080 Sync::SeqNo m_seq;
81 time_t m_received;
82};
83
84class DisplayUser : public User
85{
86public:
87 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
88 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
89 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
90 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
91 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070092 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
93 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070094 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
95 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
96 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070097 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
98 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070099private:
100 QGraphicsTextItem *m_seqTextItem;
101 QGraphicsTextItem *m_nickTextItem;
102 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700103 QGraphicsRectItem *m_innerRectItem;
104 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700105};
106
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -0700107#endif