blob: 5c8af9d5ed698eb8d85cfd6ba5f0c4ccbbc5641d [file] [log] [blame]
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -07001#ifndef DIGESTTREESCENE_H
2#define DIGESTTREESCENE_H
3
4#include <QtGui/QGraphicsScene>
5#include "ogdf/basic/GraphAttributes.h"
6#include "ogdf/basic/Graph.h"
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -07007#include <sync-seq-no.h>
8#include <sync-logic.h>
9#include <ctime>
10#include <QMap>
11#include <vector>
12#include <tr1/memory>
13
14class QGraphicsTextItem;
15
16class User;
17class DisplayUser;
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070018
19class DigestTreeScene : public QGraphicsScene
20{
21 Q_OBJECT
22
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070023typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr;
24typedef QMap<QString, DisplayUserPtr> Roster;
25typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
26typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
27
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070028public:
29 DigestTreeScene(QWidget *parent = 0);
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070030 void processUpdate(std::vector<Sync::MissingDataInfo> &v, QString digest);
31 void msgReceived(QString prefix, QString nick);
32 void plot(QString digest);
33 void plotEdge(ogdf::GraphAttributes &GA);
34 void plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString digest);
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070035private:
36 ogdf::Graph m_graph;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070037 Roster m_roster;
38 QGraphicsTextItem *m_rootDigest;
39
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070040};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070041
42class User
43{
44public:
45 User():m_received(time(NULL)) {}
46 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
47 void setNick(QString nick) {m_nick = nick;}
48 void setPrefix(QString prefix) {m_prefix = prefix;}
49 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
50 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
51 void setReceived() {m_received = time(NULL);}
52 QString getNick() { return m_nick;}
53 QString getPrefix() { return m_prefix;}
54 QString getChatroom() { return m_chatroom;}
55 Sync::SeqNo getSeqNo() { return m_seq;}
56 time_t getReceived() { return m_received;}
57private:
58 QString m_nick;
59 QString m_prefix;
60 QString m_chatroom;
61 Sync::SeqNo m_seq;
62 time_t m_received;
63};
64
65class DisplayUser : public User
66{
67public:
68 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
69 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
70 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
71 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
72 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
73 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
74 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
75 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
76private:
77 QGraphicsTextItem *m_seqTextItem;
78 QGraphicsTextItem *m_nickTextItem;
79 QGraphicsRectItem *m_rimRectItem;
80};
81
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070082#endif