mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
parent
c971602b2d
commit
3f80725c33
8 changed files with 77 additions and 3 deletions
|
@ -21,7 +21,7 @@ ExternalProject_Add(
|
||||||
MatrixStructs
|
MatrixStructs
|
||||||
|
|
||||||
GIT_REPOSITORY https://github.com/mujx/matrix-structs
|
GIT_REPOSITORY https://github.com/mujx/matrix-structs
|
||||||
GIT_TAG e6ce4fee893d7db8c6e9ece366d8184e009f003c
|
GIT_TAG 690080daa3bc1984297c4d7103cde9ea07e2e0b7
|
||||||
|
|
||||||
BUILD_IN_SOURCE 1
|
BUILD_IN_SOURCE 1
|
||||||
SOURCE_DIR ${MATRIX_STRUCTS_ROOT}
|
SOURCE_DIR ${MATRIX_STRUCTS_ROOT}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
class ImageItem;
|
class ImageItem;
|
||||||
|
class StickerItem;
|
||||||
class AudioItem;
|
class AudioItem;
|
||||||
class VideoItem;
|
class VideoItem;
|
||||||
class FileItem;
|
class FileItem;
|
||||||
|
@ -89,6 +90,11 @@ public:
|
||||||
bool with_sender,
|
bool with_sender,
|
||||||
const QString &room_id,
|
const QString &room_id,
|
||||||
QWidget *parent);
|
QWidget *parent);
|
||||||
|
TimelineItem(StickerItem *img,
|
||||||
|
const mtx::events::Sticker &e,
|
||||||
|
bool with_sender,
|
||||||
|
const QString &room_id,
|
||||||
|
QWidget *parent);
|
||||||
TimelineItem(FileItem *file,
|
TimelineItem(FileItem *file,
|
||||||
const mtx::events::RoomEvent<mtx::events::msg::File> &e,
|
const mtx::events::RoomEvent<mtx::events::msg::File> &e,
|
||||||
bool with_sender,
|
bool with_sender,
|
||||||
|
|
|
@ -57,6 +57,9 @@ protected:
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
//! Whether the user can interact with the displayed image.
|
||||||
|
bool isInteractive_ = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void openUrl();
|
void openUrl();
|
||||||
|
|
||||||
|
@ -81,3 +84,28 @@ private:
|
||||||
|
|
||||||
QSharedPointer<MatrixClient> client_;
|
QSharedPointer<MatrixClient> client_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class StickerItem : public ImageItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
StickerItem(QSharedPointer<MatrixClient> client,
|
||||||
|
const mtx::events::Sticker &event,
|
||||||
|
QWidget *parent = nullptr)
|
||||||
|
: ImageItem{client,
|
||||||
|
QString::fromStdString(event.content.url),
|
||||||
|
QString::fromStdString(event.content.body),
|
||||||
|
event.content.info.size,
|
||||||
|
parent}
|
||||||
|
, event_{event}
|
||||||
|
{
|
||||||
|
isInteractive_ = false;
|
||||||
|
setCursor(Qt::ArrowCursor);
|
||||||
|
setMouseTracking(false);
|
||||||
|
setAttribute(Qt::WA_Hover, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mtx::events::Sticker event_;
|
||||||
|
};
|
||||||
|
|
|
@ -187,7 +187,13 @@ RoomList::cleanupInvites(const std::map<QString, bool> &invites)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
utils::erase_if(rooms_, [invites](auto &room) {
|
utils::erase_if(rooms_, [invites](auto &room) {
|
||||||
return room.second->isInvite() && (invites.find(room.first) == invites.end());
|
auto room_id = room.first;
|
||||||
|
auto item = room.second;
|
||||||
|
|
||||||
|
if (!item)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return item->isInvite() && (invites.find(room_id) == invites.end());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/Utils.cc
12
src/Utils.cc
|
@ -118,6 +118,18 @@ utils::getMessageDescription(const TimelineEvent &event,
|
||||||
" sent a video clip",
|
" sent a video clip",
|
||||||
utils::descriptiveTime(ts),
|
utils::descriptiveTime(ts),
|
||||||
ts};
|
ts};
|
||||||
|
} else if (mpark::holds_alternative<mtx::events::Sticker>(event)) {
|
||||||
|
const auto msg = mpark::get<mtx::events::Sticker>(event);
|
||||||
|
QString sender = QString::fromStdString(msg.sender);
|
||||||
|
|
||||||
|
const auto username = Cache::displayName(room_id, sender);
|
||||||
|
const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts);
|
||||||
|
|
||||||
|
return DescInfo{sender == localUser ? "You" : username,
|
||||||
|
sender,
|
||||||
|
" sent a sticker",
|
||||||
|
utils::descriptiveTime(ts),
|
||||||
|
ts};
|
||||||
}
|
}
|
||||||
|
|
||||||
return DescInfo{};
|
return DescInfo{};
|
||||||
|
|
|
@ -210,6 +210,20 @@ TimelineItem::TimelineItem(ImageItem *image,
|
||||||
addSaveImageAction(image);
|
addSaveImageAction(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TimelineItem::TimelineItem(StickerItem *image,
|
||||||
|
const mtx::events::Sticker &event,
|
||||||
|
bool with_sender,
|
||||||
|
const QString &room_id,
|
||||||
|
QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, room_id_{room_id}
|
||||||
|
{
|
||||||
|
setupWidgetLayout<mtx::events::Sticker, StickerItem>(
|
||||||
|
image, event, " sent a sticker", with_sender);
|
||||||
|
|
||||||
|
addSaveImageAction(image);
|
||||||
|
}
|
||||||
|
|
||||||
TimelineItem::TimelineItem(FileItem *file,
|
TimelineItem::TimelineItem(FileItem *file,
|
||||||
const mtx::events::RoomEvent<mtx::events::msg::File> &event,
|
const mtx::events::RoomEvent<mtx::events::msg::File> &event,
|
||||||
bool with_sender,
|
bool with_sender,
|
||||||
|
|
|
@ -281,6 +281,9 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &
|
||||||
} else if (mpark::holds_alternative<mtx::events::RoomEvent<msg::Video>>(event)) {
|
} else if (mpark::holds_alternative<mtx::events::RoomEvent<msg::Video>>(event)) {
|
||||||
auto video = mpark::get<mtx::events::RoomEvent<msg::Video>>(event);
|
auto video = mpark::get<mtx::events::RoomEvent<msg::Video>>(event);
|
||||||
return processMessageEvent<VideoEvent, VideoItem>(video, direction);
|
return processMessageEvent<VideoEvent, VideoItem>(video, direction);
|
||||||
|
} else if (mpark::holds_alternative<mtx::events::Sticker>(event)) {
|
||||||
|
return processMessageEvent<mtx::events::Sticker, StickerItem>(
|
||||||
|
mpark::get<mtx::events::Sticker>(event), direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -138,6 +138,11 @@ ImageItem::setImage(const QPixmap &image)
|
||||||
void
|
void
|
||||||
ImageItem::mousePressEvent(QMouseEvent *event)
|
ImageItem::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (!isInteractive_) {
|
||||||
|
event->accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event->button() != Qt::LeftButton)
|
if (event->button() != Qt::LeftButton)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -204,7 +209,7 @@ ImageItem::paintEvent(QPaintEvent *event)
|
||||||
painter.drawPath(path);
|
painter.drawPath(path);
|
||||||
|
|
||||||
// Bottom text section
|
// Bottom text section
|
||||||
if (underMouse()) {
|
if (isInteractive_ && underMouse()) {
|
||||||
const int textBoxHeight = fontHeight / 2 + 6;
|
const int textBoxHeight = fontHeight / 2 + 6;
|
||||||
|
|
||||||
textRegion_ = QRectF(0, height_ - textBoxHeight, width_, textBoxHeight);
|
textRegion_ = QRectF(0, height_ - textBoxHeight, width_, textBoxHeight);
|
||||||
|
|
Loading…
Reference in a new issue