wiview.cpp 6.88 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 20
#include "QDeclarativeView"
#include "QDeclarativeContext"
21
#include "QGraphicsObject"
22
#include "wiview.h"
23
#include "skymap.h"
24
#include "dialogs/detaildialog.h"
25

Samikshan Bairagya's avatar
Samikshan Bairagya committed
26
#include "kstandarddirs.h"
27
#include "kdeclarative.h"
Samikshan Bairagya's avatar
Samikshan Bairagya committed
28

29
WIView::WIView(QWidget *parent, ObsConditions *obs) : QWidget(parent), m_Obs(obs)
30
{
31
    m_ModManager = new ModelManager(m_Obs);
32

33
    m_BaseView = new QDeclarativeView();
34

35
    m_Ctxt = m_BaseView->rootContext();
36

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

39
    m_BaseObj = dynamic_cast<QObject *>(m_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 63 64
    QObject *settingsIconObj = m_BaseObj->findChild<QObject *>("settingsIconObj");
    connect(settingsIconObj, SIGNAL(settingsIconClicked()), this, SLOT(onSettingsIconClicked()));

65 66
    m_BaseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    m_BaseView->show();
67 68
}

Samikshan Bairagya's avatar
Samikshan Bairagya committed
69 70
WIView::~WIView()
{
71
    delete m_ModManager;
72
    delete m_CurSoItem;
Samikshan Bairagya's avatar
Samikshan Bairagya committed
73
}
74

75
void WIView::onCategorySelected(int type)
76
{
77
    m_Ctxt->setContextProperty("soListModel", m_ModManager->returnModel(type));
78
}
79

80
void WIView::onSoListItemClicked(int type, QString typeName, int index)
81
{
82
    SkyObjItem *soitem = m_ModManager->returnModel(type)->getSkyObjItem(index);
83

84 85
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
86

87
//    soListObj->setProperty("visible", false);
88

89
    loadDetailsView(soitem, index);
90 91
}

92
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
93
{
94 95 96
    m_CurSoItem = soitem;
    m_CurIndex = index;

97 98 99
    int modelSize = m_ModManager->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *nextItem = m_ModManager->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex+1)%modelSize);
    SkyObjItem *prevItem = m_ModManager->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex-1+modelSize)%modelSize);
100

101 102 103 104 105
    QObject *nextTextObj = m_NextObj->findChild<QObject *>("nextTextObj");
    nextTextObj->setProperty("text", nextItem->getName());
    QObject *prevTextObj = m_PrevObj->findChild<QObject *>("prevTextObj");
    prevTextObj->setProperty("text", prevItem->getName());

106 107 108
    QObject *sonameObj = m_DetailsViewObj->findChild<QObject *>("sonameObj");
    QObject *posTextObj = m_DetailsViewObj->findChild<QObject *>("posTextObj");
    QObject *descTextObj = m_DetailsViewObj->findChild<QObject *>("descTextObj");
109
    QObject *descSrcTextObj = m_DetailsViewObj->findChild<QObject *>("descSrcTextObj");
110
    QObject *magTextObj = m_DetailsViewObj->findChild<QObject *>("magTextObj");
111
    QObject *sbTextObj = m_DetailsViewObj->findChild<QObject *>("sbTextObj");
112
    QObject *sizeTextObj = m_DetailsViewObj->findChild<QObject *>("sizeTextObj");
113

114
    sonameObj->setProperty("text", soitem->getLongName());
115
    posTextObj->setProperty("text", soitem->getPosition());
116
    descTextObj->setProperty("text", soitem->getDesc());
117
    descSrcTextObj->setProperty("text", soitem->getDescSource());
118

119 120
    QString magText;
    if (soitem->getType() == SkyObjItem::Constellation)
121
        magText = i18n("Magnitude:  --");
122
    else
123
        magText = i18n("Magnitude: ") + KGlobal::locale()->formatNumber(soitem->getMagnitude(), 2) + " mag";
124
    magTextObj->setProperty("text", magText);
125

126
    QString sbText = i18n("Surface Brightness") + ": " + soitem->getSurfaceBrightness();
127 128
    sbTextObj->setProperty("text", sbText);

129
    QString sizeText = i18n("Size") + ": " + soitem->getSize();
130
    sizeTextObj->setProperty("text", sizeText);
131
}
132

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

void WIView::onPrevObjClicked()
{
142 143
    int modelSize = m_ModManager->returnModel(m_CurSoItem->getType())->rowCount();
    SkyObjItem *prevItem = m_ModManager->returnModel(m_CurSoItem->getType())->getSkyObjItem((m_CurIndex-1+modelSize)%modelSize);
144 145
    loadDetailsView(prevItem, (m_CurIndex-1+modelSize)%modelSize);
}
146 147 148 149 150

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

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;
}
169 170 171 172

void WIView::onSettingsIconClicked()
{
    KStars *kstars = KStars::Instance();
173
    kstars->showWISettingsUI();
174
}