summary refs log tree commit diff
path: root/include/CommunitiesListItem.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/CommunitiesListItem.h')
-rw-r--r--include/CommunitiesListItem.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/include/CommunitiesListItem.h b/include/CommunitiesListItem.h
new file mode 100644
index 00000000..099b4fa2
--- /dev/null
+++ b/include/CommunitiesListItem.h
@@ -0,0 +1,98 @@
+#pragma once
+
+#include <QDebug>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QSharedPointer>
+#include <QWidget>
+
+#include "Community.h"
+#include "Menu.h"
+#include "ui/Theme.h"
+
+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)
+
+public:
+        CommunitiesListItem(QSharedPointer<Community> community,
+                            QString community_id,
+                            QWidget *parent = nullptr);
+
+        ~CommunitiesListItem();
+
+        void setCommunity(QSharedPointer<Community> community);
+
+        inline bool isPressed() const;
+        inline void setAvatar(const QImage &avatar_image);
+
+        QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
+        QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
+        QColor backgroundColor() const { return backgroundColor_; }
+
+        void setHighlightedBackgroundColor(QColor &color) { highlightedBackgroundColor_ = color; }
+        void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; }
+        void setBackgroundColor(QColor &color) { backgroundColor_ = color; }
+
+        QColor highlightedBackgroundColor_;
+        QColor hoverBackgroundColor_;
+        QColor backgroundColor_;
+
+signals:
+        void clicked(const QString &community_id);
+
+public slots:
+        void setPressedState(bool state);
+
+protected:
+        void mousePressEvent(QMouseEvent *event) override;
+        void paintEvent(QPaintEvent *event) override;
+        void contextMenuEvent(QContextMenuEvent *event) override;
+
+private:
+        const int IconSize = 55;
+
+        QSharedPointer<Community> community_;
+        QString communityId_;
+        QString communityName_;
+        QString communityShortDescription;
+
+        QPixmap communityAvatar_;
+
+        Menu *menu_;
+        bool isPressed_ = false;
+};
+
+inline bool
+CommunitiesListItem::isPressed() const
+{
+        return isPressed_;
+}
+
+inline void
+CommunitiesListItem::setAvatar(const QImage &avatar_image)
+{
+        communityAvatar_ = QPixmap::fromImage(
+          avatar_image.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+        update();
+}
+
+class WorldCommunityListItem : public CommunitiesListItem
+{
+        Q_OBJECT
+public:
+        WorldCommunityListItem(QWidget *parent = nullptr);
+        ~WorldCommunityListItem();
+
+protected:
+        void mousePressEvent(QMouseEvent *event) override;
+        void paintEvent(QPaintEvent *event) override;
+
+private:
+        const int IconSize = 55;
+};