wiview.cpp 6.67 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
#include "kstandarddirs.h"
25
#include "kdeclarative.h"
Samikshan Bairagya's avatar
Samikshan Bairagya committed
26

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

31
    m_BaseView = new QDeclarativeView();
32

33
    ctxt = m_BaseView->rootContext();
34

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

37
    m_BaseObj = dynamic_cast<QObject *>(m_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 58 59
    m_DetailsButtonObj = m_BaseObj->findChild<QObject *>("detailsButtonObj");
    connect(m_DetailsButtonObj, SIGNAL(detailsButtonClicked()), this, SLOT(onDetailsButtonClicked()));

60 61 62
    QObject *settingsIconObj = m_BaseObj->findChild<QObject *>("settingsIconObj");
    connect(settingsIconObj, SIGNAL(settingsIconClicked()), this, SLOT(onSettingsIconClicked()));

63 64
    m_BaseView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    m_BaseView->show();
65 66
}

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

73
void WIView::onCategorySelected(int type)
74
{
75
    ctxt->setContextProperty("soListModel", m_ModManager->returnModel(type));
76
}
77

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

82 83
//    soTypeTextObj->setProperty("text", typeName);
//    soTypeTextObj->setProperty("visible", true);
84

85
//    soListObj->setProperty("visible", false);
86

87
    loadDetailsView(soitem, index);
88 89
}

90
void WIView::loadDetailsView(SkyObjItem *soitem, int index)
91
{
92 93 94 95

    m_CurSoItem = soitem;
    m_CurIndex = index;

96 97 98
    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);
99

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

105 106 107 108
    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");
109
    QObject *sbTextObj = m_DetailsViewObj->findChild<QObject *>("sbTextObj");
110
    QObject *sizeTextObj = m_DetailsViewObj->findChild<QObject *>("sizeTextObj");
111

112
    sonameObj->setProperty("text", soitem->getLongName());
113
    posTextObj->setProperty("text", soitem->getPosition());
114
    descTextObj->setProperty("text", soitem->getDesc());
115

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

123
    QString sbText = i18n("Surface Brightness") + ": " + soitem->getSurfaceBrightness();
124 125
    sbTextObj->setProperty("text", sbText);

126
    QString sizeText = i18n("Size") + ": " + soitem->getSize();
127
    sizeTextObj->setProperty("text", sizeText);
128
}
129

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

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

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

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;
}
166 167 168 169 170 171

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