mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Basic header and footer of room list
This commit is contained in:
parent
39a43ad4ab
commit
567fe81ad7
19 changed files with 385 additions and 175 deletions
|
@ -19,14 +19,14 @@ Rectangle {
|
|||
SplitView.minimumWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
||||
SplitView.preferredWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
||||
SplitView.maximumWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
||||
color: "blue"
|
||||
color: Nheko.theme.sidebarBackground
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
SplitView.minimumWidth: Nheko.avatarSize * 3 + Nheko.paddingSmall * 2
|
||||
SplitView.preferredWidth: Nheko.avatarSize * 3 + Nheko.paddingSmall * 2
|
||||
SplitView.maximumWidth: Nheko.avatarSize * 7 + Nheko.paddingSmall * 2
|
||||
color: "red"
|
||||
RoomList {
|
||||
//SplitView.maximumWidth: Nheko.avatarSize * 7 + Nheko.paddingSmall * 2
|
||||
|
||||
SplitView.minimumWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2
|
||||
SplitView.preferredWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2
|
||||
}
|
||||
|
||||
TimelineView {
|
||||
|
@ -36,6 +36,11 @@ Rectangle {
|
|||
SplitView.minimumWidth: 400
|
||||
}
|
||||
|
||||
handle: Rectangle {
|
||||
implicitWidth: 2
|
||||
color: SplitHandle.pressed ? Nheko.colors.highlight : (SplitHandle.hovered ? Nheko.colors.light : Nheko.theme.separator)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PrivacyScreen {
|
||||
|
|
183
resources/qml/RoomList.qml
Normal file
183
resources/qml/RoomList.qml
Normal file
|
@ -0,0 +1,183 @@
|
|||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Layouts 1.3
|
||||
import im.nheko 1.0
|
||||
|
||||
Page {
|
||||
|
||||
background: Rectangle {
|
||||
color: Nheko.theme.sidebarBackground
|
||||
}
|
||||
|
||||
header: ColumnLayout {
|
||||
spacing: 0
|
||||
|
||||
Rectangle {
|
||||
color: Nheko.colors.window
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignBottom
|
||||
Layout.preferredHeight: userInfoGrid.implicitHeight + 2 * Nheko.paddingMedium
|
||||
Layout.minimumHeight: 40
|
||||
|
||||
RowLayout {
|
||||
id: userInfoGrid
|
||||
|
||||
spacing: Nheko.paddingMedium
|
||||
anchors.fill: parent
|
||||
anchors.margins: Nheko.paddingMedium
|
||||
|
||||
Avatar {
|
||||
id: avatar
|
||||
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
Layout.preferredWidth: Nheko.avatarSize
|
||||
Layout.preferredHeight: Nheko.avatarSize
|
||||
url: Nheko.currentUser.avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||
displayName: Nheko.currentUser.displayName
|
||||
userid: Nheko.currentUser.userid
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: col
|
||||
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumWidth: 100
|
||||
width: parent.width - avatar.width - logoutButton.width
|
||||
Layout.preferredWidth: parent.width - avatar.width - logoutButton.width
|
||||
spacing: 0
|
||||
|
||||
Label {
|
||||
Layout.alignment: Qt.AlignBottom
|
||||
color: Nheko.colors.text
|
||||
font.pointSize: fontMetrics.font.pointSize * 1.1
|
||||
font.weight: Font.DemiBold
|
||||
text: userNameText.elidedText
|
||||
maximumLineCount: 1
|
||||
elide: Text.ElideRight
|
||||
textFormat: Text.PlainText
|
||||
|
||||
TextMetrics {
|
||||
id: userNameText
|
||||
|
||||
font.pointSize: fontMetrics.font.pointSize * 1.1
|
||||
elide: Text.ElideRight
|
||||
elideWidth: col.width
|
||||
text: Nheko.currentUser.displayName
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.alignment: Qt.AlignTop
|
||||
color: Nheko.colors.buttonText
|
||||
font.weight: Font.Thin
|
||||
text: userIdText.elidedText
|
||||
maximumLineCount: 1
|
||||
textFormat: Text.PlainText
|
||||
font.pointSize: fontMetrics.font.pointSize * 0.9
|
||||
|
||||
TextMetrics {
|
||||
id: userIdText
|
||||
|
||||
font.pointSize: fontMetrics.font.pointSize * 0.9
|
||||
elide: Text.ElideRight
|
||||
elideWidth: col.width
|
||||
text: Nheko.currentUser.userid
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Item {
|
||||
}
|
||||
|
||||
ImageButton {
|
||||
id: logoutButton
|
||||
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
image: ":/icons/icons/ui/power-button-off.png"
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Logout")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: Nheko.theme.separator
|
||||
height: 2
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
footer: ColumnLayout {
|
||||
spacing: 0
|
||||
|
||||
Rectangle {
|
||||
color: Nheko.theme.separator
|
||||
height: 1
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: Nheko.colors.window
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignBottom
|
||||
Layout.preferredHeight: buttonRow.implicitHeight
|
||||
Layout.minimumHeight: 40
|
||||
|
||||
RowLayout {
|
||||
id: buttonRow
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.margins: Nheko.paddingMedium
|
||||
|
||||
ImageButton {
|
||||
Layout.alignment: Qt.AlignBottom | Qt.AlignLeft
|
||||
hoverEnabled: true
|
||||
width: 22
|
||||
height: 22
|
||||
image: ":/icons/icons/ui/plus-black-symbol.png"
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Start a new chat")
|
||||
Layout.margins: Nheko.paddingMedium
|
||||
}
|
||||
|
||||
ImageButton {
|
||||
Layout.alignment: Qt.AlignBottom | Qt.AlignHCenter
|
||||
hoverEnabled: true
|
||||
width: 22
|
||||
height: 22
|
||||
image: ":/icons/icons/ui/speech-bubbles-comment-option.png"
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Room directory")
|
||||
Layout.margins: Nheko.paddingMedium
|
||||
}
|
||||
|
||||
ImageButton {
|
||||
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
|
||||
hoverEnabled: true
|
||||
width: 22
|
||||
height: 22
|
||||
image: ":/icons/icons/ui/settings.png"
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("User settings")
|
||||
Layout.margins: Nheko.paddingMedium
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -49,7 +49,7 @@ Item {
|
|||
Layout.fillWidth: true
|
||||
height: 1
|
||||
z: 3
|
||||
color: Nheko.colors.mid
|
||||
color: Nheko.theme.separator
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
|
@ -112,7 +112,7 @@ Item {
|
|||
Layout.fillWidth: true
|
||||
z: 3
|
||||
height: 1
|
||||
color: Nheko.colors.mid
|
||||
color: Nheko.theme.separator
|
||||
}
|
||||
|
||||
ReplyPopup {
|
||||
|
|
|
@ -14,7 +14,7 @@ Rectangle {
|
|||
property var room: TimelineManager.timeline
|
||||
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: topLayout.height + 16
|
||||
implicitHeight: topLayout.height + Nheko.paddingMedium * 2
|
||||
z: 3
|
||||
color: Nheko.colors.window
|
||||
|
||||
|
@ -33,7 +33,7 @@ Rectangle {
|
|||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.margins: 8
|
||||
anchors.margins: Nheko.paddingMedium
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
ImageButton {
|
||||
|
|
|
@ -125,6 +125,7 @@
|
|||
|
||||
<file>qml/Root.qml</file>
|
||||
<file>qml/ChatPage.qml</file>
|
||||
<file>qml/RoomList.qml</file>
|
||||
<file>qml/TimelineView.qml</file>
|
||||
<file>qml/Avatar.qml</file>
|
||||
<file>qml/Completer.qml</file>
|
||||
|
|
|
@ -253,6 +253,8 @@ Cache::setup()
|
|||
outboundMegolmSessionDb_ = lmdb::dbi::open(txn, OUTBOUND_MEGOLM_SESSIONS_DB, MDB_CREATE);
|
||||
|
||||
txn.commit();
|
||||
|
||||
databaseReady_ = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -788,6 +790,7 @@ Cache::nextBatchToken()
|
|||
void
|
||||
Cache::deleteData()
|
||||
{
|
||||
this->databaseReady_ = false;
|
||||
// TODO: We need to remove the env_ while not accepting new requests.
|
||||
lmdb::dbi_close(env_, syncStateDb_);
|
||||
lmdb::dbi_close(env_, roomsDb_);
|
||||
|
@ -2426,7 +2429,7 @@ Cache::joinedRooms()
|
|||
std::optional<MemberInfo>
|
||||
Cache::getMember(const std::string &room_id, const std::string &user_id)
|
||||
{
|
||||
if (user_id.empty())
|
||||
if (user_id.empty() || !env_.handle())
|
||||
return std::nullopt;
|
||||
|
||||
try {
|
||||
|
@ -3551,8 +3554,8 @@ Cache::query_keys(const std::string &user_id,
|
|||
|
||||
http::client()->query_keys(
|
||||
req,
|
||||
[cb, user_id, last_changed](const mtx::responses::QueryKeys &res,
|
||||
mtx::http::RequestErr err) {
|
||||
[cb, user_id, last_changed, this](const mtx::responses::QueryKeys &res,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
nhlog::net()->warn("failed to query device keys: {},{}",
|
||||
mtx::errors::to_string(err->matrix_error.errcode),
|
||||
|
@ -3561,10 +3564,22 @@ Cache::query_keys(const std::string &user_id,
|
|||
return;
|
||||
}
|
||||
|
||||
cache::updateUserKeys(last_changed, res);
|
||||
emit userKeysUpdate(last_changed, res);
|
||||
|
||||
auto keys = cache::userKeys(user_id);
|
||||
cb(keys.value_or(UserKeyCache{}), err);
|
||||
// use context object so that we can disconnect again
|
||||
std::unique_ptr<QObject> context{new QObject};
|
||||
QObject *pcontext = context.get();
|
||||
QObject::connect(
|
||||
this,
|
||||
&Cache::verificationStatusChanged,
|
||||
pcontext,
|
||||
[cb, user_id, context_ = std::move(context)](std::string updated_user) mutable {
|
||||
if (user_id == updated_user) {
|
||||
context_.release();
|
||||
auto keys = cache::userKeys(user_id);
|
||||
cb(keys.value_or(UserKeyCache{}), {});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3999,6 +4014,8 @@ avatarUrl(const QString &room_id, const QString &user_id)
|
|||
mtx::presence::PresenceState
|
||||
presenceState(const std::string &user_id)
|
||||
{
|
||||
if (!instance_)
|
||||
return {};
|
||||
return instance_->presenceState(user_id);
|
||||
}
|
||||
std::string
|
||||
|
|
|
@ -100,6 +100,7 @@ public:
|
|||
|
||||
void saveState(const mtx::responses::Sync &res);
|
||||
bool isInitialized();
|
||||
bool isDatabaseReady() { return databaseReady_ && isInitialized(); }
|
||||
|
||||
std::string nextBatchToken();
|
||||
|
||||
|
@ -620,6 +621,8 @@ private:
|
|||
QString cacheDirectory_;
|
||||
|
||||
VerificationStorage verification_storage;
|
||||
|
||||
bool databaseReady_ = false;
|
||||
};
|
||||
|
||||
namespace cache {
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "CacheStructs.h"
|
||||
#include "CommunitiesListItem.h"
|
||||
#include "ui/Theme.h"
|
||||
|
||||
namespace mtx::responses {
|
||||
struct GroupProfile;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <set>
|
||||
|
||||
#include "Config.h"
|
||||
#include "ui/Theme.h"
|
||||
|
||||
class RippleOverlay;
|
||||
class QMouseEvent;
|
||||
|
|
|
@ -295,6 +295,7 @@ MainWindow::showChatPage()
|
|||
&Cache::secretChanged,
|
||||
userSettingsPage_,
|
||||
&UserSettingsPage::updateSecretStatus);
|
||||
emit reload();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -109,6 +109,7 @@ private slots:
|
|||
|
||||
signals:
|
||||
void focusChanged(const bool focused);
|
||||
void reload();
|
||||
|
||||
private:
|
||||
bool loadJdenticonPlugin();
|
||||
|
|
|
@ -545,49 +545,14 @@ UserSettings::applyTheme()
|
|||
{
|
||||
QFile stylefile;
|
||||
|
||||
static QPalette original;
|
||||
if (this->theme() == "light") {
|
||||
stylefile.setFileName(":/styles/styles/nheko.qss");
|
||||
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("#333"));
|
||||
QApplication::setPalette(lightActive);
|
||||
} else if (this->theme() == "dark") {
|
||||
stylefile.setFileName(":/styles/styles/nheko-dark.qss");
|
||||
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");
|
||||
QApplication::setPalette(darkActive);
|
||||
} else {
|
||||
stylefile.setFileName(":/styles/styles/system.qss");
|
||||
QApplication::setPalette(original);
|
||||
}
|
||||
QApplication::setPalette(Theme::paletteFromTheme(this->theme().toStdString()));
|
||||
|
||||
stylefile.open(QFile::ReadOnly);
|
||||
QString stylesheet = QString(stylefile.readAll());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
|
|
119
src/ui/Theme.cpp
119
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)
|
||||
Q_DECLARE_METATYPE(Theme)
|
||||
|
||||
QPalette
|
||||
Theme::paletteFromTheme(std::string_view theme)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
QColor
|
||||
Theme::getColor(const QString &key) const
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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 &
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue