wiview.cpp 7.5 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
#include "wiview.h"
19
#include "QGraphicsObject"
20
#include "skymap.h"
21

Samikshan Bairagya's avatar
Samikshan Bairagya committed
22 23
#include "kstandarddirs.h"

24
WIView::WIView ( QObject *parent, ObsConditions *obs) : QObject(parent)
25 26
{

27
    m = new ModelManager(obs);
28

Samikshan Bairagya's avatar
Samikshan Bairagya committed
29
    QDeclarativeView *baseView = new QDeclarativeView();
30 31
    ctxt = baseView->rootContext();
    ctxt->setContextProperty("catListModel", QVariant::fromValue(m->returnCatListModel( ModelManager::BaseList )));
32

33
    baseView->setSource(KStandardDirs::locate("appdata","tools/whatsinteresting/Base.qml") );
34 35
    baseObj = dynamic_cast<QObject *> (baseView->rootObject());

36 37
    soTypeTextObj = baseObj->findChild<QObject *>("soTypeTextObj") ;

Samikshan Bairagya's avatar
Samikshan Bairagya committed
38
    catListObj = baseObj->findChild<QObject *>("catListObj");
39
    connect(catListObj, SIGNAL(catListItemClicked(QString)), this, SLOT(onCatListItemClicked(QString)));
40

Samikshan Bairagya's avatar
Samikshan Bairagya committed
41
    soListObj = baseObj->findChild<QObject *>("soListObj");
42 43
    connect(soListObj, SIGNAL(soListItemClicked(int, QString, int)), this, SLOT(onSoListItemClicked(int, QString, int)));

Samikshan Bairagya's avatar
Samikshan Bairagya committed
44
    detailsViewObj = baseObj->findChild<QObject *>("detailsViewObj");
45 46
    nextObj  = baseObj->findChild<QObject *>("nextObj");
    connect(nextObj, SIGNAL(nextObjTextClicked()), this, SLOT(onNextObjTextClicked()));
47

48
    baseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
49 50 51
    baseView->show();
}

Samikshan Bairagya's avatar
Samikshan Bairagya committed
52 53 54
WIView::~WIView()
{
    delete m;
55
    delete curSoItem;
Samikshan Bairagya's avatar
Samikshan Bairagya committed
56
}
57 58 59

void WIView::onCatListItemClicked(QString category)
{
60
    if (category == "Deep-sky Objects")
61 62
    {
        ctxt->setContextProperty("catListModel", QVariant::fromValue(m->returnCatListModel( ModelManager::DeepSkyObjects )));
63 64
        soTypeTextObj->setProperty("text", category);
        soTypeTextObj->setProperty("visible", true);
65 66 67 68
    }
    else if (category == "Planets")
    {
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Planets ));
69 70
        catListObj->setProperty("visible", false);
        soListObj->setProperty("visible", true);
71 72
        soTypeTextObj->setProperty("text", category);
        soTypeTextObj->setProperty("visible", true);
73 74 75 76
    }
    else if (category == "Stars")
    {
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Stars ));
77 78
        catListObj->setProperty("visible", false);
        soListObj->setProperty("visible", true);
79 80
        soTypeTextObj->setProperty("text", category);
        soTypeTextObj->setProperty("visible", true);
81 82 83 84
    }
    else if (category == "Galaxies")
    {
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Galaxies ));
85 86
        catListObj->setProperty("visible", false);
        soListObj->setProperty("visible", true);
87 88
        soTypeTextObj->setProperty("text", category);
        soTypeTextObj->setProperty("visible", true);
89 90 91 92
    }
    else if (category == "Constellations")
    {
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Constellations ));
93 94
        catListObj->setProperty("visible", false);
        soListObj->setProperty("visible", true);
95 96
        soTypeTextObj->setProperty("text", category);
        soTypeTextObj->setProperty("visible", true);
97
    }
98
    else if (category == "Clusters")
99
    {
100
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Clusters ));
101 102
        catListObj->setProperty("visible", false);
        soListObj->setProperty("visible", true);
103 104
        soTypeTextObj->setProperty("text", category);
        soTypeTextObj->setProperty("visible", true);
105 106 107 108
    }
    else if (category == "Nebulae")
    {
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Nebulae ));
109 110
        catListObj->setProperty("visible", false);
        soListObj->setProperty("visible", true);
111 112
        soTypeTextObj->setProperty("text", category);
        soTypeTextObj->setProperty("visible", true);
113 114
    }
}
115

116
void WIView::onSoListItemClicked(int type, QString typeName, int index)
117
{
118
    SkyObjItem *soitem;
119 120 121 122 123 124 125 126

    kDebug()<<type;
    switch (type)
    {
    case 0:
        soitem = m->returnModel(ModelManager::Planets)->getSkyObjItem(index);
        break;
    case 1:
127
        soitem = m->returnModel(ModelManager::Stars)->getSkyObjItem(index);
128 129 130 131 132
        break;
    case 2:
        soitem = m->returnModel(ModelManager::Galaxies)->getSkyObjItem(index);
        break;
    case 3:
133
        soitem = m->returnModel(ModelManager::Constellations)->getSkyObjItem(index);
134
        break;
135 136 137 138 139 140 141
    case 4:
        soitem = m->returnModel(ModelManager::Clusters)->getSkyObjItem(index);
        kDebug()<<soitem->getSkyObject()->typeName();
        return;
    case 5:
        soitem = m->returnModel(ModelManager::Nebulae)->getSkyObjItem(index);
        kDebug()<<soitem->getSkyObject()->typeName();
142 143
        return;
    }
144 145 146 147 148 149 150 151 152 153 154 155 156

//    if (type == "Star")
//        soitem = m->returnModel(ModelManager::Stars)->getSkyObjItem(index);
//    else if (type == "Constellation")
//        soitem = m->returnModel(ModelManager::Constellations)->getSkyObjItem(index);
//    else if (type == "Planet")
//        soitem = m->returnModel(ModelManager::Planets)->getSkyObjItem(index);
//    else
//    {
//        kDebug()<<"Nothing for DSOs right now";
//        return;
//    }

157
    kDebug()<<soitem->getName()<<soitem->getType();
158
    soTypeTextObj->setProperty("text", typeName);
159
    soTypeTextObj->setProperty("visible", true);
160

161
    soListObj->setProperty("visible", false);
162
    loadDetailsView(soitem , index);
163 164
}

165
void WIView::loadDetailsView(SkyObjItem* soitem, int index)
166 167
{
    QObject* sonameObj = detailsViewObj->findChild<QObject *>("sonameObj");
168
    QObject* posTextObj = detailsViewObj->findChild<QObject *>("posTextObj");
169
    QObject* descTextObj = detailsViewObj->findChild<QObject *>("descTextObj");
170
    QObject* magTextObj = detailsViewObj->findChild<QObject *>("magTextObj");
171
    sonameObj->setProperty("text", soitem->getName());
172
    posTextObj->setProperty("text", soitem->getPosition());
173
    descTextObj->setProperty("text", soitem->getDesc());
174 175
    magTextObj->setProperty("text", soitem->getMagnitude());

176 177
    detailsViewObj->setProperty("visible", true);

178 179 180 181 182 183 184 185 186
    //Slew map to selected sky object
    SkyObject* so = soitem->getSkyObject();
    KStars* data = KStars::Instance();
    if (so != 0) {
        data->map()->setFocusPoint( so );
        data->map()->setFocusObject( so );
        data->map()->setDestination( *data->map()->focusPoint() );
    }

187 188
    curSoItem = soitem;
    curIndex = index;
189
}
190 191 192

void WIView::onNextObjTextClicked()
{
193 194
    int modelSize = m->returnModel(curSoItem->getTypeName())->rowCount();
    SkyObjItem *nextItem = m->returnModel(curSoItem->getTypeName())->getSkyObjItem((curIndex+1)%modelSize);
195
    loadDetailsView(nextItem, (curIndex+1)%modelSize);
Samikshan Bairagya's avatar
Samikshan Bairagya committed
196
}