mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +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.minimumWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
||||||
SplitView.preferredWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
SplitView.preferredWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
||||||
SplitView.maximumWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
SplitView.maximumWidth: Nheko.avatarSize + Nheko.paddingSmall * 2
|
||||||
color: "blue"
|
color: Nheko.theme.sidebarBackground
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
RoomList {
|
||||||
SplitView.minimumWidth: Nheko.avatarSize * 3 + Nheko.paddingSmall * 2
|
//SplitView.maximumWidth: Nheko.avatarSize * 7 + Nheko.paddingSmall * 2
|
||||||
SplitView.preferredWidth: Nheko.avatarSize * 3 + Nheko.paddingSmall * 2
|
|
||||||
SplitView.maximumWidth: Nheko.avatarSize * 7 + Nheko.paddingSmall * 2
|
SplitView.minimumWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2
|
||||||
color: "red"
|
SplitView.preferredWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineView {
|
TimelineView {
|
||||||
|
@ -36,6 +36,11 @@ Rectangle {
|
||||||
SplitView.minimumWidth: 400
|
SplitView.minimumWidth: 400
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle: Rectangle {
|
||||||
|
implicitWidth: 2
|
||||||
|
color: SplitHandle.pressed ? Nheko.colors.highlight : (SplitHandle.hovered ? Nheko.colors.light : Nheko.theme.separator)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivacyScreen {
|
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
|
Layout.fillWidth: true
|
||||||
height: 1
|
height: 1
|
||||||
z: 3
|
z: 3
|
||||||
color: Nheko.colors.mid
|
color: Nheko.theme.separator
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
@ -112,7 +112,7 @@ Item {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
z: 3
|
z: 3
|
||||||
height: 1
|
height: 1
|
||||||
color: Nheko.colors.mid
|
color: Nheko.theme.separator
|
||||||
}
|
}
|
||||||
|
|
||||||
ReplyPopup {
|
ReplyPopup {
|
||||||
|
|
|
@ -14,7 +14,7 @@ Rectangle {
|
||||||
property var room: TimelineManager.timeline
|
property var room: TimelineManager.timeline
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
implicitHeight: topLayout.height + 16
|
implicitHeight: topLayout.height + Nheko.paddingMedium * 2
|
||||||
z: 3
|
z: 3
|
||||||
color: Nheko.colors.window
|
color: Nheko.colors.window
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ Rectangle {
|
||||||
|
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.margins: 8
|
anchors.margins: Nheko.paddingMedium
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
ImageButton {
|
ImageButton {
|
||||||
|
|
|
@ -125,6 +125,7 @@
|
||||||
|
|
||||||
<file>qml/Root.qml</file>
|
<file>qml/Root.qml</file>
|
||||||
<file>qml/ChatPage.qml</file>
|
<file>qml/ChatPage.qml</file>
|
||||||
|
<file>qml/RoomList.qml</file>
|
||||||
<file>qml/TimelineView.qml</file>
|
<file>qml/TimelineView.qml</file>
|
||||||
<file>qml/Avatar.qml</file>
|
<file>qml/Avatar.qml</file>
|
||||||
<file>qml/Completer.qml</file>
|
<file>qml/Completer.qml</file>
|
||||||
|
|
|
@ -253,6 +253,8 @@ Cache::setup()
|
||||||
outboundMegolmSessionDb_ = lmdb::dbi::open(txn, OUTBOUND_MEGOLM_SESSIONS_DB, MDB_CREATE);
|
outboundMegolmSessionDb_ = lmdb::dbi::open(txn, OUTBOUND_MEGOLM_SESSIONS_DB, MDB_CREATE);
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
||||||
|
databaseReady_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -788,6 +790,7 @@ Cache::nextBatchToken()
|
||||||
void
|
void
|
||||||
Cache::deleteData()
|
Cache::deleteData()
|
||||||
{
|
{
|
||||||
|
this->databaseReady_ = false;
|
||||||
// TODO: We need to remove the env_ while not accepting new requests.
|
// TODO: We need to remove the env_ while not accepting new requests.
|
||||||
lmdb::dbi_close(env_, syncStateDb_);
|
lmdb::dbi_close(env_, syncStateDb_);
|
||||||
lmdb::dbi_close(env_, roomsDb_);
|
lmdb::dbi_close(env_, roomsDb_);
|
||||||
|
@ -2426,7 +2429,7 @@ Cache::joinedRooms()
|
||||||
std::optional<MemberInfo>
|
std::optional<MemberInfo>
|
||||||
Cache::getMember(const std::string &room_id, const std::string &user_id)
|
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;
|
return std::nullopt;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -3551,7 +3554,7 @@ Cache::query_keys(const std::string &user_id,
|
||||||
|
|
||||||
http::client()->query_keys(
|
http::client()->query_keys(
|
||||||
req,
|
req,
|
||||||
[cb, user_id, last_changed](const mtx::responses::QueryKeys &res,
|
[cb, user_id, last_changed, this](const mtx::responses::QueryKeys &res,
|
||||||
mtx::http::RequestErr err) {
|
mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
nhlog::net()->warn("failed to query device keys: {},{}",
|
nhlog::net()->warn("failed to query device keys: {},{}",
|
||||||
|
@ -3561,10 +3564,22 @@ Cache::query_keys(const std::string &user_id,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache::updateUserKeys(last_changed, res);
|
emit userKeysUpdate(last_changed, res);
|
||||||
|
|
||||||
|
// 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);
|
auto keys = cache::userKeys(user_id);
|
||||||
cb(keys.value_or(UserKeyCache{}), err);
|
cb(keys.value_or(UserKeyCache{}), {});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3999,6 +4014,8 @@ avatarUrl(const QString &room_id, const QString &user_id)
|
||||||
mtx::presence::PresenceState
|
mtx::presence::PresenceState
|
||||||
presenceState(const std::string &user_id)
|
presenceState(const std::string &user_id)
|
||||||
{
|
{
|
||||||
|
if (!instance_)
|
||||||
|
return {};
|
||||||
return instance_->presenceState(user_id);
|
return instance_->presenceState(user_id);
|
||||||
}
|
}
|
||||||
std::string
|
std::string
|
||||||
|
|
|
@ -100,6 +100,7 @@ public:
|
||||||
|
|
||||||
void saveState(const mtx::responses::Sync &res);
|
void saveState(const mtx::responses::Sync &res);
|
||||||
bool isInitialized();
|
bool isInitialized();
|
||||||
|
bool isDatabaseReady() { return databaseReady_ && isInitialized(); }
|
||||||
|
|
||||||
std::string nextBatchToken();
|
std::string nextBatchToken();
|
||||||
|
|
||||||
|
@ -620,6 +621,8 @@ private:
|
||||||
QString cacheDirectory_;
|
QString cacheDirectory_;
|
||||||
|
|
||||||
VerificationStorage verification_storage;
|
VerificationStorage verification_storage;
|
||||||
|
|
||||||
|
bool databaseReady_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace cache {
|
namespace cache {
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
#include "CacheStructs.h"
|
#include "CacheStructs.h"
|
||||||
#include "CommunitiesListItem.h"
|
#include "CommunitiesListItem.h"
|
||||||
#include "ui/Theme.h"
|
|
||||||
|
|
||||||
namespace mtx::responses {
|
namespace mtx::responses {
|
||||||
struct GroupProfile;
|
struct GroupProfile;
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "ui/Theme.h"
|
|
||||||
|
|
||||||
class RippleOverlay;
|
class RippleOverlay;
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
|
|
|
@ -295,6 +295,7 @@ MainWindow::showChatPage()
|
||||||
&Cache::secretChanged,
|
&Cache::secretChanged,
|
||||||
userSettingsPage_,
|
userSettingsPage_,
|
||||||
&UserSettingsPage::updateSecretStatus);
|
&UserSettingsPage::updateSecretStatus);
|
||||||
|
emit reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -109,6 +109,7 @@ private slots:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void focusChanged(const bool focused);
|
void focusChanged(const bool focused);
|
||||||
|
void reload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool loadJdenticonPlugin();
|
bool loadJdenticonPlugin();
|
||||||
|
|
|
@ -545,49 +545,14 @@ UserSettings::applyTheme()
|
||||||
{
|
{
|
||||||
QFile stylefile;
|
QFile stylefile;
|
||||||
|
|
||||||
static QPalette original;
|
|
||||||
if (this->theme() == "light") {
|
if (this->theme() == "light") {
|
||||||
stylefile.setFileName(":/styles/styles/nheko.qss");
|
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") {
|
} else if (this->theme() == "dark") {
|
||||||
stylefile.setFileName(":/styles/styles/nheko-dark.qss");
|
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 {
|
} else {
|
||||||
stylefile.setFileName(":/styles/styles/system.qss");
|
stylefile.setFileName(":/styles/styles/system.qss");
|
||||||
QApplication::setPalette(original);
|
|
||||||
}
|
}
|
||||||
|
QApplication::setPalette(Theme::paletteFromTheme(this->theme().toStdString()));
|
||||||
|
|
||||||
stylefile.open(QFile::ReadOnly);
|
stylefile.open(QFile::ReadOnly);
|
||||||
QString stylesheet = QString(stylefile.readAll());
|
QString stylesheet = QString(stylefile.readAll());
|
||||||
|
|
|
@ -7,29 +7,50 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include "Cache_p.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
|
#include "Logging.h"
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
Nheko::Nheko()
|
Nheko::Nheko()
|
||||||
{
|
{
|
||||||
connect(
|
connect(
|
||||||
UserSettings::instance().get(), &UserSettings::themeChanged, this, &Nheko::colorsChanged);
|
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
|
QPalette
|
||||||
Nheko::colors() const
|
Nheko::colors() const
|
||||||
{
|
{
|
||||||
return QPalette();
|
return Theme::paletteFromTheme(UserSettings::instance()->theme().toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPalette
|
QPalette
|
||||||
Nheko::inactiveColors() const
|
Nheko::inactiveColors() const
|
||||||
{
|
{
|
||||||
QPalette p;
|
auto p = colors();
|
||||||
p.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
p.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Theme
|
||||||
|
Nheko::theme() const
|
||||||
|
{
|
||||||
|
return Theme(UserSettings::instance()->theme().toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Nheko::openLink(QString link) const
|
Nheko::openLink(QString link) const
|
||||||
{
|
{
|
||||||
|
@ -79,3 +100,11 @@ Nheko::openLink(QString link) const
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UserProfile *
|
||||||
|
Nheko::currentUser() const
|
||||||
|
{
|
||||||
|
nhlog::ui()->debug("Profile requested");
|
||||||
|
|
||||||
|
return currentUser_.get();
|
||||||
|
}
|
||||||
|
|
|
@ -7,32 +7,46 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
|
||||||
|
#include "Theme.h"
|
||||||
|
#include "UserProfile.h"
|
||||||
|
|
||||||
class Nheko : public QObject
|
class Nheko : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QPalette colors READ colors NOTIFY colorsChanged)
|
Q_PROPERTY(QPalette colors READ colors NOTIFY colorsChanged)
|
||||||
Q_PROPERTY(QPalette inactiveColors READ inactiveColors 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 avatarSize READ avatarSize CONSTANT)
|
||||||
Q_PROPERTY(int paddingSmall READ paddingSmall CONSTANT)
|
Q_PROPERTY(int paddingSmall READ paddingSmall CONSTANT)
|
||||||
Q_PROPERTY(int paddingMedium READ paddingMedium CONSTANT)
|
Q_PROPERTY(int paddingMedium READ paddingMedium CONSTANT)
|
||||||
Q_PROPERTY(int paddingLarge READ paddingLarge CONSTANT)
|
Q_PROPERTY(int paddingLarge READ paddingLarge CONSTANT)
|
||||||
|
|
||||||
|
Q_PROPERTY(UserProfile *currentUser READ currentUser NOTIFY profileChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Nheko();
|
Nheko();
|
||||||
|
|
||||||
QPalette colors() const;
|
QPalette colors() const;
|
||||||
QPalette inactiveColors() const;
|
QPalette inactiveColors() const;
|
||||||
|
Theme theme() const;
|
||||||
|
|
||||||
int avatarSize() const { return 40; }
|
int avatarSize() const { return 40; }
|
||||||
|
|
||||||
int paddingSmall() const { return 4; }
|
int paddingSmall() const { return 4; }
|
||||||
int paddingMedium() const { return 8; }
|
int paddingMedium() const { return 8; }
|
||||||
int paddingLarge() const { return 20; }
|
int paddingLarge() const { return 20; }
|
||||||
|
UserProfile *currentUser() const;
|
||||||
|
|
||||||
Q_INVOKABLE void openLink(QString link) const;
|
Q_INVOKABLE void openLink(QString link) const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateUserProfile();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void colorsChanged();
|
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
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "Theme.h"
|
#include "Theme.h"
|
||||||
|
|
||||||
Theme::Theme(QObject *parent)
|
Q_DECLARE_METATYPE(Theme)
|
||||||
: QObject(parent)
|
|
||||||
|
QPalette
|
||||||
|
Theme::paletteFromTheme(std::string_view theme)
|
||||||
{
|
{
|
||||||
setColor("Black", ui::Color::Black);
|
[[maybe_unused]] static auto meta = qRegisterMetaType<Theme>("Theme");
|
||||||
|
static QPalette original;
|
||||||
setColor("BrightWhite", ui::Color::BrightWhite);
|
if (theme == "light") {
|
||||||
setColor("FadedWhite", ui::Color::FadedWhite);
|
QPalette lightActive(
|
||||||
setColor("MediumWhite", ui::Color::MediumWhite);
|
/*windowText*/ QColor("#333"),
|
||||||
|
/*button*/ QColor("white"),
|
||||||
setColor("BrightGreen", ui::Color::BrightGreen);
|
/*light*/ QColor(0xef, 0xef, 0xef),
|
||||||
setColor("DarkGreen", ui::Color::DarkGreen);
|
/*dark*/ QColor(110, 110, 110),
|
||||||
setColor("LightGreen", ui::Color::LightGreen);
|
/*mid*/ QColor(220, 220, 220),
|
||||||
|
/*text*/ QColor("#333"),
|
||||||
setColor("Gray", ui::Color::Gray);
|
/*bright_text*/ QColor("#333"),
|
||||||
setColor("Red", ui::Color::Red);
|
/*base*/ QColor("#fff"),
|
||||||
setColor("Blue", ui::Color::Blue);
|
/*window*/ QColor("white"));
|
||||||
|
lightActive.setColor(QPalette::AlternateBase, QColor("#eee"));
|
||||||
setColor("Transparent", ui::Color::Transparent);
|
lightActive.setColor(QPalette::Highlight, QColor("#38a3d8"));
|
||||||
}
|
lightActive.setColor(QPalette::ToolTipBase, lightActive.base().color());
|
||||||
|
lightActive.setColor(QPalette::ToolTipText, lightActive.text().color());
|
||||||
QColor
|
lightActive.setColor(QPalette::Link, QColor("#0077b5"));
|
||||||
Theme::rgba(int r, int g, int b, qreal a) const
|
lightActive.setColor(QPalette::ButtonText, QColor("#555459"));
|
||||||
{
|
return lightActive;
|
||||||
QColor color(r, g, b);
|
} else if (theme == "dark") {
|
||||||
color.setAlphaF(a);
|
QPalette darkActive(
|
||||||
|
/*windowText*/ QColor("#caccd1"),
|
||||||
return color;
|
/*button*/ QColor(0xff, 0xff, 0xff),
|
||||||
}
|
/*light*/ QColor("#caccd1"),
|
||||||
|
/*dark*/ QColor(110, 110, 110),
|
||||||
QColor
|
/*mid*/ QColor("#202228"),
|
||||||
Theme::getColor(const QString &key) const
|
/*text*/ QColor("#caccd1"),
|
||||||
{
|
/*bright_text*/ QColor(0xff, 0xff, 0xff),
|
||||||
if (!colors_.contains(key)) {
|
/*base*/ QColor("#202228"),
|
||||||
qWarning() << "Color with key" << key << "could not be found";
|
/*window*/ QColor("#2d3139"));
|
||||||
return QColor();
|
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::Theme(std::string_view theme)
|
||||||
Theme::setColor(const QString &key, const QColor &color)
|
|
||||||
{
|
{
|
||||||
colors_.insert(key, color);
|
auto p = paletteFromTheme(theme);
|
||||||
}
|
separator_ = p.mid().color();
|
||||||
|
if (theme == "light") {
|
||||||
void
|
sidebarBackground_ = QColor("#233649");
|
||||||
Theme::setColor(const QString &key, ui::Color color)
|
} else if (theme == "dark") {
|
||||||
{
|
sidebarBackground_ = QColor("#2d3139");
|
||||||
static const QColor palette[] = {
|
} else {
|
||||||
QColor("#171919"),
|
sidebarBackground_ = p.window().color();
|
||||||
|
}
|
||||||
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)]);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QHash>
|
#include <QPalette>
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
enum class AvatarType
|
enum class AvatarType
|
||||||
|
@ -60,36 +59,21 @@ enum class ProgressType
|
||||||
IndeterminateProgress
|
IndeterminateProgress
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Color
|
|
||||||
{
|
|
||||||
Black,
|
|
||||||
BrightWhite,
|
|
||||||
FadedWhite,
|
|
||||||
MediumWhite,
|
|
||||||
DarkGreen,
|
|
||||||
LightGreen,
|
|
||||||
BrightGreen,
|
|
||||||
Gray,
|
|
||||||
Red,
|
|
||||||
Blue,
|
|
||||||
Transparent
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ui
|
} // 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:
|
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;
|
QColor sidebarBackground() const { return sidebarBackground_; }
|
||||||
|
QColor separator() const { return separator_; }
|
||||||
void setColor(const QString &key, const QColor &color);
|
|
||||||
void setColor(const QString &key, ui::Color color);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QColor rgba(int r, int g, int b, qreal a) const;
|
QColor sidebarBackground_, separator_;
|
||||||
|
|
||||||
QHash<QString, QColor> colors_;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,18 +6,37 @@
|
||||||
|
|
||||||
#include "ThemeManager.h"
|
#include "ThemeManager.h"
|
||||||
|
|
||||||
ThemeManager::ThemeManager() { setTheme(new Theme); }
|
ThemeManager::ThemeManager() {}
|
||||||
|
|
||||||
void
|
|
||||||
ThemeManager::setTheme(Theme *theme)
|
|
||||||
{
|
|
||||||
theme_ = theme;
|
|
||||||
theme_->setParent(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor
|
QColor
|
||||||
ThemeManager::themeColor(const QString &key) const
|
ThemeManager::themeColor(const QString &key) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(theme_);
|
if (key == "Black")
|
||||||
return theme_->getColor(key);
|
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 <QCommonStyle>
|
||||||
|
|
||||||
#include "Theme.h"
|
|
||||||
|
|
||||||
class ThemeManager : public QCommonStyle
|
class ThemeManager : public QCommonStyle
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -15,7 +13,6 @@ class ThemeManager : public QCommonStyle
|
||||||
public:
|
public:
|
||||||
inline static ThemeManager &instance();
|
inline static ThemeManager &instance();
|
||||||
|
|
||||||
void setTheme(Theme *theme);
|
|
||||||
QColor themeColor(const QString &key) const;
|
QColor themeColor(const QString &key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -23,8 +20,6 @@ private:
|
||||||
|
|
||||||
ThemeManager(ThemeManager const &);
|
ThemeManager(ThemeManager const &);
|
||||||
void operator=(ThemeManager const &);
|
void operator=(ThemeManager const &);
|
||||||
|
|
||||||
Theme *theme_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline ThemeManager &
|
inline ThemeManager &
|
||||||
|
|
|
@ -27,9 +27,22 @@ UserProfile::UserProfile(QString roomid,
|
||||||
, manager(manager_)
|
, manager(manager_)
|
||||||
, model(parent)
|
, model(parent)
|
||||||
{
|
{
|
||||||
fetchDeviceList(this->userid_);
|
|
||||||
globalAvatarUrl = "";
|
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(),
|
connect(cache::client(),
|
||||||
&Cache::verificationStatusChanged,
|
&Cache::verificationStatusChanged,
|
||||||
this,
|
this,
|
||||||
|
@ -54,16 +67,6 @@ UserProfile::UserProfile(QString roomid,
|
||||||
}
|
}
|
||||||
deviceList_.reset(deviceList_.deviceList_);
|
deviceList_.reset(deviceList_.deviceList_);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this,
|
|
||||||
&UserProfile::globalUsernameRetrieved,
|
|
||||||
this,
|
|
||||||
&UserProfile::setGlobalUsername,
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
|
|
||||||
if (isGlobalUserProfile()) {
|
|
||||||
getGlobalProfileData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray>
|
QHash<int, QByteArray>
|
||||||
|
@ -157,6 +160,9 @@ UserProfile::fetchDeviceList(const QString &userID)
|
||||||
{
|
{
|
||||||
auto localUser = utils::localUser();
|
auto localUser = utils::localUser();
|
||||||
|
|
||||||
|
if (!cache::client() || !cache::client()->isDatabaseReady())
|
||||||
|
return;
|
||||||
|
|
||||||
cache::client()->query_keys(
|
cache::client()->query_keys(
|
||||||
userID.toStdString(),
|
userID.toStdString(),
|
||||||
[other_user_id = userID.toStdString(), this](const UserKeyCache &other_user_keys,
|
[other_user_id = userID.toStdString(), this](const UserKeyCache &other_user_keys,
|
||||||
|
|
Loading…
Reference in a new issue