| 183 | } |
| 184 | |
| 185 | InstallDialog::InstallDialog(const QString& uid, BaseInstance* instance, QWidget* parent) |
| 186 | : QDialog(parent), container(new PageContainer(this, QString(), this)), buttons(new QDialogButtonBox(this)) |
| 187 | { |
| 188 | auto layout = new QVBoxLayout(this); |
| 189 | // small margins look ugly on macOS on modal windows |
| 190 | #ifndef Q_OS_MACOS |
| 191 | layout->setContentsMargins(0, 0, 0, 0); |
| 192 | #endif |
| 193 | container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
| 194 | layout->addWidget(container); |
| 195 | |
| 196 | auto buttonLayout = new QHBoxLayout(this); |
| 197 | // small margins look ugly on macOS on modal windows |
| 198 | #ifndef Q_OS_MACOS |
| 199 | buttonLayout->setContentsMargins(0, 0, 6, 6); |
| 200 | #endif |
| 201 | |
| 202 | auto refreshLayout = new QHBoxLayout(this); |
| 203 | |
| 204 | auto refreshButton = new QPushButton(tr("&Refresh"), this); |
| 205 | connect(refreshButton, &QPushButton::clicked, this, [this] { pageCast(container->selectedPage())->loadList(); }); |
| 206 | refreshLayout->addWidget(refreshButton); |
| 207 | |
| 208 | auto recommendedCheckBox = new QCheckBox("Recommended", this); |
| 209 | recommendedCheckBox->setCheckState(Qt::CheckState::Checked); |
| 210 | connect(recommendedCheckBox, &QCheckBox::stateChanged, this, [this](int state) { |
| 211 | for (BasePage* page : container->getPages()) { |
| 212 | pageCast(page)->setRecommend(state == Qt::Checked); |
| 213 | } |
| 214 | }); |
| 215 | |
| 216 | refreshLayout->addWidget(recommendedCheckBox); |
| 217 | buttonLayout->addLayout(refreshLayout); |
| 218 | |
| 219 | buttons->setOrientation(Qt::Horizontal); |
| 220 | buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); |
| 221 | buttons->button(QDialogButtonBox::Ok)->setText(tr("Download")); |
| 222 | buttons->button(QDialogButtonBox::Cancel)->setText(tr("Cancel")); |
| 223 | connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); |
| 224 | connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); |
| 225 | buttonLayout->addWidget(buttons); |
| 226 | |
| 227 | container->addButtons(buttonLayout); |
| 228 | |
| 229 | setWindowTitle(dialogTitle()); |
| 230 | setWindowModality(Qt::WindowModal); |
| 231 | resize(840, 480); |
| 232 | |
| 233 | QStringList recommendedJavas; |
| 234 | if (auto mcInst = dynamic_cast<MinecraftInstance*>(instance); mcInst) { |
| 235 | auto mc = mcInst->getPackProfile()->getComponent("net.minecraft"); |
| 236 | if (mc) { |
| 237 | auto file = mc->getVersionFile(); // no need for load as it should already be loaded |
| 238 | if (file) { |
| 239 | for (auto major : file->compatibleJavaMajors) { |
| 240 | recommendedJavas.append(QString("Java %1").arg(major)); |
| 241 | } |
| 242 | } |
nothing calls this directly
no test coverage detected