wiview.cpp 6.48 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 30 31 32 33 34
//    KStars *data = KStars::Instance();

//    SkyMap *skyMap = data->map();

//    QGraphicsScene *mapScene = new QGraphicsScene(skyMap);

Samikshan Bairagya's avatar
Samikshan Bairagya committed
35
    QDeclarativeView *baseView = new QDeclarativeView();
36

37 38
    baseView->setAttribute(Qt::WA_TranslucentBackground);
    baseView->setStyleSheet("background: transparent;");
39
    baseView->setWindowFlags(Qt::FramelessWindowHint);
40

41
    ctxt = baseView->rootContext();
42

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

45
    m_BaseObj = dynamic_cast<QObject *>(baseView->rootObject());
46

47
    //soTypeTextObj = m_BaseObj->findChild<QObject *>("soTypeTextObj");
48

49 50
    m_ViewsRowObj = m_BaseObj->findChild<QObject *>("viewsRowObj");
    connect(m_ViewsRowObj, SIGNAL(categorySelected(int)), this, SLOT(onCategorySelected(int)));
51

52 53
    m_SoListObj = m_BaseObj->findChild<QObject *>("soListObj");
    connect(m_SoListObj, SIGNAL(soListItemClicked(int, QString, int)), this, SLOT(onSoListItemClicked(int, QString, int)));
54

55
    m_DetailsViewObj = m_BaseObj->findChild<QObject *>("detailsViewObj");
56

57
    m_NextObj = m_BaseObj->findChild<QObject *>("nextObj");
58 59 60
    connect(m_NextObj, SIGNAL(nextObjClicked()), this, SLOT(onNextObjClicked()));
    m_PrevObj = m_BaseObj->findChild<QObject *>("prevObj");
    connect(m_PrevObj, SIGNAL(prevObjClicked()), this, SLOT(onPrevObjClicked()));
61

62 63 64
    QObject *closeButtonObj = m_BaseObj->findChild<QObject *>("closeButtonObj");
    connect(closeButtonObj, SIGNAL(closeButtonClicked()), baseView, SLOT(close()));

65 66
    m_OptMag = obs->getOptimumMAG();

67
    baseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
68 69 70 71 72 73 74

//    mapScene->addItem(qobject_cast<QGraphicsObject *>(baseView->rootObject()));
//    mapScene->setItemIndexMethod(QGraphicsScene::NoIndex);
//    skyMap->setScene(mapScene);
//    skyMap->setOptimizationFlags(QGraphicsView::DontSavePainterState);
//    skyMap->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);

75 76 77
    baseView->show();
}

Samikshan Bairagya's avatar
Samikshan Bairagya committed
78 79 80
WIView::~WIView()
{
    delete m;
81
    delete m_CurSoItem;
Samikshan Bairagya's avatar
Samikshan Bairagya committed
82
}
83

84
void WIView::onCategorySelected(int type)
85
{
86
    QString oMagText = QString("Suggested optimum magnification : ") + QString::number(m_OptMag);
87
    QObject *oMagTextObj = m_BaseObj->findChild<QObject *>("oMagTextObj");
88

89
    switch(type)
90
    {
91 92 93
    case 0:                        ///Planet type
    case 1:                        ///Star type
    case 2:                        ///Constellation type
94
        ctxt->setContextProperty("soListModel", m->returnModel(type));
95
        break;
96 97 98
    case 3:                        ///Galaxy type
    case 4:                        ///Cluster type
    case 5:                        ///Nebula type
99
        ctxt->setContextProperty("soListModel", m->returnModel(type));
100
        oMagTextObj->setProperty("text", oMagText);
101
        break;
102 103
    }
}
104

105
void WIView::onSoListItemClicked(int type, QString typeName, int index)
106
{
107
    SkyObjItem *soitem = m->returnModel(type)->getSkyObjItem(index);
108

109 110
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
111

112
//    soListObj->setProperty("visible", false);
113

114
    loadDetailsView(soitem, index);
115 116
}

117
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
118
{
119 120 121 122 123 124 125 126 127 128 129 130 131 132

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

133 134 135 136
    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");
137
    sonameObj->setProperty("text", soitem->getName());
138
    posTextObj->setProperty("text", soitem->getPosition());
139
    descTextObj->setProperty("text", soitem->getDesc());
140 141
    magTextObj->setProperty("text", soitem->getMagnitude());

142
    ///Slew map to selected sky-object
143 144 145
    SkyObject* so = soitem->getSkyObject();
    KStars* data = KStars::Instance();
    if (so != 0) {
146 147 148
        data->map()->setFocusPoint(so);
        data->map()->setFocusObject(so);
        data->map()->setDestination(*data->map()->focusPoint());
149
    }
150
}
151

152
void WIView::onNextObjClicked()
153
{
154 155
    int modelSize = m->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
156
    loadDetailsView(nextItem, (m_CurIndex+1)%modelSize);
Samikshan Bairagya's avatar
Samikshan Bairagya committed
157
}
158 159 160 161 162 163 164

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