File indexing completed on 2024-03-24 15:17:41

0001 /*
0002     SPDX-FileCopyrightText: 2011 Rafał Kułaga <rl.kulaga@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "pwizobjectselection.h"
0008 #include "printingwizard.h"
0009 #include "kstars.h"
0010 #include "skymap.h"
0011 #include "dialogs/finddialog.h"
0012 #include "dialogs/detaildialog.h"
0013 #include "starobject.h"
0014 #include "ksplanetbase.h"
0015 #include "catalogobject.h"
0016 #include <QPointer>
0017 #include <KLocalizedString>
0018 
0019 PWizObjectSelectionUI::PWizObjectSelectionUI(PrintingWizard *wizard, QWidget *parent)
0020     : QFrame(parent), m_ParentWizard(wizard)
0021 {
0022     setupUi(this);
0023 
0024     detailsButton->setVisible(false);
0025     selectedObjLabel->setVisible(false);
0026     objInfoLabel->setVisible(false);
0027 
0028     connect(fromListButton, SIGNAL(clicked()), this, SLOT(slotSelectFromList()));
0029     connect(pointButton, SIGNAL(clicked()), this, SLOT(slotPointObject()));
0030     connect(detailsButton, SIGNAL(clicked()), this, SLOT(slotShowDetails()));
0031 }
0032 
0033 void PWizObjectSelectionUI::setSkyObject(SkyObject *obj)
0034 {
0035     m_ParentWizard->setSkyObject(obj);
0036     m_ParentWizard->updateStepButtons();
0037 
0038     QString infoStr = objectInfoString(obj);
0039 
0040     objInfoLabel->setText(infoStr);
0041 
0042     detailsButton->setVisible(true);
0043     selectedObjLabel->setVisible(true);
0044     objInfoLabel->setVisible(true);
0045 }
0046 
0047 void PWizObjectSelectionUI::slotSelectFromList()
0048 {
0049     if (FindDialog::Instance()->exec() == QDialog::Accepted)
0050     {
0051         SkyObject *obj = FindDialog::Instance()->targetObject();
0052         if (obj)
0053         {
0054             setSkyObject(obj);
0055             m_ParentWizard->updateStepButtons();
0056         }
0057     }
0058 }
0059 
0060 void PWizObjectSelectionUI::slotPointObject()
0061 {
0062     m_ParentWizard->beginPointing();
0063 }
0064 
0065 void PWizObjectSelectionUI::slotShowDetails()
0066 {
0067     if (m_ParentWizard->getSkyObject())
0068     {
0069         QPointer<DetailDialog> detailDlg(new DetailDialog(
0070                                              m_ParentWizard->getSkyObject(), KStars::Instance()->data()->ut(), KStars::Instance()->data()->geo(), this));
0071         detailDlg->exec();
0072         delete detailDlg;
0073     }
0074 }
0075 
0076 QString PWizObjectSelectionUI::objectInfoString(SkyObject *obj)
0077 {
0078     QString retVal;
0079 
0080     switch (obj->type())
0081     {
0082         case SkyObject::STAR:
0083         {
0084             StarObject *s = (StarObject *)obj;
0085 
0086             retVal = s->longname();
0087 
0088             if (s->getHDIndex() != 0)
0089             {
0090                 if (!s->longname().isEmpty())
0091                 {
0092                     retVal += QString(" ● HD%1").arg(QString::number(s->getHDIndex()));
0093                 }
0094 
0095                 else
0096                 {
0097                     retVal += QString(" ● HD%1").arg(QString::number(s->getHDIndex()));
0098                 }
0099             }
0100 
0101             retVal += " ● " + s->sptype() + ' ' + i18n("star");
0102             retVal += " ● " + i18nc("number in magnitudes", "%1 mag", QLocale().toString(s->mag(), 1));
0103 
0104             break;
0105         }
0106 
0107         case SkyObject::ASTEROID: //[fall through to planets]
0108         case SkyObject::COMET:    //[fall through to planets]
0109         case SkyObject::MOON:     //[fall through to planets]
0110 
0111         case SkyObject::PLANET:
0112         {
0113             KSPlanetBase *ps = (KSPlanetBase *)obj;
0114 
0115             retVal = ps->longname();
0116 
0117             //Type is "G5 star" for Sun
0118             QString type;
0119             if (ps->name() == i18n("Sun"))
0120             {
0121                 type = i18n("G5 star");
0122             }
0123 
0124             else if (ps->name() == i18n("Moon"))
0125             {
0126                 type = ps->translatedName();
0127             }
0128 
0129             else if (ps->name() == i18nc("Asteroid name (optional)", "Pluto") || ps->name() == i18nc("Asteroid name (optional)", "Ceres") || ps->name() == i18nc("Asteroid name (optional)", "Eris"))
0130             {
0131                 type = i18n("Dwarf planet");
0132             }
0133             else
0134             {
0135                 type = ps->typeName();
0136             }
0137 
0138             retVal += " ● " + type;
0139             retVal += " ● " + i18nc("number in magnitudes", "%1 mag", QLocale().toString(ps->mag(), 1));
0140 
0141             break;
0142         }
0143 
0144         default: // deep-sky object
0145         {
0146             auto *dso = (CatalogObject *)obj;
0147 
0148             QString oname, pname;
0149             //Show all names recorded for the object
0150             if (!dso->longname().isEmpty() && dso->longname() != dso->name())
0151             {
0152                 pname = dso->translatedLongName();
0153                 oname = dso->translatedName();
0154             }
0155 
0156             else
0157             {
0158                 pname = dso->translatedName();
0159             }
0160 
0161             if (!dso->translatedName2().isEmpty())
0162             {
0163                 if (oname.isEmpty())
0164                 {
0165                     oname = dso->translatedName2();
0166                 }
0167 
0168                 else
0169                 {
0170                     oname += " ● " + dso->translatedName2();
0171                 }
0172             }
0173 
0174             oname += " ● " + dso->catalogIdentifier();
0175 
0176             if (!oname.isEmpty())
0177                 pname += " ● " + oname;
0178 
0179             retVal = pname;
0180             retVal += " ● " + dso->typeName();
0181 
0182             break;
0183         }
0184     }
0185 
0186     return retVal;
0187 }