Ui support added for GpsLocation. Menu with button to toggle gps on or
authorniko <niko@nikosdesktop.(none)>
Fri, 31 Dec 2010 14:19:30 +0000 (16:19 +0200)
committerniko <niko@nikosdesktop.(none)>
Fri, 31 Dec 2010 14:19:30 +0000 (16:19 +0200)
off and button in FavoriteSelectionDialog to enable the use of gps
location.

zouba/src/gui/favoriteselectiondialog.cpp
zouba/src/gui/favoriteselectiondialog.h
zouba/src/gui/favoriteselectiondialog.ui
zouba/src/gui/searchdisplay.cpp
zouba/src/gui/searchdisplay.h
zouba/src/logic/gpslocation.cpp
zouba/src/logic/gpslocation.h

index e2cd364..68e3e47 100644 (file)
@@ -27,9 +27,21 @@ FavoriteSelectionDialog::FavoriteSelectionDialog(QWidget *parent) :
             locs << loc->label();
         }
     }
-
     this->ui->locations->addItems(locs);
 
+
+    if (!locations->getGpsLocation()->isUpdating())
+        this->ui->gps_button->setEnabled(false);
+    else if (!locations->getGpsLocation()->isValid())
+    {
+        this->ui->gps_button->setEnabled(false);
+        this->m_text = this->ui->gps_button->text();
+        this->ui->gps_button->setText(this->m_text + " (Searching...)");
+        this->connect(locations->getGpsLocation(), SIGNAL(gpsLocationChanged(GpsLocation*)), SLOT(gps_location_retrieved()));
+    }
+
+    //this->connect(locations->getGpsLocation(), SIGNAL(gpsLocationUpdatingChanged(bool)), SLOT(gps_updating_changed(bool)));
+
 }
 
 FavoriteSelectionDialog::~FavoriteSelectionDialog()
@@ -37,6 +49,18 @@ FavoriteSelectionDialog::~FavoriteSelectionDialog()
     delete ui;
 }
 
+void FavoriteSelectionDialog::gps_updating_changed(bool isActive)
+{
+    //this->ui->gps_button->setEnabled(isActive);
+}
+
+void FavoriteSelectionDialog::gps_location_retrieved()
+{
+    this->ui->gps_button->setEnabled(true);
+    this->ui->gps_button->setText(this->m_text);
+    this->disconnect(this, SLOT(gps_location_retrieved()));
+}
+
 void FavoriteSelectionDialog::on_locations_itemClicked(QListWidgetItem* item)
 {
     Locations *locations = Locations::GetInstance();
@@ -50,3 +74,10 @@ void FavoriteSelectionDialog::on_modify_button_clicked()
     emit(this->customizeRequested());
     this->deleteLater();
 }
+
+void FavoriteSelectionDialog::on_gps_button_clicked()
+{
+    Locations *locations = Locations::GetInstance();
+    emit(this->selectedLocation(locations->getGpsLocation()));
+    this->deleteLater();
+}
index b2e325c..1cb9732 100644 (file)
@@ -24,10 +24,14 @@ signals:
 
 private:
     Ui::FavoriteSelectionDialog *ui;
+    QString m_text;
 
 private slots:
+    void on_gps_button_clicked();
     void on_modify_button_clicked();
     void on_locations_itemClicked(QListWidgetItem* item);
+    void gps_updating_changed(bool isActive);
+    void gps_location_retrieved();
 };
 
 #endif // FAVORITESELECTIONDIALOG_H
index ffc7759..f55b5e5 100644 (file)
     </widget>
    </item>
    <item>
-    <widget class="QListWidget" name="locations"/>
+    <widget class="QPushButton" name="gps_button">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+     <property name="text">
+      <string>Current location</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QListWidget" name="locations">
+     <property name="minimumSize">
+      <size>
+       <width>0</width>
+       <height>600</height>
+      </size>
+     </property>
+    </widget>
    </item>
    <item>
     <widget class="QDialogButtonBox" name="buttonBox">
@@ -45,8 +62,8 @@
    <slot>accept()</slot>
    <hints>
     <hint type="sourcelabel">
-     <x>248</x>
-     <y>254</y>
+     <x>252</x>
+     <y>295</y>
     </hint>
     <hint type="destinationlabel">
      <x>157</x>
@@ -61,8 +78,8 @@
    <slot>reject()</slot>
    <hints>
     <hint type="sourcelabel">
-     <x>316</x>
-     <y>260</y>
+     <x>320</x>
+     <y>295</y>
     </hint>
     <hint type="destinationlabel">
      <x>286</x>
index 5a1e02c..dc3ec02 100644 (file)
@@ -37,6 +37,14 @@ SearchDisplay::SearchDisplay(QWidget *parent) :
     //this->ui->from_favorites->setIcon(QIcon::fromTheme("edit-copy"));
     //this->ui->dest_favorites->setText("Fav");
 
+    QMenuBar *menu = this->ui->menubar;
+    QAction *use_gps = new QAction("Use GPS", this);
+    use_gps->setCheckable(true);
+    use_gps->setChecked(false);
+    this->connect(use_gps, SIGNAL(toggled(bool)), SLOT(gps_status_change_requested(bool)));
+    this->connect(use_gps, SIGNAL(toggled(bool)), locations->getGpsLocation(), SLOT(enableGps(bool)));
+    menu->addAction(use_gps);
+
     this->from_selected = NULL;
     this->dest_selected = NULL;
     this->edit_window = NULL;
@@ -71,6 +79,12 @@ SearchDisplay::SearchDisplay(QWidget *parent) :
     qDebug() << "Finish constructor";
 }
 
+void SearchDisplay::gps_status_change_requested(bool status)
+{
+
+
+}
+
 SearchDisplay::~SearchDisplay()
 {
     delete ui;
index 5c41c2a..35600fa 100644 (file)
@@ -35,6 +35,8 @@ private slots:
 
     void route_finder_finished();
 
+    void gps_status_change_requested(bool status);
+
 private:
     void setEditText(QLineEdit*, QString&);
     void updateLocationLists();
index 5e8a08b..b151cb0 100644 (file)
@@ -5,7 +5,6 @@
 GpsLocation::GpsLocation(QObject *parent) :
     QObject(parent), Location("0", "0", "GPS", "GPS"),
     m_gps(QGeoPositionInfoSource::createDefaultSource(this)), m_active(false),
-    m_calculated(false),
     latitude(0), longitude(0)
 {
     m_valid = false;
@@ -28,6 +27,7 @@ void GpsLocation::enableGps(bool enable)
     else
         this->m_gps->stopUpdates();
 
+    this->m_active = enable;
     emit(this->gpsLocationUpdatingChanged(enable));
 }
 
@@ -36,7 +36,8 @@ void GpsLocation::updateLocation(QGeoPositionInfo positionInfo)
     this->latitude = positionInfo.coordinate().latitude();
     this->longitude = positionInfo.coordinate().longitude();
 
-    this->m_calculated = false;
+    this->calculateXY();
+
     this->m_valid = true;
 
     emit(this->gpsLocationChanged(this));
@@ -56,26 +57,11 @@ void GpsLocation::calculateXY()
 
     this->m_x.setNum(outX);
     this->m_y.setNum(outY);
-
-    this->m_calculated = true;
 }
 
-QString GpsLocation::x()
+bool GpsLocation::isUpdating() const
 {
-    if (!this->m_calculated)
-    {
-        this->calculateXY();
-    }
-    return this->m_x;
-}
-
-QString GpsLocation::y()
-{
-    if (!this->m_calculated)
-    {
-        this->calculateXY();
-    }
-    return this->m_y;
+    return this->m_active;
 }
 
 const double KkjZoneInfo[6][2] = {
index 580fb62..7ad6b39 100644 (file)
@@ -19,8 +19,7 @@ public:
     explicit GpsLocation(QObject *parent = 0);
     ~GpsLocation();
 
-    QString x();
-    QString y();
+    bool isUpdating() const;
 
 signals:
     void gpsLocationChanged(GpsLocation *newLocation);
@@ -37,7 +36,7 @@ private:
     void calculateXY();
 
     QGeoPositionInfoSource *m_gps;
-    bool m_active, m_calculated;
+    bool m_active;
     qreal latitude, longitude;
 
 };