wiview.cpp 6.64 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)
27 28
{

29
    m = new ModelManager(obs);
30

31
    m_BaseView = new QDeclarativeView();
32

33
    ctxt = m_BaseView->rootContext();
34

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

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

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

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

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

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

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

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

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

60 61
    m_BaseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    m_BaseView->show();
62 63
}

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

70
void WIView::onCategorySelected(int type)
71
{
72
    switch(type)
73
    {
74 75 76
    case 0:                        ///Planet type
    case 1:                        ///Star type
    case 2:                        ///Constellation type
77
        ctxt->setContextProperty("soListModel", m->returnModel(type));
78
        break;
79 80 81
    case 3:                        ///Galaxy type
    case 4:                        ///Cluster type
    case 5:                        ///Nebula type
82
        ctxt->setContextProperty("soListModel", m->returnModel(type));
83
        break;
84 85
    }
}
86

87
void WIView::onSoListItemClicked(int type, QString typeName, int index)
88
{
89
    SkyObjItem *soitem = m->returnModel(type)->getSkyObjItem(index);
90

91 92
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
93

94
//    soListObj->setProperty("visible", false);
95

96
    loadDetailsView(soitem, index);
97 98
}

99
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
100
{
101 102 103 104 105 106 107

    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);
108

109 110 111 112 113
    QObject *nextTextObj = m_NextObj->findChild<QObject *>("nextTextObj");
    nextTextObj->setProperty("text", nextItem->getName());
    QObject *prevTextObj = m_PrevObj->findChild<QObject *>("prevTextObj");
    prevTextObj->setProperty("text", prevItem->getName());

114 115 116 117
    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");
118
    QObject *sbTextObj = m_DetailsViewObj->findChild<QObject *>("sbTextObj");
119
    QObject *sizeTextObj = m_DetailsViewObj->findChild<QObject *>("sizeTextObj");
120

121
    sonameObj->setProperty("text", soitem->getLongName());
122
    posTextObj->setProperty("text", soitem->getPosition());
123
    descTextObj->setProperty("text", soitem->getDesc());
124

125 126 127 128 129
    QString magText;
    if (soitem->getType() == SkyObjItem::Constellation)
        magText = QString("Magnitude:  --");
    else
        magText = QString("Magnitude: ") + QString::number(soitem->getMagnitude()) + " mag";
130
    magTextObj->setProperty("text", magText);
131

132 133 134
    QString sbText = QString("Surface Brightness: ") + soitem->getSurfaceBrightness();
    sbTextObj->setProperty("text", sbText);

135 136
    QString sizeText = QString("Size: ") + soitem->getSize();
    sizeTextObj->setProperty("text", sizeText);
137
}
138

139
void WIView::onNextObjClicked()
140
{
141 142
    int modelSize = m->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
143
    loadDetailsView(nextItem, (m_CurIndex+1)%modelSize);
Samikshan Bairagya's avatar
Samikshan Bairagya committed
144
}
145 146 147 148 149 150 151

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);
}
152 153 154 155 156

void WIView::onSlewButtonClicked()
{
    ///Slew map to selected sky-object
    SkyObject* so = m_CurSoItem->getSkyObject();
157
    KStars* kstars = KStars::Instance();
158 159
    if (so != 0)
    {
160 161 162
        kstars->map()->setFocusPoint(so);
        kstars->map()->setFocusObject(so);
        kstars->map()->setDestination(*kstars->map()->focusPoint());
163 164
    }
}
165 166 167 168 169 170 171 172 173 174

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;
}