blob: a2cc69ae6f746ed82c833c394e4888e6ece4d6d9 [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 Zhuc61dbc22012-10-08 11:36:37 -070014const int FRESHNESS = 60;
Zhenkai Zhu86df7412012-09-27 16:30:20 -070015
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070016class QGraphicsTextItem;
17
18class User;
19class DisplayUser;
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070020typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr;
21static DisplayUserPtr DisplayUserNullPtr;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070022
23class DigestTreeScene : public QGraphicsScene
24{
25 Q_OBJECT
26
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070027typedef QMap<QString, DisplayUserPtr> Roster;
28typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
29typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
30
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 Zhu716fe852012-10-08 18:27:55 -070039 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070040 QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070041
42signals:
43 void replot();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070044 void rosterChanged(QStringList);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070045
46private slots:
47 void emitReplot();
48
Zhenkai Zhu82a62752012-06-04 17:11:04 -070049private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070050 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
51 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070052 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070053private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070054 Roster m_roster;
55 QGraphicsTextItem *m_rootDigest;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070056 DisplayUserPtr previouslyUpdatedUser;
Zhenkai Zhu716fe852012-10-08 18:27:55 -070057 QString m_currentPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070058
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070059};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070060
61class User
62{
63public:
64 User():m_received(time(NULL)) {}
65 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
66 void setNick(QString nick) {m_nick = nick;}
67 void setPrefix(QString prefix) {m_prefix = prefix;}
68 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
69 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070070 void setReceived(time_t t) {m_received = t;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070071 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070072 QString getNick() { return m_nick;}
73 QString getPrefix() { return m_prefix;}
74 QString getChatroom() { return m_chatroom;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070075 QString getOriginPrefix() { return m_originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070076 Sync::SeqNo getSeqNo() { return m_seq;}
77 time_t getReceived() { return m_received;}
78private:
79 QString m_nick;
80 QString m_prefix;
81 QString m_chatroom;
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070082 QString m_originPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070083 Sync::SeqNo m_seq;
84 time_t m_received;
85};
86
87class DisplayUser : public User
88{
89public:
90 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
91 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
92 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
93 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
94 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070095 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
96 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070097 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
98 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
99 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700100 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
101 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700102private:
103 QGraphicsTextItem *m_seqTextItem;
104 QGraphicsTextItem *m_nickTextItem;
105 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700106 QGraphicsRectItem *m_innerRectItem;
107 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700108};
109
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -0700110#endif