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 | |
| 15 | #include <QtGui/QGraphicsScene> |
| 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: |
| 47 | DigestTreeScene(QWidget *parent = 0); |
| 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 |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 54 | updateNick(QString sessionPrefix, QString nick); |
| 55 | |
| 56 | void |
| 57 | messageReceived(QString sessionPrefix); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 58 | |
| 59 | void |
| 60 | clearAll(); |
| 61 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 62 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 63 | removeNode(const QString sessionPrefix); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 64 | |
| 65 | QStringList |
| 66 | getRosterList(); |
| 67 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 68 | QStringList |
| 69 | getRosterPrefixList(); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 70 | |
| 71 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 72 | plot(QString rootDigest); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 76 | plotEdge(const std::vector<chronochat::TreeLayout::Coordinate>& v, int nodeSize); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 77 | |
| 78 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 79 | plotNode(const std::vector<chronochat::TreeLayout::Coordinate>& v, QString digest, int nodeSize); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 80 | |
| 81 | void |
| 82 | reDrawNode(DisplayUserPtr p, QColor rimColor); |
| 83 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 84 | private: |
| 85 | Roster m_roster; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 86 | |
| 87 | QString m_rootDigest; |
| 88 | QGraphicsTextItem* m_displayRootDigest; |
| 89 | |
| 90 | DisplayUserPtr m_previouslyUpdatedUser; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | class User |
| 94 | { |
| 95 | public: |
| 96 | User() |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 97 | { |
| 98 | } |
| 99 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 100 | User(QString n, QString p) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 101 | : m_nick(n) |
| 102 | , m_prefix(p) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 103 | { |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | setNick(QString nick) |
| 108 | { |
| 109 | m_nick = nick; |
| 110 | } |
| 111 | |
| 112 | void |
| 113 | setPrefix(QString prefix) |
| 114 | { |
| 115 | m_prefix = prefix; |
| 116 | } |
| 117 | |
| 118 | void |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 119 | setSeq(chronosync::SeqNo seq) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 120 | { |
| 121 | m_seq = seq; |
| 122 | } |
| 123 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 124 | QString |
| 125 | getNick() |
| 126 | { |
| 127 | return m_nick; |
| 128 | } |
| 129 | |
| 130 | QString getPrefix() |
| 131 | { |
| 132 | return m_prefix; |
| 133 | } |
| 134 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 135 | chronosync::SeqNo |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 136 | getSeqNo() |
| 137 | { |
| 138 | return m_seq; |
| 139 | } |
| 140 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 141 | private: |
| 142 | QString m_nick; |
| 143 | QString m_prefix; |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 144 | chronosync::SeqNo m_seq; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | class DisplayUser : public User |
| 148 | { |
| 149 | public: |
| 150 | DisplayUser() |
| 151 | : m_seqTextItem(NULL) |
| 152 | , m_nickTextItem(NULL) |
| 153 | , m_rimRectItem(NULL) |
| 154 | { |
| 155 | } |
| 156 | |
Yingdi Yu | d45777b | 2014-10-16 23:54:11 -0700 | [diff] [blame] | 157 | DisplayUser(QString n, QString p) |
| 158 | : User(n, p) |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 159 | , m_seqTextItem(NULL) |
| 160 | , m_nickTextItem(NULL) |
| 161 | , m_rimRectItem(NULL) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | QGraphicsTextItem* |
| 166 | getSeqTextItem() |
| 167 | { |
| 168 | return m_seqTextItem; |
| 169 | } |
| 170 | |
| 171 | QGraphicsTextItem* |
| 172 | getNickTextItem() |
| 173 | { |
| 174 | return m_nickTextItem; |
| 175 | } |
| 176 | |
| 177 | QGraphicsRectItem* |
| 178 | getRimRectItem() |
| 179 | { |
| 180 | return m_rimRectItem; |
| 181 | } |
| 182 | |
| 183 | QGraphicsRectItem* |
| 184 | getInnerRectItem() |
| 185 | { |
| 186 | return m_innerRectItem; |
| 187 | } |
| 188 | |
| 189 | QGraphicsRectItem* |
| 190 | getNickRectItem() |
| 191 | { |
| 192 | return m_nickRectItem; |
| 193 | } |
| 194 | |
| 195 | void |
| 196 | setSeqTextItem(QGraphicsTextItem* item) |
| 197 | { |
| 198 | m_seqTextItem = item; |
| 199 | } |
| 200 | |
| 201 | void |
| 202 | setNickTextItem(QGraphicsTextItem* item) |
| 203 | { |
| 204 | m_nickTextItem = item; |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | setRimRectItem(QGraphicsRectItem* item) |
| 209 | { |
| 210 | m_rimRectItem = item; |
| 211 | } |
| 212 | |
| 213 | void |
| 214 | setInnerRectItem(QGraphicsRectItem* item) |
| 215 | { |
| 216 | m_innerRectItem = item; |
| 217 | } |
| 218 | |
| 219 | void |
| 220 | setNickRectItem(QGraphicsRectItem* item) |
| 221 | { |
| 222 | m_nickRectItem = item; |
| 223 | } |
| 224 | |
| 225 | private: |
| 226 | QGraphicsTextItem* m_seqTextItem; |
| 227 | QGraphicsTextItem* m_nickTextItem; |
| 228 | QGraphicsRectItem* m_rimRectItem; |
| 229 | QGraphicsRectItem* m_innerRectItem; |
| 230 | QGraphicsRectItem* m_nickRectItem; |
| 231 | }; |
| 232 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 233 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 234 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 235 | #endif // CHRONOCHAT_DIGEST_TREE_SCENE_HPP |