File indexing completed on 2024-07-14 07:17:22

0001 /*
0002     SPDX-FileCopyrightText: 2012 Samikshan Bairagya <samikshan@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "skyobjects/supernova.h"
0008 #include "supernovaecomponent.h"
0009 #include "notifyupdatesui.h"
0010 #include "ui_notifyupdatesui.h"
0011 #include "kstars.h"
0012 #include "kstarsdata.h"
0013 #include "skymap.h"
0014 #include "QTreeWidget"
0015 
0016 #include <QApplication>
0017 
0018 NotifyUpdatesUI::NotifyUpdatesUI(QWidget *parent) : QDialog(parent), ui(new Ui::NotifyUpdatesUI)
0019 {
0020     ui->setupUi(this);
0021     setWindowTitle(i18nc("@title:window", "New Supernova(e) Discovered"));
0022     connect(ui->centrePushButton, SIGNAL(clicked()), SLOT(slotCenter()));
0023 }
0024 
0025 NotifyUpdatesUI::~NotifyUpdatesUI()
0026 {
0027     delete ui;
0028 }
0029 
0030 void NotifyUpdatesUI::addItems(QList<SkyObject *> updatesList)
0031 {
0032     //int len = updatesList.size();
0033     foreach (SkyObject *so, updatesList)
0034     {
0035         Supernova *sup = (Supernova *)so;
0036 
0037         QString name       = sup->name();
0038         QString hostGalaxy = i18n("Host Galaxy :: %1", sup->getHostGalaxy());
0039         QString magnitude  = i18n("Magnitude :: %1", QString::number(sup->getMagnitude()));
0040         QString type       = i18n("Type :: %1", sup->getType());
0041         QString position =
0042             i18n("Position :: RA : %1 Dec : %2", sup->getRA().toHMSString(), sup->getDec().toDMSString());
0043         QString date = i18n("Date :: %1", sup->getDate());
0044 
0045         QTreeWidgetItem *info    = new QTreeWidgetItem(ui->infoTreeWidget);
0046         QTreeWidgetItem *hGalaxy = new QTreeWidgetItem(info);
0047         QTreeWidgetItem *t       = new QTreeWidgetItem(info);
0048         QTreeWidgetItem *mag     = new QTreeWidgetItem(info);
0049         QTreeWidgetItem *pos     = new QTreeWidgetItem(info);
0050         QTreeWidgetItem *dt      = new QTreeWidgetItem(info);
0051 
0052         info->setText(0, name);
0053         hGalaxy->setText(0, hostGalaxy);
0054         pos->setText(0, position);
0055         mag->setText(0, magnitude);
0056         t->setText(0, type);
0057         dt->setText(0, date);
0058         ui->infoTreeWidget->addTopLevelItem(info);
0059     }
0060 }
0061 
0062 void NotifyUpdatesUI::slotCenter()
0063 {
0064     KStars *kstars = KStars::Instance();
0065     SkyObject *o   = 0;
0066     // get selected item
0067     if (ui->infoTreeWidget->currentItem() != 0)
0068     {
0069         if (ui->infoTreeWidget->currentItem()->childCount() > 0) //Serial No. is selected
0070             o = kstars->data()->objectNamed(ui->infoTreeWidget->currentItem()->text(0));
0071         else
0072             o = kstars->data()->objectNamed(ui->infoTreeWidget->currentItem()->parent()->text(0));
0073     }
0074     if (o != 0)
0075     {
0076         kstars->map()->setFocusPoint(o);
0077         kstars->map()->setFocusObject(o);
0078         kstars->map()->setDestination(*kstars->map()->focusPoint());
0079     }
0080 }