mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Merge pull request #92 from pupper68k/0.7.0-dev-bugfix-71
Add settings option to display avatars as squares
This commit is contained in:
commit
15c1cd5d66
6 changed files with 51 additions and 4 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,8 +1,14 @@
|
|||
build
|
||||
tags
|
||||
cscope*
|
||||
.clang_complete
|
||||
*wintoastlib*
|
||||
|
||||
# GTAGS
|
||||
GTAGS
|
||||
GRTAGS
|
||||
GPATH
|
||||
|
||||
# C++ objects and libs
|
||||
|
||||
*.slo
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "AvatarProvider.h"
|
||||
|
@ -141,6 +142,8 @@ RoomInfoListItem::resizeEvent(QResizeEvent *)
|
|||
void
|
||||
RoomInfoListItem::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
bool rounded = QSettings().value("user/avatar/circles", true).toBool();
|
||||
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPainter p(this);
|
||||
|
@ -288,7 +291,8 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
|||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(brush);
|
||||
|
||||
p.drawEllipse(avatarRegion.center(), wm.iconSize / 2, wm.iconSize / 2);
|
||||
rounded ? p.drawEllipse(avatarRegion.center(), wm.iconSize / 2, wm.iconSize / 2)
|
||||
: p.drawRoundedRect(avatarRegion, 3, 3);
|
||||
|
||||
QFont bubbleFont;
|
||||
bubbleFont.setPointSizeF(bubbleFont.pointSizeF() * 1.4);
|
||||
|
@ -301,7 +305,9 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
|||
p.save();
|
||||
|
||||
QPainterPath path;
|
||||
path.addEllipse(wm.padding, wm.padding, wm.iconSize, wm.iconSize);
|
||||
rounded ? path.addEllipse(wm.padding, wm.padding, wm.iconSize, wm.iconSize)
|
||||
: path.addRoundedRect(avatarRegion, 3, 3);
|
||||
|
||||
p.setClipPath(path);
|
||||
|
||||
p.drawPixmap(avatarRegion, roomAvatar_);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
*
|
||||
|
|
|
@ -53,6 +53,7 @@ UserSettings::load()
|
|||
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
||||
theme_ = settings.value("user/theme", defaultTheme_).toString();
|
||||
font_ = settings.value("user/font_family", "default").toString();
|
||||
avatarCircles_ = settings.value("user/avatar/circles", true).toBool();
|
||||
emojiFont_ = settings.value("user/emoji_font_family", "default").toString();
|
||||
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
||||
|
||||
|
@ -118,6 +119,10 @@ UserSettings::save()
|
|||
settings.setValue("start_in_tray", isStartInTrayEnabled_);
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup("avatar");
|
||||
settings.setValue("circles", avatarCircles_);
|
||||
settings.endGroup();
|
||||
|
||||
settings.setValue("font_size", baseFontSize_);
|
||||
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
|
||||
settings.setValue("read_receipts", isReadReceiptsEnabled_);
|
||||
|
@ -192,6 +197,15 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
groupViewLayout->addWidget(groupViewLabel);
|
||||
groupViewLayout->addWidget(groupViewToggle_, 0, Qt::AlignRight);
|
||||
|
||||
auto avatarViewLayout = new QHBoxLayout;
|
||||
avatarViewLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||
auto avatarViewLabel = new QLabel(tr("Circular Avatars"), this);
|
||||
avatarViewLabel->setFont(font);
|
||||
avatarCircles_ = new Toggle(this);
|
||||
|
||||
avatarViewLayout->addWidget(avatarViewLabel);
|
||||
avatarViewLayout->addWidget(avatarCircles_, 0, Qt::AlignRight);
|
||||
|
||||
auto typingLayout = new QHBoxLayout;
|
||||
typingLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||
auto typingLabel = new QLabel(tr("Typing notifications"), this);
|
||||
|
@ -368,6 +382,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
mainLayout_->addLayout(startInTrayOptionLayout_);
|
||||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
mainLayout_->addLayout(groupViewLayout);
|
||||
mainLayout_->addLayout(avatarViewLayout);
|
||||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
mainLayout_->addLayout(typingLayout);
|
||||
mainLayout_->addLayout(receiptsLayout);
|
||||
|
@ -448,6 +463,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
settings_->setGroupView(!isDisabled);
|
||||
});
|
||||
|
||||
connect(avatarCircles_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||
settings_->setAvatarCircles(!isDisabled);
|
||||
});
|
||||
|
||||
connect(typingNotifications_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||
settings_->setTypingNotifications(!isDisabled);
|
||||
});
|
||||
|
|
|
@ -86,6 +86,12 @@ public:
|
|||
save();
|
||||
}
|
||||
|
||||
void setAvatarCircles(bool state)
|
||||
{
|
||||
avatarCircles_ = state;
|
||||
save();
|
||||
}
|
||||
|
||||
QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; }
|
||||
bool isTrayEnabled() const { return isTrayEnabled_; }
|
||||
bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; }
|
||||
|
@ -113,6 +119,7 @@ private:
|
|||
bool isTypingNotificationsEnabled_;
|
||||
bool isReadReceiptsEnabled_;
|
||||
bool hasDesktopNotifications_;
|
||||
bool avatarCircles_;
|
||||
double baseFontSize_;
|
||||
QString font_;
|
||||
QString emojiFont_;
|
||||
|
@ -162,6 +169,7 @@ private:
|
|||
Toggle *typingNotifications_;
|
||||
Toggle *readReceipts_;
|
||||
Toggle *desktopNotifications_;
|
||||
Toggle *avatarCircles_;
|
||||
QLabel *deviceFingerprintValue_;
|
||||
QLabel *deviceIdValue_;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
|
||||
#include "AvatarProvider.h"
|
||||
#include "Utils.h"
|
||||
|
@ -100,6 +101,8 @@ Avatar::setIcon(const QIcon &icon)
|
|||
void
|
||||
Avatar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
bool rounded = QSettings().value("user/avatar/circles", true).toBool();
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
|
@ -113,7 +116,8 @@ Avatar::paintEvent(QPaintEvent *)
|
|||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(brush);
|
||||
painter.drawEllipse(r.center(), hs, hs);
|
||||
rounded ? painter.drawEllipse(r.center(), hs, hs)
|
||||
: painter.drawRoundedRect(r, 3, 3);
|
||||
}
|
||||
|
||||
switch (type_) {
|
||||
|
@ -126,7 +130,10 @@ Avatar::paintEvent(QPaintEvent *)
|
|||
}
|
||||
case ui::AvatarType::Image: {
|
||||
QPainterPath ppath;
|
||||
ppath.addEllipse(width() / 2 - hs, height() / 2 - hs, size_, size_);
|
||||
|
||||
rounded ? ppath.addEllipse(width() / 2 - hs, height() / 2 - hs, size_, size_)
|
||||
: ppath.addRoundedRect(r, 3, 3);
|
||||
|
||||
painter.setClipPath(ppath);
|
||||
painter.drawPixmap(QRect(width() / 2 - hs, height() / 2 - hs, size_, size_),
|
||||
pixmap_);
|
||||
|
|
Loading…
Reference in a new issue