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