From 3dd05ff869e5113fc9a5f474786c226dd556fc1b Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Mon, 8 Feb 2021 08:24:51 -0700 Subject: 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. --- src/updatedialog.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/updatedialog.cpp (limited to 'src/updatedialog.cpp') 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 + +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); +} -- cgit v1.3.1 From f486e6fa4e5893c4f437147e5a031e64b48035e7 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Thu, 11 Feb 2021 18:39:06 -0700 Subject: Updates to text, title and buttons --- src/selfupdater.cpp | 8 +++++--- src/updatedialog.cpp | 12 ++++++++++-- src/updatedialog.h | 3 ++- src/updatedialog.ui | 34 ++++------------------------------ 4 files changed, 21 insertions(+), 36 deletions(-) (limited to 'src/updatedialog.cpp') diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 68aecc46..4b2894fd 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -165,9 +165,11 @@ void SelfUpdater::startUpdate() auto latestRelease = m_UpdateCandidates.begin()->second; - UpdateDialog dialog(m_Parent, tr("New update available (%1 -> %2)") - .arg(MOShared::createVersionInfo().displayString(3)) - .arg(latestRelease["tag_name"].toString())); + UpdateDialog dialog(m_Parent); + dialog.setVersions( + MOShared::createVersionInfo().displayString(3), + latestRelease["tag_name"].toString() + ); // We concatenate release details. We only include pre-release if those are // the latest release: diff --git a/src/updatedialog.cpp b/src/updatedialog.cpp index 1be58576..d3336e93 100644 --- a/src/updatedialog.cpp +++ b/src/updatedialog.cpp @@ -6,12 +6,11 @@ using namespace MOBase; -UpdateDialog::UpdateDialog(QWidget* parent, const QString& title) : +UpdateDialog::UpdateDialog(QWidget* parent) : 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); }); @@ -57,3 +56,12 @@ void UpdateDialog::setChangeLogs(const QString& text) { m_changeLogs.setText(text); } + +void UpdateDialog::setVersions(const QString& oldVersion, const QString& newVersion) +{ + ui->updateLabel->setText( + tr("Mod Organizer %1 is available. The current version is %2. Updating will not affect your mods or profiles.") + .arg(newVersion) + .arg(oldVersion) + ); +} diff --git a/src/updatedialog.h b/src/updatedialog.h index dbcf28a7..1dd5e0b1 100644 --- a/src/updatedialog.h +++ b/src/updatedialog.h @@ -13,10 +13,11 @@ class UpdateDialog : public QDialog Q_OBJECT; public: - UpdateDialog(QWidget* parent, const QString& title); + UpdateDialog(QWidget* parent); ~UpdateDialog(); void setChangeLogs(const QString& text); + void setVersions(const QString& oldVersion, const QString& newVersion); private: std::unique_ptr ui; diff --git a/src/updatedialog.ui b/src/updatedialog.ui index 43a17346..874cbb80 100644 --- a/src/updatedialog.ui +++ b/src/updatedialog.ui @@ -17,7 +17,7 @@ - New update available (xxxx) + Update available true @@ -27,7 +27,7 @@ - + 0 @@ -80,40 +80,14 @@ - - - 400 - 0 - - - - - 400 - 16777215 - - - Do you want to install the update? All your mods and setup will be left untouched. -Select Show Details option to see the full change-log. + Update text placeholder true - - - - Qt::Horizontal - - - - 20 - 20 - - - - @@ -121,7 +95,7 @@ Select Show Details option to see the full change-log. - Show Details... + Changelog -- cgit v1.3.1