summary refs log tree commit diff
path: root/src/TimelineViewManager.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-26 11:33:26 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-26 11:33:26 +0300
commit43b1bdfe63ea1344627a41f0d1df157aa11a120d (patch)
tree180d98e5faa6be93a709b71156311fe9609404ea /src/TimelineViewManager.cc
parentFix login UX (diff)
downloadnheko-43b1bdfe63ea1344627a41f0d1df157aa11a120d.tar.xz
Remove nick colors
Diffstat (limited to 'src/TimelineViewManager.cc')
-rw-r--r--src/TimelineViewManager.cc240
1 files changed, 112 insertions, 128 deletions
diff --git a/src/TimelineViewManager.cc b/src/TimelineViewManager.cc

index a02e89e9..3cb61889 100644 --- a/src/TimelineViewManager.cc +++ b/src/TimelineViewManager.cc
@@ -30,12 +30,12 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<MatrixClient> client, QW : QStackedWidget(parent) , client_(client) { - setStyleSheet("QWidget { background: #f8fbfe; color: #e8e8e8; border: none;}"); + setStyleSheet("QWidget { background: #f8fbfe; color: #e8e8e8; border: none;}"); - connect(client_.data(), - SIGNAL(messageSent(const QString &, const QString &, int)), - this, - SLOT(messageSent(const QString &, const QString &, int))); + connect(client_.data(), + SIGNAL(messageSent(const QString &, const QString &, int)), + this, + SLOT(messageSent(const QString &, const QString &, int))); } TimelineViewManager::~TimelineViewManager() @@ -45,195 +45,179 @@ TimelineViewManager::~TimelineViewManager() void TimelineViewManager::messageSent(const QString &event_id, const QString &roomid, int txn_id) { - // We save the latest valid transaction ID for later use. - QSettings settings; - settings.setValue("client/transaction_id", txn_id + 1); + // We save the latest valid transaction ID for later use. + QSettings settings; + settings.setValue("client/transaction_id", txn_id + 1); - auto view = views_[roomid]; - view->updatePendingMessage(txn_id, event_id); + auto view = views_[roomid]; + view->updatePendingMessage(txn_id, event_id); } void TimelineViewManager::sendTextMessage(const QString &msg) { - auto room_id = active_room_; - auto view = views_[room_id]; + auto room_id = active_room_; + auto view = views_[room_id]; - view->addUserTextMessage(msg, client_->transactionId()); - client_->sendTextMessage(room_id, msg); + view->addUserTextMessage(msg, client_->transactionId()); + client_->sendTextMessage(room_id, msg); } void TimelineViewManager::clearAll() { - NICK_COLORS.clear(); + for (auto view : views_) + removeWidget(view.data()); - for (auto view : views_) - removeWidget(view.data()); - - views_.clear(); + views_.clear(); } void TimelineViewManager::initialize(const Rooms &rooms) { - for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) { - auto roomid = it.key(); + for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) { + auto roomid = it.key(); - // Create a history view with the room events. - TimelineView *view = new TimelineView(it.value().timeline(), client_, it.key()); - views_.insert(it.key(), QSharedPointer<TimelineView>(view)); + // Create a history view with the room events. + TimelineView *view = new TimelineView(it.value().timeline(), client_, it.key()); + views_.insert(it.key(), QSharedPointer<TimelineView>(view)); - connect(view, - &TimelineView::updateLastTimelineMessage, - this, - &TimelineViewManager::updateRoomsLastMessage); + connect(view, + &TimelineView::updateLastTimelineMessage, + this, + &TimelineViewManager::updateRoomsLastMessage); - // Add the view in the widget stack. - addWidget(view); - } + // Add the view in the widget stack. + addWidget(view); + } } void TimelineViewManager::initialize(const QList<QString> &rooms) { - for (const auto &roomid : rooms) { - // Create a history view without any events. - TimelineView *view = new TimelineView(client_, roomid); - views_.insert(roomid, QSharedPointer<TimelineView>(view)); + for (const auto &roomid : rooms) { + // Create a history view without any events. + TimelineView *view = new TimelineView(client_, roomid); + views_.insert(roomid, QSharedPointer<TimelineView>(view)); - connect(view, - &TimelineView::updateLastTimelineMessage, - this, - &TimelineViewManager::updateRoomsLastMessage); + connect(view, + &TimelineView::updateLastTimelineMessage, + this, + &TimelineViewManager::updateRoomsLastMessage); - // Add the view in the widget stack. - addWidget(view); - } + // Add the view in the widget stack. + addWidget(view); + } } void TimelineViewManager::sync(const Rooms &rooms) { - for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) { - auto roomid = it.key(); + for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) { + auto roomid = it.key(); - if (!views_.contains(roomid)) { - qDebug() << "Ignoring event from unknown room" << roomid; - continue; - } + if (!views_.contains(roomid)) { + qDebug() << "Ignoring event from unknown room" << roomid; + continue; + } - auto view = views_.value(roomid); + auto view = views_.value(roomid); - int msgs_added = view->addEvents(it.value().timeline()); + int msgs_added = view->addEvents(it.value().timeline()); - if (msgs_added > 0) { - // TODO: When the app window gets active the current - // unread count (if any) should be cleared. - auto isAppActive = QApplication::activeWindow() != nullptr; + if (msgs_added > 0) { + // TODO: When the app window gets active the current + // unread count (if any) should be cleared. + auto isAppActive = QApplication::activeWindow() != nullptr; - if (roomid != active_room_ || !isAppActive) - emit unreadMessages(roomid, msgs_added); - } - } + if (roomid != active_room_ || !isAppActive) + emit unreadMessages(roomid, msgs_added); + } + } } void TimelineViewManager::setHistoryView(const QString &room_id) { - if (!views_.contains(room_id)) { - qDebug() << "Room ID from RoomList is not present in ViewManager" << room_id; - return; - } + if (!views_.contains(room_id)) { + qDebug() << "Room ID from RoomList is not present in ViewManager" << room_id; + return; + } - active_room_ = room_id; - auto view = views_.value(room_id); + active_room_ = room_id; + auto view = views_.value(room_id); - setCurrentWidget(view.data()); + setCurrentWidget(view.data()); - view->fetchHistory(); - view->scrollDown(); + view->fetchHistory(); + view->scrollDown(); } -QMap<QString, QString> TimelineViewManager::NICK_COLORS; QMap<QString, QString> TimelineViewManager::DISPLAY_NAMES; QString TimelineViewManager::chooseRandomColor() { - std::random_device random_device; - std::mt19937 engine{ random_device() }; - std::uniform_real_distribution<float> dist(0, 1); - - float hue = dist(engine); - float saturation = 0.9; - float value = 0.7; + std::random_device random_device; + std::mt19937 engine{ random_device() }; + std::uniform_real_distribution<float> dist(0, 1); - int hue_i = hue * 6; + float hue = dist(engine); + float saturation = 0.9; + float value = 0.7; - float f = hue * 6 - hue_i; + int hue_i = hue * 6; - float p = value * (1 - saturation); - float q = value * (1 - f * saturation); - float t = value * (1 - (1 - f) * saturation); + float f = hue * 6 - hue_i; - float r = 0; - float g = 0; - float b = 0; + float p = value * (1 - saturation); + float q = value * (1 - f * saturation); + float t = value * (1 - (1 - f) * saturation); - if (hue_i == 0) { - r = value; - g = t; - b = p; - } else if (hue_i == 1) { - r = q; - g = value; - b = p; - } else if (hue_i == 2) { - r = p; - g = value; - b = t; - } else if (hue_i == 3) { - r = p; - g = q; - b = value; - } else if (hue_i == 4) { - r = t; - g = p; - b = value; - } else if (hue_i == 5) { - r = value; - g = p; - b = q; - } + float r = 0; + float g = 0; + float b = 0; - int ri = r * 256; - int gi = g * 256; - int bi = b * 256; + if (hue_i == 0) { + r = value; + g = t; + b = p; + } else if (hue_i == 1) { + r = q; + g = value; + b = p; + } else if (hue_i == 2) { + r = p; + g = value; + b = t; + } else if (hue_i == 3) { + r = p; + g = q; + b = value; + } else if (hue_i == 4) { + r = t; + g = p; + b = value; + } else if (hue_i == 5) { + r = value; + g = p; + b = q; + } - QColor color(ri, gi, bi); - - return color.name(); -} - -QString -TimelineViewManager::getUserColor(const QString &userid) -{ - auto color = NICK_COLORS.value(userid); + int ri = r * 256; + int gi = g * 256; + int bi = b * 256; - if (color.isEmpty()) { - color = chooseRandomColor(); - NICK_COLORS.insert(userid, color); - } + QColor color(ri, gi, bi); - return color; + return color.name(); } QString TimelineViewManager::displayName(const QString &userid) { - if (DISPLAY_NAMES.contains(userid)) - return DISPLAY_NAMES.value(userid); + if (DISPLAY_NAMES.contains(userid)) + return DISPLAY_NAMES.value(userid); - return userid; + return userid; }