2018-01-09 16:07:32 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
#include "Community.h"
|
2018-04-28 15:27:12 +03:00
|
|
|
#include "Config.h"
|
2018-01-09 16:07:32 +03:00
|
|
|
#include "ui/Theme.h"
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
class RippleOverlay;
|
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
class CommunitiesListItem : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QColor highlightedBackgroundColor READ highlightedBackgroundColor WRITE
|
|
|
|
setHighlightedBackgroundColor)
|
|
|
|
Q_PROPERTY(
|
|
|
|
QColor hoverBackgroundColor READ hoverBackgroundColor WRITE setHoverBackgroundColor)
|
|
|
|
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
Q_PROPERTY(QColor avatarFgColor READ avatarFgColor WRITE setAvatarFgColor)
|
|
|
|
Q_PROPERTY(QColor avatarBgColor READ avatarBgColor WRITE setAvatarBgColor)
|
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
public:
|
|
|
|
CommunitiesListItem(QSharedPointer<Community> community,
|
|
|
|
QString community_id,
|
|
|
|
QWidget *parent = nullptr);
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
void setCommunity(QSharedPointer<Community> community) { community_ = community; };
|
2018-01-09 16:07:32 +03:00
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
bool isPressed() const { return isPressed_; }
|
|
|
|
void setAvatar(const QImage &img);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
|
|
|
|
QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
|
|
|
|
QColor backgroundColor() const { return backgroundColor_; }
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
QColor avatarFgColor() const { return avatarFgColor_; }
|
|
|
|
QColor avatarBgColor() const { return avatarBgColor_; }
|
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
void setHighlightedBackgroundColor(QColor &color) { highlightedBackgroundColor_ = color; }
|
|
|
|
void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; }
|
|
|
|
void setBackgroundColor(QColor &color) { backgroundColor_ = color; }
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
void setAvatarFgColor(QColor &color) { avatarFgColor_ = color; }
|
|
|
|
void setAvatarBgColor(QColor &color) { avatarBgColor_ = color; }
|
|
|
|
|
|
|
|
QSize sizeHint() const override
|
|
|
|
{
|
|
|
|
return QSize(IconSize + IconSize / 3, IconSize + IconSize / 3);
|
|
|
|
}
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void clicked(const QString &community_id);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setPressedState(bool state);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
|
|
|
|
private:
|
2018-04-28 15:27:12 +03:00
|
|
|
const int IconSize = 36;
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
QSharedPointer<Community> community_;
|
|
|
|
QString communityId_;
|
|
|
|
QString communityName_;
|
|
|
|
QString communityShortDescription;
|
|
|
|
|
|
|
|
QPixmap communityAvatar_;
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
QColor highlightedBackgroundColor_;
|
|
|
|
QColor hoverBackgroundColor_;
|
|
|
|
QColor backgroundColor_;
|
|
|
|
|
|
|
|
QColor avatarFgColor_;
|
|
|
|
QColor avatarBgColor_;
|
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
bool isPressed_ = false;
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
RippleOverlay *rippleOverlay_;
|
|
|
|
};
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
inline void
|
2018-04-28 15:27:12 +03:00
|
|
|
CommunitiesListItem::setAvatar(const QImage &img)
|
2018-01-09 16:07:32 +03:00
|
|
|
{
|
|
|
|
communityAvatar_ = QPixmap::fromImage(
|
2018-04-28 15:27:12 +03:00
|
|
|
img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
2018-01-09 16:07:32 +03:00
|
|
|
update();
|
|
|
|
}
|