Kstars

pwizobjectselection.cpp
1 /*
2  SPDX-FileCopyrightText: 2011 Rafał Kułaga <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "pwizobjectselection.h"
8 #include "printingwizard.h"
9 #include "kstars.h"
10 #include "skymap.h"
11 #include "dialogs/finddialog.h"
12 #include "dialogs/detaildialog.h"
13 #include "starobject.h"
14 #include "ksplanetbase.h"
15 #include "catalogobject.h"
16 #include <QPointer>
17 #include <KLocalizedString>
18 
20  : QFrame(parent), m_ParentWizard(wizard)
21 {
22  setupUi(this);
23 
24  detailsButton->setVisible(false);
25  selectedObjLabel->setVisible(false);
26  objInfoLabel->setVisible(false);
27 
28  connect(fromListButton, SIGNAL(clicked()), this, SLOT(slotSelectFromList()));
29  connect(pointButton, SIGNAL(clicked()), this, SLOT(slotPointObject()));
30  connect(detailsButton, SIGNAL(clicked()), this, SLOT(slotShowDetails()));
31 }
32 
34 {
35  m_ParentWizard->setSkyObject(obj);
36  m_ParentWizard->updateStepButtons();
37 
38  QString infoStr = objectInfoString(obj);
39 
40  objInfoLabel->setText(infoStr);
41 
42  detailsButton->setVisible(true);
43  selectedObjLabel->setVisible(true);
44  objInfoLabel->setVisible(true);
45 }
46 
47 void PWizObjectSelectionUI::slotSelectFromList()
48 {
49  if (FindDialog::Instance()->exec() == QDialog::Accepted)
50  {
51  SkyObject *obj = FindDialog::Instance()->targetObject();
52  if (obj)
53  {
54  setSkyObject(obj);
55  m_ParentWizard->updateStepButtons();
56  }
57  }
58 }
59 
60 void PWizObjectSelectionUI::slotPointObject()
61 {
62  m_ParentWizard->beginPointing();
63 }
64 
65 void PWizObjectSelectionUI::slotShowDetails()
66 {
67  if (m_ParentWizard->getSkyObject())
68  {
70  m_ParentWizard->getSkyObject(), KStars::Instance()->data()->ut(), KStars::Instance()->data()->geo(), this));
71  detailDlg->exec();
72  delete detailDlg;
73  }
74 }
75 
77 {
78  QString retVal;
79 
80  switch (obj->type())
81  {
82  case SkyObject::STAR:
83  {
84  StarObject *s = (StarObject *)obj;
85 
86  retVal = s->longname();
87 
88  if (s->getHDIndex() != 0)
89  {
90  if (!s->longname().isEmpty())
91  {
92  retVal += QString(" ● HD%1").arg(QString::number(s->getHDIndex()));
93  }
94 
95  else
96  {
97  retVal += QString(" ● HD%1").arg(QString::number(s->getHDIndex()));
98  }
99  }
100 
101  retVal += " ● " + s->sptype() + ' ' + i18n("star");
102  retVal += " ● " + i18nc("number in magnitudes", "%1 mag", QLocale().toString(s->mag(), 1));
103 
104  break;
105  }
106 
107  case SkyObject::ASTEROID: //[fall through to planets]
108  case SkyObject::COMET: //[fall through to planets]
109  case SkyObject::MOON: //[fall through to planets]
110 
111  case SkyObject::PLANET:
112  {
113  KSPlanetBase *ps = (KSPlanetBase *)obj;
114 
115  retVal = ps->longname();
116 
117  //Type is "G5 star" for Sun
118  QString type;
119  if (ps->name() == i18n("Sun"))
120  {
121  type = i18n("G5 star");
122  }
123 
124  else if (ps->name() == i18n("Moon"))
125  {
126  type = ps->translatedName();
127  }
128 
129  else if (ps->name() == i18nc("Asteroid name (optional)", "Pluto") || ps->name() == i18nc("Asteroid name (optional)", "Ceres") || ps->name() == i18nc("Asteroid name (optional)", "Eris"))
130  {
131  type = i18n("Dwarf planet");
132  }
133  else
134  {
135  type = ps->typeName();
136  }
137 
138  retVal += " ● " + type;
139  retVal += " ● " + i18nc("number in magnitudes", "%1 mag", QLocale().toString(ps->mag(), 1));
140 
141  break;
142  }
143 
144  default: // deep-sky object
145  {
146  auto *dso = (CatalogObject *)obj;
147 
148  QString oname, pname;
149  //Show all names recorded for the object
150  if (!dso->longname().isEmpty() && dso->longname() != dso->name())
151  {
152  pname = dso->translatedLongName();
153  oname = dso->translatedName();
154  }
155 
156  else
157  {
158  pname = dso->translatedName();
159  }
160 
161  if (!dso->translatedName2().isEmpty())
162  {
163  if (oname.isEmpty())
164  {
165  oname = dso->translatedName2();
166  }
167 
168  else
169  {
170  oname += " ● " + dso->translatedName2();
171  }
172  }
173 
174  oname += " ● " + dso->catalogIdentifier();
175 
176  if (!oname.isEmpty())
177  pname += " ● " + oname;
178 
179  retVal = pname;
180  retVal += " ● " + dso->typeName();
181 
182  break;
183  }
184  }
185 
186  return retVal;
187 }
QString number(int n, int base)
SkyObject * getSkyObject()
Get selected SkyObject, for which FinderChart is created.
static QString objectInfoString(SkyObject *obj)
Static function: get QString with basic information about SkyObject.
Class representing Printing Wizard for KStars printed documents (currently only finder charts).
virtual QString name(void) const
Definition: skyobject.h:145
QString translatedName() const
Definition: skyobject.h:148
float mag() const
Definition: skyobject.h:206
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void updateStepButtons()
Update Next/Previous step buttons.
int getHDIndex() const
Definition: starobject.h:248
static KStars * Instance()
Definition: kstars.h:125
int type(void) const
Definition: skyobject.h:188
QString i18n(const char *text, const TYPE &arg...)
QString longname(void) const override
If star is unnamed return "star" otherwise return the longname.
Definition: starobject.h:133
subclass of SkyObject specialized for stars.
Definition: starobject.h:32
bool isEmpty() const const
GeoLocation * geo()
Definition: kstarsdata.h:229
QString sptype(void) const
Returns entire spectral type string.
Definition: starobject.cpp:549
void setupUi(QWidget *widget)
const KStarsDateTime & ut() const
Definition: kstarsdata.h:156
static QString typeName(const int t)
Definition: skyobject.cpp:338
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void setSkyObject(SkyObject *obj)
Set SkyObject for which FinderChart is created.
void setSkyObject(SkyObject *obj)
Update UI elements for newly selected SkyObject.
void beginPointing()
Set SkyMap to pointing mode and hide Printing Wizard.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
virtual QString longname(void) const
Definition: skyobject.h:164
KStarsData * data() const
Definition: kstars.h:137
A simple container object to hold the minimum information for a Deeb Sky Object to be drawn on the sk...
Definition: catalogobject.h:40
PWizObjectSelectionUI(PrintingWizard *wizard, QWidget *parent=nullptr)
Constructor.
Information about an object in the sky.
Definition: skyobject.h:41
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.