Dynamic button text
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
e7ad373d89
commit
05d2c1f0b0
@ -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) {
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user