nheko/include/CommunitiesListItem.h

82 lines
1.9 KiB
C
Raw Normal View History

#pragma once
2017-10-30 03:01:42 +01:00
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
2017-10-30 03:01:42 +01:00
#include <QSharedPointer>
#include <QWidget>
#include "Community.h"
2017-10-30 03:01:42 +01:00
#include "Menu.h"
#include "ui/Theme.h"
class CommunitiesListItem : public QWidget
{
2017-10-30 03:01:42 +01:00
Q_OBJECT
public:
2017-10-30 03:01:42 +01:00
CommunitiesListItem(QSharedPointer<Community> community,
QString community_id,
QWidget *parent = nullptr);
2017-10-30 03:01:42 +01:00
~CommunitiesListItem();
2017-10-30 03:01:42 +01:00
void setCommunity(QSharedPointer<Community> community);
2017-10-30 03:01:42 +01:00
inline bool isPressed() const;
inline void setAvatar(const QImage &avatar_image);
signals:
2017-10-30 03:01:42 +01:00
void clicked(const QString &community_id);
public slots:
2017-10-30 03:01:42 +01:00
void setPressedState(bool state);
protected:
2017-10-30 03:01:42 +01:00
void mousePressEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
private:
2017-10-30 03:01:42 +01:00
const int IconSize = 55;
2017-10-30 03:01:42 +01:00
QSharedPointer<Community> community_;
QString communityId_;
QString communityName_;
QString communityShortDescription;
2017-10-30 03:01:42 +01:00
QPixmap communityAvatar_;
2017-10-30 03:01:42 +01:00
Menu *menu_;
bool isPressed_ = false;
};
inline bool
CommunitiesListItem::isPressed() const
{
2017-10-30 03:01:42 +01:00
return isPressed_;
}
inline void
CommunitiesListItem::setAvatar(const QImage &avatar_image)
{
2017-10-30 03:01:42 +01:00
communityAvatar_ = QPixmap::fromImage(
avatar_image.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
update();
}
class WorldCommunityListItem : public CommunitiesListItem
{
2017-10-30 03:01:42 +01:00
Q_OBJECT
public:
2017-10-30 03:01:42 +01:00
WorldCommunityListItem(QWidget *parent = nullptr);
~WorldCommunityListItem();
protected:
2017-10-30 03:01:42 +01:00
void mousePressEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
private:
2017-10-30 03:01:42 +01:00
const int IconSize = 55;
};