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