Refactored Avatar and RoomInfoListItem to access rounding settings in place

This commit is contained in:
Aidan Hahn 2019-09-01 14:41:23 -07:00
parent b10d453bd5
commit a1c2aed36a
No known key found for this signature in database
GPG key ID: 327711E983899316
8 changed files with 22 additions and 2267119 deletions

View file

@ -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_),

View file

@ -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;
};