|
| 1 | +#include "ScmEditorDialog.hpp" |
| 2 | +#include "ui_scmEditorDialog.h" |
| 3 | + |
| 4 | +ScmEditorDialog::ScmEditorDialog() |
| 5 | + : StelDialog("ScmEditorDialog") |
| 6 | +{ |
| 7 | + ui = new Ui_scmEditorDialog; |
| 8 | +} |
| 9 | + |
| 10 | +ScmEditorDialog::~ScmEditorDialog() |
| 11 | +{ |
| 12 | + delete ui; |
| 13 | +} |
| 14 | + |
| 15 | +void ScmEditorDialog::retranslate() |
| 16 | +{ |
| 17 | + if (dialog) |
| 18 | + { |
| 19 | + ui->retranslateUi(dialog); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +void ScmEditorDialog::createDialogContent() |
| 24 | +{ |
| 25 | + ui->setupUi(dialog); |
| 26 | + |
| 27 | + connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate())); |
| 28 | + connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint))); |
| 29 | + connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close); |
| 30 | + |
| 31 | + // LABELS TAB |
| 32 | + connect(ui->enNameTE, &QTextEdit::textChanged, this, [this]() |
| 33 | + { |
| 34 | + constellationEnglishName = ui->enNameTE->toPlainText(); |
| 35 | + if(constellationEnglishName.isEmpty()) |
| 36 | + { |
| 37 | + ui->saveLabelsBtn->setEnabled(false); |
| 38 | + } |
| 39 | + else |
| 40 | + { |
| 41 | + ui->saveLabelsBtn->setEnabled(true); |
| 42 | + } |
| 43 | + updateLabelsSavedLabel(false); |
| 44 | + }); |
| 45 | + connect(ui->natNameTE, &QTextEdit::textChanged, this, [this]() |
| 46 | + { |
| 47 | + constellationNativeName = ui->natNameTE->toPlainText(); |
| 48 | + if (constellationNativeName->isEmpty()) |
| 49 | + { |
| 50 | + constellationNativeName = std::nullopt; |
| 51 | + } |
| 52 | + updateLabelsSavedLabel(false); |
| 53 | + }); |
| 54 | + connect(ui->pronounceTE, &QTextEdit::textChanged, this, [this]() |
| 55 | + { |
| 56 | + constellationPronounce = ui->pronounceTE->toPlainText(); |
| 57 | + if (constellationPronounce->isEmpty()) |
| 58 | + { |
| 59 | + constellationPronounce = std::nullopt; |
| 60 | + } |
| 61 | + updateLabelsSavedLabel(false); |
| 62 | + }); |
| 63 | + connect(ui->ipaTE, &QTextEdit::textChanged, this, [this]() |
| 64 | + { |
| 65 | + constellationIpa = ui->ipaTE->toPlainText(); |
| 66 | + if (constellationIpa->isEmpty()) |
| 67 | + { |
| 68 | + constellationIpa = std::nullopt; |
| 69 | + } |
| 70 | + updateLabelsSavedLabel(false); |
| 71 | + }); |
| 72 | + ui->saveLabelsBtn->setEnabled(false); |
| 73 | + connect(ui->saveLabelsBtn, &QPushButton::clicked, this, &ScmEditorDialog::saveLabels); |
| 74 | + updateLabelsSavedLabel(false); |
| 75 | +} |
| 76 | + |
| 77 | +void ScmEditorDialog::saveLabels() |
| 78 | +{ |
| 79 | + qDebug() << "ScmEditorDialog: Saving labels:"; |
| 80 | + qDebug() << " English Name:" << constellationEnglishName; |
| 81 | + if(constellationNativeName) qDebug() << " Native Name:" << constellationNativeName.value_or("N/A"); |
| 82 | + if(constellationPronounce) qDebug() << " Pronounce:" << constellationPronounce.value_or("N/A"); |
| 83 | + if(constellationIpa) qDebug() << " IPA:" << constellationIpa.value_or("N/A"); |
| 84 | + |
| 85 | + updateLabelsSavedLabel(true); |
| 86 | +} |
| 87 | + |
| 88 | +void ScmEditorDialog::updateLabelsSavedLabel(bool saved) |
| 89 | +{ |
| 90 | + if (saved) |
| 91 | + { |
| 92 | + ui->labelsSavedLbl->setText("Saved labels."); |
| 93 | + } |
| 94 | + else |
| 95 | + { |
| 96 | + ui->labelsSavedLbl->setText(""); |
| 97 | + } |
| 98 | +} |
0 commit comments