diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index 8981cb98..ee338c2d 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -58,16 +58,8 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
topLayout_->setSpacing(0);
topLayout_->setMargin(0);
- communitiesSideBar_ = new QWidget(this);
- communitiesSideBar_->setFixedWidth(ui::sidebar::CommunitiesSidebarSize);
- communitiesSideBarLayout_ = new QVBoxLayout(communitiesSideBar_);
- communitiesSideBarLayout_->setSpacing(0);
- communitiesSideBarLayout_->setMargin(0);
-
communitiesList_ = new CommunitiesList(client, this);
- communitiesSideBarLayout_->addWidget(communitiesList_);
- // communitiesSideBarLayout_->addStretch(1);
- topLayout_->addWidget(communitiesSideBar_);
+ topLayout_->addWidget(communitiesList_);
auto splitter = new Splitter(this);
splitter->setHandleWidth(0);
@@ -806,12 +798,12 @@ ChatPage::setGroupViewState(bool isEnabled)
{
if (!isEnabled) {
communitiesList_->communityChanged("world");
- communitiesSideBar_->hide();
+ communitiesList_->hide();
return;
}
- communitiesSideBar_->show();
+ communitiesList_->show();
}
void
diff --git a/src/CommunitiesList.cc b/src/CommunitiesList.cc
index 2f547936..25021ba4 100644
--- a/src/CommunitiesList.cc
+++ b/src/CommunitiesList.cc
@@ -32,13 +32,7 @@ CommunitiesList::CommunitiesList(QSharedPointer<MatrixClient> client, QWidget *p
contentsLayout_->setSpacing(0);
contentsLayout_->setMargin(0);
- WorldCommunityListItem *world_list_item = new WorldCommunityListItem();
- contentsLayout_->addWidget(world_list_item);
- communities_.emplace("world", QSharedPointer<CommunitiesListItem>(world_list_item));
- connect(world_list_item,
- &WorldCommunityListItem::clicked,
- this,
- &CommunitiesList::highlightSelectedCommunity);
+ addGlobalItem();
contentsLayout_->addStretch(1);
scrollArea_->setWidget(scrollAreaContents_);
@@ -62,14 +56,7 @@ CommunitiesList::setCommunities(const std::map<QString, QSharedPointer<Community
{
communities_.clear();
- // TODO: still not sure how to handle the "world" special-case
- WorldCommunityListItem *world_list_item = new WorldCommunityListItem();
- communities_.emplace("world", QSharedPointer<CommunitiesListItem>(world_list_item));
- connect(world_list_item,
- &WorldCommunityListItem::clicked,
- this,
- &CommunitiesList::highlightSelectedCommunity);
- contentsLayout_->insertWidget(0, world_list_item);
+ addGlobalItem();
for (const auto &community : communities) {
addCommunity(community.second, community.first);
@@ -78,7 +65,7 @@ CommunitiesList::setCommunities(const std::map<QString, QSharedPointer<Community
client_->fetchCommunityRooms(community.first);
}
- world_list_item->setPressedState(true);
+ communities_["world"]->setPressedState(true);
emit communityChanged("world");
}
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);
}
|