blob: 9d9dee46929f921b3e719c4076b09b06662f0441 [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 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 Zhu716fe852012-10-08 18:27:55 -070039 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070040
41signals:
42 void replot();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070043 void rosterChanged(QStringList);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070044
45private slots:
46 void emitReplot();
47
Zhenkai Zhu82a62752012-06-04 17:11:04 -070048private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070049 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
50 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070051 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070052private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070053 Roster m_roster;
54 QGraphicsTextItem *m_rootDigest;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070055 DisplayUserPtr previouslyUpdatedUser;
Zhenkai Zhu716fe852012-10-08 18:27:55 -070056 QString m_currentPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070057
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070058};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070059
60class User
61{
62public:
63 User():m_received(time(NULL)) {}
64 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
65 void setNick(QString nick) {m_nick = nick;}
66 void setPrefix(QString prefix) {m_prefix = prefix;}
67 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
68 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070069 void setReceived(time_t t) {m_received = t;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070070 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070071 QString getNick() { return m_nick;}
72 QString getPrefix() { return m_prefix;}
73 QString getChatroom() { return m_chatroom;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070074 QString getOriginPrefix() { return m_originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070075 Sync::SeqNo getSeqNo() { return m_seq;}
76 time_t getReceived() { return m_received;}
77private:
78 QString m_nick;
79 QString m_prefix;
80 QString m_chatroom;
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070081 QString m_originPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070082 Sync::SeqNo m_seq;
83 time_t m_received;
84};
85
86class DisplayUser : public User
87{
88public:
89 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
90 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
91 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
92 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
93 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070094 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
95 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070096 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
97 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
98 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070099 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
100 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700101private:
102 QGraphicsTextItem *m_seqTextItem;
103 QGraphicsTextItem *m_nickTextItem;
104 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700105 QGraphicsRectItem *m_innerRectItem;
106 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700107};
108
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -0700109#endif