summary refs log tree commit diff
path: root/src/CommunitiesListItem.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-28 15:27:12 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-28 15:27:12 +0300
commit7621dc0cb028ff15ac2375c31a1dd6fd64b4b94b (patch)
treead22bea3f559aabfe4a6c57ca5bea79b89efe5de /src/CommunitiesListItem.cc
parentRemove old/unused code (diff)
downloadnheko-7621dc0cb028ff15ac2375c31a1dd6fd64b4b94b.tar.xz
Fix UI inconsistencies between room list & communities
fixes #204
fixes #255
Diffstat (limited to '')
-rw-r--r--src/CommunitiesListItem.cc181
1 files changed, 37 insertions, 144 deletions
diff --git a/src/CommunitiesListItem.cc b/src/CommunitiesListItem.cc
index 5aedfcbc..e86216e8 100644
--- a/src/CommunitiesListItem.cc
+++ b/src/CommunitiesListItem.cc
@@ -1,4 +1,7 @@
 #include "CommunitiesListItem.h"
+#include "Painter.h"
+#include "Ripple.h"
+#include "RippleOverlay.h"
 
 CommunitiesListItem::CommunitiesListItem(QSharedPointer<Community> community,
                                          QString community_id,
@@ -7,16 +10,17 @@ CommunitiesListItem::CommunitiesListItem(QSharedPointer<Community> community,
   , community_(community)
   , communityId_(community_id)
 {
-        // menu_ = new Menu(this);
-        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
-        setFixedHeight(ui::sidebar::CommunitiesSidebarSize);
-        setFixedWidth(ui::sidebar::CommunitiesSidebarSize);
-}
+        setMouseTracking(true);
+        setAttribute(Qt::WA_Hover);
 
-void
-CommunitiesListItem::setCommunity(QSharedPointer<Community> community)
-{
-        community_ = community;
+        QPainterPath path;
+        path.addRect(0, 0, parent->width(), height());
+        rippleOverlay_ = new RippleOverlay(this);
+        rippleOverlay_->setClipPath(path);
+        rippleOverlay_->setClipping(true);
+
+        if (communityId_ == "world")
+                communityAvatar_ = QPixmap(":/icons/icons/ui/world.svg");
 }
 
 void
@@ -39,17 +43,24 @@ CommunitiesListItem::mousePressEvent(QMouseEvent *event)
         emit clicked(communityId_);
 
         setPressedState(true);
+
+        QPoint pos           = event->pos();
+        qreal radiusEndValue = static_cast<qreal>(width()) / 3;
+
+        auto ripple = new Ripple(pos);
+        ripple->setRadiusEndValue(radiusEndValue);
+        ripple->setOpacityStartValue(0.15);
+        ripple->setColor("white");
+        ripple->radiusAnimation()->setDuration(200);
+        ripple->opacityAnimation()->setDuration(400);
+        rippleOverlay_->addRipple(ripple);
 }
 
 void
-CommunitiesListItem::paintEvent(QPaintEvent *event)
+CommunitiesListItem::paintEvent(QPaintEvent *)
 {
-        Q_UNUSED(event);
-
-        QPainter p(this);
-        p.setRenderHint(QPainter::TextAntialiasing);
-        p.setRenderHint(QPainter::SmoothPixmapTransform);
-        p.setRenderHint(QPainter::Antialiasing);
+        Painter p(this);
+        PainterHighQualityEnabler hq(p);
 
         if (isPressed_)
                 p.fillRect(rect(), highlightedBackgroundColor_);
@@ -58,139 +69,21 @@ CommunitiesListItem::paintEvent(QPaintEvent *event)
         else
                 p.fillRect(rect(), backgroundColor_);
 
-        QFont font;
-        font.setPixelSize(conf::fontSize);
-
-        p.setPen(QColor("#333"));
-
-        QRect avatarRegion((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize);
-
-        font.setBold(false);
-        p.setPen(Qt::NoPen);
-
-        // We using the first letter of room's name.
         if (communityAvatar_.isNull()) {
-                QBrush brush;
-                brush.setStyle(Qt::SolidPattern);
-                brush.setColor("#eee");
-
-                p.setPen(Qt::NoPen);
-                p.setBrush(brush);
-
-                p.drawEllipse(avatarRegion.center(), IconSize / 2, IconSize / 2);
-
-                font.setPixelSize(conf::roomlist::fonts::bubble);
+                QFont font;
+                font.setPixelSize(conf::roomlist::fonts::communityBubble);
                 p.setFont(font);
-                p.setPen(QColor("#000"));
-                p.setBrush(Qt::NoBrush);
-                p.drawText(
-                  avatarRegion.translated(0, -1), Qt::AlignCenter, QChar(community_->getName()[0]));
+
+                p.drawLetterAvatar(community_->getName()[0],
+                                   avatarFgColor_,
+                                   avatarBgColor_,
+                                   width(),
+                                   height(),
+                                   IconSize);
         } else {
                 p.save();
 
-                QPainterPath path;
-                path.addEllipse(
-                  (width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize);
-                p.setClipPath(path);
-
-                p.drawPixmap(avatarRegion, communityAvatar_);
+                p.drawAvatar(communityAvatar_, width(), height(), IconSize);
                 p.restore();
         }
-
-        // TODO: Discord-style community ping counts?
-        /*if (unreadMsgCount_ > 0) {
-                QColor textColor("white");
-                QColor backgroundColor("#38A3D8");
-
-                QBrush brush;
-                brush.setStyle(Qt::SolidPattern);
-                brush.setColor(backgroundColor);
-
-                if (isPressed_)
-                        brush.setColor(textColor);
-
-                QFont unreadCountFont;
-                unreadCountFont.setPixelSize(conf::roomlist::fonts::badge);
-                unreadCountFont.setBold(true);
-
-                p.setBrush(brush);
-                p.setPen(Qt::NoPen);
-                p.setFont(unreadCountFont);
-
-                int diameter = 20;
-
-                QRectF r(
-                  width() - diameter - 5, height() - diameter - 5, diameter, diameter);
-
-                p.setPen(Qt::NoPen);
-                p.drawEllipse(r);
-
-                p.setPen(QPen(textColor));
-
-                if (isPressed_)
-                        p.setPen(QPen(backgroundColor));
-
-                p.setBrush(Qt::NoBrush);
-                p.drawText(
-                  r.translated(0, -0.5), Qt::AlignCenter, QString::number(unreadMsgCount_));
-        }*/
-}
-
-void
-CommunitiesListItem::contextMenuEvent(QContextMenuEvent *event)
-{
-        Q_UNUSED(event);
-
-        // menu_->popup(event->globalPos());
-}
-
-WorldCommunityListItem::WorldCommunityListItem(QWidget *parent)
-  : CommunitiesListItem(QSharedPointer<Community>(), "", parent)
-{}
-
-void
-WorldCommunityListItem::mousePressEvent(QMouseEvent *event)
-{
-        if (event->buttons() == Qt::RightButton) {
-                QWidget::mousePressEvent(event);
-                return;
-        }
-
-        emit CommunitiesListItem::clicked("world");
-
-        setPressedState(true);
-}
-
-void
-WorldCommunityListItem::paintEvent(QPaintEvent *event)
-{
-        Q_UNUSED(event);
-
-        static QPixmap worldIcon(":/icons/icons/ui/world.png");
-
-        QPainter p(this);
-        p.setRenderHint(QPainter::SmoothPixmapTransform);
-        p.setRenderHint(QPainter::Antialiasing);
-
-        if (isPressed())
-                p.fillRect(rect(), highlightedBackgroundColor_);
-        else if (underMouse())
-                p.fillRect(rect(), hoverBackgroundColor_);
-        else
-                p.fillRect(rect(), backgroundColor_);
-
-        QBrush brush;
-        brush.setStyle(Qt::SolidPattern);
-        brush.setColor("#FFFFFF");
-
-        p.setPen(Qt::NoPen);
-        p.setBrush(brush);
-
-        QRect avatarRegion((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize);
-        p.drawEllipse(avatarRegion.center(), IconSize / 2, IconSize / 2);
-        QPainterPath path;
-        path.addEllipse((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize);
-        p.setClipPath(path);
-
-        p.drawPixmap(avatarRegion, worldIcon);
 }