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 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 12 | #include "digest-tree-scene.hpp" |
Alexander Afanasyev | f829f4d | 2013-05-07 15:59:36 -0700 | [diff] [blame] | 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 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 24 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 25 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 26 | static const double Pi = 3.14159265358979323846264338327950288419717; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 27 | static const int NODE_SIZE = 40; |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 28 | |
Zhenkai Zhu | 7f52e1b | 2012-10-09 11:45:36 -0700 | [diff] [blame] | 29 | //DisplayUserPtr DisplayUserNullPtr; |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 30 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 31 | DigestTreeScene::DigestTreeScene(QWidget *parent) |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 32 | : QGraphicsScene(parent) |
| 33 | { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 34 | m_previouslyUpdatedUser = DisplayUserNullPtr; |
Zhenkai Zhu | 6fcdee4 | 2012-05-30 17:02:49 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 38 | DigestTreeScene::processSyncUpdate(const std::vector<chronochat::NodeInfo>& nodeInfos, |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 39 | const QString& digest) |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 40 | { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 41 | m_rootDigest = digest; |
Yingdi Yu | 5a5ff20 | 2014-03-17 10:03:02 -0700 | [diff] [blame] | 42 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 43 | bool rePlot = false; |
| 44 | |
| 45 | // Update roster info |
Yingdi Yu | 1cc45d9 | 2015-02-09 14:19:54 -0800 | [diff] [blame] | 46 | for (size_t i = 0; i < nodeInfos.size(); i++) { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 47 | Roster_iterator it = m_roster.find(nodeInfos[i].sessionPrefix); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 48 | if (it == m_roster.end()) { |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 49 | rePlot = true; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 50 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 51 | DisplayUserPtr p(new DisplayUser()); |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 52 | p->setPrefix(nodeInfos[i].sessionPrefix); |
| 53 | p->setSeq(nodeInfos[i].seqNo); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 54 | m_roster.insert(p->getPrefix(), p); |
| 55 | } |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 56 | else { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 57 | it.value()->setSeq(nodeInfos[i].seqNo); |
Zhenkai Zhu | d1c5a97 | 2012-06-05 14:07:41 -0700 | [diff] [blame] | 58 | } |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 61 | if (rePlot) |
| 62 | // If new nodes exist, we need to re-arrange node |
| 63 | plot(m_rootDigest); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 64 | else { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 65 | // No new node, update seqNo & digest |
Yingdi Yu | 1cc45d9 | 2015-02-09 14:19:54 -0800 | [diff] [blame] | 66 | for (size_t i = 0; i < nodeInfos.size(); i++) { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 67 | Roster_iterator it = m_roster.find(nodeInfos[i].sessionPrefix); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 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(); |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 72 | std::string s = boost::lexical_cast<std::string>(p->getSeqNo()); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 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(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 76 | item->setPos(rectBR.x() + (rectBR.width() - textBR.width())/2, |
| 77 | rectBR.y() + (rectBR.height() - textBR.height())/2); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 80 | m_displayRootDigest->setPlainText(digest); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
| 84 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 85 | DigestTreeScene::updateNick(QString sessionPrefix, QString nick) |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 86 | { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 87 | Roster_iterator it = m_roster.find(sessionPrefix); |
| 88 | if (it != m_roster.end()) { |
| 89 | DisplayUserPtr p = it.value(); |
| 90 | if (nick != p->getNick()) { |
| 91 | p->setNick(nick); |
| 92 | QGraphicsTextItem *nickItem = p->getNickTextItem(); |
| 93 | QGraphicsRectItem *nickRectItem = p->getNickRectItem(); |
| 94 | nickItem->setPlainText(p->getNick()); |
| 95 | QRectF rectBR = nickRectItem->boundingRect(); |
| 96 | QRectF nickBR = nickItem->boundingRect(); |
| 97 | nickItem->setPos(rectBR.x() + (rectBR.width() - nickBR.width())/2, rectBR.y() + 5); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | DigestTreeScene::messageReceived(QString sessionPrefix) |
| 104 | { |
| 105 | Roster_iterator it = m_roster.find(sessionPrefix); |
| 106 | if (it != m_roster.end()) { |
| 107 | DisplayUserPtr p = it.value(); |
| 108 | |
| 109 | reDrawNode(p, Qt::red); |
| 110 | |
| 111 | if (m_previouslyUpdatedUser != DisplayUserNullPtr && m_previouslyUpdatedUser != p) { |
| 112 | reDrawNode(m_previouslyUpdatedUser, Qt::darkBlue); |
| 113 | } |
| 114 | |
| 115 | m_previouslyUpdatedUser = p; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | DigestTreeScene::clearAll() |
| 121 | { |
| 122 | clear(); |
| 123 | m_roster.clear(); |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | DigestTreeScene::removeNode(const QString sessionPrefix) |
| 128 | { |
| 129 | m_roster.remove(sessionPrefix); |
| 130 | plot(m_rootDigest); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Zhenkai Zhu | 9036e03 | 2012-09-27 20:59:33 -0700 | [diff] [blame] | 133 | QStringList |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 134 | DigestTreeScene::getRosterList() |
| 135 | { |
Zhenkai Zhu | 9036e03 | 2012-09-27 20:59:33 -0700 | [diff] [blame] | 136 | QStringList rosterList; |
| 137 | RosterIterator it(m_roster); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 138 | while (it.hasNext()) { |
Zhenkai Zhu | 9036e03 | 2012-09-27 20:59:33 -0700 | [diff] [blame] | 139 | it.next(); |
| 140 | DisplayUserPtr p = it.value(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 141 | if (p != DisplayUserNullPtr) { |
Zhenkai Zhu | 9036e03 | 2012-09-27 20:59:33 -0700 | [diff] [blame] | 142 | rosterList << "- " + p->getNick(); |
| 143 | } |
| 144 | } |
| 145 | return rosterList; |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 148 | QStringList |
| 149 | DigestTreeScene::getRosterPrefixList() |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 150 | { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 151 | QStringList prefixList; |
| 152 | RosterIterator it(m_roster); |
| 153 | while (it.hasNext()) { |
| 154 | it.next(); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 155 | DisplayUserPtr p = it.value(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 156 | if (p != DisplayUserNullPtr) { |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 157 | prefixList << "- " + p->getPrefix(); |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 158 | } |
| 159 | } |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 160 | return prefixList; |
| 161 | } |
Zhenkai Zhu | 86df741 | 2012-09-27 16:30:20 -0700 | [diff] [blame] | 162 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 163 | void |
| 164 | DigestTreeScene::plot(QString rootDigest) |
| 165 | { |
| 166 | clear(); |
Zhenkai Zhu | 6082ede | 2012-09-27 17:28:46 -0700 | [diff] [blame] | 167 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 168 | shared_ptr<TreeLayout> layout(new OneLevelTreeLayout()); |
| 169 | layout->setSiblingDistance(100); |
| 170 | layout->setLevelDistance(100); |
Zhenkai Zhu | 716fe85 | 2012-10-08 18:27:55 -0700 | [diff] [blame] | 171 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 172 | std::vector<TreeLayout::Coordinate> childNodesCo(m_roster.size()); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 173 | layout->setOneLevelLayout(childNodesCo); |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 174 | plotEdge(childNodesCo, NODE_SIZE); |
| 175 | plotNode(childNodesCo, rootDigest, NODE_SIZE); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 176 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 177 | m_previouslyUpdatedUser = DisplayUserNullPtr; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 181 | DigestTreeScene::plotEdge(const std::vector<TreeLayout::Coordinate> &childNodesCo, int nodeSize) |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 182 | { |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 183 | int n = childNodesCo.size(); |
| 184 | for (int i = 0; i < n; i++) { |
| 185 | double x1 = 0.0, y1 = 0.0; |
| 186 | double x2 = childNodesCo[i].x, y2 = childNodesCo[i].y; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 187 | QPointF src(x1 + nodeSize/2, y1 + nodeSize/2); |
| 188 | QPointF dest(x2 + nodeSize/2, y2 + nodeSize/2); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 189 | QLineF line(src, dest); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 190 | double angle = ::acos(line.dx() / line.length()); |
| 191 | |
| 192 | double arrowSize = 10; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 193 | QPointF sourceArrowP0 = src + QPointF((nodeSize/2 + 10) * line.dx() / line.length(), |
| 194 | (nodeSize/2 +10) * line.dy() / line.length()); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 195 | QPointF sourceArrowP1 = sourceArrowP0 + QPointF(cos(angle + Pi / 3 - Pi/2) * arrowSize, |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 196 | sin(angle + Pi / 3 - Pi/2) * arrowSize); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 197 | QPointF sourceArrowP2 = sourceArrowP0 + QPointF(cos(angle + Pi - Pi / 3 - Pi/2) * arrowSize, |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 198 | sin(angle + Pi - Pi / 3 - Pi/2) * arrowSize); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 199 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 200 | addLine(QLineF(sourceArrowP0, dest), QPen(Qt::black)); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 201 | addPolygon(QPolygonF() << sourceArrowP0<< sourceArrowP1 << |
| 202 | sourceArrowP2, QPen(Qt::black), QBrush(Qt::black)); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 207 | DigestTreeScene::plotNode(const std::vector<TreeLayout::Coordinate>& childNodesCo, |
| 208 | QString digest, int nodeSize) |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 209 | { |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 210 | RosterIterator it(m_roster); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 211 | int n = childNodesCo.size(); |
| 212 | int rim = 3; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame] | 213 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 214 | // plot root node |
| 215 | QRectF rootBoundingRect(0, 0, nodeSize, nodeSize); |
| 216 | QRectF rootInnerBoundingRect(rim, rim, nodeSize - rim * 2, nodeSize - rim * 2); |
| 217 | addRect(rootBoundingRect, QPen(Qt::black), QBrush(Qt::darkRed)); |
| 218 | addRect(rootInnerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray)); |
Zhenkai Zhu | c547061 | 2012-06-05 12:28:59 -0700 | [diff] [blame] | 219 | QRectF digestRect(- 5.5 * nodeSize , - nodeSize, 12 * nodeSize, 30); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 220 | addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); |
Zhenkai Zhu | 27df8d4 | 2012-06-05 12:04:04 -0700 | [diff] [blame] | 221 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 222 | QGraphicsTextItem *digestItem = addText(digest); |
| 223 | QRectF digestBoundingRect = digestItem->boundingRect(); |
Zhenkai Zhu | 27df8d4 | 2012-06-05 12:04:04 -0700 | [diff] [blame] | 224 | digestItem->setDefaultTextColor(Qt::black); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 225 | digestItem->setFont(QFont("Cursive", 12, QFont::Bold)); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 226 | digestItem->setPos(- 4.5 * nodeSize + (12 * nodeSize - digestBoundingRect.width()) / 2, |
| 227 | - nodeSize + 5); |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 228 | m_displayRootDigest = digestItem; |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 229 | |
| 230 | // plot child nodes |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 231 | for (int i = 0; i < n; i++) { |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 232 | if (it.hasNext()) |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 233 | it.next(); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 234 | else |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 235 | abort(); |
Zhenkai Zhu | d13acd0 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 236 | |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 237 | double x = childNodesCo[i].x; |
| 238 | double y = childNodesCo[i].y; |
| 239 | QRectF boundingRect(x, y, nodeSize, nodeSize); |
| 240 | QRectF innerBoundingRect(x + rim, y + rim, nodeSize - rim * 2, nodeSize - rim * 2); |
| 241 | DisplayUserPtr p = it.value(); |
| 242 | QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue)); |
| 243 | p->setRimRectItem(rectItem); |
| 244 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 245 | QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, |
| 246 | QPen(Qt::black), |
| 247 | QBrush(Qt::lightGray)); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 248 | p->setInnerRectItem(innerRectItem); |
| 249 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 250 | std::string s = boost::lexical_cast<std::string>(p->getSeqNo()); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 251 | QGraphicsTextItem *seqItem = addText(s.c_str()); |
| 252 | seqItem->setFont(QFont("Cursive", 12, QFont::Bold)); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 253 | QRectF seqBoundingRect = seqItem->boundingRect(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 254 | seqItem->setPos(x + nodeSize / 2 - seqBoundingRect.width() / 2, |
| 255 | y + nodeSize / 2 - seqBoundingRect.height() / 2); |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 256 | p->setSeqTextItem(seqItem); |
| 257 | |
| 258 | QRectF textRect(x - nodeSize / 2, y + nodeSize, 2 * nodeSize, 30); |
| 259 | QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); |
| 260 | p->setNickRectItem(nickRectItem); |
| 261 | QGraphicsTextItem *nickItem = addText(p->getNick()); |
| 262 | QRectF textBoundingRect = nickItem->boundingRect(); |
| 263 | nickItem->setDefaultTextColor(Qt::white); |
| 264 | nickItem->setFont(QFont("Cursive", 12, QFont::Bold)); |
| 265 | nickItem->setPos(x + nodeSize / 2 - textBoundingRect.width() / 2, y + nodeSize + 5); |
| 266 | p->setNickTextItem(nickItem); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 267 | } |
Zhenkai Zhu | 21d75f9 | 2012-06-04 21:23:34 -0700 | [diff] [blame] | 268 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 271 | void |
| 272 | DigestTreeScene::reDrawNode(DisplayUserPtr p, QColor rimColor) |
| 273 | { |
| 274 | QGraphicsRectItem *rimItem = p->getRimRectItem(); |
| 275 | rimItem->setBrush(QBrush(rimColor)); |
| 276 | QGraphicsRectItem *innerItem = p->getInnerRectItem(); |
| 277 | innerItem->setBrush(QBrush(Qt::lightGray)); |
| 278 | QGraphicsTextItem *seqTextItem = p->getSeqTextItem(); |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 279 | std::string s = boost::lexical_cast<std::string>(p->getSeqNo()); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 280 | seqTextItem->setPlainText(s.c_str()); |
| 281 | QRectF textBR = seqTextItem->boundingRect(); |
| 282 | QRectF innerBR = innerItem->boundingRect(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 283 | seqTextItem->setPos(innerBR.x() + (innerBR.width() - textBR.width())/2, |
| 284 | innerBR.y() + (innerBR.height() - textBR.height())/2); |
Zhenkai Zhu | 82a6275 | 2012-06-04 17:11:04 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 287 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 288 | |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 289 | #if WAF |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 290 | #include "digest-tree-scene.moc" |
Yingdi Yu | 4212586 | 2014-08-07 17:04:28 -0700 | [diff] [blame] | 291 | // #include "digest-tree-scene.cpp.moc" |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 292 | #endif |