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