• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
kswizard.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  kswizard.cpp - description
3  -------------------
4  begin : Wed 28 Jan 2004
5  copyright : (C) 2004 by Jason Harris
6  email : kstars@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "kswizard.h"
19 
20 #include <QFile>
21 #include <QStackedWidget>
22 #include <QPixmap>
23 
24 #include <klineedit.h>
25 #include <kpushbutton.h>
26 #include <knewstuff3/downloaddialog.h>
27 #include <kstandarddirs.h>
28 
29 #include "kstarsdata.h"
30 #include "geolocation.h"
31 #include "widgets/dmsbox.h"
32 
33 namespace {
34  bool hasPrefix(QString str, QString prefix) {
35  if( prefix.isEmpty() )
36  return true;
37  return str.startsWith( prefix, Qt::CaseInsensitive );
38  }
39 }
40 
41 WizWelcomeUI::WizWelcomeUI( QWidget *parent ) : QFrame( parent ) {
42  setupUi( this );
43 }
44 
45 WizLocationUI::WizLocationUI( QWidget *parent ) : QFrame( parent ) {
46  setupUi( this );
47 }
48 
49 WizDownloadUI::WizDownloadUI( QWidget *parent ) : QFrame( parent ) {
50  setupUi( this );
51 }
52 
53 KSWizard::KSWizard( QWidget *parent ) :
54  KDialog( parent )
55 {
56  wizardStack = new QStackedWidget( this );
57  setMainWidget( wizardStack );
58  setCaption( i18n("Setup Wizard") );
59  setButtons( KDialog::User1|KDialog::User2|KDialog::Ok|KDialog::Cancel );
60  setButtonGuiItem( KDialog::User1, KGuiItem( i18n("&Next >"), QString(), i18n("Go to next Wizard page") ) );
61  setButtonGuiItem( KDialog::User2, KGuiItem( i18n("< &Back"), QString(), i18n("Go to previous Wizard page") ) );
62 
63  WizWelcomeUI* welcome = new WizWelcomeUI( wizardStack );
64  location = new WizLocationUI( wizardStack );
65  WizDownloadUI* download = new WizDownloadUI( wizardStack );
66 
67  wizardStack->addWidget( welcome );
68  wizardStack->addWidget( location );
69  wizardStack->addWidget( download );
70  wizardStack->setCurrentWidget( welcome );
71 
72  //Load images into banner frames.
73  QPixmap im;
74  if( im.load(KStandardDirs::locate("appdata", "wzstars.png")) )
75  welcome->Banner->setPixmap( im );
76  if( im.load(KStandardDirs::locate("appdata", "wzgeo.png")) )
77  location->Banner->setPixmap( im );
78  if( im.load(KStandardDirs::locate("appdata", "wzdownload.png")) )
79  download->Banner->setPixmap( im );
80 
81  //connect signals/slots
82  connect( this, SIGNAL( user1Clicked() ), this, SLOT( slotNextPage() ) );
83  connect( this, SIGNAL( user2Clicked() ), this, SLOT( slotPrevPage() ) );
84  connect( location->CityListBox, SIGNAL( itemSelectionChanged () ), this, SLOT( slotChangeCity() ) );
85  connect( location->CityFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterCities() ) );
86  connect( location->ProvinceFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterCities() ) );
87  connect( location->CountryFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterCities() ) );
88  connect( download->DownloadButton, SIGNAL( clicked() ), this, SLOT( slotDownload() ) );
89 
90  //Disable Back button
91  enableButton( KDialog::User2, false );
92 
93  //Initialize Geographic Location page
94  initGeoPage();
95 }
96 
97 //Do NOT delete members of filteredCityList! They are not created by KSWizard.
98 KSWizard::~KSWizard()
99 {}
100 
101 void KSWizard::setButtonsEnabled() {
102  enableButton( KDialog::User1, wizardStack->currentIndex() < wizardStack->count()-1 );
103  enableButton( KDialog::User2, wizardStack->currentIndex() > 0 );
104 }
105 
106 void KSWizard::slotNextPage() {
107  wizardStack->setCurrentIndex( wizardStack->currentIndex() + 1 );
108  setButtonsEnabled();
109 }
110 
111 void KSWizard::slotPrevPage() {
112  wizardStack->setCurrentIndex( wizardStack->currentIndex() - 1 );
113  setButtonsEnabled();
114 }
115 
116 void KSWizard::initGeoPage() {
117  KStarsData* data = KStarsData::Instance();
118  location->LongBox->setReadOnly( true );
119  location->LatBox->setReadOnly( true );
120 
121  //Populate the CityListBox
122  //flag the ID of the current City
123  foreach ( GeoLocation *loc, data->getGeoList() ) {
124  location->CityListBox->addItem( loc->fullName() );
125  filteredCityList.append( loc );
126  if ( loc->fullName() == data->geo()->fullName() ) {
127  Geo = loc;
128  }
129  }
130 
131  //Sort alphabetically
132  location->CityListBox->sortItems();
133  //preset to current city
134  location->CityListBox->setCurrentItem(location->CityListBox->findItems(QString(data->geo()->fullName()),
135  Qt::MatchExactly).at(0));
136 }
137 
138 void KSWizard::slotChangeCity() {
139  if ( location->CityListBox->currentItem() ) {
140  for ( int i=0; i < filteredCityList.size(); ++i ) {
141  if ( filteredCityList[i]->fullName() == location->CityListBox->currentItem()->text() ) {
142  Geo = filteredCityList[i];
143  break;
144  }
145  }
146  location->LongBox->showInDegrees( Geo->lng() );
147  location->LatBox->showInDegrees( Geo->lat() );
148  }
149 }
150 
151 void KSWizard::slotFilterCities() {
152  location->CityListBox->clear();
153  //Do NOT delete members of filteredCityList!
154  filteredCityList.clear();
155 
156  foreach ( GeoLocation *loc, KStarsData::Instance()->getGeoList() ) {
157  if( hasPrefix( loc->translatedName(), location->CityFilter->text() ) &&
158  hasPrefix( loc->translatedCountry(), location->CountryFilter->text() ) &&
159  hasPrefix( loc->translatedProvince(), location->ProvinceFilter->text() )
160  )
161  {
162  location->CityListBox->addItem( loc->fullName() );
163  filteredCityList.append( loc );
164  }
165  }
166  location->CityListBox->sortItems();
167 
168  if ( location->CityListBox->count() > 0 ) // set first item in list as selected
169  location->CityListBox->setCurrentItem( location->CityListBox->item(0) );
170 }
171 
172 void KSWizard::slotDownload() {
173  KNS3::DownloadDialog dlg;
174  dlg.exec();
175 }
176 
177 #include "kswizard.moc"
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
GeoLocation::translatedName
QString translatedName() const
Definition: geolocation.cpp:78
WizWelcomeUI::WizWelcomeUI
WizWelcomeUI(QWidget *parent=0)
Definition: kswizard.cpp:41
kswizard.h
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
GeoLocation::lng
const dms * lng() const
Definition: geolocation.h:76
KDialog
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
geolocation.h
WizWelcomeUI
Definition: kswizard.h:30
GeoLocation::translatedProvince
QString translatedProvince() const
Definition: geolocation.cpp:88
KSWizard::KSWizard
KSWizard(QWidget *parent=0)
Constructor parent pointer to the parent widget.
Definition: kswizard.cpp:53
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
KStarsData::getGeoList
QList< GeoLocation * > getGeoList()
Definition: kstarsdata.h:167
WizLocationUI::WizLocationUI
WizLocationUI(QWidget *parent=0)
Definition: kswizard.cpp:45
WizDownloadUI::WizDownloadUI
WizDownloadUI(QWidget *parent=0)
Definition: kswizard.cpp:49
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
WizLocationUI
Definition: kswizard.h:36
kstarsdata.h
KSWizard::~KSWizard
virtual ~KSWizard()
Destructor.
Definition: kswizard.cpp:98
dmsbox.h
GeoLocation::translatedCountry
QString translatedCountry() const
Definition: geolocation.cpp:92
QFrame
WizDownloadUI
Definition: kswizard.h:42
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal