From 237c7ad114b7c3d6960fdaf712b600e715eff082 Mon Sep 17 00:00:00 2001 From: redsky17 Date: Sun, 20 Jan 2019 04:43:48 +0000 Subject: Author Color Fixes Author color is now cached so that it will not be re-calculated each time a new message is posted. This cache gets cleared when the theme is changed. Additionally, the author color is now automatically refreshed when the theme is changed, fixing the issue where you had to change rooms before the colors would switch. --- src/MainWindow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 55dbba34..450eb71a 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -112,7 +112,11 @@ MainWindow::MainWindow(QWidget *parent) connect( userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool))); - + connect(userSettingsPage_, &UserSettingsPage::themeChanged, this, [this]() { + utils::clearAuthorColors(); + }); + connect( + userSettingsPage_, &UserSettingsPage::themeChanged, chat_page_, &ChatPage::themeChanged); connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, -- cgit 1.5.1 From d70bc94f61d67ff619bcd15e25ac7dac678d2850 Mon Sep 17 00:00:00 2001 From: redsky17 Date: Thu, 24 Jan 2019 04:54:35 +0000 Subject: Fix lambda capture error --- src/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 450eb71a..51b23fe2 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -112,7 +112,7 @@ MainWindow::MainWindow(QWidget *parent) connect( userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool))); - connect(userSettingsPage_, &UserSettingsPage::themeChanged, this, [this]() { + connect(userSettingsPage_, &UserSettingsPage::themeChanged, this, []() { utils::clearAuthorColors(); }); connect( -- cgit 1.5.1 From 2ba51c821e3893499ba08df1d7f442869933a286 Mon Sep 17 00:00:00 2001 From: redsky17 Date: Sat, 26 Jan 2019 02:53:43 +0000 Subject: Update user colors to use Cache vs Utils User colors are now stored in cache. This is consistent with other similar variables. I think there's a bug right now where it doesn't properly refresh colors for the TimeLineItem when the theme is changed. --- src/Cache.cpp | 29 +++++++++++++++++++++++++++++ src/Cache.h | 6 ++++++ src/MainWindow.cpp | 2 +- src/Utils.cpp | 22 ---------------------- src/Utils.h | 12 ------------ src/timeline/TimelineItem.cpp | 12 +++++++----- 6 files changed, 43 insertions(+), 40 deletions(-) (limited to 'src/MainWindow.cpp') diff --git a/src/Cache.cpp b/src/Cache.cpp index a9094e2d..d6a7b509 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -2059,6 +2059,7 @@ Cache::roomMembers(const std::string &room_id) QHash Cache::DisplayNames; QHash Cache::AvatarUrls; +QHash Cache::UserColors; QString Cache::displayName(const QString &room_id, const QString &user_id) @@ -2090,6 +2091,16 @@ Cache::avatarUrl(const QString &room_id, const QString &user_id) return QString(); } +QString +Cache::userColor(const QString &user_id) +{ + if (UserColors.contains(user_id)) { + return UserColors[user_id]; + } + + return QString(); +} + void Cache::insertDisplayName(const QString &room_id, const QString &user_id, @@ -2119,3 +2130,21 @@ Cache::removeAvatarUrl(const QString &room_id, const QString &user_id) auto fmt = QString("%1 %2").arg(room_id).arg(user_id); AvatarUrls.remove(fmt); } + +void +Cache::insertUserColor(const QString &user_id, const QString &color_name) +{ + UserColors.insert(user_id, color_name); +} + +void +Cache::removeUserColor(const QString &user_id) +{ + UserColors.remove(user_id); +} + +void +Cache::clearUserColors() +{ + UserColors.clear(); +} \ No newline at end of file diff --git a/src/Cache.h b/src/Cache.h index b730d6fc..1a133618 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -282,13 +282,16 @@ public: static QHash DisplayNames; static QHash AvatarUrls; + static QHash UserColors; static std::string displayName(const std::string &room_id, const std::string &user_id); static QString displayName(const QString &room_id, const QString &user_id); static QString avatarUrl(const QString &room_id, const QString &user_id); + static QString userColor(const QString &user_id); static void removeDisplayName(const QString &room_id, const QString &user_id); static void removeAvatarUrl(const QString &room_id, const QString &user_id); + static void removeUserColor(const QString &user_id); static void insertDisplayName(const QString &room_id, const QString &user_id, @@ -296,6 +299,9 @@ public: static void insertAvatarUrl(const QString &room_id, const QString &user_id, const QString &avatar_url); + static void insertUserColor(const QString &user_id, const QString &color_name); + + static void clearUserColors(); //! Load saved data for the display names & avatars. void populateMembers(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 51b23fe2..2e062c0c 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -113,7 +113,7 @@ MainWindow::MainWindow(QWidget *parent) connect( userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool))); connect(userSettingsPage_, &UserSettingsPage::themeChanged, this, []() { - utils::clearAuthorColors(); + Cache::clearUserColors(); }); connect( userSettingsPage_, &UserSettingsPage::themeChanged, chat_page_, &ChatPage::themeChanged); diff --git a/src/Utils.cpp b/src/Utils.cpp index 66bc86f6..1d1dbeb2 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -513,28 +513,6 @@ utils::luminance(const QColor &col) return lum; } -void -utils::clearAuthorColors() -{ - authorColors_.clear(); -} - -QString -utils::getAuthorColor(const QString &author) -{ - if (authorColors_.contains(author)) { - return authorColors_[author]; - } else { - return ""; - } -} - -void -utils::addAuthorColor(const QString &author, const QString &color) -{ - authorColors_[author] = color; -} - void utils::centerWidget(QWidget *widget, QWidget *parent) { diff --git a/src/Utils.h b/src/Utils.h index b6f89f73..8672e7d4 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -246,18 +246,6 @@ computeContrast(const qreal &one, const qreal &two); qreal luminance(const QColor &col); -//! Clear the author color hashmap -void -clearAuthorColors(); - -//! Get the given QString from the authorColors hash -QString -getAuthorColor(const QString &author); - -//! Put the given QString into the authorColor hash -void -addAuthorColor(const QString &author, const QString &color); - //! Center a widget in relation to another widget. void centerWidget(QWidget *widget, QWidget *parent); diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index 103bd6d6..11341b92 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -608,15 +608,17 @@ void TimelineItem::refreshAuthorColor() { if (userName_) { - QString userColor = utils::getAuthorColor(userName_->text()); + QString userColor = Cache::userColor(userName_->text()); if (userColor.isEmpty()) { + // This attempts to refresh this item since it's not drawn + // which allows us to get the background color accurately. qApp->style()->polish(this); // generate user's unique color. auto backCol = backgroundColor().name(); userColor = utils::generateContrastingHexColor(userName_->text(), backCol); - utils::addAuthorColor(userName_->text(), userColor); + Cache::insertUserColor(userName_->text(), userColor); + userName_->setStyleSheet("QLabel { color : " + userColor + "; }"); } - userName_->setStyleSheet("QLabel { color : " + userColor + "; }"); } } // The username/timestamp is displayed along with the message body. @@ -655,13 +657,13 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam // TimelineItem isn't displayed. This forces the QSS to get // loaded. - QString userColor = utils::getAuthorColor(user_id); + QString userColor = Cache::userColor(user_id); if (userColor.isEmpty()) { qApp->style()->polish(this); // generate user's unique color. auto backCol = backgroundColor().name(); userColor = utils::generateContrastingHexColor(user_id, backCol); - utils::addAuthorColor(user_id, userColor); + Cache::insertUserColor(user_id, userColor); } userName_->setStyleSheet("QLabel { color : " + userColor + "; }"); -- cgit 1.5.1 From 6c31f5fe7a417ba904b7c31aa5065363a8f9d94b Mon Sep 17 00:00:00 2001 From: redsky17 Date: Sat, 26 Jan 2019 18:03:49 +0000 Subject: Add initial support for QtIndenticon Add initial loading of qt jdenticon plugin: https://github.com/redsky17/qt-jdenticon Currently, the library's functionality has not been integrated into the rest of nheko. Next step is to add a configuration item in the User Settings and use the plugin to generate avatars for users without their own picture. These avatars should be cached in the Cache object. --- CMakeLists.txt | 3 +++ includes/jdenticoninterface.h | 17 +++++++++++++++++ src/MainWindow.cpp | 29 +++++++++++++++++++++++++++++ src/MainWindow.h | 6 ++++++ 4 files changed, 55 insertions(+) create mode 100644 includes/jdenticoninterface.h (limited to 'src/MainWindow.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 515e49d8..45a63829 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,6 +282,9 @@ include_directories(SYSTEM ${TWEENY_INCLUDE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/src) include_directories(${Boost_INCLUDE_DIRS}) +# local inclue directory +include_directories(includes) + qt5_wrap_cpp(MOC_HEADERS # Dialogs src/dialogs/CreateRoom.h diff --git a/includes/jdenticoninterface.h b/includes/jdenticoninterface.h new file mode 100644 index 00000000..2108a726 --- /dev/null +++ b/includes/jdenticoninterface.h @@ -0,0 +1,17 @@ +#ifndef JDENTICONINTERFACE_H +#define JDENTICONINTERFACE_H + +#include + +class JdenticonInterface +{ +public: + virtual ~JdenticonInterface() {} + virtual QString generate(const QString &message, uint16_t size) = 0; +}; + +#define JdenticonInterface_iid "redsky17.Qt.JdenticonInterface" + +Q_DECLARE_INTERFACE(JdenticonInterface, JdenticonInterface_iid) + +#endif // JDENTICONINTERFACE_H diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 2e062c0c..8da7d659 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -166,6 +167,10 @@ MainWindow::MainWindow(QWidget *parent) showChatPage(); } + + if (loadJdenticonPlugin()) { + nhlog::ui()->info("loaded jdenticon."); + } } void @@ -479,3 +484,27 @@ MainWindow::showDialog(QWidget *dialog) dialog->raise(); dialog->show(); } + +bool +MainWindow::loadJdenticonPlugin() +{ + QDir pluginsDir(qApp->applicationDirPath()); + + bool plugins = pluginsDir.cd("plugins"); + if (plugins) { + foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { + QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); + QObject *plugin = pluginLoader.instance(); + if (plugin) { + jdenticonInteface_ = qobject_cast(plugin); + if (jdenticonInteface_) { + nhlog::ui()->info("Found jdenticon plugin."); + return true; + } + } + } + } + + nhlog::ui()->info("jdenticon plugin not found."); + return false; +} \ No newline at end of file diff --git a/src/MainWindow.h b/src/MainWindow.h index 2336a929..1aadbf4d 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -31,6 +31,8 @@ #include "dialogs/UserProfile.h" #include "ui/OverlayModal.h" +#include "jdenticoninterface.h" + class ChatPage; class LoadingIndicator; class OverlayModal; @@ -129,6 +131,8 @@ private slots: void removeOverlayProgressBar(); private: + bool loadJdenticonPlugin(); + void showDialog(QWidget *dialog); bool hasActiveUser(); void restoreWindowSize(); @@ -158,4 +162,6 @@ private: //! Overlay modal used to project other widgets. OverlayModal *modal_ = nullptr; LoadingIndicator *spinner_ = nullptr; + + JdenticonInterface *jdenticonInteface_ = nullptr; }; -- cgit 1.5.1 From faff23ed386113f26d422ad10448d3b9e4951bf5 Mon Sep 17 00:00:00 2001 From: redsky17 Date: Sat, 26 Jan 2019 18:11:30 +0000 Subject: Fix lint issues in last commit --- src/MainWindow.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 8da7d659..7d9a8902 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -17,9 +17,9 @@ #include #include +#include #include #include -#include #include @@ -488,23 +488,23 @@ MainWindow::showDialog(QWidget *dialog) bool MainWindow::loadJdenticonPlugin() { - QDir pluginsDir(qApp->applicationDirPath()); - - bool plugins = pluginsDir.cd("plugins"); - if (plugins) { - foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { - QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); - QObject *plugin = pluginLoader.instance(); - if (plugin) { - jdenticonInteface_ = qobject_cast(plugin); - if (jdenticonInteface_) { - nhlog::ui()->info("Found jdenticon plugin."); - return true; + QDir pluginsDir(qApp->applicationDirPath()); + + bool plugins = pluginsDir.cd("plugins"); + if (plugins) { + foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { + QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); + QObject *plugin = pluginLoader.instance(); + if (plugin) { + jdenticonInteface_ = qobject_cast(plugin); + if (jdenticonInteface_) { + nhlog::ui()->info("Found jdenticon plugin."); + return true; + } } } } - } - nhlog::ui()->info("jdenticon plugin not found."); - return false; + nhlog::ui()->info("jdenticon plugin not found."); + return false; } \ No newline at end of file -- cgit 1.5.1