diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-05-14 23:35:34 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-05-15 13:05:55 +0200 |
commit | 567fe81ad78e707a4b914976a92c855d4ac8fc45 (patch) | |
tree | b0f4511c6e5c32fedae69a217df5669c0e5eab0e /src/ui | |
parent | Reorganize TimelineView to prepare porting the room list (diff) | |
download | nheko-567fe81ad78e707a4b914976a92c855d4ac8fc45.tar.xz |
Basic header and footer of room list
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/NhekoGlobalObject.cpp | 33 | ||||
-rw-r--r-- | src/ui/NhekoGlobalObject.h | 16 | ||||
-rw-r--r-- | src/ui/Theme.cpp | 117 | ||||
-rw-r--r-- | src/ui/Theme.h | 38 | ||||
-rw-r--r-- | src/ui/ThemeManager.cpp | 39 | ||||
-rw-r--r-- | src/ui/ThemeManager.h | 5 | ||||
-rw-r--r-- | src/ui/UserProfile.cpp | 28 |
7 files changed, 156 insertions, 120 deletions
diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp index e5e6825e..70abfbb8 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp @@ -7,29 +7,50 @@ #include <QDesktopServices> #include <QUrl> +#include "Cache_p.h" #include "ChatPage.h" +#include "Logging.h" #include "UserSettingsPage.h" +#include "Utils.h" Nheko::Nheko() { connect( UserSettings::instance().get(), &UserSettings::themeChanged, this, &Nheko::colorsChanged); + connect(ChatPage::instance(), &ChatPage::contentLoaded, this, &Nheko::updateUserProfile); +} + +void +Nheko::updateUserProfile() +{ + if (cache::client() && cache::client()->isInitialized()) + currentUser_.reset( + new UserProfile("", utils::localUser(), ChatPage::instance()->timelineManager())); + else + currentUser_.reset(); + emit profileChanged(); } QPalette Nheko::colors() const { - return QPalette(); + return Theme::paletteFromTheme(UserSettings::instance()->theme().toStdString()); } QPalette Nheko::inactiveColors() const { - QPalette p; + auto p = colors(); p.setCurrentColorGroup(QPalette::ColorGroup::Inactive); return p; } +Theme +Nheko::theme() const +{ + return Theme(UserSettings::instance()->theme().toStdString()); +} + void Nheko::openLink(QString link) const { @@ -79,3 +100,11 @@ Nheko::openLink(QString link) const QDesktopServices::openUrl(url); } } + +UserProfile * +Nheko::currentUser() const +{ + nhlog::ui()->debug("Profile requested"); + + return currentUser_.get(); +} diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index d952c266..fe645a34 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -7,32 +7,46 @@ #include <QObject> #include <QPalette> +#include "Theme.h" +#include "UserProfile.h" + class Nheko : public QObject { Q_OBJECT Q_PROPERTY(QPalette colors READ colors NOTIFY colorsChanged) Q_PROPERTY(QPalette inactiveColors READ inactiveColors NOTIFY colorsChanged) + Q_PROPERTY(Theme theme READ theme NOTIFY colorsChanged) Q_PROPERTY(int avatarSize READ avatarSize CONSTANT) Q_PROPERTY(int paddingSmall READ paddingSmall CONSTANT) Q_PROPERTY(int paddingMedium READ paddingMedium CONSTANT) Q_PROPERTY(int paddingLarge READ paddingLarge CONSTANT) + Q_PROPERTY(UserProfile *currentUser READ currentUser NOTIFY profileChanged) + public: Nheko(); QPalette colors() const; QPalette inactiveColors() const; + Theme theme() const; int avatarSize() const { return 40; } int paddingSmall() const { return 4; } int paddingMedium() const { return 8; } int paddingLarge() const { return 20; } + UserProfile *currentUser() const; Q_INVOKABLE void openLink(QString link) const; +private slots: + void updateUserProfile(); + signals: void colorsChanged(); -}; + void profileChanged(); +private: + QScopedPointer<UserProfile> currentUser_; +}; diff --git a/src/ui/Theme.cpp b/src/ui/Theme.cpp index 4341bd63..ca2a4ce0 100644 --- a/src/ui/Theme.cpp +++ b/src/ui/Theme.cpp @@ -2,76 +2,65 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -#include <QDebug> - #include "Theme.h" -Theme::Theme(QObject *parent) - : QObject(parent) -{ - setColor("Black", ui::Color::Black); - - setColor("BrightWhite", ui::Color::BrightWhite); - setColor("FadedWhite", ui::Color::FadedWhite); - setColor("MediumWhite", ui::Color::MediumWhite); - - setColor("BrightGreen", ui::Color::BrightGreen); - setColor("DarkGreen", ui::Color::DarkGreen); - setColor("LightGreen", ui::Color::LightGreen); - - setColor("Gray", ui::Color::Gray); - setColor("Red", ui::Color::Red); - setColor("Blue", ui::Color::Blue); - - setColor("Transparent", ui::Color::Transparent); -} - -QColor -Theme::rgba(int r, int g, int b, qreal a) const -{ - QColor color(r, g, b); - color.setAlphaF(a); - - return color; -} +Q_DECLARE_METATYPE(Theme) -QColor -Theme::getColor(const QString &key) const +QPalette +Theme::paletteFromTheme(std::string_view theme) { - if (!colors_.contains(key)) { - qWarning() << "Color with key" << key << "could not be found"; - return QColor(); + [[maybe_unused]] static auto meta = qRegisterMetaType<Theme>("Theme"); + static QPalette original; + if (theme == "light") { + QPalette lightActive( + /*windowText*/ QColor("#333"), + /*button*/ QColor("white"), + /*light*/ QColor(0xef, 0xef, 0xef), + /*dark*/ QColor(110, 110, 110), + /*mid*/ QColor(220, 220, 220), + /*text*/ QColor("#333"), + /*bright_text*/ QColor("#333"), + /*base*/ QColor("#fff"), + /*window*/ QColor("white")); + lightActive.setColor(QPalette::AlternateBase, QColor("#eee")); + lightActive.setColor(QPalette::Highlight, QColor("#38a3d8")); + lightActive.setColor(QPalette::ToolTipBase, lightActive.base().color()); + lightActive.setColor(QPalette::ToolTipText, lightActive.text().color()); + lightActive.setColor(QPalette::Link, QColor("#0077b5")); + lightActive.setColor(QPalette::ButtonText, QColor("#555459")); + return lightActive; + } else if (theme == "dark") { + QPalette darkActive( + /*windowText*/ QColor("#caccd1"), + /*button*/ QColor(0xff, 0xff, 0xff), + /*light*/ QColor("#caccd1"), + /*dark*/ QColor(110, 110, 110), + /*mid*/ QColor("#202228"), + /*text*/ QColor("#caccd1"), + /*bright_text*/ QColor(0xff, 0xff, 0xff), + /*base*/ QColor("#202228"), + /*window*/ QColor("#2d3139")); + darkActive.setColor(QPalette::AlternateBase, QColor("#2d3139")); + darkActive.setColor(QPalette::Highlight, QColor("#38a3d8")); + darkActive.setColor(QPalette::ToolTipBase, darkActive.base().color()); + darkActive.setColor(QPalette::ToolTipText, darkActive.text().color()); + darkActive.setColor(QPalette::Link, QColor("#38a3d8")); + darkActive.setColor(QPalette::ButtonText, "#727274"); + return darkActive; + } else { + return original; } - - return colors_.value(key); } -void -Theme::setColor(const QString &key, const QColor &color) +Theme::Theme(std::string_view theme) { - colors_.insert(key, color); -} - -void -Theme::setColor(const QString &key, ui::Color color) -{ - static const QColor palette[] = { - QColor("#171919"), - - QColor("#EBEBEB"), - QColor("#C9C9C9"), - QColor("#929292"), - - QColor("#1C3133"), - QColor("#577275"), - QColor("#46A451"), - - QColor("#5D6565"), - QColor("#E22826"), - QColor("#81B3A9"), - - rgba(0, 0, 0, 0), - }; - - colors_.insert(key, palette[static_cast<int>(color)]); + auto p = paletteFromTheme(theme); + separator_ = p.mid().color(); + if (theme == "light") { + sidebarBackground_ = QColor("#233649"); + } else if (theme == "dark") { + sidebarBackground_ = QColor("#2d3139"); + } else { + sidebarBackground_ = p.window().color(); + } } diff --git a/src/ui/Theme.h b/src/ui/Theme.h index 3243c076..64bc8273 100644 --- a/src/ui/Theme.h +++ b/src/ui/Theme.h @@ -5,8 +5,7 @@ #pragma once #include <QColor> -#include <QHash> -#include <QObject> +#include <QPalette> namespace ui { enum class AvatarType @@ -60,36 +59,21 @@ enum class ProgressType IndeterminateProgress }; -enum class Color -{ - Black, - BrightWhite, - FadedWhite, - MediumWhite, - DarkGreen, - LightGreen, - BrightGreen, - Gray, - Red, - Blue, - Transparent -}; - } // namespace ui -class Theme : public QObject +class Theme : public QPalette { - Q_OBJECT + Q_GADGET + Q_PROPERTY(QColor sidebarBackground READ sidebarBackground CONSTANT) + Q_PROPERTY(QColor separator READ separator CONSTANT) public: - explicit Theme(QObject *parent = nullptr); + Theme() {} + explicit Theme(std::string_view theme); + static QPalette paletteFromTheme(std::string_view theme); - QColor getColor(const QString &key) const; - - void setColor(const QString &key, const QColor &color); - void setColor(const QString &key, ui::Color color); + QColor sidebarBackground() const { return sidebarBackground_; } + QColor separator() const { return separator_; } private: - QColor rgba(int r, int g, int b, qreal a) const; - - QHash<QString, QColor> colors_; + QColor sidebarBackground_, separator_; }; diff --git a/src/ui/ThemeManager.cpp b/src/ui/ThemeManager.cpp index 834f5083..b7b3df40 100644 --- a/src/ui/ThemeManager.cpp +++ b/src/ui/ThemeManager.cpp @@ -6,18 +6,37 @@ #include "ThemeManager.h" -ThemeManager::ThemeManager() { setTheme(new Theme); } - -void -ThemeManager::setTheme(Theme *theme) -{ - theme_ = theme; - theme_->setParent(this); -} +ThemeManager::ThemeManager() {} QColor ThemeManager::themeColor(const QString &key) const { - Q_ASSERT(theme_); - return theme_->getColor(key); + if (key == "Black") + return QColor("#171919"); + + else if (key == "BrightWhite") + return QColor("#EBEBEB"); + else if (key == "FadedWhite") + return QColor("#C9C9C9"); + else if (key == "MediumWhite") + return QColor("#929292"); + + else if (key == "BrightGreen") + return QColor("#1C3133"); + else if (key == "DarkGreen") + return QColor("#577275"); + else if (key == "LightGreen") + return QColor("#46A451"); + + else if (key == "Gray") + return QColor("#5D6565"); + else if (key == "Red") + return QColor("#E22826"); + else if (key == "Blue") + return QColor("#81B3A9"); + + else if (key == "Transparent") + return QColor(0, 0, 0, 0); + + return (QColor(0, 0, 0, 0)); } diff --git a/src/ui/ThemeManager.h b/src/ui/ThemeManager.h index f2099730..cbb355fd 100644 --- a/src/ui/ThemeManager.h +++ b/src/ui/ThemeManager.h @@ -6,8 +6,6 @@ #include <QCommonStyle> -#include "Theme.h" - class ThemeManager : public QCommonStyle { Q_OBJECT @@ -15,7 +13,6 @@ class ThemeManager : public QCommonStyle public: inline static ThemeManager &instance(); - void setTheme(Theme *theme); QColor themeColor(const QString &key) const; private: @@ -23,8 +20,6 @@ private: ThemeManager(ThemeManager const &); void operator=(ThemeManager const &); - - Theme *theme_; }; inline ThemeManager & diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 0f330964..cef8bd85 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -27,9 +27,22 @@ UserProfile::UserProfile(QString roomid, , manager(manager_) , model(parent) { - fetchDeviceList(this->userid_); globalAvatarUrl = ""; + connect(this, + &UserProfile::globalUsernameRetrieved, + this, + &UserProfile::setGlobalUsername, + Qt::QueuedConnection); + + if (isGlobalUserProfile()) { + getGlobalProfileData(); + } + + if (!cache::client() || !cache::client()->isDatabaseReady()) + return; + + fetchDeviceList(this->userid_); connect(cache::client(), &Cache::verificationStatusChanged, this, @@ -54,16 +67,6 @@ UserProfile::UserProfile(QString roomid, } deviceList_.reset(deviceList_.deviceList_); }); - - connect(this, - &UserProfile::globalUsernameRetrieved, - this, - &UserProfile::setGlobalUsername, - Qt::QueuedConnection); - - if (isGlobalUserProfile()) { - getGlobalProfileData(); - } } QHash<int, QByteArray> @@ -157,6 +160,9 @@ UserProfile::fetchDeviceList(const QString &userID) { auto localUser = utils::localUser(); + if (!cache::client() || !cache::client()->isDatabaseReady()) + return; + cache::client()->query_keys( userID.toStdString(), [other_user_id = userID.toStdString(), this](const UserKeyCache &other_user_keys, |