wiview.cpp 8.36 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
    ctxt = baseView->rootContext();
31

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

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

37 38 39 40
    containerObj = baseObj->findChild<QObject *>("containerObj");

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

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

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

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

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

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

void WIView::onCategorySelected(int type)
118
{
119
    switch(type)
120
    {
121 122
    case 0:
        kDebug()<<"Planets Selected";
123
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Planets ));
124 125 126
        kDebug()<<"Model created successfully";
        break;
    case 1:
127
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Stars ));
128 129
        break;
    case 2:
130
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Constellations ));
131 132 133 134 135
        break;
    case 3:
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Galaxies ));
        break;
    case 4:
136
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Clusters ));
137 138
        break;
    case 5:
139
        ctxt->setContextProperty("soListModel", m->returnModel( ModelManager::Nebulae ));
140
        break;
141 142
    }
}
143

144
void WIView::onSoListItemClicked(int type, QString typeName, int index)
145
{
146
    SkyObjItem *soitem;
147 148 149 150 151 152 153 154

    kDebug()<<type;
    switch (type)
    {
    case 0:
        soitem = m->returnModel(ModelManager::Planets)->getSkyObjItem(index);
        break;
    case 1:
155
        soitem = m->returnModel(ModelManager::Stars)->getSkyObjItem(index);
156 157 158 159 160
        break;
    case 2:
        soitem = m->returnModel(ModelManager::Galaxies)->getSkyObjItem(index);
        break;
    case 3:
161
        soitem = m->returnModel(ModelManager::Constellations)->getSkyObjItem(index);
162
        break;
163 164 165 166 167 168 169
    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();
170 171
        return;
    }
172 173 174 175 176 177 178 179 180 181 182 183 184

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

185
    kDebug()<<soitem->getName()<<soitem->getType();
186 187
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
188

189
//    soListObj->setProperty("visible", false);
190
    loadDetailsView(soitem , index);
191 192
}

193
void WIView::loadDetailsView(SkyObjItem* soitem, int index)
194 195
{
    QObject* sonameObj = detailsViewObj->findChild<QObject *>("sonameObj");
196
    QObject* posTextObj = detailsViewObj->findChild<QObject *>("posTextObj");
197
    QObject* descTextObj = detailsViewObj->findChild<QObject *>("descTextObj");
198
    QObject* magTextObj = detailsViewObj->findChild<QObject *>("magTextObj");
199
    sonameObj->setProperty("text", soitem->getName());
200
    posTextObj->setProperty("text", soitem->getPosition());
201
    descTextObj->setProperty("text", soitem->getDesc());
202 203
    magTextObj->setProperty("text", soitem->getMagnitude());

204 205 206 207 208 209 210 211 212
    //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() );
    }

213 214
    curSoItem = soitem;
    curIndex = index;
215
}
216 217 218

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