summaryrefslogtreecommitdiff
path: root/src/updatedialog.cpp
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2021-02-08 08:24:51 -0700
committerChris Bessent <lost.dragonist@gmail.com>2021-02-11 17:58:10 -0700
commit3dd05ff869e5113fc9a5f474786c226dd556fc1b (patch)
treec028228dcf5b1f4be43bcc68624a4f97d7cc2de1 /src/updatedialog.cpp
parentf058125e6679560e5ade95a76c05acd6eb5274d4 (diff)
Create a new dialog for the update window
The idea here is to be able to resize the window and better handle markdown formatting. Everything was stolen from the LOOT dialog.
Diffstat (limited to 'src/updatedialog.cpp')
-rw-r--r--src/updatedialog.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/updatedialog.cpp b/src/updatedialog.cpp
new file mode 100644
index 00000000..1be58576
--- /dev/null
+++ b/src/updatedialog.cpp
@@ -0,0 +1,59 @@
+#include "updatedialog.h"
+#include "ui_updatedialog.h"
+
+#include "lootdialog.h" // for MarkdownPage
+#include <QWebChannel>
+
+using namespace MOBase;
+
+UpdateDialog::UpdateDialog(QWidget* parent, const QString& title) :
+ QDialog(parent, Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), ui(new Ui::UpdateDialog)
+{
+ // Basic UI stuff
+ ui->setupUi(this);
+ setWindowTitle(title);
+ connect(ui->installButton, &QPushButton::pressed, this, [&]{ done(QDialog::Accepted); });
+ connect(ui->cancelButton, &QPushButton::pressed, this, [&]{ done(QDialog::Rejected); });
+
+ // Replace a label with an icon
+ QIcon icon = style()->standardIcon(QStyle::SP_MessageBoxQuestion);
+ QPixmap pixmap = icon.pixmap(QSize(32, 32));
+ ui->iconLabel->setPixmap(pixmap);
+ ui->iconLabel->setScaledContents(true);
+
+ // Setting up the Markdown stuff
+ auto* page = new MarkdownPage(this);
+ ui->detailsWebView->setPage(page);
+
+ auto* channel = new QWebChannel(this);
+ channel->registerObject("content", &m_changeLogs);
+ page->setWebChannel(channel);
+
+ const QString path = QApplication::applicationDirPath() + "/resources/markdown.html";
+ QFile f(path);
+
+ if (f.open(QFile::ReadOnly)) {
+ const QString html = f.readAll();
+ if (!html.isEmpty()) {
+ ui->detailsWebView->setHtml(html);
+ } else {
+ log::error("failed to read '{}', {}", path, f.errorString());
+ }
+ } else {
+ log::error("can't open '{}', {}", path, f.errorString());
+ }
+
+ // Setting up the expander
+ m_expander.set(ui->detailsButton, ui->detailsWidget);
+ connect(&m_expander, &ExpanderWidget::toggled, this, [&]{ adjustSize(); });
+
+ // Adjust sizes after the expander hides stuff
+ adjustSize();
+}
+
+UpdateDialog::~UpdateDialog() = default;
+
+void UpdateDialog::setChangeLogs(const QString& text)
+{
+ m_changeLogs.setText(text);
+}