Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 9 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 10 | */ |
| 11 | |
Alexander Afanasyev | f829f4d | 2013-05-07 15:59:36 -0700 | [diff] [blame] | 12 | #include "digesttreescene.h" |
| 13 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 14 | #include <QtGui> |
Alexander Afanasyev | f829f4d | 2013-05-07 15:59:36 -0700 | [diff] [blame] | 15 | |
| 16 | #ifndef Q_MOC_RUN |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 17 | #include <vector> |
| 18 | #include <iostream> |
| 19 | #include <assert.h> |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 20 | #include <boost/lexical_cast.hpp> |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 21 | #include <memory> |
Alexander Afanasyev | f829f4d | 2013-05-07 15:59:36 -0700 | [diff] [blame] | 22 | #endif |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 23 | |
| 24 | static const double Pi = 3.14159265358979323846264338327950288419717; |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 25 | |
Zhenkai Zhu | 7f52e1b | 2012-10-09 11:45:36 -0700 | [diff] [blame] | 26 | //DisplayUserPtr DisplayUserNullPtr; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 27 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 28 | DigestTreeScene::DigestTreeScene(QWidget *parent) |
| 29 | : QGraphicsScene(parent) |
| 30 | { |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 31 | previouslyUpdatedUser = DisplayUserNullPtr; |
Zhenkai Zhu | 6fcdee4 | 2012-05-30 17:02:49 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 35 | DigestTreeScene::processUpdate(const std::vector<Sync::MissingDataInfo> &v, QString digest) |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 36 | { |
| 37 | int n = v.size(); |
| 38 | bool rePlot = false; |
| 39 | for (int i = 0; i < n; i++) |
| 40 | { |
| 41 | Roster_iterator it = m_roster.find(v[i].prefix.c_str()); |
Zhenkai Zhu | d1c5a97 | 2012-06-05 14:07:41 -0700 | [diff] [blame] | 42 | if (it == m_roster.end()) |
| 43 | { |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 44 | rePlot = true; |
| 45 | DisplayUserPtr p(new DisplayUser()); |
Zhenkai Zhu | c61dbc2 | 2012-10-08 11:36:37 -0700 | [diff] [blame] | 46 | time_t tempTime = time(NULL) - FRESHNESS + 1; |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 47 | p->setReceived(tempTime); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 48 | p->setPrefix(v[i].prefix.c_str()); |
| 49 | p->setSeq(v[i].high); |
| 50 | m_roster.insert(p->getPrefix(), p); |
| 51 | } |
Zhenkai Zhu | d1c5a97 | 2012-06-05 14:07:41 -0700 | [diff] [blame] | 52 | else |
| 53 | { |
| 54 | it.value()->setSeq(v[i].high); |
| 55 | } |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | if (rePlot) |
| 59 | { |
| 60 | plot(digest); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 61 | QTimer::singleShot(2100, this, SLOT(emitReplot())); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 62 | } |
| 63 | else |
| 64 | { |
| 65 | for (int i = 0; i < n; i++) |
| 66 | { |
| 67 | Roster_iterator it = m_roster.find(v[i].prefix.c_str()); |
| 68 | if (it != m_roster.end()) { |
| 69 | DisplayUserPtr p = it.value(); |
| 70 | QGraphicsTextItem *item = p->getSeqTextItem(); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 71 | QGraphicsRectItem *rectItem = p->getInnerRectItem(); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 72 | std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq()); |
| 73 | item->setPlainText(s.c_str()); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 74 | QRectF textBR = item->boundingRect(); |
| 75 | QRectF rectBR = rectItem->boundingRect(); |
| 76 | item->setPos(rectBR.x() + (rectBR.width() - textBR.width())/2, rectBR.y() + (rectBR.height() - textBR.height())/2); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | m_rootDigest->setPlainText(digest); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 84 | DigestTreeScene::emitReplot() |
| 85 | { |
| 86 | emit replot(); |
| 87 | } |
| 88 | |
Zhenkai Zhu | 9036e03 | 2012-09-27 20:59:33 -0700 | [diff] [blame] | 89 | QStringList |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 90 | DigestTreeScene::getRosterList() |
| 91 | { |
Zhenkai Zhu | 9036e03 | 2012-09-27 20:59:33 -0700 | [diff] [blame] | 92 | QStringList rosterList; |
| 93 | RosterIterator it(m_roster); |
| 94 | while(it.hasNext()) |
| 95 | { |
| 96 | it.next(); |
| 97 | DisplayUserPtr p = it.value(); |
| 98 | if (p != DisplayUserNullPtr) |
| 99 | { |
| 100 | rosterList << "- " + p->getNick(); |
| 101 | } |
| 102 | } |
| 103 | return rosterList; |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 107 | DigestTreeScene::msgReceived(QString prefix, QString nick) |
| 108 | { |
| 109 | Roster_iterator it = m_roster.find(prefix); |
| 110 | if (it != m_roster.end()) |
| 111 | { |
Zhenkai Zhu | 716fe85 | 2012-10-08 18:27:55 -0700 | [diff] [blame] | 112 | std::cout << "Updating for prefix = " << prefix.toStdString() << " nick = " << nick.toStdString() << std::endl; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 113 | DisplayUserPtr p = it.value(); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 114 | p->setReceived(time(NULL)); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 115 | if (nick != p->getNick()) { |
Zhenkai Zhu | 716fe85 | 2012-10-08 18:27:55 -0700 | [diff] [blame] | 116 | std::cout << "old nick = " << p->getNick().toStdString() << std::endl; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 117 | p->setNick(nick); |
| 118 | QGraphicsTextItem *nickItem = p->getNickTextItem(); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 119 | QGraphicsRectItem *nickRectItem = p->getNickRectItem(); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 120 | nickItem->setPlainText(p->getNick()); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 121 | QRectF rectBR = nickRectItem->boundingRect(); |
| 122 | QRectF nickBR = nickItem->boundingRect(); |
| 123 | nickItem->setPos(rectBR.x() + (rectBR.width() - nickBR.width())/2, rectBR.y() + 5); |
Zhenkai Zhu | 25e33e5 | 2012-09-28 13:00:07 -0700 | [diff] [blame] | 124 | emit rosterChanged(QStringList()); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 125 | } |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 126 | |
| 127 | reDrawNode(p, Qt::red); |
| 128 | |
Zhenkai Zhu | d1c5a97 | 2012-06-05 14:07:41 -0700 | [diff] [blame] | 129 | if (previouslyUpdatedUser != DisplayUserNullPtr && previouslyUpdatedUser != p) |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 130 | { |
| 131 | reDrawNode(previouslyUpdatedUser, Qt::darkBlue); |
| 132 | } |
| 133 | |
| 134 | previouslyUpdatedUser = p; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | void |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 139 | DigestTreeScene::clearAll() |
| 140 | { |
| 141 | clear(); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 142 | m_roster.clear(); |
| 143 | } |
| 144 | |
Zhenkai Zhu | 591e8c3 | 2012-09-26 11:57:50 -0700 | [diff] [blame] | 145 | bool |
| 146 | DigestTreeScene::removeNode(const QString prefix) |
| 147 | { |
| 148 | int removedCount = m_roster.remove(prefix); |
| 149 | return (removedCount > 0); |
| 150 | } |
| 151 | |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 152 | void |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 153 | DigestTreeScene::plot(QString digest) |
| 154 | { |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 155 | #ifdef __DEBUG |
| 156 | std::cout << "Plotting at time: " << time(NULL) << std::endl; |
| 157 | #endif |
Zhenkai Zhu | 6fcdee4 | 2012-05-30 17:02:49 -0700 | [diff] [blame] | 158 | clear(); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 159 | |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 160 | int nodeSize = 40; |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 161 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 162 | int siblingDistance = 100, levelDistance = 100; |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 163 | std::auto_ptr<TreeLayout> layout(new OneLevelTreeLayout()); |
| 164 | layout->setSiblingDistance(siblingDistance); |
| 165 | layout->setLevelDistance(levelDistance); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 166 | |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 167 | // do some cleaning, get rid of stale member info |
| 168 | Roster_iterator it = m_roster.begin(); |
Zhenkai Zhu | 25e33e5 | 2012-09-28 13:00:07 -0700 | [diff] [blame] | 169 | QStringList staleUserList; |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 170 | while (it != m_roster.end()) |
| 171 | { |
| 172 | DisplayUserPtr p = it.value(); |
| 173 | if (p != DisplayUserNullPtr) |
| 174 | { |
| 175 | time_t now = time(NULL); |
Zhenkai Zhu | c61dbc2 | 2012-10-08 11:36:37 -0700 | [diff] [blame] | 176 | if (now - p->getReceived() >= FRESHNESS) |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 177 | { |
| 178 | #ifdef __DEBUG |
| 179 | std::cout << "Removing user: " << p->getNick().toStdString() << std::endl; |
| 180 | std::cout << "now - last = " << now - p->getReceived() << std::endl; |
| 181 | #endif |
Zhenkai Zhu | 25e33e5 | 2012-09-28 13:00:07 -0700 | [diff] [blame] | 182 | staleUserList << p->getNick(); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 183 | p = DisplayUserNullPtr; |
| 184 | it = m_roster.erase(it); |
| 185 | } |
| 186 | else |
| 187 | { |
Zhenkai Zhu | 716fe85 | 2012-10-08 18:27:55 -0700 | [diff] [blame] | 188 | if (!m_currentPrefix.startsWith("/private/local") && p->getPrefix().startsWith("/private/local")) |
| 189 | { |
| 190 | #ifdef __DEBUG |
| 191 | std::cout << "erasing: " << p->getPrefix().toStdString() << std::endl; |
| 192 | #endif |
| 193 | staleUserList << p->getNick(); |
| 194 | p = DisplayUserNullPtr; |
| 195 | it = m_roster.erase(it); |
| 196 | continue; |
| 197 | } |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 198 | ++it; |
| 199 | } |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | it = m_roster.erase(it); |
| 204 | } |
| 205 | } |
| 206 | |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 207 | // for simpicity here, whenever we replot, we also redo the roster list |
Zhenkai Zhu | 25e33e5 | 2012-09-28 13:00:07 -0700 | [diff] [blame] | 208 | emit rosterChanged(staleUserList); |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 209 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 210 | int n = m_roster.size(); |
Zhenkai Zhu | 716fe85 | 2012-10-08 18:27:55 -0700 | [diff] [blame] | 211 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 212 | std::vector<TreeLayout::Coordinate> childNodesCo(n); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 213 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 214 | layout->setOneLevelLayout(childNodesCo); |
| 215 | |
| 216 | plotEdge(childNodesCo, nodeSize); |
| 217 | plotNode(childNodesCo, digest, nodeSize); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 218 | |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 219 | previouslyUpdatedUser = DisplayUserNullPtr; |
| 220 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | void |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 224 | DigestTreeScene::plotEdge(const std::vector<TreeLayout::Coordinate> &childNodesCo, int nodeSize) |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 225 | { |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 226 | int n = childNodesCo.size(); |
| 227 | for (int i = 0; i < n; i++) { |
| 228 | double x1 = 0.0, y1 = 0.0; |
| 229 | double x2 = childNodesCo[i].x, y2 = childNodesCo[i].y; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 230 | QPointF src(x1 + nodeSize/2, y1 + nodeSize/2); |
| 231 | QPointF dest(x2 + nodeSize/2, y2 + nodeSize/2); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 232 | QLineF line(src, dest); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 233 | double angle = ::acos(line.dx() / line.length()); |
| 234 | |
| 235 | double arrowSize = 10; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 236 | QPointF sourceArrowP0 = src + QPointF((nodeSize/2 + 10) * line.dx() / line.length(), (nodeSize/2 +10) * line.dy() / line.length()); |
| 237 | QPointF sourceArrowP1 = sourceArrowP0 + QPointF(cos(angle + Pi / 3 - Pi/2) * arrowSize, |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 238 | sin(angle + Pi / 3 - Pi/2) * arrowSize); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 239 | QPointF sourceArrowP2 = sourceArrowP0 + QPointF(cos(angle + Pi - Pi / 3 - Pi/2) * arrowSize, |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 240 | sin(angle + Pi - Pi / 3 - Pi/2) * arrowSize); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 241 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 242 | addLine(QLineF(sourceArrowP0, dest), QPen(Qt::black)); |
| 243 | addPolygon(QPolygonF() << sourceArrowP0<< sourceArrowP1 << sourceArrowP2, QPen(Qt::black), QBrush(Qt::black)); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 248 | DigestTreeScene::plotNode(const std::vector<TreeLayout::Coordinate> &childNodesCo, QString digest, int nodeSize) |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 249 | { |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 250 | RosterIterator it(m_roster); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 251 | int n = childNodesCo.size(); |
| 252 | int rim = 3; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 253 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 254 | // plot root node |
| 255 | QRectF rootBoundingRect(0, 0, nodeSize, nodeSize); |
| 256 | QRectF rootInnerBoundingRect(rim, rim, nodeSize - rim * 2, nodeSize - rim * 2); |
| 257 | addRect(rootBoundingRect, QPen(Qt::black), QBrush(Qt::darkRed)); |
| 258 | addRect(rootInnerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray)); |
Zhenkai Zhu | c547061 | 2012-06-05 12:28:59 -0700 | [diff] [blame] | 259 | QRectF digestRect(- 5.5 * nodeSize , - nodeSize, 12 * nodeSize, 30); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 260 | addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); |
Zhenkai Zhu | 27df8d4 | 2012-06-05 12:04:04 -0700 | [diff] [blame] | 261 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 262 | QGraphicsTextItem *digestItem = addText(digest); |
| 263 | QRectF digestBoundingRect = digestItem->boundingRect(); |
Zhenkai Zhu | 27df8d4 | 2012-06-05 12:04:04 -0700 | [diff] [blame] | 264 | digestItem->setDefaultTextColor(Qt::black); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 265 | digestItem->setFont(QFont("Cursive", 12, QFont::Bold)); |
Zhenkai Zhu | c547061 | 2012-06-05 12:28:59 -0700 | [diff] [blame] | 266 | digestItem->setPos(- 4.5 * nodeSize + (12 * nodeSize - digestBoundingRect.width()) / 2, - nodeSize + 5); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 267 | m_rootDigest = digestItem; |
| 268 | |
| 269 | // plot child nodes |
| 270 | for (int i = 0; i < n; i++) |
| 271 | { |
| 272 | if (it.hasNext()) |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 273 | { |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 274 | it.next(); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 275 | } |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 276 | else |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 277 | { |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 278 | abort(); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 279 | } |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 280 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 281 | double x = childNodesCo[i].x; |
| 282 | double y = childNodesCo[i].y; |
| 283 | QRectF boundingRect(x, y, nodeSize, nodeSize); |
| 284 | QRectF innerBoundingRect(x + rim, y + rim, nodeSize - rim * 2, nodeSize - rim * 2); |
| 285 | DisplayUserPtr p = it.value(); |
| 286 | QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue)); |
| 287 | p->setRimRectItem(rectItem); |
| 288 | |
| 289 | QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray)); |
| 290 | p->setInnerRectItem(innerRectItem); |
| 291 | |
| 292 | std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq()); |
| 293 | QGraphicsTextItem *seqItem = addText(s.c_str()); |
| 294 | seqItem->setFont(QFont("Cursive", 12, QFont::Bold)); |
| 295 | QRectF seqBoundingRect = seqItem->boundingRect(); |
| 296 | seqItem->setPos(x + nodeSize / 2 - seqBoundingRect.width() / 2, y + nodeSize / 2 - seqBoundingRect.height() / 2); |
| 297 | p->setSeqTextItem(seqItem); |
| 298 | |
| 299 | QRectF textRect(x - nodeSize / 2, y + nodeSize, 2 * nodeSize, 30); |
| 300 | QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); |
| 301 | p->setNickRectItem(nickRectItem); |
| 302 | QGraphicsTextItem *nickItem = addText(p->getNick()); |
| 303 | QRectF textBoundingRect = nickItem->boundingRect(); |
| 304 | nickItem->setDefaultTextColor(Qt::white); |
| 305 | nickItem->setFont(QFont("Cursive", 12, QFont::Bold)); |
| 306 | nickItem->setPos(x + nodeSize / 2 - textBoundingRect.width() / 2, y + nodeSize + 5); |
| 307 | p->setNickTextItem(nickItem); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 308 | } |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 309 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 312 | void |
| 313 | DigestTreeScene::reDrawNode(DisplayUserPtr p, QColor rimColor) |
| 314 | { |
| 315 | QGraphicsRectItem *rimItem = p->getRimRectItem(); |
| 316 | rimItem->setBrush(QBrush(rimColor)); |
| 317 | QGraphicsRectItem *innerItem = p->getInnerRectItem(); |
| 318 | innerItem->setBrush(QBrush(Qt::lightGray)); |
| 319 | QGraphicsTextItem *seqTextItem = p->getSeqTextItem(); |
| 320 | std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq()); |
| 321 | seqTextItem->setPlainText(s.c_str()); |
| 322 | QRectF textBR = seqTextItem->boundingRect(); |
| 323 | QRectF innerBR = innerItem->boundingRect(); |
| 324 | seqTextItem->setPos(innerBR.x() + (innerBR.width() - textBR.width())/2, innerBR.y() + (innerBR.height() - textBR.height())/2); |
| 325 | } |
| 326 | |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 327 | #if WAF |
| 328 | #include "digesttreescene.moc" |
| 329 | #include "digesttreescene.cpp.moc" |
| 330 | #endif |