diff --git a/include/ChatPage.h b/include/ChatPage.h
index 16c0c322..831f3933 100644
--- a/include/ChatPage.h
+++ b/include/ChatPage.h
@@ -143,8 +143,6 @@ private:
Splitter *splitter;
QWidget *sideBar_;
- QWidget *communitiesSideBar_;
- QVBoxLayout *communitiesSideBarLayout_;
QVBoxLayout *sideBarLayout_;
QWidget *sideBarTopWidget_;
QVBoxLayout *sideBarTopWidgetLayout_;
diff --git a/include/CommunitiesList.h b/include/CommunitiesList.h
index d03d32a2..81408f58 100644
--- a/include/CommunitiesList.h
+++ b/include/CommunitiesList.h
@@ -30,6 +30,8 @@ public slots:
void highlightSelectedCommunity(const QString &id);
private:
+ void addGlobalItem() { addCommunity(QSharedPointer<Community>(new Community), "world"); }
+
//! Check whether or not a community id is currently managed.
bool communityExists(const QString &id)
{
diff --git a/include/CommunitiesListItem.h b/include/CommunitiesListItem.h
index c9272524..9309d334 100644
--- a/include/CommunitiesListItem.h
+++ b/include/CommunitiesListItem.h
@@ -7,9 +7,11 @@
#include <QWidget>
#include "Community.h"
-#include "Menu.h"
+#include "Config.h"
#include "ui/Theme.h"
+class RippleOverlay;
+
class CommunitiesListItem : public QWidget
{
Q_OBJECT
@@ -19,27 +21,37 @@ class CommunitiesListItem : public QWidget
QColor hoverBackgroundColor READ hoverBackgroundColor WRITE setHoverBackgroundColor)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
+ Q_PROPERTY(QColor avatarFgColor READ avatarFgColor WRITE setAvatarFgColor)
+ Q_PROPERTY(QColor avatarBgColor READ avatarBgColor WRITE setAvatarBgColor)
+
public:
CommunitiesListItem(QSharedPointer<Community> community,
QString community_id,
QWidget *parent = nullptr);
- void setCommunity(QSharedPointer<Community> community);
+ void setCommunity(QSharedPointer<Community> community) { community_ = community; };
- inline bool isPressed() const;
- inline void setAvatar(const QImage &avatar_image);
+ bool isPressed() const { return isPressed_; }
+ void setAvatar(const QImage &img);
QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
QColor backgroundColor() const { return backgroundColor_; }
+ QColor avatarFgColor() const { return avatarFgColor_; }
+ QColor avatarBgColor() const { return avatarBgColor_; }
+
void setHighlightedBackgroundColor(QColor &color) { highlightedBackgroundColor_ = color; }
void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; }
void setBackgroundColor(QColor &color) { backgroundColor_ = color; }
- QColor highlightedBackgroundColor_;
- QColor hoverBackgroundColor_;
- QColor backgroundColor_;
+ void setAvatarFgColor(QColor &color) { avatarFgColor_ = color; }
+ void setAvatarBgColor(QColor &color) { avatarBgColor_ = color; }
+
+ QSize sizeHint() const override
+ {
+ return QSize(IconSize + IconSize / 3, IconSize + IconSize / 3);
+ }
signals:
void clicked(const QString &community_id);
@@ -50,10 +62,9 @@ public slots:
protected:
void mousePressEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
- void contextMenuEvent(QContextMenuEvent *event) override;
private:
- const int IconSize = 55;
+ const int IconSize = 36;
QSharedPointer<Community> community_;
QString communityId_;
@@ -62,34 +73,22 @@ private:
QPixmap communityAvatar_;
- Menu *menu_;
+ QColor highlightedBackgroundColor_;
+ QColor hoverBackgroundColor_;
+ QColor backgroundColor_;
+
+ QColor avatarFgColor_;
+ QColor avatarBgColor_;
+
bool isPressed_ = false;
-};
-inline bool
-CommunitiesListItem::isPressed() const
-{
- return isPressed_;
-}
+ RippleOverlay *rippleOverlay_;
+};
inline void
-CommunitiesListItem::setAvatar(const QImage &avatar_image)
+CommunitiesListItem::setAvatar(const QImage &img)
{
communityAvatar_ = QPixmap::fromImage(
- avatar_image.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
update();
}
-
-class WorldCommunityListItem : public CommunitiesListItem
-{
- Q_OBJECT
-public:
- WorldCommunityListItem(QWidget *parent = nullptr);
-
-protected:
- void mousePressEvent(QMouseEvent *event) override;
- void paintEvent(QPaintEvent *event) override;
-
-private:
- const int IconSize = 55;
-};
diff --git a/include/Community.h b/include/Community.h
index 5b759e55..6a398099 100644
--- a/include/Community.h
+++ b/include/Community.h
@@ -1,15 +1,12 @@
#pragma once
#include <QJsonObject>
-#include <QObject>
#include <QString>
#include <QUrl>
+#include <vector>
-class Community : public QObject
+struct Community
{
- Q_OBJECT
-
-public:
void parseProfile(const QJsonObject &profile);
void parseRooms(const QJsonObject &rooms);
@@ -19,7 +16,6 @@ public:
QString getLongDescription() const { return long_description_; }
std::vector<QString> getRoomList() const { return rooms_; }
-private:
QUrl avatar_;
QString name_;
QString short_description_;
diff --git a/include/Config.h b/include/Config.h
index d7021d92..1d05e82d 100644
--- a/include/Config.h
+++ b/include/Config.h
@@ -61,10 +61,11 @@ static constexpr int cornerRadius = 3;
// RoomList specific.
namespace roomlist {
namespace fonts {
-static constexpr int heading = 13;
-static constexpr int timestamp = heading;
-static constexpr int badge = 10;
-static constexpr int bubble = 20;
+static constexpr int heading = 13;
+static constexpr int timestamp = heading;
+static constexpr int badge = 10;
+static constexpr int bubble = 20;
+static constexpr int communityBubble = bubble - 4;
} // namespace fonts
} // namespace roomlist
diff --git a/include/ui/Painter.h b/include/ui/Painter.h
new file mode 100644
index 00000000..9558b004
--- /dev/null
+++ b/include/ui/Painter.h
@@ -0,0 +1,161 @@
+#pragma once
+
+#include <QFontMetrics>
+#include <QPaintDevice>
+#include <QPainter>
+
+class Painter : public QPainter
+{
+public:
+ explicit Painter(QPaintDevice *device)
+ : QPainter(device)
+ {}
+
+ void drawTextLeft(int x, int y, const QString &text)
+ {
+ QFontMetrics m(fontMetrics());
+ drawText(x, y + m.ascent(), text);
+ }
+
+ void drawTextRight(int x, int y, int outerw, const QString &text, int textWidth = -1)
+ {
+ QFontMetrics m(fontMetrics());
+ if (textWidth < 0)
+ textWidth = m.width(text);
+ drawText((outerw - x - textWidth), y + m.ascent(), text);
+ }
+
+ void drawPixmapLeft(int x, int y, const QPixmap &pix, const QRect &from)
+ {
+ drawPixmap(QPoint(x, y), pix, from);
+ }
+
+ void drawPixmapLeft(const QPoint &p, const QPixmap &pix, const QRect &from)
+ {
+ return drawPixmapLeft(p.x(), p.y(), pix, from);
+ }
+
+ void drawPixmapLeft(int x, int y, int w, int h, const QPixmap &pix, const QRect &from)
+ {
+ drawPixmap(QRect(x, y, w, h), pix, from);
+ }
+
+ void drawPixmapLeft(const QRect &r, const QPixmap &pix, const QRect &from)
+ {
+ return drawPixmapLeft(r.x(), r.y(), r.width(), r.height(), pix, from);
+ }
+
+ void drawPixmapLeft(int x, int y, int outerw, const QPixmap &pix)
+ {
+ Q_UNUSED(outerw);
+ drawPixmap(QPoint(x, y), pix);
+ }
+
+ void drawPixmapLeft(const QPoint &p, int outerw, const QPixmap &pix)
+ {
+ return drawPixmapLeft(p.x(), p.y(), outerw, pix);
+ }
+
+ void drawPixmapRight(int x, int y, int outerw, const QPixmap &pix, const QRect &from)
+ {
+ drawPixmap(
+ QPoint((outerw - x - (from.width() / pix.devicePixelRatio())), y), pix, from);
+ }
+
+ void drawPixmapRight(const QPoint &p, int outerw, const QPixmap &pix, const QRect &from)
+ {
+ return drawPixmapRight(p.x(), p.y(), outerw, pix, from);
+ }
+ void drawPixmapRight(int x,
+ int y,
+ int w,
+ int h,
+ int outerw,
+ const QPixmap &pix,
+ const QRect &from)
+ {
+ drawPixmap(QRect((outerw - x - w), y, w, h), pix, from);
+ }
+
+ void drawPixmapRight(const QRect &r, int outerw, const QPixmap &pix, const QRect &from)
+ {
+ return drawPixmapRight(r.x(), r.y(), r.width(), r.height(), outerw, pix, from);
+ }
+
+ void drawPixmapRight(int x, int y, int outerw, const QPixmap &pix)
+ {
+ drawPixmap(QPoint((outerw - x - (pix.width() / pix.devicePixelRatio())), y), pix);
+ }
+
+ void drawPixmapRight(const QPoint &p, int outerw, const QPixmap &pix)
+ {
+ return drawPixmapRight(p.x(), p.y(), outerw, pix);
+ }
+
+ void drawAvatar(const QPixmap &pix, int w, int h, int d)
+ {
+ QPainterPath pp;
+ pp.addEllipse((w - d) / 2, (h - d) / 2, d, d);
+
+ QRect region((w - d) / 2, (h - d) / 2, d, d);
+
+ setClipPath(pp);
+ drawPixmap(region, pix);
+ }
+
+ void drawLetterAvatar(const QChar &c,
+ const QColor &penColor,
+ const QColor &brushColor,
+ int w,
+ int h,
+ int d)
+ {
+ QRect region((w - d) / 2, (h - d) / 2, d, d);
+
+ setPen(Qt::NoPen);
+ setBrush(brushColor);
+
+ drawEllipse(region.center(), d / 2, d / 2);
+
+ setBrush(Qt::NoBrush);
+ drawEllipse(region.center(), d / 2, d / 2);
+
+ setPen(penColor);
+ drawText(region.translated(0, -1), Qt::AlignCenter, c);
+ }
+};
+
+class PainterHighQualityEnabler
+{
+public:
+ PainterHighQualityEnabler(Painter &p)
+ : _painter(p)
+ {
+ static constexpr QPainter::RenderHint Hints[] = {QPainter::Antialiasing,
+ QPainter::SmoothPixmapTransform,
+ QPainter::TextAntialiasing,
+ QPainter::HighQualityAntialiasing};
+
+ auto hints = _painter.renderHints();
+ for (const auto &hint : Hints) {
+ if (!(hints & hint))
+ hints_ |= hint;
+ }
+
+ if (hints_)
+ _painter.setRenderHints(hints_);
+ }
+
+ ~PainterHighQualityEnabler()
+ {
+ if (hints_)
+ _painter.setRenderHints(hints_, false);
+ }
+
+ PainterHighQualityEnabler(const PainterHighQualityEnabler &other) = delete;
+ PainterHighQualityEnabler &operator=(const PainterHighQualityEnabler &other) = delete;
+
+private:
+ Painter &_painter;
+ QPainter::RenderHints hints_ = 0;
+};
diff --git a/include/ui/Theme.h b/include/ui/Theme.h
index 54bd4f5f..7a0bdcb7 100644
--- a/include/ui/Theme.h
+++ b/include/ui/Theme.h
@@ -15,7 +15,7 @@ enum class AvatarType
namespace sidebar {
static const int SmallSize = 60;
static const int NormalSize = 260;
-static const int CommunitiesSidebarSize = 64;
+static const int CommunitiesSidebarSize = 48;
}
// Default font size.
const int FontSize = 16;
|