diff --git a/src/ui/Avatar.cpp b/src/ui/Avatar.cpp
index 4b4cd272..501a8968 100644
--- a/src/ui/Avatar.cpp
+++ b/src/ui/Avatar.cpp
@@ -1,12 +1,14 @@
#include <QPainter>
+#include <QSettings>
+#include "AvatarProvider.h"
#include "Utils.h"
#include "ui/Avatar.h"
-Avatar::Avatar(QWidget *parent)
+Avatar::Avatar(QWidget *parent, int size)
: QWidget(parent)
+ , size_(size)
{
- size_ = ui::AvatarSize;
type_ = ui::AvatarType::Letter;
letter_ = "A";
@@ -61,35 +63,31 @@ Avatar::setBackgroundColor(const QColor &color)
}
void
-Avatar::setSize(int size)
+Avatar::setLetter(const QString &letter)
{
- size_ = size;
-
- if (!image_.isNull())
- pixmap_ = utils::scaleImageToPixmap(image_, size_);
-
- QFont _font(font());
- _font.setPointSizeF(size_ * (ui::FontSize) / 40);
-
- setFont(_font);
+ letter_ = letter;
+ type_ = ui::AvatarType::Letter;
update();
}
void
-Avatar::setLetter(const QString &letter)
+Avatar::setImage(const QString &avatar_url)
{
- letter_ = letter;
- type_ = ui::AvatarType::Letter;
- update();
+ AvatarProvider::resolve(avatar_url, size_, this, [this](QPixmap pm) {
+ type_ = ui::AvatarType::Image;
+ pixmap_ = pm;
+ update();
+ });
}
void
-Avatar::setImage(const QImage &image)
+Avatar::setImage(const QString &room, const QString &user)
{
- image_ = image;
- type_ = ui::AvatarType::Image;
- pixmap_ = utils::scaleImageToPixmap(image_, size_);
- update();
+ AvatarProvider::resolve(room, user, size_, this, [this](QPixmap pm) {
+ type_ = ui::AvatarType::Image;
+ pixmap_ = pm;
+ update();
+ });
}
void
@@ -103,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);
@@ -116,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_) {
@@ -129,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_);
diff --git a/src/ui/Avatar.h b/src/ui/Avatar.h
index 41967af5..a643c8c4 100644
--- a/src/ui/Avatar.h
+++ b/src/ui/Avatar.h
@@ -15,13 +15,13 @@ class Avatar : public QWidget
Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor)
public:
- explicit Avatar(QWidget *parent = 0);
+ explicit Avatar(QWidget *parent = 0, int size = ui::AvatarSize);
void setBackgroundColor(const QColor &color);
void setIcon(const QIcon &icon);
- void setImage(const QImage &image);
+ void setImage(const QString &avatar_url);
+ void setImage(const QString &room, const QString &user);
void setLetter(const QString &letter);
- void setSize(int size);
void setTextColor(const QColor &color);
QColor backgroundColor() const;
@@ -41,7 +41,6 @@ private:
QColor background_color_;
QColor text_color_;
QIcon icon_;
- QImage image_;
QPixmap pixmap_;
int size_;
};
diff --git a/src/ui/InfoMessage.cpp b/src/ui/InfoMessage.cpp
index fa575d76..27bc0a5f 100644
--- a/src/ui/InfoMessage.cpp
+++ b/src/ui/InfoMessage.cpp
@@ -2,6 +2,7 @@
#include "Config.h"
#include <QDateTime>
+#include <QLocale>
#include <QPainter>
#include <QPen>
#include <QtGlobal>
@@ -61,14 +62,14 @@ DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent)
{
auto now = QDateTime::currentDateTime();
- QString fmt;
+ QString fmt = QLocale::system().dateFormat(QLocale::LongFormat);
- if (now.date().year() != datetime.date().year())
- fmt = QString("ddd d MMMM yy");
- else
- fmt = QString("ddd d MMMM");
+ if (now.date().year() == datetime.date().year()) {
+ QRegularExpression rx("[^a-zA-Z]*y+[^a-zA-Z]*");
+ fmt = fmt.remove(rx);
+ }
- msg_ = datetime.toString(fmt);
+ msg_ = datetime.date().toString(fmt);
QFontMetrics fm{font()};
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|