summary refs log tree commit diff
path: root/src/dialogs/RawMessage.h
blob: e95f675cd79919d4691deca3f34b92a4810b38fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 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