2018-01-09 16:07:32 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "CommunitiesListItem.h"
|
|
|
|
#include "Community.h"
|
|
|
|
#include "ui/Theme.h"
|
|
|
|
|
|
|
|
class CommunitiesList : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-05-08 18:43:56 +03:00
|
|
|
CommunitiesList(QWidget *parent = nullptr);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
2018-01-24 21:46:37 +03:00
|
|
|
void setCommunities(const std::map<QString, QSharedPointer<Community>> &communities);
|
|
|
|
void clear() { communities_.clear(); }
|
|
|
|
|
|
|
|
void addCommunity(QSharedPointer<Community> community, const QString &id);
|
2018-01-25 15:34:15 +03:00
|
|
|
void removeCommunity(const QString &id) { communities_.erase(id); };
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
signals:
|
2018-01-24 21:46:37 +03:00
|
|
|
void communityChanged(const QString &id);
|
2018-06-09 16:03:14 +03:00
|
|
|
void avatarRetrieved(const QString &id, const QPixmap &img);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
public slots:
|
2018-01-24 21:46:37 +03:00
|
|
|
void updateCommunityAvatar(const QString &id, const QPixmap &img);
|
|
|
|
void highlightSelectedCommunity(const QString &id);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
private:
|
2018-06-09 16:03:14 +03:00
|
|
|
void fetchCommunityAvatar(const QString &id, const QString &avatarUrl);
|
2018-04-28 15:27:12 +03:00
|
|
|
void addGlobalItem() { addCommunity(QSharedPointer<Community>(new Community), "world"); }
|
|
|
|
|
2018-01-24 21:46:37 +03:00
|
|
|
//! Check whether or not a community id is currently managed.
|
|
|
|
bool communityExists(const QString &id)
|
|
|
|
{
|
|
|
|
return communities_.find(id) != communities_.end();
|
|
|
|
}
|
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
QVBoxLayout *topLayout_;
|
|
|
|
QVBoxLayout *contentsLayout_;
|
|
|
|
QWidget *scrollAreaContents_;
|
|
|
|
QScrollArea *scrollArea_;
|
|
|
|
|
2018-01-24 21:46:37 +03:00
|
|
|
std::map<QString, QSharedPointer<CommunitiesListItem>> communities_;
|
2018-01-09 16:07:32 +03:00
|
|
|
};
|