done with GUI
diff --git a/chatdialog.cpp b/chatdialog.cpp
index b7edf20..6fd93df 100644
--- a/chatdialog.cpp
+++ b/chatdialog.cpp
@@ -17,6 +17,8 @@
DigestTreeScene *scene = new DigestTreeScene();
treeViewer->setScene(scene);
+ QRectF rect = scene->itemsBoundingRect();
+ scene->setSceneRect(rect);
//scene->plot();
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
@@ -144,3 +146,21 @@
updateLabels();
}
}
+
+void
+ChatDialog::resizeEvent(QResizeEvent *e)
+{
+ fitView();
+}
+
+void
+ChatDialog::showEvent(QShowEvent *e)
+{
+ fitView();
+}
+
+void
+ChatDialog::fitView()
+{
+ treeViewer->fitInView(treeViewer->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
+}
diff --git a/chatdialog.h b/chatdialog.h
index 3ae668b..9ca77c0 100644
--- a/chatdialog.h
+++ b/chatdialog.h
@@ -26,6 +26,9 @@
void readSettings();
void writeSettings();
void updateLabels();
+ void resizeEvent(QResizeEvent *);
+ void showEvent(QShowEvent *);
+ void fitView();
private slots:
void returnPressed();
diff --git a/digesttreescene.cpp b/digesttreescene.cpp
index 2d2f631..5133e4c 100644
--- a/digesttreescene.cpp
+++ b/digesttreescene.cpp
@@ -10,9 +10,33 @@
static const double Pi = 3.14159265358979323846264338327950288419717;
+static void
+testDraw(DigestTreeScene * scene)
+{
+ std::string prefix[5] = {"/ndn/1", "/ndn/2", "/ndn/3", "/ndn/4", "/ndn/5"};
+ std::string nick[5] = {"tom", "jerry", "jason", "michael", "hurry"};
+ std::vector<Sync::MissingDataInfo> v;
+ for (int i = 0; i < 5; i++)
+ {
+ Sync::MissingDataInfo mdi = {prefix[i], Sync::SeqNo(0), Sync::SeqNo(i * (2 << i) )};
+ v.push_back(mdi);
+ }
+
+ scene->processUpdate(v, "12341234@!#%!@");
+
+ for (int i = 0; i < 5; i++)
+ {
+ scene-> msgReceived(prefix[i].c_str(), nick[i].c_str());
+ }
+}
+
+DigestTreeScene::DisplayUserPtr DigestTreeScene::DisplayUserNullPtr;
+
DigestTreeScene::DigestTreeScene(QWidget *parent)
: QGraphicsScene(parent)
{
+ previouslyUpdatedUser = DisplayUserNullPtr;
+ testDraw(this);
}
void
@@ -44,8 +68,12 @@
if (it != m_roster.end()) {
DisplayUserPtr p = it.value();
QGraphicsTextItem *item = p->getSeqTextItem();
+ QGraphicsRectItem *rectItem = p->getInnerRectItem();
std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
item->setPlainText(s.c_str());
+ QRectF textBR = item->boundingRect();
+ QRectF rectBR = rectItem->boundingRect();
+ item->setPos(rectBR.x() + (rectBR.width() - textBR.width())/2, rectBR.y() + (rectBR.height() - textBR.height())/2);
}
}
m_rootDigest->setPlainText(digest);
@@ -53,6 +81,21 @@
}
void
+DigestTreeScene::reDrawNode(DisplayUserPtr p, QColor rimColor)
+{
+ QGraphicsRectItem *rimItem = p->getRimRectItem();
+ rimItem->setBrush(QBrush(rimColor));
+ QGraphicsRectItem *innerItem = p->getInnerRectItem();
+ innerItem->setBrush(QBrush(Qt::lightGray));
+ QGraphicsTextItem *seqTextItem = p->getSeqTextItem();
+ std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
+ seqTextItem->setPlainText(s.c_str());
+ QRectF textBR = seqTextItem->boundingRect();
+ QRectF innerBR = innerItem->boundingRect();
+ seqTextItem->setPos(innerBR.x() + (innerBR.width() - textBR.width())/2, innerBR.y() + (innerBR.height() - textBR.height())/2);
+}
+
+void
DigestTreeScene::msgReceived(QString prefix, QString nick)
{
Roster_iterator it = m_roster.find(prefix);
@@ -62,10 +105,21 @@
if (nick != p->getNick()) {
p->setNick(nick);
QGraphicsTextItem *nickItem = p->getNickTextItem();
+ QGraphicsRectItem *nickRectItem = p->getNickRectItem();
nickItem->setPlainText(p->getNick());
+ QRectF rectBR = nickRectItem->boundingRect();
+ QRectF nickBR = nickItem->boundingRect();
+ nickItem->setPos(rectBR.x() + (rectBR.width() - nickBR.width())/2, rectBR.y() + 5);
}
- QGraphicsRectItem *rimItem = p->getRimRectItem();
- rimItem->setBrush(QBrush(Qt::red));
+
+ reDrawNode(p, Qt::red);
+
+ if (previouslyUpdatedUser != DisplayUserNullPtr)
+ {
+ reDrawNode(previouslyUpdatedUser, Qt::darkBlue);
+ }
+
+ previouslyUpdatedUser = p;
}
}
@@ -83,7 +137,7 @@
}
ogdf::GraphAttributes GA(m_graph);
- int nodeSize = 50;
+ int nodeSize = 40;
int siblingDistance = 100, levelDistance = 100;
ogdf::TreeLayout layout;
layout.siblingDistance(siblingDistance);
@@ -92,13 +146,15 @@
int width = GA.boundingBox().width();
int height = GA.boundingBox().height();
- setSceneRect(QRect(- (width + nodeSize) / 2, - 40, width + nodeSize, height + nodeSize));
+ //setSceneRect(QRect(- (width + nodeSize) / 2, - 50, width + nodeSize, height + nodeSize));
GA.setAllWidth(nodeSize);
GA.setAllHeight(nodeSize);
plotEdge(GA);
plotNode(GA, rootIndex, digest);
+ previouslyUpdatedUser = DisplayUserNullPtr;
+
}
void
@@ -141,19 +197,19 @@
int rim = 3;
QRectF boundingRect(x, y, w, h);
QRectF innerBoundingRect(x + rim, y + rim, w - rim * 2, h - rim * 2);
- addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
if (n->index() == rootIndex)
{
addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkRed));
+ addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
- QRectF digestRect(x - w / 2, y - h - 5, 2 * w, 30);
+ QRectF digestRect(x - w, y - h, 3 * w, 30);
addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
QGraphicsTextItem *digestItem = addText(digest);
QRectF digestBoundingRect = digestItem->boundingRect();
digestItem->setDefaultTextColor(Qt::white);
digestItem->setFont(QFont("Cursive", 12, QFont::Bold));
- digestItem->setPos(x + w / 2 - digestBoundingRect.width() / 2, y - h - 15);
+ digestItem->setPos(x - w + (3 * w - digestBoundingRect.width()) / 2, y - h + 5);
m_rootDigest = digestItem;
}
else
@@ -170,6 +226,9 @@
QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue));
p->setRimRectItem(rectItem);
+ QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
+ p->setInnerRectItem(innerRectItem);
+
std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
QGraphicsTextItem *seqItem = addText(s.c_str());
seqItem->setFont(QFont("Cursive", 12, QFont::Bold));
@@ -177,15 +236,17 @@
seqItem->setPos(x + w / 2 - seqBoundingRect.width() / 2, y + h / 2 - seqBoundingRect.height() / 2);
p->setSeqTextItem(seqItem);
- QRectF textRect(x - w / 2, y + h + 10, 2 * w, 30);
- addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
+ QRectF textRect(x - w / 2, y + h, 2 * w, 30);
+ QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
+ p->setNickRectItem(nickRectItem);
QGraphicsTextItem *nickItem = addText(p->getNick());
QRectF textBoundingRect = nickItem->boundingRect();
nickItem->setDefaultTextColor(Qt::white);
nickItem->setFont(QFont("Cursive", 12, QFont::Bold));
- nickItem->setPos(x + w / 2 - textBoundingRect.width() / 2, y + h + 15);
+ nickItem->setPos(x + w / 2 - textBoundingRect.width() / 2, y + h + 5);
p->setNickTextItem(nickItem);
}
+
}
}
diff --git a/digesttreescene.h b/digesttreescene.h
index 5c8af9d..08a50d0 100644
--- a/digesttreescene.h
+++ b/digesttreescene.h
@@ -10,6 +10,7 @@
#include <QMap>
#include <vector>
#include <tr1/memory>
+#include <QColor>
class QGraphicsTextItem;
@@ -24,18 +25,22 @@
typedef QMap<QString, DisplayUserPtr> Roster;
typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator;
typedef QMapIterator<QString, DisplayUserPtr> RosterIterator;
+static DisplayUserPtr DisplayUserNullPtr;
public:
DigestTreeScene(QWidget *parent = 0);
void processUpdate(std::vector<Sync::MissingDataInfo> &v, QString digest);
void msgReceived(QString prefix, QString nick);
+private:
void plot(QString digest);
void plotEdge(ogdf::GraphAttributes &GA);
void plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString digest);
+ void reDrawNode(DisplayUserPtr p, QColor rimColor);
private:
ogdf::Graph m_graph;
Roster m_roster;
QGraphicsTextItem *m_rootDigest;
+ DisplayUserPtr previouslyUpdatedUser;
};
@@ -70,13 +75,19 @@
QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;}
QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;}
QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;}
+ QGraphicsRectItem *getInnerRectItem() {return m_innerRectItem;}
+ QGraphicsRectItem *getNickRectItem() {return m_nickRectItem;}
void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;}
void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;}
void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;}
+ void setInnerRectItem(QGraphicsRectItem *item) {m_innerRectItem = item;}
+ void setNickRectItem(QGraphicsRectItem *item) {m_nickRectItem = item;}
private:
QGraphicsTextItem *m_seqTextItem;
QGraphicsTextItem *m_nickTextItem;
QGraphicsRectItem *m_rimRectItem;
+ QGraphicsRectItem *m_innerRectItem;
+ QGraphicsRectItem *m_nickRectItem;
};
#endif