Added buttons

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-07-13 20:38:08 +03:00
parent 1495bfb73e
commit b9ed8283b7
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
3 changed files with 76 additions and 23 deletions

View File

@ -45,7 +45,7 @@ ExportToModListDialog::ExportToModListDialog(InstancePtr instance, QWidget* pare
: QDialog(parent), m_template_changed(false), name(instance->name()), ui(new Ui::ExportToModListDialog) : QDialog(parent), m_template_changed(false), name(instance->name()), ui(new Ui::ExportToModListDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->optionsGroup->setDisabled(false); enableCustom(false);
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get()); MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
if (mcInstance) { if (mcInstance) {
@ -60,6 +60,9 @@ ExportToModListDialog::ExportToModListDialog(InstancePtr instance, QWidget* pare
connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger); connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger); connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger); connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
connect(ui->authorsButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Authors); });
connect(ui->versionButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Version); });
connect(ui->urlButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Url); });
connect(ui->templateText, &QTextEdit::textChanged, this, [this] { connect(ui->templateText, &QTextEdit::textChanged, this, [this] {
if (ui->templateText->toPlainText() != exampleLines[format]) if (ui->templateText->toPlainText() != exampleLines[format])
ui->formatComboBox->setCurrentIndex(5); ui->formatComboBox->setCurrentIndex(5);
@ -81,38 +84,38 @@ void ExportToModListDialog::formatChanged(int index)
{ {
switch (index) { switch (index) {
case 0: { case 0: {
ui->optionsGroup->setDisabled(false); enableCustom(false);
ui->resultText->show(); ui->resultText->show();
format = ExportToModList::HTML; format = ExportToModList::HTML;
break; break;
} }
case 1: { case 1: {
ui->optionsGroup->setDisabled(false); enableCustom(false);
ui->resultText->show(); ui->resultText->show();
format = ExportToModList::MARKDOWN; format = ExportToModList::MARKDOWN;
break; break;
} }
case 2: { case 2: {
ui->optionsGroup->setDisabled(false); enableCustom(false);
ui->resultText->hide(); ui->resultText->hide();
format = ExportToModList::PLAINTXT; format = ExportToModList::PLAINTXT;
break; break;
} }
case 3: { case 3: {
ui->optionsGroup->setDisabled(false); enableCustom(false);
ui->resultText->hide(); ui->resultText->hide();
format = ExportToModList::JSON; format = ExportToModList::JSON;
break; break;
} }
case 4: { case 4: {
ui->optionsGroup->setDisabled(false); enableCustom(false);
ui->resultText->hide(); ui->resultText->hide();
format = ExportToModList::CSV; format = ExportToModList::CSV;
break; break;
} }
case 5: { case 5: {
m_template_changed = true; m_template_changed = true;
ui->optionsGroup->setDisabled(true); enableCustom(true);
ui->resultText->hide(); ui->resultText->hide();
format = ExportToModList::CUSTOM; format = ExportToModList::CUSTOM;
break; break;
@ -191,3 +194,30 @@ QString ExportToModListDialog::extension()
} }
return ".txt"; return ".txt";
} }
void ExportToModListDialog::addExtra(ExportToModList::OptionalData option)
{
if (format != ExportToModList::CUSTOM)
return;
switch (option) {
case ExportToModList::Authors:
ui->templateText->insertPlainText("{authors}");
break;
case ExportToModList::Url:
ui->templateText->insertPlainText("{url}");
break;
case ExportToModList::Version:
ui->templateText->insertPlainText("{version}");
break;
}
}
void ExportToModListDialog::enableCustom(bool enabled)
{
ui->authorsCheckBox->setHidden(enabled);
ui->versionCheckBox->setHidden(enabled);
ui->urlCheckBox->setHidden(enabled);
ui->authorsButton->setHidden(!enabled);
ui->versionButton->setHidden(!enabled);
ui->urlButton->setHidden(!enabled);
}

View File

@ -41,9 +41,11 @@ class ExportToModListDialog : public QDialog {
void formatChanged(int index); void formatChanged(int index);
void triggerImp(); void triggerImp();
void trigger(int) { triggerImp(); }; void trigger(int) { triggerImp(); };
void addExtra(ExportToModList::OptionalData option);
private: private:
QString extension(); QString extension();
void enableCustom(bool enabled);
QList<Mod*> m_allMods; QList<Mod*> m_allMods;
bool m_template_changed; bool m_template_changed;
QString name; QString name;

View File

@ -25,22 +25,6 @@
<string>Settings</string> <string>Settings</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="formatComboBox"> <widget class="QComboBox" name="formatComboBox">
<item> <item>
@ -114,9 +98,46 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="versionButton">
<property name="text">
<string>Version</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="authorsButton">
<property name="text">
<string>Authors</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="urlButton">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>