Qt: support fatal error as htmk

This commit is contained in:
Megamouse 2022-12-05 23:46:26 +01:00
parent ca0ca2e5a8
commit a6b44ea1bb
6 changed files with 21 additions and 25 deletions

View file

@ -4,19 +4,10 @@
#include <QTextDocument>
#include <QIcon>
static QString process_dialog_text(std::string_view text)
fatal_error_dialog::fatal_error_dialog(std::string_view text, bool is_html) : QMessageBox()
{
auto html = Qt::convertFromPlainText(QString::fromUtf8(text.data(), text.size()));
const QString msg = QString::fromUtf8(text.data(), text.size());
// Let's preserve some html elements destroyed by convertFromPlainText
const QRegExp link_re{ R"(&lt;a\shref='([a-z0-9?=&#:\/\.\-]+)'&gt;([a-z0-9?=&#:\/\.\-]+)&lt;\/a&gt;)", Qt::CaseSensitive, QRegExp::RegExp2};
html = html.replace(link_re, "<a href=\\1>\\2</a>");
return html;
}
fatal_error_dialog::fatal_error_dialog(std::string_view text) : QMessageBox()
{
#ifndef __APPLE__
setWindowIcon(QIcon(":/rpcs3.ico"));
#endif
@ -24,14 +15,17 @@ fatal_error_dialog::fatal_error_dialog(std::string_view text) : QMessageBox()
setIcon(QMessageBox::Icon::Critical);
setTextFormat(Qt::TextFormat::RichText);
setText(QString(R"(
<p style="white-space: nowrap;">
<style>
p {white-space: nowrap;}
</style>
<p>
%1<br>
%2<br>
<a href='https://github.com/RPCS3/rpcs3/wiki/How-to-ask-for-Support'>https://github.com/RPCS3/rpcs3/wiki/How-to-ask-for-Support</a><br>
%3<br>
</p>
)")
.arg(process_dialog_text(text))
.arg(is_html ? msg : Qt::convertFromPlainText(msg))
.arg(tr("HOW TO REPORT ERRORS:"))
.arg(tr("Please, don't send incorrect reports. Thanks for understanding.")));
layout()->setSizeConstraint(QLayout::SetFixedSize);