QML the raw message dialog

This commit is contained in:
Loren Burkholder 2021-07-30 22:13:58 -04:00
parent 4c151cc3c7
commit dab1c9068a
9 changed files with 74 additions and 70 deletions

View file

@ -496,7 +496,6 @@ qt5_wrap_cpp(MOC_HEADERS
src/dialogs/LeaveRoom.h src/dialogs/LeaveRoom.h
src/dialogs/Logout.h src/dialogs/Logout.h
src/dialogs/PreviewUploadOverlay.h src/dialogs/PreviewUploadOverlay.h
src/dialogs/RawMessage.h
src/dialogs/ReCaptcha.h src/dialogs/ReCaptcha.h
# Emoji # Emoji

View file

@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.15
import QtQuick.Controls 2.15
import im.nheko 1.0
ApplicationWindow {
id: rawMessageRoot
property alias rawMessage: rawMessageView.text
x: MainWindow.x + (MainWindow.width / 2) - (width / 2)
y: MainWindow.y + (MainWindow.height / 2) - (height / 2)
height: 420
width: 420
palette: Nheko.colors
color: Nheko.colors.window
flags: Qt.Tool | Qt.WindowStaysOnTopHint
Shortcut {
sequence: StandardKey.Cancel
onActivated: rawMessageRoot.close()
}
ScrollView {
anchors.fill: parent
palette: Nheko.colors
padding: Nheko.paddingMedium
TextArea {
id: rawMessageView
font: Nheko.monospaceFont()
palette: Nheko.colors
readOnly: true
}
}
footer: DialogButtonBox {
standardButtons: DialogButtonBox.Ok
onAccepted: rawMessageRoot.close()
}
}

View file

@ -104,6 +104,14 @@ Page {
} }
Component {
id: rawMessageDialog
RawMessageDialog {
}
}
Shortcut { Shortcut {
sequence: "Ctrl+K" sequence: "Ctrl+K"
onActivated: { onActivated: {

View file

@ -258,6 +258,13 @@ Item {
dialog.show(); dialog.show();
} }
function onShowRawMessageDialog(rawMessage) {
var dialog = rawMessageDialog.createObject(timelineRoot, {
"rawMessage": rawMessage
});
dialog.show();
}
target: room target: room
} }

View file

@ -177,6 +177,7 @@
<file>qml/RoomMembers.qml</file> <file>qml/RoomMembers.qml</file>
<file>qml/InviteDialog.qml</file> <file>qml/InviteDialog.qml</file>
<file>qml/ReadReceipts.qml</file> <file>qml/ReadReceipts.qml</file>
<file>qml/RawMessageDialog.qml</file>
</qresource> </qresource>
<qresource prefix="/media"> <qresource prefix="/media">
<file>media/ring.ogg</file> <file>media/ring.ogg</file>

View file

@ -1,60 +0,0 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QFont>
#include <QFontDatabase>
#include <QTextBrowser>
#include <QVBoxLayout>
#include <QWidget>
#include "nlohmann/json.hpp"
#include "Logging.h"
#include "MainWindow.h"
#include "ui/FlatButton.h"
namespace dialogs {
class RawMessage : public QWidget
{
Q_OBJECT
public:
RawMessage(QString msg, QWidget *parent = nullptr)
: QWidget{parent}
{
QFont monospaceFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
auto layout = new QVBoxLayout{this};
auto viewer = new QTextBrowser{this};
viewer->setFont(monospaceFont);
viewer->setText(msg);
layout->setSpacing(0);
layout->setMargin(0);
layout->addWidget(viewer);
setAutoFillBackground(true);
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_DeleteOnClose, true);
QSize winsize;
QPoint center;
auto window = MainWindow::instance();
if (window) {
winsize = window->frameGeometry().size();
center = window->frameGeometry().center();
move(center.x() - (width() * 0.5), center.y() - (height() * 0.5));
} else {
nhlog::ui()->warn("unable to retrieve MainWindow's size");
}
raise();
show();
}
};
} // namespace dialogs

View file

@ -31,7 +31,6 @@
#include "ReadReceiptsModel.h" #include "ReadReceiptsModel.h"
#include "TimelineViewManager.h" #include "TimelineViewManager.h"
#include "Utils.h" #include "Utils.h"
#include "dialogs/RawMessage.h"
Q_DECLARE_METATYPE(QModelIndex) Q_DECLARE_METATYPE(QModelIndex)
@ -1026,14 +1025,13 @@ TimelineModel::formatDateSeparator(QDate date) const
} }
void void
TimelineModel::viewRawMessage(QString id) const TimelineModel::viewRawMessage(QString id)
{ {
auto e = events.get(id.toStdString(), "", false); auto e = events.get(id.toStdString(), "", false);
if (!e) if (!e)
return; return;
std::string ev = mtx::accessors::serialize_event(*e).dump(4); std::string ev = mtx::accessors::serialize_event(*e).dump(4);
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev)); emit showRawMessageDialog(QString::fromStdString(ev));
Q_UNUSED(dialog);
} }
void void
@ -1047,15 +1045,14 @@ TimelineModel::forwardMessage(QString eventId, QString roomId)
} }
void void
TimelineModel::viewDecryptedRawMessage(QString id) const TimelineModel::viewDecryptedRawMessage(QString id)
{ {
auto e = events.get(id.toStdString(), ""); auto e = events.get(id.toStdString(), "");
if (!e) if (!e)
return; return;
std::string ev = mtx::accessors::serialize_event(*e).dump(4); std::string ev = mtx::accessors::serialize_event(*e).dump(4);
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev)); emit showRawMessageDialog(QString::fromStdString(ev));
Q_UNUSED(dialog);
} }
void void

View file

@ -236,9 +236,9 @@ public:
Q_INVOKABLE QString formatGuestAccessEvent(QString id); Q_INVOKABLE QString formatGuestAccessEvent(QString id);
Q_INVOKABLE QString formatPowerLevelEvent(QString id); Q_INVOKABLE QString formatPowerLevelEvent(QString id);
Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void viewRawMessage(QString id);
Q_INVOKABLE void forwardMessage(QString eventId, QString roomId); Q_INVOKABLE void forwardMessage(QString eventId, QString roomId);
Q_INVOKABLE void viewDecryptedRawMessage(QString id) const; Q_INVOKABLE void viewDecryptedRawMessage(QString id);
Q_INVOKABLE void openUserProfile(QString userid); Q_INVOKABLE void openUserProfile(QString userid);
Q_INVOKABLE void editAction(QString id); Q_INVOKABLE void editAction(QString id);
Q_INVOKABLE void replyAction(QString id); Q_INVOKABLE void replyAction(QString id);
@ -350,6 +350,7 @@ signals:
void replyChanged(QString reply); void replyChanged(QString reply);
void editChanged(QString reply); void editChanged(QString reply);
void openReadReceiptsDialog(ReadReceiptsProxy *rr); void openReadReceiptsDialog(ReadReceiptsProxy *rr);
void showRawMessageDialog(QString rawMessage);
void paginationInProgressChanged(const bool); void paginationInProgressChanged(const bool);
void newCallEvent(const mtx::events::collections::TimelineEvents &event); void newCallEvent(const mtx::events::collections::TimelineEvents &event);
void scrollToIndex(int index); void scrollToIndex(int index);

View file

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <QFontDatabase>
#include <QObject> #include <QObject>
#include <QPalette> #include <QPalette>
@ -38,6 +39,10 @@ public:
int paddingLarge() const { return 20; } int paddingLarge() const { return 20; }
UserProfile *currentUser() const; UserProfile *currentUser() const;
Q_INVOKABLE QFont monospaceFont() const
{
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
}
Q_INVOKABLE void openLink(QString link) const; Q_INVOKABLE void openLink(QString link) const;
Q_INVOKABLE void setStatusMessage(QString msg) const; Q_INVOKABLE void setStatusMessage(QString msg) const;
Q_INVOKABLE void showUserSettingsPage() const; Q_INVOKABLE void showUserSettingsPage() const;