matrixion/src/ui/Avatar.h

49 lines
1.2 KiB
C
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#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);
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);
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
};