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