mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 04:28:49 +03:00
added logic in avatar class to determine rounding type
This commit is contained in:
parent
89015b9f18
commit
26002bf0e4
2 changed files with 25 additions and 5 deletions
|
@ -3,12 +3,15 @@
|
||||||
#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);
|
||||||
|
@ -101,6 +104,11 @@ Avatar::setIcon(const QIcon &icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Avatar::rounded(bool setting)
|
||||||
|
{
|
||||||
|
rounded_ = setting;
|
||||||
|
}
|
||||||
|
|
||||||
Avatar::paintEvent(QPaintEvent *)
|
Avatar::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
@ -116,7 +124,11 @@ Avatar::paintEvent(QPaintEvent *)
|
||||||
|
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
painter.drawEllipse(r.center(), hs, hs);
|
rounded_ ?
|
||||||
|
painter.drawEllipse(r.center(), hs, hs) :
|
||||||
|
painter.drawRoundedRect( r,
|
||||||
|
AVATAR_RECT_ROUND,
|
||||||
|
AVATAR_RECT_ROUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
|
@ -129,7 +141,13 @@ Avatar::paintEvent(QPaintEvent *)
|
||||||
}
|
}
|
||||||
case ui::AvatarType::Image: {
|
case ui::AvatarType::Image: {
|
||||||
QPainterPath ppath;
|
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,
|
||||||
|
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_),
|
||||||
pixmap_);
|
pixmap_);
|
||||||
|
|
|
@ -23,6 +23,7 @@ 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 rounded(bool setting);
|
||||||
|
|
||||||
QColor backgroundColor() const;
|
QColor backgroundColor() const;
|
||||||
QColor textColor() const;
|
QColor textColor() const;
|
||||||
|
@ -44,4 +45,5 @@ private:
|
||||||
QImage image_;
|
QImage image_;
|
||||||
QPixmap pixmap_;
|
QPixmap pixmap_;
|
||||||
int size_;
|
int size_;
|
||||||
|
bool rounded_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue