blob: 6a30e1883409e8c62aae915e72976527a1794302 [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
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;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070027static DisplayUserPtr DisplayUserNullPtr;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070028
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070029public:
30 DigestTreeScene(QWidget *parent = 0);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070031 void processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest);
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070032 void msgReceived(QString prefix, QString nick);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070033 void clearAll();
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070034 void plot(QString digest);
Zhenkai Zhu591e8c32012-09-26 11:57:50 -070035 bool removeNode(const QString prefix);
Zhenkai Zhu82a62752012-06-04 17:11:04 -070036private:
Zhenkai Zhu21d75f92012-06-04 21:23:34 -070037 void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
38 void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
Zhenkai Zhud13acd02012-06-04 15:25:20 -070039 void reDrawNode(DisplayUserPtr p, QColor rimColor);
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070040private:
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070041 Roster m_roster;
42 QGraphicsTextItem *m_rootDigest;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070043 DisplayUserPtr previouslyUpdatedUser;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070044
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070045};
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070046
47class User
48{
49public:
50 User():m_received(time(NULL)) {}
51 User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {}
52 void setNick(QString nick) {m_nick = nick;}
53 void setPrefix(QString prefix) {m_prefix = prefix;}
54 void setChatroom(QString chatroom) {m_chatroom = chatroom;}
55 void setSeq(Sync::SeqNo seq) {m_seq = seq;}
56 void setReceived() {m_received = time(NULL);}
57 QString getNick() { return m_nick;}
58 QString getPrefix() { return m_prefix;}
59 QString getChatroom() { return m_chatroom;}
60 Sync::SeqNo getSeqNo() { return m_seq;}
61 time_t getReceived() { return m_received;}
62private:
63 QString m_nick;
64 QString m_prefix;
65 QString m_chatroom;
66 Sync::SeqNo m_seq;
67 time_t m_received;
68};
69
70class DisplayUser : public User
71{
72public:
73 DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
74 DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {}
75 QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
76 QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
77 QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070078 QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
79 QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070080 void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
81 void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
82 void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
Zhenkai Zhud13acd02012-06-04 15:25:20 -070083 void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
84 void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070085private:
86 QGraphicsTextItem *m_seqTextItem;
87 QGraphicsTextItem *m_nickTextItem;
88 QGraphicsRectItem *m_rimRectItem;
Zhenkai Zhud13acd02012-06-04 15:25:20 -070089 QGraphicsRectItem *m_innerRectItem;
90 QGraphicsRectItem *m_nickRectItem;
Zhenkai Zhu71b42cb2012-06-04 09:42:53 -070091};
92
Zhenkai Zhuf474a0a2012-05-30 15:06:29 -070093#endif