2017-05-16 21:46:45 +03:00
|
|
|
#pragma once
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
#include "Theme.h"
|
|
|
|
|
|
|
|
class Avatar : public QWidget
|
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_OBJECT
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor)
|
|
|
|
Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor)
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
public:
|
2020-02-04 06:58:43 +03:00
|
|
|
explicit Avatar(QWidget *parent = nullptr, int size = ui::AvatarSize);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
void setBackgroundColor(const QColor &color);
|
2019-08-26 02:24:56 +03:00
|
|
|
void setImage(const QString &avatar_url);
|
|
|
|
void setImage(const QString &room, const QString &user);
|
2018-01-12 11:21:53 +03:00
|
|
|
void setLetter(const QString &letter);
|
2017-09-10 12:59:21 +03:00
|
|
|
void setTextColor(const QColor &color);
|
2020-04-29 21:23:00 +03:00
|
|
|
void setDevicePixelRatio(double ratio);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
QColor backgroundColor() const;
|
|
|
|
QColor textColor() const;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
QSize sizeHint() const override;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
protected:
|
2017-09-10 12:59:21 +03:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
private:
|
2017-09-10 12:59:21 +03:00
|
|
|
void init();
|
|
|
|
|
|
|
|
ui::AvatarType type_;
|
2018-01-12 11:21:53 +03:00
|
|
|
QString letter_;
|
2020-02-28 05:20:27 +03:00
|
|
|
QString avatar_url_, room_, user_;
|
2017-09-10 12:59:21 +03:00
|
|
|
QColor background_color_;
|
|
|
|
QColor text_color_;
|
|
|
|
QPixmap pixmap_;
|
|
|
|
int size_;
|
2017-04-06 02:06:42 +03:00
|
|
|
};
|