blob: fd048285499fc63a874c19d2560e577c7618fd75 [file] [log] [blame]
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -07001#ifndef DIGESTTREESCENE_H
2#define DIGESTTREESCENE_H
3
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -07004#include "treelayout.h"
5
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -07006#include <QtGui/QGraphicsScene>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -07007#include <QColor>
8#include <QMap>
9
10#ifndef Q_MOC_RUN
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070011#include <sync-seq-no.h>
12#include <sync-logic.h>
13#include <ctime>
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070014#include <vector>
15#include <tr1/memory>
Alexander Afanasyevf829f4d2013-05-07 15:59:36 -070016#endif
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070017
Zhenkai Zhuc61dbc22012-10-08 11:36:37 -070018const int FRESHNESS = 60;
Zhenkai Zhu86df7412012-09-27 16:30:20 -070019
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070020class QGraphicsTextItem;
21
22class User;
23class DisplayUser;
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070024typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr;
25static DisplayUserPtr DisplayUserNullPtr;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070026
27class DigestTreeScene : public QGraphicsScene
28{
29 Q_OBJECT
30
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070031typedef QMap<QString, DisplayUserPtr> Roster;
32typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
33typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
34
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070035public:
36 DigestTreeScene(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070037 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070038 void msgReceived(QString prefix, QString nick);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070039 void clearAll();
Zhenkai Zhu591e8c32012-09-26 11:57:50 -070040 bool removeNode(const QString prefix);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070041 void plot(QString digest);
Zhenkai Zhu6082ede2012-09-27 17:28:46 -070042 QStringList getRosterList();
Zhenkai Zhu716fe852012-10-08 18:27:55 -070043 void setCurrentPrefix(QString prefix) {m_currentPrefix = prefix;}
Zhenkai Zhu7f52e1b2012-10-09 11:45:36 -070044 QMap<QString, DisplayUserPtr> getRosterFull() { return m_roster;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070045
46signals:
47 void replot();
Zhenkai Zhu25e33e52012-09-28 13:00:07 -070048 void rosterChanged(QStringList);
Zhenkai Zhu86df7412012-09-27 16:30:20 -070049
50private slots:
51 void emitReplot();
52
Zhenkai Zhu82a62752012-06-04 17:11:04 -070053private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070054 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
55 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070056 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070057private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070058 Roster m_roster;
59 QGraphicsTextItem *m_rootDigest;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070060 DisplayUserPtr previouslyUpdatedUser;
Zhenkai Zhu716fe852012-10-08 18:27:55 -070061 QString m_currentPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070062
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070063};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070064
65class User
66{
67public:
68 User():m_received(time(NULL)) {}
69 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
70 void setNick(QString nick) {m_nick = nick;}
71 void setPrefix(QString prefix) {m_prefix = prefix;}
72 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
73 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
Zhenkai Zhu86df7412012-09-27 16:30:20 -070074 void setReceived(time_t t) {m_received = t;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070075 void setOriginPrefix(QString originPrefix) { m_originPrefix = originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070076 QString getNick() { return m_nick;}
77 QString getPrefix() { return m_prefix;}
78 QString getChatroom() { return m_chatroom;}
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070079 QString getOriginPrefix() { return m_originPrefix;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070080 Sync::SeqNo getSeqNo() { return m_seq;}
81 time_t getReceived() { return m_received;}
82private:
83 QString m_nick;
84 QString m_prefix;
85 QString m_chatroom;
Zhenkai Zhue95c64a2012-09-27 21:46:44 -070086 QString m_originPrefix;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070087 Sync::SeqNo m_seq;
88 time_t m_received;
89};
90
91class DisplayUser : public User
92{
93public:
94 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
95 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
96 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
97 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
98 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070099 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
100 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700101 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
102 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
103 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700104 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
105 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700106private:
107 QGraphicsTextItem *m_seqTextItem;
108 QGraphicsTextItem *m_nickTextItem;
109 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -0700110 QGraphicsRectItem *m_innerRectItem;
111 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -0700112};
113
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -0700114#endif