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