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