diff options
author | TheKodeToad <TheKodeToad@proton.me> | 2023-06-22 18:18:33 +0100 |
---|---|---|
committer | TheKodeToad <TheKodeToad@proton.me> | 2023-06-22 18:18:33 +0100 |
commit | 05d2c1f0b06519eba9cc5ad22848106b49f9bd15 (patch) | |
tree | 9b2c3161531fc02580cf915abd1224d097c1dab4 | |
parent | e7ad373d892d9040445011d47fe103922eb1abd6 (diff) | |
download | PrismLauncher-05d2c1f0b06519eba9cc5ad22848106b49f9bd15.tar.gz PrismLauncher-05d2c1f0b06519eba9cc5ad22848106b49f9bd15.tar.bz2 PrismLauncher-05d2c1f0b06519eba9cc5ad22848106b49f9bd15.zip |
Dynamic button text
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
-rw-r--r-- | launcher/ui/dialogs/InstallLoaderDialog.cpp | 23 | ||||
-rw-r--r-- | launcher/ui/dialogs/InstallLoaderDialog.h | 3 |
2 files changed, 19 insertions, 7 deletions
diff --git a/launcher/ui/dialogs/InstallLoaderDialog.cpp b/launcher/ui/dialogs/InstallLoaderDialog.cpp index cc8d7e54..6e1ad1c0 100644 --- a/launcher/ui/dialogs/InstallLoaderDialog.cpp +++ b/launcher/ui/dialogs/InstallLoaderDialog.cpp @@ -75,7 +75,7 @@ class LoaderPage : public VersionSelectWidget, public BasePage { }; InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, QWidget* parent) - : QDialog(parent), m_profile(profile), m_container(new PageContainer(this)) + : QDialog(parent), m_profile(profile), m_container(new PageContainer(this)), m_buttons(new QDialogButtonBox(this)) { auto layout = new QVBoxLayout(this); @@ -92,17 +92,20 @@ InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, Q }); buttonLayout->addWidget(refreshButton); - auto buttons = new QDialogButtonBox(this); - buttons->setOrientation(Qt::Horizontal); - buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); - connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); - buttonLayout->addWidget(buttons); + m_buttons->setOrientation(Qt::Horizontal); + m_buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); + connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); + buttonLayout->addWidget(m_buttons); layout->addLayout(buttonLayout); setWindowTitle(dialogTitle()); resize(650, 400); + + connect(m_container, &PageContainer::selectedPageChanged, this, + [this](BasePage* previous, BasePage* selected) { updateAcceptButton(selected); }); + updateAcceptButton(m_container->selectedPage()); } QList<BasePage*> InstallLoaderDialog::getPages() @@ -123,6 +126,12 @@ QString InstallLoaderDialog::dialogTitle() return tr("Install Loader"); } +void InstallLoaderDialog::updateAcceptButton(const BasePage* page) +{ + auto installed = !m_profile->getComponentVersion(page->id()).isNull(); + m_buttons->button(QDialogButtonBox::Ok)->setText(installed ? tr("&Update") : tr("&Install")); +} + void InstallLoaderDialog::done(int result) { if (result == Accepted) { diff --git a/launcher/ui/dialogs/InstallLoaderDialog.h b/launcher/ui/dialogs/InstallLoaderDialog.h index 7a32e427..6c8762dc 100644 --- a/launcher/ui/dialogs/InstallLoaderDialog.h +++ b/launcher/ui/dialogs/InstallLoaderDialog.h @@ -24,6 +24,7 @@ class MinecraftInstance; class PageContainer; class PackProfile; +class QDialogButtonBox; class InstallLoaderDialog : public QDialog, public BasePageProvider { Q_OBJECT @@ -34,9 +35,11 @@ class InstallLoaderDialog : public QDialog, public BasePageProvider { QList<BasePage*> getPages() override; QString dialogTitle() override; + void updateAcceptButton(const BasePage* page); void done(int result) override; private: std::shared_ptr<PackProfile> m_profile; PageContainer* m_container; + QDialogButtonBox* m_buttons; }; |