wiview.cpp 4.69 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 32 33
    baseView->setAttribute(Qt::WA_TranslucentBackground);
    baseView->setStyleSheet("background: transparent;");

34
    ctxt = baseView->rootContext();
35

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

38
    m_BaseObj = dynamic_cast<QObject *>(baseView->rootObject());
39

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

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

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

48
    m_DetailsViewObj = m_BaseObj->findChild<QObject *>("detailsViewObj");
49
    m_NextObj = m_BaseObj->findChild<QObject *>("nextObj");
50
    connect(m_NextObj, SIGNAL(nextObjTextClicked()), this, SLOT(onNextObjTextClicked()));
51

52 53
    m_OptMag = obs->getOptimumMAG();

54
    baseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
55 56 57
    baseView->show();
}

Samikshan Bairagya's avatar
Samikshan Bairagya committed
58 59 60
WIView::~WIView()
{
    delete m;
61
    delete m_CurSoItem;
Samikshan Bairagya's avatar
Samikshan Bairagya committed
62
}
63

64
void WIView::onCategorySelected(int type)
65
{
66
    QString oMagText = QString("Suggested optimum magnification : ") + QString::number(m_OptMag);
67
    QObject *oMagTextObj = m_BaseObj->findChild<QObject *>("oMagTextObj");
68

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

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

89 90
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
91

92
//    soListObj->setProperty("visible", false);
93
    loadDetailsView(soitem, index);
94 95
}

96
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
97
{
98 99 100 101
    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");
102
    sonameObj->setProperty("text", soitem->getName());
103
    posTextObj->setProperty("text", soitem->getPosition());
104
    descTextObj->setProperty("text", soitem->getDesc());
105 106
    magTextObj->setProperty("text", soitem->getMagnitude());

107
    ///Slew map to selected sky-object
108 109 110
    SkyObject* so = soitem->getSkyObject();
    KStars* data = KStars::Instance();
    if (so != 0) {
111 112 113
        data->map()->setFocusPoint(so);
        data->map()->setFocusObject(so);
        data->map()->setDestination(*data->map()->focusPoint());
114 115
    }

116
    m_CurSoItem = soitem;
117
    m_CurIndex = index;
118
}
119 120 121

void WIView::onNextObjTextClicked()
{
122 123
    int modelSize = m->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
124
    loadDetailsView(nextItem, (m_CurIndex+1)%modelSize);
Samikshan Bairagya's avatar
Samikshan Bairagya committed
125
}