2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-03-26 22:02:53 +03:00
|
|
|
#include <QDateTime>
|
2020-05-18 04:30:04 +03:00
|
|
|
#include <QInputDialog>
|
2021-01-23 02:30:45 +03:00
|
|
|
#include <QMenu>
|
2017-04-09 03:54:39 +03:00
|
|
|
#include <QMouseEvent>
|
2017-05-19 03:28:15 +03:00
|
|
|
#include <QPainter>
|
2019-09-04 05:59:08 +03:00
|
|
|
#include <QtGlobal>
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2019-08-26 02:24:56 +03:00
|
|
|
#include "AvatarProvider.h"
|
2018-04-21 16:34:50 +03:00
|
|
|
#include "Cache.h"
|
2020-05-18 04:30:04 +03:00
|
|
|
#include "ChatPage.h"
|
2017-07-15 17:11:46 +03:00
|
|
|
#include "Config.h"
|
2020-05-18 04:30:04 +03:00
|
|
|
#include "Logging.h"
|
|
|
|
#include "MatrixClient.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
#include "RoomInfoListItem.h"
|
2020-01-31 08:12:02 +03:00
|
|
|
#include "Splitter.h"
|
2020-03-15 18:19:22 +03:00
|
|
|
#include "UserSettingsPage.h"
|
2018-01-12 11:21:53 +03:00
|
|
|
#include "Utils.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "ui/Ripple.h"
|
|
|
|
#include "ui/RippleOverlay.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-05-25 10:01:53 +03:00
|
|
|
constexpr int MaxUnreadCountDisplayed = 99;
|
2018-03-20 22:23:01 +03:00
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
struct WidgetMetrics
|
|
|
|
{
|
|
|
|
int maxHeight;
|
|
|
|
int iconSize;
|
|
|
|
int padding;
|
|
|
|
int unit;
|
|
|
|
|
|
|
|
int unreadLineWidth;
|
|
|
|
int unreadLineOffset;
|
|
|
|
|
|
|
|
int inviteBtnX;
|
|
|
|
int inviteBtnY;
|
|
|
|
};
|
|
|
|
|
|
|
|
WidgetMetrics
|
|
|
|
getMetrics(const QFont &font)
|
|
|
|
{
|
|
|
|
WidgetMetrics m;
|
|
|
|
|
|
|
|
const int height = QFontMetrics(font).lineSpacing();
|
|
|
|
|
|
|
|
m.unit = height;
|
2018-10-10 22:02:59 +03:00
|
|
|
m.maxHeight = std::ceil((double)height * 3.8);
|
|
|
|
m.iconSize = std::ceil((double)height * 2.8);
|
2018-10-06 17:21:03 +03:00
|
|
|
m.padding = std::ceil((double)height / 2.0);
|
|
|
|
m.unreadLineWidth = m.padding - m.padding / 3;
|
|
|
|
m.unreadLineOffset = m.padding - m.padding / 4;
|
|
|
|
|
|
|
|
m.inviteBtnX = m.iconSize + 2 * m.padding;
|
2019-12-13 23:05:28 +03:00
|
|
|
m.inviteBtnY = m.iconSize / 2.0 + m.padding + m.padding / 3.0;
|
2018-10-06 17:21:03 +03:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
2017-12-19 23:36:12 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
RoomInfoListItem::init(QWidget *parent)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
setMouseTracking(true);
|
|
|
|
setAttribute(Qt::WA_Hover);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-02-28 05:20:27 +03:00
|
|
|
auto wm = getMetrics(QFont{});
|
|
|
|
setFixedHeight(wm.maxHeight);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
QPainterPath path;
|
|
|
|
path.addRect(0, 0, parent->width(), height());
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
ripple_overlay_ = new RippleOverlay(this);
|
|
|
|
ripple_overlay_->setClipPath(path);
|
|
|
|
ripple_overlay_->setClipping(true);
|
2018-03-18 16:54:53 +03:00
|
|
|
|
2020-03-03 03:23:04 +03:00
|
|
|
avatar_ = new Avatar(nullptr, wm.iconSize);
|
2020-02-28 05:20:27 +03:00
|
|
|
avatar_->setLetter(utils::firstChar(roomName_));
|
2020-03-03 03:23:04 +03:00
|
|
|
avatar_->resize(wm.iconSize, wm.iconSize);
|
2020-02-28 05:20:27 +03:00
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
unreadCountFont_.setPointSizeF(unreadCountFont_.pointSizeF() * 0.8);
|
2018-03-18 16:54:53 +03:00
|
|
|
unreadCountFont_.setBold(true);
|
2018-09-30 13:24:36 +03:00
|
|
|
|
2018-05-25 10:01:53 +03:00
|
|
|
bubbleDiameter_ = QFontMetrics(unreadCountFont_).averageCharWidth() * 3;
|
2018-03-18 16:54:53 +03:00
|
|
|
|
2021-01-23 02:30:45 +03:00
|
|
|
menu_ = new QMenu(this);
|
2018-04-21 16:34:50 +03:00
|
|
|
leaveRoom_ = new QAction(tr("Leave room"), this);
|
|
|
|
connect(leaveRoom_, &QAction::triggered, this, [this]() { emit leaveRoom(roomId_); });
|
2020-05-18 04:30:04 +03:00
|
|
|
|
|
|
|
connect(menu_, &QMenu::aboutToShow, this, [this]() {
|
|
|
|
menu_->clear();
|
|
|
|
menu_->addAction(leaveRoom_);
|
|
|
|
|
|
|
|
menu_->addSection(QIcon(":/icons/icons/ui/tag.png"), tr("Tag room as:"));
|
|
|
|
|
|
|
|
auto roomInfo = cache::singleRoomInfo(roomId_.toStdString());
|
|
|
|
|
|
|
|
auto tags = ChatPage::instance()->communitiesList()->currentTags();
|
|
|
|
|
|
|
|
// add default tag, remove server notice tag
|
|
|
|
if (std::find(tags.begin(), tags.end(), "m.favourite") == tags.end())
|
|
|
|
tags.push_back("m.favourite");
|
|
|
|
if (std::find(tags.begin(), tags.end(), "m.lowpriority") == tags.end())
|
|
|
|
tags.push_back("m.lowpriority");
|
|
|
|
if (auto it = std::find(tags.begin(), tags.end(), "m.server_notice");
|
|
|
|
it != tags.end())
|
|
|
|
tags.erase(it);
|
|
|
|
|
|
|
|
for (const auto &tag : tags) {
|
|
|
|
QString tagName;
|
|
|
|
if (tag == "m.favourite")
|
|
|
|
tagName = tr("Favourite", "Standard matrix tag for favourites");
|
|
|
|
else if (tag == "m.lowpriority")
|
|
|
|
tagName =
|
|
|
|
tr("Low Priority", "Standard matrix tag for low priority rooms");
|
|
|
|
else if (tag == "m.server_notice")
|
|
|
|
tagName =
|
|
|
|
tr("Server Notice", "Standard matrix tag for server notices");
|
|
|
|
else if ((tag.size() > 2 && tag.substr(0, 2) == "u.") ||
|
|
|
|
tag.find(".") !=
|
|
|
|
std::string::npos) // tag manager creates tags without u., which
|
|
|
|
// is wrong, but we still want to display them
|
|
|
|
tagName = QString::fromStdString(tag.substr(2));
|
|
|
|
|
|
|
|
if (tagName.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto tagAction = menu_->addAction(tagName);
|
|
|
|
tagAction->setCheckable(true);
|
|
|
|
tagAction->setWhatsThis(tr("Adds or removes the specified tag.",
|
|
|
|
"WhatsThis hint for tag menu actions"));
|
|
|
|
|
2021-01-22 05:18:36 +03:00
|
|
|
for (const auto &riTag : roomInfo.tags) {
|
2020-05-18 04:30:04 +03:00
|
|
|
if (riTag == tag) {
|
|
|
|
tagAction->setChecked(true);
|
|
|
|
break;
|
|
|
|
}
|
2021-01-22 05:18:36 +03:00
|
|
|
}
|
2020-05-18 04:30:04 +03:00
|
|
|
|
|
|
|
connect(tagAction, &QAction::triggered, this, [this, tag](bool checked) {
|
|
|
|
if (checked)
|
|
|
|
http::client()->put_tag(
|
|
|
|
roomId_.toStdString(),
|
|
|
|
tag,
|
|
|
|
{},
|
|
|
|
[tag](mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::ui()->error(
|
|
|
|
"Failed to add tag: {}, {}",
|
|
|
|
tag,
|
|
|
|
err->matrix_error.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
else
|
|
|
|
http::client()->delete_tag(
|
|
|
|
roomId_.toStdString(),
|
|
|
|
tag,
|
|
|
|
[tag](mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::ui()->error(
|
|
|
|
"Failed to delete tag: {}, {}",
|
|
|
|
tag,
|
|
|
|
err->matrix_error.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
auto newTagAction = menu_->addAction(tr("New tag...", "Add a new tag to the room"));
|
|
|
|
connect(newTagAction, &QAction::triggered, this, [this]() {
|
|
|
|
QString tagName =
|
|
|
|
QInputDialog::getText(this,
|
|
|
|
tr("New Tag", "Tag name prompt title"),
|
|
|
|
tr("Tag:", "Tag name prompt"));
|
|
|
|
if (tagName.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string tag = "u." + tagName.toStdString();
|
|
|
|
|
|
|
|
http::client()->put_tag(
|
|
|
|
roomId_.toStdString(), tag, {}, [tag](mtx::http::RequestErr err) {
|
|
|
|
if (err) {
|
|
|
|
nhlog::ui()->error("Failed to add tag: {}, {}",
|
|
|
|
tag,
|
|
|
|
err->matrix_error.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-12-19 23:36:12 +03:00
|
|
|
}
|
|
|
|
|
2020-10-17 01:57:29 +03:00
|
|
|
RoomInfoListItem::RoomInfoListItem(QString room_id, const RoomInfo &info, QWidget *parent)
|
2017-12-19 23:36:12 +03:00
|
|
|
: QWidget(parent)
|
2018-04-21 16:34:50 +03:00
|
|
|
, roomType_{info.is_invite ? RoomType::Invited : RoomType::Joined}
|
|
|
|
, roomId_(std::move(room_id))
|
|
|
|
, roomName_{QString::fromStdString(std::move(info.name))}
|
|
|
|
, isPressed_(false)
|
|
|
|
, unreadMsgCount_(0)
|
2019-01-25 05:43:54 +03:00
|
|
|
, unreadHighlightedMsgCount_(0)
|
2017-12-19 23:36:12 +03:00
|
|
|
{
|
|
|
|
init(parent);
|
2017-05-19 03:28:15 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RoomInfoListItem::resizeEvent(QResizeEvent *)
|
2017-08-05 15:59:24 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
// Update ripple's clipping path.
|
|
|
|
QPainterPath path;
|
|
|
|
path.addRect(0, 0, width(), height());
|
2017-08-05 15:59:24 +03:00
|
|
|
|
2020-01-31 08:12:02 +03:00
|
|
|
const auto sidebarSizes = splitter::calculateSidebarSizes(QFont{});
|
2018-10-07 14:09:47 +03:00
|
|
|
|
|
|
|
if (width() > sidebarSizes.small)
|
2018-04-30 09:27:12 +03:00
|
|
|
setToolTip("");
|
|
|
|
else
|
|
|
|
setToolTip(roomName_);
|
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
ripple_overlay_->setClipPath(path);
|
|
|
|
ripple_overlay_->setClipping(true);
|
2017-08-05 15:59:24 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RoomInfoListItem::paintEvent(QPaintEvent *event)
|
2017-05-19 03:28:15 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
p.setRenderHint(QPainter::TextAntialiasing);
|
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
QFontMetrics metrics(QFont{});
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2017-12-19 23:36:12 +03:00
|
|
|
QPen titlePen(titleColor_);
|
|
|
|
QPen subtitlePen(subtitleColor_);
|
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
auto wm = getMetrics(QFont{});
|
|
|
|
|
2020-04-29 21:23:00 +03:00
|
|
|
QPixmap pixmap(avatar_->size() * p.device()->devicePixelRatioF());
|
|
|
|
pixmap.setDevicePixelRatio(p.device()->devicePixelRatioF());
|
2017-11-16 17:33:52 +03:00
|
|
|
if (isPressed_) {
|
|
|
|
p.fillRect(rect(), highlightedBackgroundColor_);
|
2017-12-19 23:36:12 +03:00
|
|
|
titlePen.setColor(highlightedTitleColor_);
|
|
|
|
subtitlePen.setColor(highlightedSubtitleColor_);
|
2020-03-03 03:23:04 +03:00
|
|
|
pixmap.fill(highlightedBackgroundColor_);
|
2017-11-16 17:33:52 +03:00
|
|
|
} else if (underMouse()) {
|
|
|
|
p.fillRect(rect(), hoverBackgroundColor_);
|
2019-01-12 17:35:56 +03:00
|
|
|
titlePen.setColor(hoverTitleColor_);
|
|
|
|
subtitlePen.setColor(hoverSubtitleColor_);
|
2020-03-03 03:23:04 +03:00
|
|
|
pixmap.fill(hoverBackgroundColor_);
|
2017-11-16 17:33:52 +03:00
|
|
|
} else {
|
|
|
|
p.fillRect(rect(), backgroundColor_);
|
2019-01-12 17:35:56 +03:00
|
|
|
titlePen.setColor(titleColor_);
|
|
|
|
subtitlePen.setColor(subtitleColor_);
|
2020-03-03 03:23:04 +03:00
|
|
|
pixmap.fill(backgroundColor_);
|
2017-11-16 17:33:52 +03:00
|
|
|
}
|
|
|
|
|
2020-03-03 03:23:04 +03:00
|
|
|
avatar_->render(&pixmap, QPoint(), QRegion(), RenderFlags(DrawChildren));
|
|
|
|
p.drawPixmap(QPoint(wm.padding, wm.padding), pixmap);
|
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
// Description line with the default font.
|
2018-10-06 17:21:03 +03:00
|
|
|
int bottom_y = wm.maxHeight - wm.padding - metrics.ascent() / 2;
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2020-01-31 08:12:02 +03:00
|
|
|
const auto sidebarSizes = splitter::calculateSidebarSizes(QFont{});
|
2018-10-07 14:09:47 +03:00
|
|
|
|
|
|
|
if (width() > sidebarSizes.small) {
|
2018-10-06 17:21:03 +03:00
|
|
|
QFont headingFont;
|
|
|
|
headingFont.setWeight(QFont::Medium);
|
|
|
|
p.setFont(headingFont);
|
2017-12-19 23:36:12 +03:00
|
|
|
p.setPen(titlePen);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2018-10-07 16:32:46 +03:00
|
|
|
QFont tsFont;
|
|
|
|
tsFont.setPointSizeF(tsFont.pointSizeF() * 0.9);
|
2019-07-05 05:58:06 +03:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
|
2020-05-01 00:59:17 +03:00
|
|
|
const int msgStampWidth =
|
|
|
|
QFontMetrics(tsFont).width(lastMsgInfo_.descriptiveTime) + 4;
|
2019-07-05 05:58:06 +03:00
|
|
|
#else
|
2019-07-05 04:31:28 +03:00
|
|
|
const int msgStampWidth =
|
2020-05-01 00:59:17 +03:00
|
|
|
QFontMetrics(tsFont).horizontalAdvance(lastMsgInfo_.descriptiveTime) + 4;
|
2019-07-05 05:58:06 +03:00
|
|
|
#endif
|
2018-03-19 19:10:48 +03:00
|
|
|
// We use the full width of the widget if there is no unread msg bubble.
|
|
|
|
const int bottomLineWidthLimit = (unreadMsgCount_ > 0) ? msgStampWidth : 0;
|
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
// Name line.
|
2018-10-06 17:21:03 +03:00
|
|
|
QFontMetrics fontNameMetrics(headingFont);
|
|
|
|
int top_y = 2 * wm.padding + fontNameMetrics.ascent() / 2;
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
const auto name = metrics.elidedText(
|
|
|
|
roomName(),
|
|
|
|
Qt::ElideRight,
|
|
|
|
(width() - wm.iconSize - 2 * wm.padding - msgStampWidth) * 0.8);
|
|
|
|
p.drawText(QPoint(2 * wm.padding + wm.iconSize, top_y), name);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2017-12-19 23:36:12 +03:00
|
|
|
if (roomType_ == RoomType::Joined) {
|
2018-10-06 17:21:03 +03:00
|
|
|
p.setFont(QFont{});
|
2017-12-19 23:36:12 +03:00
|
|
|
p.setPen(subtitlePen);
|
2017-05-07 17:15:38 +03:00
|
|
|
|
2019-11-02 20:17:06 +03:00
|
|
|
int descriptionLimit = std::max(
|
|
|
|
0, width() - 3 * wm.padding - bottomLineWidthLimit - wm.iconSize);
|
2017-12-19 23:36:12 +03:00
|
|
|
auto description =
|
|
|
|
metrics.elidedText(lastMsgInfo_.body, Qt::ElideRight, descriptionLimit);
|
2019-11-02 20:17:06 +03:00
|
|
|
p.drawText(QPoint(2 * wm.padding + wm.iconSize, bottom_y), description);
|
2017-12-19 23:36:12 +03:00
|
|
|
|
2018-03-18 16:54:53 +03:00
|
|
|
// We show the last message timestamp.
|
2018-03-19 00:38:04 +03:00
|
|
|
p.save();
|
2019-01-13 01:03:25 +03:00
|
|
|
if (isPressed_) {
|
2018-03-19 00:38:04 +03:00
|
|
|
p.setPen(QPen(highlightedTimestampColor_));
|
2019-01-13 01:03:25 +03:00
|
|
|
} else if (underMouse()) {
|
|
|
|
p.setPen(QPen(hoverTimestampColor_));
|
|
|
|
} else {
|
2018-03-19 00:38:04 +03:00
|
|
|
p.setPen(QPen(timestampColor_));
|
2019-01-13 01:03:25 +03:00
|
|
|
}
|
2018-03-19 00:38:04 +03:00
|
|
|
|
2018-10-07 16:32:46 +03:00
|
|
|
p.setFont(tsFont);
|
2018-10-06 17:21:03 +03:00
|
|
|
p.drawText(QPoint(width() - wm.padding - msgStampWidth, top_y),
|
2020-05-01 00:59:17 +03:00
|
|
|
lastMsgInfo_.descriptiveTime);
|
2018-03-19 00:38:04 +03:00
|
|
|
p.restore();
|
2017-12-19 23:36:12 +03:00
|
|
|
} else {
|
2018-10-06 17:21:03 +03:00
|
|
|
int btnWidth = (width() - wm.iconSize - 6 * wm.padding) / 2;
|
2017-07-01 12:46:58 +03:00
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
acceptBtnRegion_ = QRectF(wm.inviteBtnX, wm.inviteBtnY, btnWidth, 20);
|
|
|
|
declineBtnRegion_ = QRectF(
|
|
|
|
wm.inviteBtnX + btnWidth + 2 * wm.padding, wm.inviteBtnY, btnWidth, 20);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-12-19 23:36:12 +03:00
|
|
|
QPainterPath acceptPath;
|
|
|
|
acceptPath.addRoundedRect(acceptBtnRegion_, 10, 10);
|
2017-04-15 02:56:04 +03:00
|
|
|
|
2017-12-19 23:36:12 +03:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.fillPath(acceptPath, btnColor_);
|
|
|
|
p.drawPath(acceptPath);
|
2017-04-15 02:56:04 +03:00
|
|
|
|
2017-12-19 23:36:12 +03:00
|
|
|
QPainterPath declinePath;
|
|
|
|
declinePath.addRoundedRect(declineBtnRegion_, 10, 10);
|
2017-04-15 02:56:04 +03:00
|
|
|
|
2017-12-19 23:36:12 +03:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.fillPath(declinePath, btnColor_);
|
|
|
|
p.drawPath(declinePath);
|
|
|
|
|
|
|
|
p.setPen(QPen(btnTextColor_));
|
2018-10-06 17:21:03 +03:00
|
|
|
p.setFont(QFont{});
|
2019-12-13 23:05:28 +03:00
|
|
|
p.drawText(acceptBtnRegion_,
|
|
|
|
Qt::AlignCenter,
|
|
|
|
metrics.elidedText(tr("Accept"), Qt::ElideRight, btnWidth));
|
|
|
|
p.drawText(declineBtnRegion_,
|
|
|
|
Qt::AlignCenter,
|
|
|
|
metrics.elidedText(tr("Decline"), Qt::ElideRight, btnWidth));
|
2017-09-10 12:59:21 +03:00
|
|
|
}
|
|
|
|
}
|
2017-07-01 12:46:58 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
p.setPen(Qt::NoPen);
|
2017-07-15 17:11:46 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
if (unreadMsgCount_ > 0) {
|
|
|
|
QBrush brush;
|
|
|
|
brush.setStyle(Qt::SolidPattern);
|
2019-01-25 05:43:54 +03:00
|
|
|
if (unreadHighlightedMsgCount_ > 0) {
|
|
|
|
brush.setColor(mentionedColor());
|
|
|
|
} else {
|
|
|
|
brush.setColor(bubbleBgColor());
|
|
|
|
}
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
if (isPressed_)
|
2018-03-19 21:26:14 +03:00
|
|
|
brush.setColor(bubbleFgColor());
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
p.setBrush(brush);
|
|
|
|
p.setPen(Qt::NoPen);
|
2018-03-18 16:54:53 +03:00
|
|
|
p.setFont(unreadCountFont_);
|
2017-08-06 18:53:31 +03:00
|
|
|
|
2018-05-25 10:01:53 +03:00
|
|
|
// Extra space on the x-axis to accomodate the extra character space
|
|
|
|
// inside the bubble.
|
|
|
|
const int x_width = unreadMsgCount_ > MaxUnreadCountDisplayed
|
|
|
|
? QFontMetrics(p.font()).averageCharWidth()
|
|
|
|
: 0;
|
|
|
|
|
2018-10-06 17:21:03 +03:00
|
|
|
QRectF r(width() - bubbleDiameter_ - wm.padding - x_width,
|
2018-05-25 10:01:53 +03:00
|
|
|
bottom_y - bubbleDiameter_ / 2 - 5,
|
|
|
|
bubbleDiameter_ + x_width,
|
|
|
|
bubbleDiameter_);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2018-10-07 14:09:47 +03:00
|
|
|
if (width() == sidebarSizes.small)
|
2018-05-25 10:01:53 +03:00
|
|
|
r = QRectF(width() - bubbleDiameter_ - 5,
|
|
|
|
height() - bubbleDiameter_ - 5,
|
|
|
|
bubbleDiameter_ + x_width,
|
|
|
|
bubbleDiameter_);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(r);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2018-03-19 21:26:14 +03:00
|
|
|
p.setPen(QPen(bubbleFgColor()));
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
if (isPressed_)
|
2018-03-19 21:26:14 +03:00
|
|
|
p.setPen(QPen(bubbleBgColor()));
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2018-05-25 10:01:53 +03:00
|
|
|
auto countTxt = unreadMsgCount_ > MaxUnreadCountDisplayed
|
|
|
|
? QString("99+")
|
|
|
|
: QString::number(unreadMsgCount_);
|
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
p.setBrush(Qt::NoBrush);
|
2018-05-25 10:01:53 +03:00
|
|
|
p.drawText(r.translated(0, -0.5), Qt::AlignCenter, countTxt);
|
2017-09-10 12:59:21 +03:00
|
|
|
}
|
2018-09-13 19:15:58 +03:00
|
|
|
|
|
|
|
if (!isPressed_ && hasUnreadMessages_) {
|
|
|
|
QPen pen;
|
2018-10-06 17:21:03 +03:00
|
|
|
pen.setWidth(wm.unreadLineWidth);
|
2018-09-13 19:15:58 +03:00
|
|
|
pen.setColor(highlightedBackgroundColor_);
|
|
|
|
|
|
|
|
p.setPen(pen);
|
2018-10-06 17:21:03 +03:00
|
|
|
p.drawLine(0, wm.unreadLineOffset, 0, height() - wm.unreadLineOffset);
|
2018-09-13 19:15:58 +03:00
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2019-01-25 05:43:54 +03:00
|
|
|
RoomInfoListItem::updateUnreadMessageCount(int count, int highlightedCount)
|
2017-04-15 02:56:04 +03:00
|
|
|
{
|
2019-01-25 05:43:54 +03:00
|
|
|
unreadMsgCount_ = count;
|
|
|
|
unreadHighlightedMsgCount_ = highlightedCount;
|
2017-09-10 12:59:21 +03:00
|
|
|
update();
|
2017-04-15 02:56:04 +03:00
|
|
|
}
|
|
|
|
|
2020-03-15 21:56:39 +03:00
|
|
|
enum NotificationImportance : short
|
2020-03-15 17:38:56 +03:00
|
|
|
{
|
2020-03-15 21:56:39 +03:00
|
|
|
ImportanceDisabled = -1,
|
|
|
|
AllEventsRead = 0,
|
2020-03-15 23:28:32 +03:00
|
|
|
NewMessage = 1,
|
|
|
|
NewMentions = 2,
|
|
|
|
Invite = 3
|
2020-03-15 17:38:56 +03:00
|
|
|
};
|
|
|
|
|
2020-03-16 00:05:21 +03:00
|
|
|
short int
|
2020-03-14 02:30:50 +03:00
|
|
|
RoomInfoListItem::calculateImportance() const
|
|
|
|
{
|
2020-03-15 18:19:22 +03:00
|
|
|
// Returns the degree of importance of the unread messages in the room.
|
2020-03-15 21:56:39 +03:00
|
|
|
// If sorting by importance is disabled in settings, this only ever
|
2020-03-15 23:28:32 +03:00
|
|
|
// returns ImportanceDisabled or Invite
|
|
|
|
if (isInvite()) {
|
2020-03-15 17:38:56 +03:00
|
|
|
return Invite;
|
2020-10-17 01:57:29 +03:00
|
|
|
} else if (!ChatPage::instance()->userSettings()->sortByImportance()) {
|
2020-03-15 23:28:32 +03:00
|
|
|
return ImportanceDisabled;
|
2020-03-15 17:38:56 +03:00
|
|
|
} else if (unreadHighlightedMsgCount_) {
|
|
|
|
return NewMentions;
|
|
|
|
} else if (unreadMsgCount_) {
|
|
|
|
return NewMessage;
|
|
|
|
} else {
|
|
|
|
return AllEventsRead;
|
|
|
|
}
|
2020-03-14 02:30:50 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RoomInfoListItem::setPressedState(bool state)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2018-01-09 16:07:32 +03:00
|
|
|
if (isPressed_ != state) {
|
2017-09-10 12:59:21 +03:00
|
|
|
isPressed_ = state;
|
|
|
|
update();
|
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RoomInfoListItem::contextMenuEvent(QContextMenuEvent *event)
|
2017-05-31 19:42:07 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_UNUSED(event);
|
2017-05-31 19:42:07 +03:00
|
|
|
|
2017-12-19 23:36:12 +03:00
|
|
|
if (roomType_ == RoomType::Invited)
|
|
|
|
return;
|
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
menu_->popup(event->globalPos());
|
2017-05-31 19:42:07 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RoomInfoListItem::mousePressEvent(QMouseEvent *event)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
if (event->buttons() == Qt::RightButton) {
|
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
return;
|
2020-12-15 02:17:44 +03:00
|
|
|
} else if (event->buttons() == Qt::LeftButton) {
|
|
|
|
if (roomType_ == RoomType::Invited) {
|
|
|
|
const auto point = event->pos();
|
2017-12-19 23:36:12 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
if (acceptBtnRegion_.contains(point))
|
|
|
|
emit acceptInvite(roomId_);
|
2017-12-19 23:36:12 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
if (declineBtnRegion_.contains(point))
|
|
|
|
emit declineInvite(roomId_);
|
2017-12-19 23:36:12 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-12-19 23:36:12 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
emit clicked(roomId_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
setPressedState(true);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
// Ripple on mouse position by default.
|
|
|
|
QPoint pos = event->pos();
|
|
|
|
qreal radiusEndValue = static_cast<qreal>(width()) / 3;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
Ripple *ripple = new Ripple(pos);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
ripple->setRadiusEndValue(radiusEndValue);
|
|
|
|
ripple->setOpacityStartValue(0.15);
|
|
|
|
ripple->setColor(QColor("white"));
|
|
|
|
ripple->radiusAnimation()->setDuration(200);
|
|
|
|
ripple->opacityAnimation()->setDuration(400);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2020-12-15 02:17:44 +03:00
|
|
|
ripple_overlay_->addRipple(ripple);
|
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-10-22 19:03:55 +03:00
|
|
|
void
|
2019-08-26 02:24:56 +03:00
|
|
|
RoomInfoListItem::setAvatar(const QString &avatar_url)
|
2017-10-22 19:03:55 +03:00
|
|
|
{
|
2020-03-22 22:43:45 +03:00
|
|
|
if (avatar_url.isEmpty())
|
|
|
|
avatar_->setLetter(utils::firstChar(roomName_));
|
|
|
|
else
|
|
|
|
avatar_->setImage(avatar_url);
|
2017-10-22 19:03:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RoomInfoListItem::setDescriptionMessage(const DescInfo &info)
|
|
|
|
{
|
|
|
|
lastMsgInfo_ = info;
|
|
|
|
update();
|
|
|
|
}
|