|
| 1 | +/* TombRaiderLinuxLauncher |
| 2 | + * Martin Bångens Copyright (C) 2025 |
| 3 | + * This program is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU General Public License as published by |
| 5 | + * the Free Software Foundation, either version 3 of the License, or |
| 6 | + * (at your option) any later version. |
| 7 | +
|
| 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | + * GNU General Public License for more details. |
| 12 | + */ |
| 13 | + |
| 14 | +#include "../src/Dialog.hpp" |
| 15 | + |
| 16 | + |
| 17 | +Dialog::Dialog(QWidget *parent) |
| 18 | + : QWidget(parent), |
| 19 | + m_layout(new QVBoxLayout(this)), |
| 20 | + m_label(new QLabel(this)), |
| 21 | + m_optionContainer(new QWidget(this)), |
| 22 | + m_optionLayout(new QVBoxLayout(m_optionContainer)), |
| 23 | + m_buttonGroup(new QButtonGroup(this)), |
| 24 | + m_okButton(new QPushButton("OK", this)) |
| 25 | +{ |
| 26 | + m_layout->addWidget(m_label); |
| 27 | + m_layout->addWidget(m_optionContainer); |
| 28 | + m_layout->addWidget(m_okButton); |
| 29 | + |
| 30 | + connect(m_okButton, &QPushButton::clicked, this, [this]() { |
| 31 | + emit okClicked(); |
| 32 | + }); |
| 33 | +} |
| 34 | + |
| 35 | +void Dialog::setMessage(const QString &text) { |
| 36 | + m_label->setText(text); |
| 37 | +} |
| 38 | + |
| 39 | +void Dialog::setOptions(const QStringList &options) { |
| 40 | + // Clear old options |
| 41 | + qDeleteAll(m_buttonGroup->buttons()); |
| 42 | + QLayoutItem *child; |
| 43 | + while ((child = m_optionLayout->takeAt(0)) != nullptr) { |
| 44 | + delete child->widget(); |
| 45 | + delete child; |
| 46 | + } |
| 47 | + |
| 48 | + if (options.isEmpty()) { |
| 49 | + m_optionContainer->hide(); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + m_optionContainer->show(); |
| 54 | + for (const QString &opt : options) { |
| 55 | + QRadioButton *rb = new QRadioButton(opt); |
| 56 | + m_buttonGroup->addButton(rb); |
| 57 | + m_optionLayout->addWidget(rb); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +QString Dialog::selectedOption() const { |
| 62 | + auto btn = m_buttonGroup->checkedButton(); |
| 63 | + return btn ? btn->text() : QString(); |
| 64 | +} |
| 65 | + |
0 commit comments