Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions plugins/SkyCultureMaker/src/ScmSkyCulture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ bool scm::ScmSkyCulture::saveDescriptionAsMarkdown(QFile &file)

out << "## References\n" << desc.references << "\n\n";

out << "## Classification\n " << classificationTypeToString(desc.classification) << "\n\n";

out << "## License\n### " << license.name << "\n" << license.description << "\n\n";
out << "## License\n\n" << license.name << "\n\n";

try
{
Expand Down
29 changes: 21 additions & 8 deletions plugins/SkyCultureMaker/src/SkyCultureMaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,6 @@ void SkyCultureMaker::updateSkyCultureDialog()
scmSkyCultureDialog->setConstellations(currentSkyCulture->getConstellations());
}

void SkyCultureMaker::setSkyCultureDialogInfoLabel(const QString &text)
{
if (scmSkyCultureDialog != nullptr)
{
scmSkyCultureDialog->setInfoLabel(text);
}
}

void SkyCultureMaker::setSkyCultureDescription(const scm::Description &description)
{
if (currentSkyCulture != nullptr)
Expand Down Expand Up @@ -585,3 +577,24 @@ void SkyCultureMaker::initSetting(QSettings *conf, const QString key, const QVar
conf->setValue(key, defaultValue);
}
}

void SkyCultureMaker::showUserInfoMessage(QWidget *parent, const QString &dialogName, const QString &message)
{
const QString level = q_("INFO");
const QString title = dialogName.isEmpty() ? level : dialogName + ": " + level;
QMessageBox::information(parent, title, message);
}

void SkyCultureMaker::showUserWarningMessage(QWidget *parent, const QString &dialogName, const QString &message)
{
const QString level = q_("WARNING");
const QString title = dialogName.isEmpty() ? level : dialogName + ": " + level;
QMessageBox::warning(parent, title, message);
}

void SkyCultureMaker::showUserErrorMessage(QWidget *parent, const QString &dialogName, const QString &message)
{
const QString level = q_("ERROR");
const QString title = dialogName.isEmpty() ? level : dialogName + ": " + level;
QMessageBox::critical(parent, title, message);
}
34 changes: 28 additions & 6 deletions plugins/SkyCultureMaker/src/SkyCultureMaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QDir>
#include <QFile>
#include <QFont>
#include <QMessageBox>

class QPixmap;
class StelButton;
Expand Down Expand Up @@ -177,12 +178,6 @@ class SkyCultureMaker : public StelModule
*/
void updateSkyCultureDialog();

/**
* @brief Sets the info label text in the sky culture dialog.
* @param text The text to set in the info label.
*/
void setSkyCultureDialogInfoLabel(const QString &text);

/**
* @brief Sets the current sky culture description.
* @param description The description to set.
Expand Down Expand Up @@ -238,6 +233,33 @@ class SkyCultureMaker : public StelModule
*/
void openConstellationDialog(const QString &constellationId);

/**
* @brief Displays an information message to the user.
*
* @param parent The parent widget of the message box.
* @param dialogName The name of the dialog to be shown in the title bar.
* @param message The message to be displayed.
*/
void showUserInfoMessage(QWidget *parent, const QString &dialogName, const QString &message);

/**
* @brief Displays a warning message to the user.
*
* @param parent The parent widget of the message box.
* @param dialogName The name of the dialog to be shown in the title bar.
* @param message The message to be displayed.
*/
void showUserWarningMessage(QWidget *parent, const QString &dialogName, const QString &message);

/**
* @brief Displays an error message to the user.
*
* @param parent The parent widget of the message box.
* @param dialogName The name of the dialog to be shown in the title bar.
* @param message The message to be displayed.
*/
void showUserErrorMessage(QWidget *parent, const QString &dialogName, const QString &message);

signals:
void eventIsScmEnabled(bool b);

Expand Down
104 changes: 55 additions & 49 deletions plugins/SkyCultureMaker/src/gui/ScmConstellationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ void ScmConstellationDialog::loadFromConstellation(scm::ScmConstellation *conste
constellationPronounce = constellation->getPronounce();
constellationIPA = constellation->getIPA();

ui->enNameTE->setPlainText(constellationEnglishName);
ui->idTE->setPlainText(constellationId);
ui->natNameTE->setPlainText(constellationNativeName.value_or(""));
ui->pronounceTE->setPlainText(constellationPronounce.value_or(""));
ui->ipaTE->setPlainText(constellationIPA.value_or(""));
ui->enNameLE->setText(constellationEnglishName);
ui->idLE->setText(constellationId);
ui->natNameLE->setText(constellationNativeName.value_or(""));
ui->pronounceLE->setText(constellationPronounce.value_or(""));
ui->ipaLE->setText(constellationIPA.value_or(""));

// Hide the original constellation while editing
constellation->hide();
Expand Down Expand Up @@ -115,7 +115,7 @@ void ScmConstellationDialog::setIsDarkConstellation(bool isDark)
}

// the value changed, so we should reset some data from the previous mode
if(isDarkConstellation != isDark)
if (isDarkConstellation != isDark)
{
// reset drawn lines as they are not compatible between modes
draw->resetDrawing();
Expand Down Expand Up @@ -200,38 +200,38 @@ void ScmConstellationDialog::createDialogContent()

// LABELS TAB

connect(ui->enNameTE, &QTextEdit::textChanged, this,
connect(ui->enNameLE, &QLineEdit::textChanged, this,
[this]()
{
constellationEnglishName = ui->enNameTE->toPlainText();
constellationEnglishName = ui->enNameLE->text();

QString newConstId = constellationEnglishName.toLower().replace(" ", "_");
constellationPlaceholderId = newConstId;
ui->idTE->setPlaceholderText(newConstId);
ui->idLE->setPlaceholderText(newConstId);
});
connect(ui->idTE, &QTextEdit::textChanged, this, [this]() { constellationId = ui->idTE->toPlainText(); });
connect(ui->natNameTE, &QTextEdit::textChanged, this,
connect(ui->idLE, &QLineEdit::textChanged, this, [this]() { constellationId = ui->idLE->text(); });
connect(ui->natNameLE, &QLineEdit::textChanged, this,
[this]()
{
constellationNativeName = ui->natNameTE->toPlainText();
constellationNativeName = ui->natNameLE->text();
if (constellationNativeName->isEmpty())
{
constellationNativeName = std::nullopt;
}
});
connect(ui->pronounceTE, &QTextEdit::textChanged, this,
connect(ui->pronounceLE, &QLineEdit::textChanged, this,
[this]()
{
constellationPronounce = ui->pronounceTE->toPlainText();
constellationPronounce = ui->pronounceLE->text();
if (constellationPronounce->isEmpty())
{
constellationPronounce = std::nullopt;
}
});
connect(ui->ipaTE, &QTextEdit::textChanged, this,
connect(ui->ipaLE, &QLineEdit::textChanged, this,
[this]()
{
constellationIPA = ui->ipaTE->toPlainText();
constellationIPA = ui->ipaLE->text();
if (constellationIPA->isEmpty())
{
constellationIPA = std::nullopt;
Expand All @@ -241,10 +241,6 @@ void ScmConstellationDialog::createDialogContent()

void ScmConstellationDialog::handleFontChanged()
{
QFont infoLblFont = QApplication::font();
infoLblFont.setBold(true);
ui->infoLbl->setFont(infoLblFont);

QFont labelsTitleFont = QApplication::font();
labelsTitleFont.setPixelSize(labelsTitleFont.pixelSize() + 2);
labelsTitleFont.setBold(true);
Expand Down Expand Up @@ -300,21 +296,20 @@ void ScmConstellationDialog::triggerUploadImage()

if (!fileInfo.isFile())
{
ui->infoLbl->setText(q_("Choosen path is not a valid file:\n") + filePath);
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Chosen path is not a valid file:\n") + filePath);
return;
}

if (!(fileInfo.suffix().compare("PNG", Qt::CaseInsensitive) == 0 ||
fileInfo.suffix().compare("JPG", Qt::CaseInsensitive) == 0 ||
fileInfo.suffix().compare("JPEG", Qt::CaseInsensitive) == 0))
{
ui->infoLbl->setText(q_("Chosen file is not a PNG, JPG or JPEG image:\n") + filePath);
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Chosen file is not a PNG, JPG or JPEG image:\n") + filePath);
return;
}

// Reset text
ui->infoLbl->setText("");

QPixmap image = QPixmap(fileInfo.absoluteFilePath());
imageItem->setImage(image);
imageItem->show();
Expand All @@ -337,7 +332,8 @@ void ScmConstellationDialog::bindSelectedStar()
{
if (!imageItem->hasAnchorSelection())
{
ui->infoLbl->setText(q_("WARNING: Select an anchor to bind to."));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("No anchor was selected. Please select an anchor to bind to."));
qDebug() << "SkyCultureMaker: No anchor was selected.";
return;
}
Expand All @@ -347,38 +343,41 @@ void ScmConstellationDialog::bindSelectedStar()

if (!objectMgr.getWasSelected())
{
ui->infoLbl->setText(q_("WARNING: Select a star to bind to the current selected anchor."));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("No star was selected to bind to the current selected anchor."));
qDebug() << "SkyCultureMaker: No star was selected to bind to.";
return;
}

StelObjectP stelObj = objectMgr.getLastSelectedObject();
assert(stelObj != nullptr); // Checked through getWasSelected
if (stelObj->getType().compare("star", Qt::CaseInsensitive) != 0)
if (stelObj->getType().compare("star", Qt::CaseInsensitive) != 0 &&
stelObj->getType().compare("nebula", Qt::CaseInsensitive) != 0)
{
ui->infoLbl->setText(q_("WARNING: The selected object must be of type star."));
qDebug() << "SkyCultureMaker: The selected object is not of type start, got " << stelObj->getType();
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("The selected object must be of type Star or Nebula."));
qDebug() << "SkyCultureMaker: The selected object is not of type Star, got " << stelObj->getType();
return;
}

ScmConstellationImageAnchor *anchor = imageItem->getSelectedAnchor();
if (anchor == nullptr)
{
ui->infoLbl->setText(q_("WARNING: No anchor is selected."));
qDebug() << "SkyCultureMaker: No anchor is selected";
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("No anchor was selected. Please select an anchor to bind to."));
qDebug() << "SkyCultureMaker: No anchor was selected";
return;
}

bool success = anchor->trySetStarHip(stelObj->getID());
if (success == false)
{
ui->infoLbl->setText(q_("WARNING: The selected object must contain a HIP number."));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("The selected object must contain a HIP number."));
qDebug() << "SkyCultureMaker: The object does not contain a HIP, id = " << stelObj->getID();
return;
}

ui->infoLbl->setText(""); // Reset

updateArtwork();
}

Expand All @@ -396,14 +395,16 @@ bool ScmConstellationDialog::canConstellationBeSaved() const
scm::ScmSkyCulture *currentSkyCulture = maker->getCurrentSkyCulture();
if (currentSkyCulture == nullptr)
{
ui->infoLbl->setText(q_("WARNING: Could not save: Sky Culture is not set"));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Could not save: Sky Culture is not set"));
qDebug() << "SkyCultureMaker: Could not save: Sky Culture is not set";
return false;
}

if (constellationEnglishName.isEmpty())
{
ui->infoLbl->setText(q_("WARNING: Could not save: English name is empty"));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Could not save: English name is empty"));
qDebug() << "SkyCultureMaker: Could not save: English name is empty";
return false;
}
Expand All @@ -412,15 +413,17 @@ bool ScmConstellationDialog::canConstellationBeSaved() const
QString finalId = constellationId.isEmpty() ? constellationPlaceholderId : constellationId;
if (finalId.isEmpty())
{
ui->infoLbl->setText(q_("WARNING: Could not save: Constellation ID is empty"));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Could not save: Constellation ID is empty"));
qDebug() << "SkyCultureMaker: Could not save: Constellation ID is empty";
return false;
}

// Not editing a constellation, but the ID already exists
if (constellationBeingEdited == nullptr && currentSkyCulture->getConstellation(finalId) != nullptr)
{
ui->infoLbl->setText(q_("WARNING: Could not save: Constellation with this ID already exists"));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Could not save: Constellation with this ID already exists"));
qDebug() << "SkyCultureMaker: Could not save: Constellation with this ID already exists, id = "
<< finalId;
return false;
Expand All @@ -429,7 +432,8 @@ bool ScmConstellationDialog::canConstellationBeSaved() const
else if (constellationBeingEdited != nullptr && constellationBeingEdited->getId() != finalId &&
currentSkyCulture->getConstellation(finalId) != nullptr)
{
ui->infoLbl->setText(q_("WARNING: Could not save: Constellation with this ID already exists"));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Could not save: Constellation with this ID already exists"));
qDebug() << "SkyCultureMaker: Could not save: Constellation with this ID already exists, id = "
<< finalId;
return false;
Expand All @@ -439,7 +443,8 @@ bool ScmConstellationDialog::canConstellationBeSaved() const
auto drawnConstellation = maker->getScmDraw()->getCoordinates();
if (drawnConstellation.empty())
{
ui->infoLbl->setText(q_("WARNING: Could not save: The constellation does not contain any drawings"));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Could not save: The constellation does not contain any drawings"));
qDebug() << "SkyCultureMaker: Could not save: The constellation does not contain any drawings";
return false;
}
Expand All @@ -449,8 +454,9 @@ bool ScmConstellationDialog::canConstellationBeSaved() const
{
if (!imageItem->isImageAnchored())
{
ui->infoLbl->setText(q_("WARNING: Could not save: An artwork is attached, but not all "
"anchors have a star bound."));
maker->showUserErrorMessage(this->dialog, ui->titleBar->title(),
q_("Could not save: An artwork is attached, but not all "
"anchors have a star bound."));
qDebug() << "SkyCultureMaker: Could not save: An artwork is attached, but not all "
"anchors have a star bound.";
return false;
Expand Down Expand Up @@ -524,22 +530,22 @@ void ScmConstellationDialog::resetDialog()
setIsDarkConstellation(false);

constellationId.clear();
ui->idTE->clear();
ui->idLE->clear();

constellationPlaceholderId.clear();
ui->idTE->setPlaceholderText("");
ui->idLE->setPlaceholderText("");

constellationEnglishName.clear();
ui->enNameTE->clear();
ui->enNameLE->clear();

constellationNativeName = std::nullopt;
ui->natNameTE->clear();
ui->natNameLE->clear();

constellationPronounce = std::nullopt;
ui->pronounceTE->clear();
ui->pronounceLE->clear();

constellationIPA = std::nullopt;
ui->ipaTE->clear();
ui->ipaLE->clear();

ui->bind_star->setEnabled(false);
imageItem->hide();
Expand Down
Loading
Loading