From e9ee29978d60f9fb5e661c5a02f33d8e3ad3655f Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Wed, 12 Sep 2018 16:27:25 +0300 Subject: Add context menu option to show the raw message fixes #437 --- src/dialogs/RawMessage.h | 56 ++++++++++++++++++++++++++++++++++++++++++++ src/dialogs/RoomSettings.cpp | 5 ++-- 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/dialogs/RawMessage.h (limited to 'src/dialogs') diff --git a/src/dialogs/RawMessage.h b/src/dialogs/RawMessage.h new file mode 100644 index 00000000..5a7335f4 --- /dev/null +++ b/src/dialogs/RawMessage.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "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 diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index a9739f3e..7409c5bd 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -190,9 +191,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) auto infoLabel = new QLabel(tr("Info").toUpper(), this); infoLabel->setFont(font); - QFont monospaceFont; - monospaceFont.setFamily("Courier New"); - monospaceFont.setStyleHint(QFont::Courier); + QFont monospaceFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); auto roomIdLabel = new QLabel(room_id, this); roomIdLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); -- cgit 1.5.1