wiview.cpp 6.06 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(QWidget *parent, ObsConditions *obs) : QWidget(parent)
25 26
{

27
    m = new ModelManager(obs);
28

29
    KStars *data = KStars::Instance();
30

Samikshan Bairagya's avatar
Samikshan Bairagya committed
31
    QDeclarativeView *baseView = new QDeclarativeView();
32

33
    ctxt = baseView->rootContext();
34

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

37
    m_BaseObj = dynamic_cast<QObject *>(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
    baseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
58
    baseView->show();
59
    data->setWIView(baseView);
60 61
}

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

68
void WIView::onCategorySelected(int type)
69
{
70
    switch(type)
71
    {
72 73 74
    case 0:                        ///Planet type
    case 1:                        ///Star type
    case 2:                        ///Constellation type
75
        ctxt->setContextProperty("soListModel", m->returnModel(type));
76
        break;
77 78 79
    case 3:                        ///Galaxy type
    case 4:                        ///Cluster type
    case 5:                        ///Nebula type
80
        ctxt->setContextProperty("soListModel", m->returnModel(type));
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

94
    loadDetailsView(soitem, index);
95 96
}

97
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
98
{
99 100 101 102 103 104 105 106 107 108 109 110 111 112

    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);
    //QString nextObjText = QString("Next: ") + nextItem->getName();
    QObject *nextTextObj = m_NextObj->findChild<QObject *>("nextTextObj");
    nextTextObj->setProperty("text", nextItem->getName());
    //QString prevObjText = QString("Previous: ") + prevItem->getName();
    QObject *prevTextObj = m_PrevObj->findChild<QObject *>("prevTextObj");
    prevTextObj->setProperty("text", prevItem->getName());

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

    QString magText = QString("Magnitude: ") + QString::number(soitem->getMagnitude());

122
    sonameObj->setProperty("text", soitem->getLongName());
123
    posTextObj->setProperty("text", soitem->getPosition());
124
    descTextObj->setProperty("text", soitem->getDesc());
125 126 127 128
    magTextObj->setProperty("text", magText);
    /*
    sbTextObj->setProperty("text", magText);
    sizeTextObj->setProperty("text", soitem->getSize());*/
129
}
130

131
void WIView::onNextObjClicked()
132
{
133 134
    int modelSize = m->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
135
    loadDetailsView(nextItem, (m_CurIndex+1)%modelSize);
Samikshan Bairagya's avatar
Samikshan Bairagya committed
136
}
137 138 139 140 141 142 143

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);
}
144 145 146 147 148 149 150 151 152 153 154 155 156

void WIView::onSlewButtonClicked()
{
    ///Slew map to selected sky-object
    SkyObject* so = m_CurSoItem->getSkyObject();
    KStars* data = KStars::Instance();
    if (so != 0)
    {
        data->map()->setFocusPoint(so);
        data->map()->setFocusObject(so);
        data->map()->setDestination(*data->map()->focusPoint());
    }
}