|
1 | 1 | #include "ScmEditorDialog.hpp" |
2 | 2 | #include "ui_scmEditorDialog.h" |
| 3 | +#include <QFileDialog> |
| 4 | +#include <QFileSystemModel> |
| 5 | +#include <QMessageBox> |
3 | 6 |
|
4 | 7 | ScmEditorDialog::ScmEditorDialog() |
5 | 8 | : StelDialog("ScmEditorDialog") |
@@ -29,58 +32,99 @@ void ScmEditorDialog::createDialogContent() |
29 | 32 | connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close); |
30 | 33 |
|
31 | 34 | // LABELS TAB |
32 | | - connect(ui->enNameTE, &QTextEdit::textChanged, this, [this]() |
33 | | - { |
34 | | - constellationEnglishName = ui->enNameTE->toPlainText(); |
35 | | - if(constellationEnglishName.isEmpty()) |
| 35 | + connect(ui->enNameTE, |
| 36 | + &QTextEdit::textChanged, |
| 37 | + this, |
| 38 | + [this]() |
36 | 39 | { |
37 | | - ui->saveLabelsBtn->setEnabled(false); |
38 | | - } |
39 | | - else |
| 40 | + constellationEnglishName = ui->enNameTE->toPlainText(); |
| 41 | + if (constellationEnglishName.isEmpty()) |
| 42 | + { |
| 43 | + ui->saveLabelsBtn->setEnabled(false); |
| 44 | + } |
| 45 | + else |
| 46 | + { |
| 47 | + ui->saveLabelsBtn->setEnabled(true); |
| 48 | + } |
| 49 | + updateLabelsSavedLabel(false); |
| 50 | + }); |
| 51 | + connect(ui->natNameTE, |
| 52 | + &QTextEdit::textChanged, |
| 53 | + this, |
| 54 | + [this]() |
40 | 55 | { |
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()) |
| 56 | + constellationNativeName = ui->natNameTE->toPlainText(); |
| 57 | + if (constellationNativeName->isEmpty()) |
| 58 | + { |
| 59 | + constellationNativeName = std::nullopt; |
| 60 | + } |
| 61 | + updateLabelsSavedLabel(false); |
| 62 | + }); |
| 63 | + connect(ui->pronounceTE, |
| 64 | + &QTextEdit::textChanged, |
| 65 | + this, |
| 66 | + [this]() |
49 | 67 | { |
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()) |
| 68 | + constellationPronounce = ui->pronounceTE->toPlainText(); |
| 69 | + if (constellationPronounce->isEmpty()) |
| 70 | + { |
| 71 | + constellationPronounce = std::nullopt; |
| 72 | + } |
| 73 | + updateLabelsSavedLabel(false); |
| 74 | + }); |
| 75 | + connect(ui->ipaTE, |
| 76 | + &QTextEdit::textChanged, |
| 77 | + this, |
| 78 | + [this]() |
67 | 79 | { |
68 | | - constellationIpa = std::nullopt; |
69 | | - } |
70 | | - updateLabelsSavedLabel(false); |
71 | | - }); |
| 80 | + constellationIpa = ui->ipaTE->toPlainText(); |
| 81 | + if (constellationIpa->isEmpty()) |
| 82 | + { |
| 83 | + constellationIpa = std::nullopt; |
| 84 | + } |
| 85 | + updateLabelsSavedLabel(false); |
| 86 | + }); |
72 | 87 | ui->saveLabelsBtn->setEnabled(false); |
73 | 88 | connect(ui->saveLabelsBtn, &QPushButton::clicked, this, &ScmEditorDialog::saveLabels); |
74 | 89 | updateLabelsSavedLabel(false); |
| 90 | + |
| 91 | + /* ============================================= SCM importer/converter ============================================= */ |
| 92 | + auto fsModel = new QFileSystemModel(this); |
| 93 | + fsModel->setRootPath(QDir::homePath()); |
| 94 | + ui->fileSystem->setModel(fsModel); |
| 95 | + ui->fileSystem->setRootIndex(fsModel->index(QDir::homePath())); |
| 96 | + |
| 97 | + connect(ui->fileSystem, |
| 98 | + &QTreeView::doubleClicked, |
| 99 | + this, |
| 100 | + [this, fsModel](const QModelIndex &idx) |
| 101 | + { |
| 102 | + const QString path = fsModel->filePath(idx); |
| 103 | + ui->filePathLineEdit->setText(path); |
| 104 | + }); |
| 105 | + connect(ui->pushButton, &QPushButton::clicked, this, [this]() |
| 106 | + { |
| 107 | + const QString path = ui->filePathLineEdit->text(); |
| 108 | + if (path.isEmpty()) |
| 109 | + { |
| 110 | + QMessageBox::warning(dialog, tr("No file selected"), tr("Please pick a file first.")); |
| 111 | + return; |
| 112 | + } |
| 113 | + qDebug() << "Importing file:" << path; |
| 114 | + }); |
| 115 | + /* ================================================================================================================== */ |
75 | 116 | } |
76 | 117 |
|
77 | 118 | void ScmEditorDialog::saveLabels() |
78 | 119 | { |
79 | 120 | qDebug() << "ScmEditorDialog: Saving labels:"; |
80 | 121 | 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"); |
| 122 | + if (constellationNativeName) |
| 123 | + qDebug() << " Native Name:" << constellationNativeName.value_or("N/A"); |
| 124 | + if (constellationPronounce) |
| 125 | + qDebug() << " Pronounce:" << constellationPronounce.value_or("N/A"); |
| 126 | + if (constellationIpa) |
| 127 | + qDebug() << " IPA:" << constellationIpa.value_or("N/A"); |
84 | 128 |
|
85 | 129 | updateLabelsSavedLabel(true); |
86 | 130 | } |
|
0 commit comments