wiview.cpp 6.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/***************************************************************************
                          wiview.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : 2012/26/05
    copyright            : (C) 2012 by Samikshan Bairagya
    email                : samikshan@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

18

19
#include "QGraphicsObject"
20
#include "wiview.h"
21
#include "skymap.h"
22
#include "dialogs/detaildialog.h"
23

Samikshan Bairagya's avatar
Samikshan Bairagya committed
24 25
#include "kstandarddirs.h"

26
WIView::WIView(QWidget *parent, ObsConditions *obs) : QWidget(parent), m_Obs(obs)
27
{
28
    m = new ModelManager(obs);
29

30
    m_BaseView = new QDeclarativeView();
31

32
    ctxt = m_BaseView->rootContext();
33

34
    m_BaseView->setSource(KStandardDirs::locate("appdata","tools/whatsinteresting/qml/wiview.qml"));
35

36
    m_BaseObj = dynamic_cast<QObject *>(m_BaseView->rootObject());
37

38
    //soTypeTextObj = m_BaseObj->findChild<QObject *>("soTypeTextObj");
39

40 41
    m_ViewsRowObj = m_BaseObj->findChild<QObject *>("viewsRowObj");
    connect(m_ViewsRowObj, SIGNAL(categorySelected(int)), this, SLOT(onCategorySelected(int)));
42

43 44
    m_SoListObj = m_BaseObj->findChild<QObject *>("soListObj");
    connect(m_SoListObj, SIGNAL(soListItemClicked(int, QString, int)), this, SLOT(onSoListItemClicked(int, QString, int)));
45

46
    m_DetailsViewObj = m_BaseObj->findChild<QObject *>("detailsViewObj");
47

48
    m_NextObj = m_BaseObj->findChild<QObject *>("nextObj");
49 50 51
    connect(m_NextObj, SIGNAL(nextObjClicked()), this, SLOT(onNextObjClicked()));
    m_PrevObj = m_BaseObj->findChild<QObject *>("prevObj");
    connect(m_PrevObj, SIGNAL(prevObjClicked()), this, SLOT(onPrevObjClicked()));
52

53 54 55
    m_SlewButtonObj = m_BaseObj->findChild<QObject *>("slewButtonObj");
    connect(m_SlewButtonObj, SIGNAL(slewButtonClicked()), this, SLOT(onSlewButtonClicked()));

56 57 58
    m_DetailsButtonObj = m_BaseObj->findChild<QObject *>("detailsButtonObj");
    connect(m_DetailsButtonObj, SIGNAL(detailsButtonClicked()), this, SLOT(onDetailsButtonClicked()));

59 60 61
    QObject *settingsIconObj = m_BaseObj->findChild<QObject *>("settingsIconObj");
    connect(settingsIconObj, SIGNAL(settingsIconClicked()), this, SLOT(onSettingsIconClicked()));

62 63
    m_BaseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    m_BaseView->show();
64 65
}

Samikshan Bairagya's avatar
Samikshan Bairagya committed
66 67 68
WIView::~WIView()
{
    delete m;
69
    delete m_CurSoItem;
Samikshan Bairagya's avatar
Samikshan Bairagya committed
70
}
71

72
void WIView::onCategorySelected(int type)
73
{
74
    ctxt->setContextProperty("soListModel", m->returnModel(type));
75
}
76

77
void WIView::onSoListItemClicked(int type, QString typeName, int index)
78
{
79
    SkyObjItem *soitem = m->returnModel(type)->getSkyObjItem(index);
80

81 82
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
83

84
//    soListObj->setProperty("visible", false);
85

86
    loadDetailsView(soitem, index);
87 88
}

89
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
90
{
91 92 93 94 95 96 97

    m_CurSoItem = soitem;
    m_CurIndex = index;

    int modelSize = m->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
    SkyObjItem *prevItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex-1+modelSize)%modelSize);
98

99 100 101 102 103
    QObject *nextTextObj = m_NextObj->findChild<QObject *>("nextTextObj");
    nextTextObj->setProperty("text", nextItem->getName());
    QObject *prevTextObj = m_PrevObj->findChild<QObject *>("prevTextObj");
    prevTextObj->setProperty("text", prevItem->getName());

104 105 106 107
    QObject *sonameObj = m_DetailsViewObj->findChild<QObject *>("sonameObj");
    QObject *posTextObj = m_DetailsViewObj->findChild<QObject *>("posTextObj");
    QObject *descTextObj = m_DetailsViewObj->findChild<QObject *>("descTextObj");
    QObject *magTextObj = m_DetailsViewObj->findChild<QObject *>("magTextObj");
108
    QObject *sbTextObj = m_DetailsViewObj->findChild<QObject *>("sbTextObj");
109
    QObject *sizeTextObj = m_DetailsViewObj->findChild<QObject *>("sizeTextObj");
110

111
    sonameObj->setProperty("text", soitem->getLongName());
112
    posTextObj->setProperty("text", soitem->getPosition());
113
    descTextObj->setProperty("text", soitem->getDesc());
114

115 116
    QString magText;
    if (soitem->getType() == SkyObjItem::Constellation)
117
        magText = i18n("Magnitude:  --");
118
    else
119
        magText = i18n("Magnitude: %1 %2", soitem->getMagnitude(), " mag");
120
    magTextObj->setProperty("text", magText);
121

122
    QString sbText = i18n("Surface Brightness: %1", soitem->getSurfaceBrightness());
123 124
    sbTextObj->setProperty("text", sbText);

125
    QString sizeText = i18n("Size: %1", soitem->getSize());
126
    sizeTextObj->setProperty("text", sizeText);
127
}
128

129
void WIView::onNextObjClicked()
130
{
131 132
    int modelSize = m->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
133
    loadDetailsView(nextItem, (m_CurIndex+1)%modelSize);
Samikshan Bairagya's avatar
Samikshan Bairagya committed
134
}
135 136 137 138 139 140 141

void WIView::onPrevObjClicked()
{
    int modelSize = m->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *prevItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex-1+modelSize)%modelSize);
    loadDetailsView(prevItem, (m_CurIndex-1+modelSize)%modelSize);
}
142 143 144 145 146

void WIView::onSlewButtonClicked()
{
    ///Slew map to selected sky-object
    SkyObject* so = m_CurSoItem->getSkyObject();
147
    KStars* kstars = KStars::Instance();
148 149
    if (so != 0)
    {
150 151 152
        kstars->map()->setFocusPoint(so);
        kstars->map()->setFocusObject(so);
        kstars->map()->setDestination(*kstars->map()->focusPoint());
153 154
    }
}
155 156 157 158 159 160 161 162 163 164

void WIView::onDetailsButtonClicked()
{
    ///Code taken from WUTDialog::slotDetails()
    KStars *kstars = KStars::Instance();
    SkyObject* so = m_CurSoItem->getSkyObject();
    DetailDialog *detail = new DetailDialog(so, kstars->data()->lt(), kstars->data()->geo(), kstars);
    detail->exec();
    delete detail;
}
165 166 167 168 169 170

void WIView::onSettingsIconClicked()
{
    KStars *kstars = KStars::Instance();
    kstars->showWIWizard();
}