mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 04:28:49 +03:00
Refactored Avatar and RoomInfoListItem to access rounding settings in place
This commit is contained in:
parent
b10d453bd5
commit
a1c2aed36a
8 changed files with 22 additions and 2267119 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
build
|
||||
tags
|
||||
cscope*
|
||||
.clang_complete
|
||||
*wintoastlib*
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QtGlobal>
|
||||
#include <QSettings>
|
||||
|
||||
#include "Cache.h"
|
||||
#include "Config.h"
|
||||
|
@ -140,6 +141,8 @@ RoomInfoListItem::resizeEvent(QResizeEvent *)
|
|||
void
|
||||
RoomInfoListItem::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
bool rounded = QSettings().value("user/avatar/circles", true).toBool();
|
||||
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPainter p(this);
|
||||
|
@ -287,11 +290,9 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
|||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(brush);
|
||||
|
||||
rounded_ ?
|
||||
rounded ?
|
||||
p.drawEllipse(avatarRegion.center(), wm.iconSize / 2, wm.iconSize / 2) :
|
||||
p.drawRoundedRect( avatarRegion,
|
||||
AVATAR_RECT_ROUND,
|
||||
AVATAR_RECT_ROUND);
|
||||
p.drawRoundedRect(avatarRegion, 3, 3);
|
||||
|
||||
QFont bubbleFont;
|
||||
bubbleFont.setPointSizeF(bubbleFont.pointSizeF() * 1.4);
|
||||
|
@ -304,11 +305,9 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
|||
p.save();
|
||||
|
||||
QPainterPath path;
|
||||
rounded_ ?
|
||||
rounded ?
|
||||
path.addEllipse(wm.padding, wm.padding, wm.iconSize, wm.iconSize) :
|
||||
path.addRoundedRect( avatarRegion,
|
||||
AVATAR_RECT_ROUND,
|
||||
AVATAR_RECT_ROUND);
|
||||
path.addRoundedRect(avatarRegion, 3, 3);
|
||||
|
||||
p.setClipPath(path);
|
||||
|
||||
|
@ -455,9 +454,3 @@ RoomInfoListItem::setDescriptionMessage(const DescInfo &info)
|
|||
lastMsgInfo_ = info;
|
||||
update();
|
||||
}
|
||||
|
||||
void
|
||||
RoomInfoListItem::setRounded(bool setting)
|
||||
{
|
||||
rounded_ = setting;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,6 @@ public:
|
|||
void setTimestampColor(QColor &color) { timestampColor_ = color; }
|
||||
void setAvatarFgColor(QColor &color) { avatarFgColor_ = color; }
|
||||
void setAvatarBgColor(QColor &color) { avatarBgColor_ = color; }
|
||||
void setAvatarRounded(bool setting) { rounded_ = setting; }
|
||||
|
||||
void setHighlightedTitleColor(QColor &color) { highlightedTitleColor_ = color; }
|
||||
void setHighlightedSubtitleColor(QColor &color) { highlightedSubtitleColor_ = color; }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
*
|
||||
|
@ -135,11 +136,10 @@ UserInfoWidget::reset()
|
|||
}
|
||||
|
||||
void
|
||||
UserInfoWidget::setAvatar(const QImage &img, bool rounded)
|
||||
UserInfoWidget::setAvatar(const QImage &img)
|
||||
{
|
||||
avatar_image_ = img;
|
||||
userAvatar_->setImage(img);
|
||||
userAvatar_->setRounded(rounded);
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +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).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();
|
||||
|
||||
|
@ -119,7 +119,7 @@ UserSettings::save()
|
|||
settings.setValue("start_in_tray", isStartInTrayEnabled_);
|
||||
settings.endGroup();
|
||||
|
||||
settings.startGroup("avatar");
|
||||
settings.beginGroup("avatar");
|
||||
settings.setValue("circles", avatarCircles_);
|
||||
settings.endGroup();
|
||||
|
||||
|
@ -383,7 +383,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
mainLayout_->addLayout(groupViewLayout);
|
||||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
mainLayout_->addWidget(avatarViewLayout);
|
||||
mainLayout_->addLayout(avatarViewLayout);
|
||||
mainLayout_->addWidget(new HorizontalLine(this));
|
||||
mainLayout_->addLayout(typingLayout);
|
||||
mainLayout_->addLayout(receiptsLayout);
|
||||
|
@ -465,7 +465,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
});
|
||||
|
||||
connect(groupViewToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||
settings_->setRounded(!isDisabled);
|
||||
settings_->setAvatarCircles(!isDisabled);
|
||||
});
|
||||
|
||||
connect(typingNotifications_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||
|
|
2267079
src/cscope.out
2267079
src/cscope.out
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,15 @@
|
|||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
|
||||
#include "Utils.h"
|
||||
#include "ui/Avatar.h"
|
||||
|
||||
#define AVATAR_RECT_ROUND 5
|
||||
|
||||
Avatar::Avatar(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
size_ = ui::AvatarSize;
|
||||
type_ = ui::AvatarType::Letter;
|
||||
letter_ = "A";
|
||||
rounded_ = true;
|
||||
|
||||
QFont _font(font());
|
||||
_font.setPointSizeF(ui::FontSize);
|
||||
|
@ -103,15 +101,12 @@ Avatar::setIcon(const QIcon &icon)
|
|||
update();
|
||||
}
|
||||
|
||||
void
|
||||
Avatar::setRounded(bool setting)
|
||||
{
|
||||
rounded_ = setting;
|
||||
}
|
||||
|
||||
void
|
||||
Avatar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
|
||||
bool rounded = QSettings().value("user/avatar/circles", true).toBool();
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
|
@ -125,11 +120,9 @@ Avatar::paintEvent(QPaintEvent *)
|
|||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(brush);
|
||||
rounded_ ?
|
||||
rounded ?
|
||||
painter.drawEllipse(r.center(), hs, hs) :
|
||||
painter.drawRoundedRect( r,
|
||||
AVATAR_RECT_ROUND,
|
||||
AVATAR_RECT_ROUND);
|
||||
painter.drawRoundedRect(r, 3, 3);
|
||||
}
|
||||
|
||||
switch (type_) {
|
||||
|
@ -143,11 +136,9 @@ Avatar::paintEvent(QPaintEvent *)
|
|||
case ui::AvatarType::Image: {
|
||||
QPainterPath ppath;
|
||||
|
||||
rounded_ ?
|
||||
rounded ?
|
||||
ppath.addEllipse(width() / 2 - hs, height() / 2 - hs, size_, size_) :
|
||||
ppath.addRoundedRect( r,
|
||||
AVATAR_RECT_ROUND,
|
||||
AVATAR_RECT_ROUND);
|
||||
ppath.addRoundedRect(r, 3, 3);
|
||||
|
||||
painter.setClipPath(ppath);
|
||||
painter.drawPixmap(QRect(width() / 2 - hs, height() / 2 - hs, size_, size_),
|
||||
|
|
|
@ -23,7 +23,6 @@ public:
|
|||
void setLetter(const QString &letter);
|
||||
void setSize(int size);
|
||||
void setTextColor(const QColor &color);
|
||||
void setRounded(bool setting);
|
||||
|
||||
QColor backgroundColor() const;
|
||||
QColor textColor() const;
|
||||
|
@ -45,5 +44,4 @@ private:
|
|||
QImage image_;
|
||||
QPixmap pixmap_;
|
||||
int size_;
|
||||
bool rounded_ = true;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue