wiview.cpp 6.6 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

19
#include "QGraphicsObject"
20
#include "wiview.h"
21
#include "skymap.h"
22
#include "dialogs/detaildialog.h"
23

Samikshan Bairagya's avatar
Samikshan Bairagya committed
24 25
#include "kstandarddirs.h"

26
WIView::WIView(QWidget *parent, ObsConditions *obs) : QWidget(parent)
27 28
{

29
    m = new ModelManager(obs);
30

31
    KStars *kstars = KStars::Instance();
32

Samikshan Bairagya's avatar
Samikshan Bairagya committed
33
    QDeclarativeView *baseView = new QDeclarativeView();
34

35
    ctxt = baseView->rootContext();
36

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

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

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

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

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

49
    m_DetailsViewObj = m_BaseObj->findChild<QObject *>("detailsViewObj");
50

51
    m_NextObj = m_BaseObj->findChild<QObject *>("nextObj");
52 53 54
    connect(m_NextObj, SIGNAL(nextObjClicked()), this, SLOT(onNextObjClicked()));
    m_PrevObj = m_BaseObj->findChild<QObject *>("prevObj");
    connect(m_PrevObj, SIGNAL(prevObjClicked()), this, SLOT(onPrevObjClicked()));
55

56 57 58
    m_SlewButtonObj = m_BaseObj->findChild<QObject *>("slewButtonObj");
    connect(m_SlewButtonObj, SIGNAL(slewButtonClicked()), this, SLOT(onSlewButtonClicked()));

59 60 61
    m_DetailsButtonObj = m_BaseObj->findChild<QObject *>("detailsButtonObj");
    connect(m_DetailsButtonObj, SIGNAL(detailsButtonClicked()), this, SLOT(onDetailsButtonClicked()));

62
    baseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
63
    baseView->show();
64
    kstars->setWIView(baseView);
65 66
}

Samikshan Bairagya's avatar
Samikshan Bairagya committed
67 68 69
WIView::~WIView()
{
    delete m;
70
    delete m_CurSoItem;
Samikshan Bairagya's avatar
Samikshan Bairagya committed
71
}
72

73
void WIView::onCategorySelected(int type)
74
{
75
    switch(type)
76
    {
77 78 79
    case 0:                        ///Planet type
    case 1:                        ///Star type
    case 2:                        ///Constellation type
80
        ctxt->setContextProperty("soListModel", m->returnModel(type));
81
        break;
82 83 84
    case 3:                        ///Galaxy type
    case 4:                        ///Cluster type
    case 5:                        ///Nebula type
85
        ctxt->setContextProperty("soListModel", m->returnModel(type));
86
        break;
87 88
    }
}
89

90
void WIView::onSoListItemClicked(int type, QString typeName, int index)
91
{
92
    SkyObjItem *soitem = m->returnModel(type)->getSkyObjItem(index);
93

94 95
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
96

97
//    soListObj->setProperty("visible", false);
98

99
    loadDetailsView(soitem, index);
100 101
}

102
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
103
{
104 105 106 107 108 109 110 111 112 113 114 115 116 117

    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());

118 119 120 121
    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");
122 123 124 125 126
//    QObject *sbTextObj = m_DetailsViewObj->findChild<QObject *>("sbTextObj");
//    QObject *sizeTextObj = m_DetailsViewObj->findChild<QObject *>("sizeTextObj");

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

127
    sonameObj->setProperty("text", soitem->getLongName());
128
    posTextObj->setProperty("text", soitem->getPosition());
129
    descTextObj->setProperty("text", soitem->getDesc());
130 131 132 133
    magTextObj->setProperty("text", magText);
    /*
    sbTextObj->setProperty("text", magText);
    sizeTextObj->setProperty("text", soitem->getSize());*/
134
}
135

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

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);
}
149 150 151 152 153

void WIView::onSlewButtonClicked()
{
    ///Slew map to selected sky-object
    SkyObject* so = m_CurSoItem->getSkyObject();
154
    KStars* kstars = KStars::Instance();
155 156
    if (so != 0)
    {
157 158 159
        kstars->map()->setFocusPoint(so);
        kstars->map()->setFocusObject(so);
        kstars->map()->setDestination(*kstars->map()->focusPoint());
160 161
    }
}
162 163 164 165 166 167 168 169 170 171

void WIView::onDetailsButtonClicked()
{
    ///Code taken from WUTDialog::slotDetails()
    KStars *kstars = KStars::Instance();
    SkyObject* so = m_CurSoItem->getSkyObject();
    DetailDialog *detail = new DetailDialog(so, kstars->data()->lt(), kstars->data()->geo(), kstars);
    detail->exec();
    delete detail;
}