Fixed toolbar and menu items.
[medard] / src / mainwindow.cpp
index a410ce2..c82f413 100644 (file)
@@ -206,41 +206,57 @@ void MainWindow::setupUi()
 #ifdef Q_WS_MAEMO_6
 void MainWindow::setupMenu()
 {
-    QStringList domainsList;
-    domainsList << tr("Europe") << tr("Czech Republic");
-
-    MWidgetAction *domainAction = new MWidgetAction(centralWidget());
-    domainAction->setLocation(MAction::ApplicationMenuLocation);
-
-    m_domainComboBox = new MComboBox;
-    m_domainComboBox->setTitle(tr("Domain"));
-    m_domainComboBox->setIconVisible(false);
-    m_domainComboBox->addItems(domainsList);
-    domainAction->setWidget(m_domainComboBox);
-    addAction(domainAction);
-    connect(m_domainComboBox, SIGNAL(activated(int)), this, SLOT(forecastDomainChanged(int)));
-
-    MAction *seaLevelPreasureAction = new MAction("icon-m-weather-cloudy", tr("Sea Level Pressure"), this);
+    QStringList forecastDomainList;
+    forecastDomainList << tr("Europe") 
+                       << tr("Czech Republic");
+
+    MWidgetAction *forecastDomainAction = new MWidgetAction(centralWidget());
+    forecastDomainAction->setLocation(MAction::ApplicationMenuLocation);
+
+    m_forecastDomainComboBox = new MComboBox;
+    m_forecastDomainComboBox->setTitle(tr("Domain"));
+    m_forecastDomainComboBox->setStyleName ("CommonComboBox");
+    m_forecastDomainComboBox->setIconVisible(false);
+    m_forecastDomainComboBox->addItems(forecastDomainList);
+    forecastDomainAction->setWidget(m_forecastDomainComboBox);
+    addAction(forecastDomainAction);
+    connect(m_forecastDomainComboBox, SIGNAL(activated(int)), this, SLOT(forecastDomainChanged(int)));
+
+    QStringList forecastTypeList;
+    forecastTypeList << tr("Sea Level Pressure")
+                     << tr("Precipitation")
+                     << tr("Wind Velocity")
+                     << tr("Cloudiness")
+                     << tr("Temperature");
+
+    MWidgetAction *forecastTypeAction = new MWidgetAction(centralWidget());
+    forecastTypeAction->setLocation(MAction::ApplicationMenuLocation);
+
+    m_forecastTypeComboBox = new MComboBox;
+    m_forecastTypeComboBox->setTitle(tr("Forecast"));
+    m_forecastTypeComboBox->setStyleName ("CommonComboBox");
+    m_forecastTypeComboBox->setIconVisible(false);
+    m_forecastTypeComboBox->addItems(forecastTypeList);
+    forecastTypeAction->setWidget(m_forecastTypeComboBox);
+    addAction(forecastTypeAction);
+    connect(m_forecastTypeComboBox, SIGNAL(activated(int)), this, SLOT(forecastTypeChanged(int)));
+
+    MAction *seaLevelPreasureAction = new MAction("icon-m-weather-cloudy", "", this);
     seaLevelPreasureAction->setLocation(MAction::ToolBarLocation);
     addAction(seaLevelPreasureAction);
     connect(seaLevelPreasureAction, SIGNAL(triggered()), this, SLOT(seaLevelPreasureMenuClicked()));
 
-    MAction *precipitationAction = new MAction("icon-m-weather-rain", tr("Precipitation"), this);
+    MAction *precipitationAction = new MAction("icon-m-weather-rain", "", this);
     precipitationAction->setLocation(MAction::ToolBarLocation);
     addAction(precipitationAction);
     connect(precipitationAction, SIGNAL(triggered()), this, SLOT(precipitationMenuClicked()));
 
-    MAction *windVelocityAction = new MAction("icon-m-weather-stormy", tr("Wind Velocity"), this);
-    windVelocityAction->setLocation(MAction::ToolBarLocation);
-    addAction(windVelocityAction);
-    connect(windVelocityAction, SIGNAL(triggered()), this, SLOT(windVelocityMenuClicked()));
-
-    MAction *cloudinessAction = new MAction("icon-m-weather-partly-sunny", tr("Cloudinese"), this);
+    MAction *cloudinessAction = new MAction("icon-m-weather-partly-sunny", "", this);
     cloudinessAction->setLocation(MAction::ToolBarLocation);
     addAction(cloudinessAction);
     connect(cloudinessAction, SIGNAL(triggered()), this, SLOT(cloudinessMenuClicked()));
 
-    MAction *temperatureAction = new MAction("icon-m-weather-hot", tr("Temperature"), this);
+    MAction *temperatureAction = new MAction("icon-m-weather-hot", "", this);
     temperatureAction->setLocation(MAction::ToolBarLocation);
     addAction(temperatureAction);
     connect(temperatureAction, SIGNAL(triggered()), this, SLOT(temperatureMenuClicked()));
@@ -303,7 +319,7 @@ void MainWindow::loadSettings()
 
     m_downloader->setForecastDomain((MedardDownloader::ForecastDomain) forecastDomain);
 #ifdef Q_WS_MAEMO_6
-    m_domainComboBox->setCurrentIndex(forecastDomain);
+    m_forecastDomainComboBox->setCurrentIndex(forecastDomain);
 #else
     m_domainActionGroup->actions().at(forecastDomain)->setChecked(true);
 #endif
@@ -379,29 +395,62 @@ void MainWindow::updateNavigationButtons()
     }
 }
 
+void MainWindow::setForecastType(const QString label, MedardDownloader::ForecastType type)
+{
+    m_forecastTypeLabel->setText(label);
+    m_forecast->clearImage(false);
+    m_downloader->setForecastType(type);
+    m_downloader->downloadImage();
+
+    QSettings settings;
+    settings.setValue("ForecastType", type);
+}
+
+void MainWindow::setForecastDateOffset(int offset)
+{
+    m_forecast->clearImage(false);
+    m_downloader->setForecastDateOffset(m_downloader->forecastDateOffset() + offset);
+    m_downloader->downloadImage();
+}
+
 void MainWindow::seaLevelPreasureMenuClicked()
 {
-    forecastTypeChanged(tr("Sea Level Pressure"), MedardDownloader::SeaLevelPressure);
+#ifdef Q_WS_MAEMO_6
+    m_forecastTypeComboBox->setCurrentIndex(MedardDownloader::SeaLevelPressure);
+#endif
+    setForecastType(tr("Sea Level Pressure"), MedardDownloader::SeaLevelPressure);
 }
 
 void MainWindow::precipitationMenuClicked()
 {
-    forecastTypeChanged(tr("Precipitation"), MedardDownloader::Precipitation);
+#ifdef Q_WS_MAEMO_6
+    m_forecastTypeComboBox->setCurrentIndex(MedardDownloader::Precipitation);
+#endif
+    setForecastType(tr("Precipitation"), MedardDownloader::Precipitation);
 }
 
 void MainWindow::windVelocityMenuClicked()
 {
-    forecastTypeChanged(tr("Wind Velocity"), MedardDownloader::WindVelocity);
+#ifdef Q_WS_MAEMO_6
+    m_forecastTypeComboBox->setCurrentIndex(MedardDownloader::WindVelocity);
+#endif
+    setForecastType(tr("Wind Velocity"), MedardDownloader::WindVelocity);
 }
 
 void MainWindow::cloudinessMenuClicked()
 {
-    forecastTypeChanged(tr("Cloudiness"), MedardDownloader::Cloudiness);
+#ifdef Q_WS_MAEMO_6
+    m_forecastTypeComboBox->setCurrentIndex(MedardDownloader::Cloudiness);
+#endif
+    setForecastType(tr("Cloudiness"), MedardDownloader::Cloudiness);
 }
 
 void MainWindow::temperatureMenuClicked()
 {
-    forecastTypeChanged(tr("Temperature"), MedardDownloader::Temperature);
+#ifdef Q_WS_MAEMO_6
+    m_forecastTypeComboBox->setCurrentIndex(MedardDownloader::Temperature);
+#endif
+    setForecastType(tr("Temperature"), MedardDownloader::Temperature);
 }
 
 void MainWindow::aboutMenuClicked()
@@ -424,40 +473,22 @@ void MainWindow::downloadAgainClicked()
 
 void MainWindow::plusDayClicked()
 {
-    forecastDateOffsetChanged(+24);
+    setForecastDateOffset(+24);
 }
 
 void MainWindow::minusDayClicked()
 {
-    forecastDateOffsetChanged(-24);
+    setForecastDateOffset(-24);
 }
 
 void MainWindow::plusHourClicked()
 {
-    forecastDateOffsetChanged(+1);
+    setForecastDateOffset(+1);
 }
 
 void MainWindow::minusHourClicked()
 {
-    forecastDateOffsetChanged(-1);
-}
-
-void MainWindow::forecastTypeChanged(const QString label, MedardDownloader::ForecastType type)
-{
-    m_forecastTypeLabel->setText(label);
-    m_forecast->clearImage(false);
-    m_downloader->setForecastType(type);
-    m_downloader->downloadImage();
-
-    QSettings settings;
-    settings.setValue("ForecastType", type);
-}
-
-void MainWindow::forecastDateOffsetChanged(int offset)
-{
-    m_forecast->clearImage(false);
-    m_downloader->setForecastDateOffset(m_downloader->forecastDateOffset() + offset);
-    m_downloader->downloadImage();
+    setForecastDateOffset(-1);
 }
 
 #ifdef Q_WS_MAEMO_6
@@ -475,6 +506,32 @@ void MainWindow::forecastDomainChanged(int index)
     QSettings settings;
     settings.setValue("ForecastDomain", index);
 }
+
+void MainWindow::forecastTypeChanged(int index)
+{
+    switch ((MedardDownloader::ForecastType) index) {
+        case MedardDownloader::SeaLevelPressure:
+            setForecastType(tr("Sea Level Pressure"), MedardDownloader::SeaLevelPressure);
+            break;
+
+        case MedardDownloader::Precipitation:
+            setForecastType(tr("Precipitation"), MedardDownloader::Precipitation);
+            break;
+
+        case MedardDownloader::WindVelocity:
+            setForecastType(tr("Wind Velocity"), MedardDownloader::WindVelocity);
+            break;
+
+        case MedardDownloader::Cloudiness:
+            setForecastType(tr("Cloudiness"), MedardDownloader::Cloudiness);
+            break;
+
+        case MedardDownloader::Temperature:
+            setForecastType(tr("Temperature"), MedardDownloader::Temperature);
+            break;
+    }
+}
+
 #else
 void MainWindow::forecastDomainChanged(QAction *action)
 {