MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / NewInstanceDialog

Method NewInstanceDialog

launcher/ui/dialogs/NewInstanceDialog.cpp:70–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68#include "ui/widgets/PageContainer.h"
69
70NewInstanceDialog::NewInstanceDialog(const QString& initialGroup,
71 const QString& url,
72 const QMap<QString, QString>& extra_info,
73 QWidget* parent)
74 : QDialog(parent), ui(new Ui::NewInstanceDialog)
75{
76 ui->setupUi(this);
77
78 setWindowIcon(QIcon::fromTheme("new"));
79
80 InstIconKey = "default";
81 ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey));
82
83 QStringList groups = APPLICATION->instances()->getGroups();
84 groups.prepend("");
85 int index = groups.indexOf(initialGroup);
86 if (index == -1) {
87 index = 1;
88 groups.insert(index, initialGroup);
89 }
90 ui->groupBox->addItems(groups);
91 ui->groupBox->setCurrentIndex(index);
92 ui->groupBox->lineEdit()->setPlaceholderText(tr("No group"));
93
94 // NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not
95 // move this below.
96 m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
97
98 m_container = new PageContainer(this, {}, this);
99 m_container->useSidebarStyle(false);
100 m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
101 m_container->layout()->setContentsMargins(0, 0, 0, 0);
102 ui->verticalLayout->insertWidget(2, m_container);
103
104 m_container->addButtons(m_buttons);
105 connect(m_container, &PageContainer::selectedPageChanged, this, [this](BasePage* previous, BasePage* selected) {
106 m_buttons->button(QDialogButtonBox::Ok)->setEnabled(creationTask && !instName().isEmpty());
107 });
108
109 // Bonk Qt over its stupid head and make sure it understands which button is the default one...
110 // See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
111 auto OkButton = m_buttons->button(QDialogButtonBox::Ok);
112 OkButton->setDefault(true);
113 OkButton->setAutoDefault(true);
114 OkButton->setText(tr("OK"));
115 connect(OkButton, &QPushButton::clicked, this, &NewInstanceDialog::accept);
116
117 auto CancelButton = m_buttons->button(QDialogButtonBox::Cancel);
118 CancelButton->setDefault(false);
119 CancelButton->setAutoDefault(false);
120 CancelButton->setText(tr("Cancel"));
121 connect(CancelButton, &QPushButton::clicked, this, &NewInstanceDialog::reject);
122
123 auto HelpButton = m_buttons->button(QDialogButtonBox::Help);
124 HelpButton->setDefault(false);
125 HelpButton->setAutoDefault(false);
126 HelpButton->setText(tr("Help"));
127 connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);

Callers

nothing calls this directly

Calls 15

iconsMethod · 0.80
getGroupsMethod · 0.80
instancesMethod · 0.80
insertMethod · 0.80
useSidebarStyleMethod · 0.80
layoutMethod · 0.80
addButtonsMethod · 0.80
setEnabledMethod · 0.80
setExtraInfoMethod · 0.80
setupUiMethod · 0.45
setIconMethod · 0.45
getIconMethod · 0.45

Tested by

no test coverage detected