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)
|
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);
|
auto layout = new QVBoxLayout(this);
|
||||||
|
|
||||||
@ -92,17 +92,20 @@ InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, Q
|
|||||||
});
|
});
|
||||||
buttonLayout->addWidget(refreshButton);
|
buttonLayout->addWidget(refreshButton);
|
||||||
|
|
||||||
auto buttons = new QDialogButtonBox(this);
|
m_buttons->setOrientation(Qt::Horizontal);
|
||||||
buttons->setOrientation(Qt::Horizontal);
|
m_buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
||||||
buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
buttonLayout->addWidget(m_buttons);
|
||||||
buttonLayout->addWidget(buttons);
|
|
||||||
|
|
||||||
layout->addLayout(buttonLayout);
|
layout->addLayout(buttonLayout);
|
||||||
|
|
||||||
setWindowTitle(dialogTitle());
|
setWindowTitle(dialogTitle());
|
||||||
resize(650, 400);
|
resize(650, 400);
|
||||||
|
|
||||||
|
connect(m_container, &PageContainer::selectedPageChanged, this,
|
||||||
|
[this](BasePage* previous, BasePage* selected) { updateAcceptButton(selected); });
|
||||||
|
updateAcceptButton(m_container->selectedPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<BasePage*> InstallLoaderDialog::getPages()
|
QList<BasePage*> InstallLoaderDialog::getPages()
|
||||||
@ -123,6 +126,12 @@ QString InstallLoaderDialog::dialogTitle()
|
|||||||
return tr("Install Loader");
|
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)
|
void InstallLoaderDialog::done(int result)
|
||||||
{
|
{
|
||||||
if (result == Accepted) {
|
if (result == Accepted) {
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
class MinecraftInstance;
|
class MinecraftInstance;
|
||||||
class PageContainer;
|
class PageContainer;
|
||||||
class PackProfile;
|
class PackProfile;
|
||||||
|
class QDialogButtonBox;
|
||||||
|
|
||||||
class InstallLoaderDialog : public QDialog, public BasePageProvider {
|
class InstallLoaderDialog : public QDialog, public BasePageProvider {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -34,9 +35,11 @@ class InstallLoaderDialog : public QDialog, public BasePageProvider {
|
|||||||
QList<BasePage*> getPages() override;
|
QList<BasePage*> getPages() override;
|
||||||
QString dialogTitle() override;
|
QString dialogTitle() override;
|
||||||
|
|
||||||
|
void updateAcceptButton(const BasePage* page);
|
||||||
void done(int result) override;
|
void done(int result) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<PackProfile> m_profile;
|
std::shared_ptr<PackProfile> m_profile;
|
||||||
PageContainer* m_container;
|
PageContainer* m_container;
|
||||||
|
QDialogButtonBox* m_buttons;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user