Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -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 | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 12 | #ifndef CHRONOCHAT_DIGEST_TREE_SCENE_HPP |
| 13 | #define CHRONOCHAT_DIGEST_TREE_SCENE_HPP |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 14 | |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame^] | 15 | #include <QGraphicsScene> |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 16 | #include <QColor> |
| 17 | #include <QMap> |
| 18 | |
| 19 | #ifndef Q_MOC_RUN |
| 20 | #include "tree-layout.hpp" |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 21 | #include "chat-dialog-backend.hpp" |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 22 | #include <ctime> |
| 23 | #include <vector> |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 24 | #endif |
| 25 | |
| 26 | const int FRESHNESS = 60; |
| 27 | |
| 28 | class QGraphicsTextItem; |
| 29 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 30 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 31 | |
| 32 | class User; |
| 33 | class DisplayUser; |
Yingdi Yu | 1cc45d9 | 2015-02-09 14:19:54 -0800 | [diff] [blame] | 34 | typedef std::shared_ptr<DisplayUser> DisplayUserPtr; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 35 | typedef QMap<QString, DisplayUserPtr> Roster; |
| 36 | typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator; |
| 37 | typedef QMapIterator<QString, DisplayUserPtr> RosterIterator; |
| 38 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 39 | static DisplayUserPtr DisplayUserNullPtr; |
| 40 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 41 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 42 | class DigestTreeScene : public QGraphicsScene |
| 43 | { |
| 44 | Q_OBJECT |
| 45 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 46 | public: |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame^] | 47 | DigestTreeScene(QObject *parent = 0); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 48 | |
| 49 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 50 | processSyncUpdate(const std::vector<chronochat::NodeInfo>& nodeInfos, |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 51 | const QString& digest); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 52 | |
| 53 | void |
Qiuhan Ding | 7a4e7ef | 2015-02-03 20:25:50 -0800 | [diff] [blame] | 54 | updateNode(QString sessionPrefix, QString nick, uint64_t seqNo); |
| 55 | |
| 56 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 57 | updateNick(QString sessionPrefix, QString nick); |
| 58 | |
| 59 | void |
| 60 | messageReceived(QString sessionPrefix); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 61 | |
| 62 | void |
| 63 | clearAll(); |
| 64 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 65 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 66 | removeNode(const QString sessionPrefix); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 67 | |
| 68 | QStringList |
| 69 | getRosterList(); |
| 70 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 71 | QStringList |
| 72 | getRosterPrefixList(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 73 | |
| 74 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 75 | plot(QString rootDigest); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 79 | plotEdge(const std::vector<chronochat::TreeLayout::Coordinate>& v, int nodeSize); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 80 | |
| 81 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 82 | plotNode(const std::vector<chronochat::TreeLayout::Coordinate>& v, QString digest, int nodeSize); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 83 | |
| 84 | void |
| 85 | reDrawNode(DisplayUserPtr p, QColor rimColor); |
| 86 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 87 | private: |
| 88 | Roster m_roster; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 89 | |
| 90 | QString m_rootDigest; |
| 91 | QGraphicsTextItem* m_displayRootDigest; |
| 92 | |
| 93 | DisplayUserPtr m_previouslyUpdatedUser; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | class User |
| 97 | { |
| 98 | public: |
| 99 | User() |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 100 | { |
| 101 | } |
| 102 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 103 | User(QString n, QString p) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 104 | : m_nick(n) |
| 105 | , m_prefix(p) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 106 | { |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | setNick(QString nick) |
| 111 | { |
| 112 | m_nick = nick; |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | setPrefix(QString prefix) |
| 117 | { |
| 118 | m_prefix = prefix; |
| 119 | } |
| 120 | |
| 121 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 122 | setSeq(chronosync::SeqNo seq) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 123 | { |
| 124 | m_seq = seq; |
| 125 | } |
| 126 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 127 | QString |
| 128 | getNick() |
| 129 | { |
| 130 | return m_nick; |
| 131 | } |
| 132 | |
| 133 | QString getPrefix() |
| 134 | { |
| 135 | return m_prefix; |
| 136 | } |
| 137 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 138 | chronosync::SeqNo |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 139 | getSeqNo() |
| 140 | { |
| 141 | return m_seq; |
| 142 | } |
| 143 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 144 | private: |
| 145 | QString m_nick; |
| 146 | QString m_prefix; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 147 | chronosync::SeqNo m_seq; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | class DisplayUser : public User |
| 151 | { |
| 152 | public: |
| 153 | DisplayUser() |
| 154 | : m_seqTextItem(NULL) |
| 155 | , m_nickTextItem(NULL) |
| 156 | , m_rimRectItem(NULL) |
| 157 | { |
| 158 | } |
| 159 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 160 | DisplayUser(QString n, QString p) |
| 161 | : User(n, p) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 162 | , m_seqTextItem(NULL) |
| 163 | , m_nickTextItem(NULL) |
| 164 | , m_rimRectItem(NULL) |
| 165 | { |
| 166 | } |
| 167 | |
| 168 | QGraphicsTextItem* |
| 169 | getSeqTextItem() |
| 170 | { |
| 171 | return m_seqTextItem; |
| 172 | } |
| 173 | |
| 174 | QGraphicsTextItem* |
| 175 | getNickTextItem() |
| 176 | { |
| 177 | return m_nickTextItem; |
| 178 | } |
| 179 | |
| 180 | QGraphicsRectItem* |
| 181 | getRimRectItem() |
| 182 | { |
| 183 | return m_rimRectItem; |
| 184 | } |
| 185 | |
| 186 | QGraphicsRectItem* |
| 187 | getInnerRectItem() |
| 188 | { |
| 189 | return m_innerRectItem; |
| 190 | } |
| 191 | |
| 192 | QGraphicsRectItem* |
| 193 | getNickRectItem() |
| 194 | { |
| 195 | return m_nickRectItem; |
| 196 | } |
| 197 | |
| 198 | void |
| 199 | setSeqTextItem(QGraphicsTextItem* item) |
| 200 | { |
| 201 | m_seqTextItem = item; |
| 202 | } |
| 203 | |
| 204 | void |
| 205 | setNickTextItem(QGraphicsTextItem* item) |
| 206 | { |
| 207 | m_nickTextItem = item; |
| 208 | } |
| 209 | |
| 210 | void |
| 211 | setRimRectItem(QGraphicsRectItem* item) |
| 212 | { |
| 213 | m_rimRectItem = item; |
| 214 | } |
| 215 | |
| 216 | void |
| 217 | setInnerRectItem(QGraphicsRectItem* item) |
| 218 | { |
| 219 | m_innerRectItem = item; |
| 220 | } |
| 221 | |
| 222 | void |
| 223 | setNickRectItem(QGraphicsRectItem* item) |
| 224 | { |
| 225 | m_nickRectItem = item; |
| 226 | } |
| 227 | |
| 228 | private: |
| 229 | QGraphicsTextItem* m_seqTextItem; |
| 230 | QGraphicsTextItem* m_nickTextItem; |
| 231 | QGraphicsRectItem* m_rimRectItem; |
| 232 | QGraphicsRectItem* m_innerRectItem; |
| 233 | QGraphicsRectItem* m_nickRectItem; |
| 234 | }; |
| 235 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 236 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 237 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 238 | #endif // CHRONOCHAT_DIGEST_TREE_SCENE_HPP |