2018-01-09 16:07:32 +03:00
|
|
|
#include "CommunitiesListItem.h"
|
2018-04-28 15:27:12 +03:00
|
|
|
#include "Painter.h"
|
|
|
|
#include "Ripple.h"
|
|
|
|
#include "RippleOverlay.h"
|
2018-04-30 21:41:47 +03:00
|
|
|
#include "Utils.h"
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
CommunitiesListItem::CommunitiesListItem(QSharedPointer<Community> community,
|
|
|
|
QString community_id,
|
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, community_(community)
|
|
|
|
, communityId_(community_id)
|
|
|
|
{
|
2018-04-28 15:27:12 +03:00
|
|
|
setMouseTracking(true);
|
|
|
|
setAttribute(Qt::WA_Hover);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
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");
|
2018-01-09 16:07:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommunitiesListItem::setPressedState(bool state)
|
|
|
|
{
|
|
|
|
if (isPressed_ != state) {
|
|
|
|
isPressed_ = state;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommunitiesListItem::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->buttons() == Qt::RightButton) {
|
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit clicked(communityId_);
|
|
|
|
|
|
|
|
setPressedState(true);
|
2018-04-28 15:27:12 +03:00
|
|
|
|
|
|
|
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);
|
2018-01-09 16:07:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-28 15:27:12 +03:00
|
|
|
CommunitiesListItem::paintEvent(QPaintEvent *)
|
2018-01-09 16:07:32 +03:00
|
|
|
{
|
2018-04-28 15:27:12 +03:00
|
|
|
Painter p(this);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
if (isPressed_)
|
|
|
|
p.fillRect(rect(), highlightedBackgroundColor_);
|
|
|
|
else if (underMouse())
|
|
|
|
p.fillRect(rect(), hoverBackgroundColor_);
|
|
|
|
else
|
|
|
|
p.fillRect(rect(), backgroundColor_);
|
|
|
|
|
|
|
|
if (communityAvatar_.isNull()) {
|
2018-04-28 15:27:12 +03:00
|
|
|
QFont font;
|
|
|
|
font.setPixelSize(conf::roomlist::fonts::communityBubble);
|
2018-01-09 16:07:32 +03:00
|
|
|
p.setFont(font);
|
2018-04-28 15:27:12 +03:00
|
|
|
|
2018-04-30 21:41:47 +03:00
|
|
|
p.drawLetterAvatar(utils::firstChar(community_->getName()),
|
2018-04-28 15:27:12 +03:00
|
|
|
avatarFgColor_,
|
|
|
|
avatarBgColor_,
|
|
|
|
width(),
|
|
|
|
height(),
|
|
|
|
IconSize);
|
2018-01-09 16:07:32 +03:00
|
|
|
} else {
|
|
|
|
p.save();
|
|
|
|
|
2018-04-28 15:27:12 +03:00
|
|
|
p.drawAvatar(communityAvatar_, width(), height(), IconSize);
|
2018-01-09 16:07:32 +03:00
|
|
|
p.restore();
|
|
|
|
}
|
|
|
|
}
|
2018-05-11 16:00:14 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
CommunitiesListItem::setAvatar(const QImage &img)
|
|
|
|
{
|
|
|
|
communityAvatar_ = utils::scaleImageToPixmap(img, IconSize);
|
|
|
|
update();
|
|
|
|
}
|