wiview.cpp 5.41 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 50
    m_OptMag = obs->getOptimumMAG();

51
    baseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
52 53 54
    baseView->show();
}

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

61
void WIView::onCategorySelected(int type)
62
{
63 64 65
    QString oMagText = QString("Suggested optimum magnification : ") + QString::number(m_OptMag);
    QObject* oMagTextObj = baseObj->findChild<QObject *>("oMagTextObj");

66
    switch(type)
67
    {
68
    case 0:
69
        ctxt->setContextProperty("soListModel", m->returnModel( type ));
70 71
        break;
    case 1:
72
        ctxt->setContextProperty("soListModel", m->returnModel( type ));
73 74
        break;
    case 2:
75
        ctxt->setContextProperty("soListModel", m->returnModel( type ));
76 77
        break;
    case 3:
78
        ctxt->setContextProperty("soListModel", m->returnModel( type ));
79
        oMagTextObj->setProperty("text", oMagText);
80 81
        break;
    case 4:
82
        ctxt->setContextProperty("soListModel", m->returnModel( type ));
83
        oMagTextObj->setProperty("text", oMagText);
84 85
        break;
    case 5:
86
        ctxt->setContextProperty("soListModel", m->returnModel( type ));
87
        oMagTextObj->setProperty("text", oMagText);
88
        break;
89 90
    }
}
91

92
void WIView::onSoListItemClicked(int type, QString typeName, int index)
93
{
94
    SkyObjItem *soitem;
95 96 97 98 99

    kDebug()<<type;
    switch (type)
    {
    case 0:
100
        soitem = m->returnModel(type)->getSkyObjItem(index);
101 102
        break;
    case 1:
103
        soitem = m->returnModel(type)->getSkyObjItem(index);
104 105
        break;
    case 2:
106
        soitem = m->returnModel(type)->getSkyObjItem(index);
107 108
        break;
    case 3:
109
        soitem = m->returnModel(type)->getSkyObjItem(index);
110
        break;
111
    case 4:
112 113
        soitem = m->returnModel(type)->getSkyObjItem(index);
        break;
114
    case 5:
115 116
        soitem = m->returnModel(type)->getSkyObjItem(index);
        break;
117
    }
118

119
    kDebug()<<soitem->getName()<<soitem->getType();
120 121
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
122

123
//    soListObj->setProperty("visible", false);
124
    loadDetailsView(soitem , index);
125 126
}

127
void WIView::loadDetailsView(SkyObjItem* soitem, int index)
128 129
{
    QObject* sonameObj = detailsViewObj->findChild<QObject *>("sonameObj");
130
    QObject* posTextObj = detailsViewObj->findChild<QObject *>("posTextObj");
131
    QObject* descTextObj = detailsViewObj->findChild<QObject *>("descTextObj");
132
    QObject* magTextObj = detailsViewObj->findChild<QObject *>("magTextObj");
133
    sonameObj->setProperty("text", soitem->getName());
134
    posTextObj->setProperty("text", soitem->getPosition());
135
    descTextObj->setProperty("text", soitem->getDesc());
136 137
    magTextObj->setProperty("text", soitem->getMagnitude());

138 139 140 141 142 143 144 145 146
    //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() );
    }

147
    curSoItem = soitem;
148
    m_CurIndex = index;
149
}
150 151 152

void WIView::onNextObjTextClicked()
{
153 154
    int modelSize = m->returnModel(curSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m->returnModel(curSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
155
    loadDetailsView(nextItem, (m_CurIndex+1)%modelSize);
Samikshan Bairagya's avatar
Samikshan Bairagya committed
156
}