* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef Q_WS_MAEMO_6
+#include <MLayout>
+#include <MAction>
+#include <MWidgetAction>
+#include <MComboBox>
+#endif
+
#include <QtGui>
#include <QSettings>
#include "aboutdialog.h"
#include "mainwindow.h"
+#ifdef Q_WS_MAEMO_6
+MainWindow::MainWindow(QGraphicsItem *parent) : MApplicationPage(parent)
+{
+ m_downloader = new MedardDownloader();
+
+ connect(m_downloader, SIGNAL(downloadFinished(const QString &, const QDateTime &)), this,
+ SLOT(downloadedFinished(const QString &, const QDateTime &)));
+ connect(m_downloader, SIGNAL(downloadFailed()), this, SLOT(downloadFailed()));
+
+ m_forecast = new ForecastWidget();
+ m_forecast->setPreferredSize(m_downloader->imageSize());
+
+ m_forecastTypeLabel = new MLabel();
+ m_forecastTypeLabel->setAlignment(Qt::AlignCenter);
+ m_forecastTypeLabel->setPreferredSize(220, 80);
+
+ m_forecastInitialDateLabel = new MLabel();
+ m_forecastInitialDateLabel->setAlignment(Qt::AlignCenter);
+// m_forecastInitialDateLabel->setDisabled(true);
+
+ m_forecastDateLabel = new MLabel();
+ m_forecastDateLabel->setAlignment(Qt::AlignCenter);
+
+ m_downloadRetryButton = new MButton(tr("Download again"));
+ m_downloadRetryButton->setPreferredWidth(220);
+
+ connect(m_downloadRetryButton, SIGNAL(clicked()), this, SLOT(downloadAgainClicked()));
+
+ m_minusDayButton = new MButton(tr("-1 d"));
+ m_minusDayButton->setPreferredWidth(50);
+ m_plusDayButton = new MButton(tr("+1 d"));
+ m_plusDayButton->setPreferredWidth(50);
+ m_minusHourButton = new MButton(tr("-1 h"));
+ m_minusHourButton->setPreferredWidth(50);
+ m_plusHourButton = new MButton(tr("+1 h"));
+ m_plusHourButton->setPreferredWidth(50);
+
+ connect(m_minusDayButton, SIGNAL(clicked()), this, SLOT(minusDayClicked()));
+ connect(m_plusDayButton, SIGNAL(clicked()), this, SLOT(plusDayClicked()));
+ connect(m_minusHourButton, SIGNAL(clicked()), this, SLOT(minusHourClicked()));
+ connect(m_plusHourButton, SIGNAL(clicked()), this, SLOT(plusHourClicked()));
+
+ setupUi();
+ setupMenu();
+
+ loadSettings();
+}
+#else
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
m_downloader = new MedardDownloader();
loadSettings();
}
+#endif
MainWindow::~MainWindow()
{
delete m_downloader;
}
+#ifdef Q_WS_MAEMO_6
+void MainWindow::setupUi()
+{
+ setAttribute(Qt::WA_LockPortraitOrientation, true);
+ setWindowTitle(tr("Medard"));
+ setPannable(false);
+
+ QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Horizontal);
+ centralWidget()->setLayout(mainLayout);
+
+ mainLayout->addItem(m_forecast);
+
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
+ mainLayout->addItem(layout);
+
+ layout->addItem(m_forecastTypeLabel);
+ layout->addItem(m_forecastDateLabel);
+ layout->addItem(m_forecastInitialDateLabel);
+ layout->addItem(m_downloadRetryButton);
+
+ QGraphicsLinearLayout *dayNavigationBox = new QGraphicsLinearLayout(Qt::Horizontal);
+ dayNavigationBox->addItem(m_minusDayButton);
+ dayNavigationBox->addItem(m_plusDayButton);
+ layout->addItem(dayNavigationBox);
+
+ QGraphicsLinearLayout *hourNavigationBox = new QGraphicsLinearLayout(Qt::Horizontal);
+ hourNavigationBox->addItem(m_minusHourButton);
+ hourNavigationBox->addItem(m_plusHourButton);
+ layout->addItem(hourNavigationBox);
+
+ hideNavigationButtons(false);
+}
+#else
void MainWindow::setupUi()
{
#ifdef Q_WS_MAEMO_5
hideNavigationButtons(false);
}
+#endif
+#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);
+ seaLevelPreasureAction->setLocation(MAction::ToolBarLocation);
+ addAction(seaLevelPreasureAction);
+ connect(seaLevelPreasureAction, SIGNAL(triggered()), this, SLOT(seaLevelPreasureMenuClicked()));
+
+ MAction *precipitationAction = new MAction("icon-m-weather-rain", tr("Precipitation"), 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);
+ cloudinessAction->setLocation(MAction::ToolBarLocation);
+ addAction(cloudinessAction);
+ connect(cloudinessAction, SIGNAL(triggered()), this, SLOT(cloudinessMenuClicked()));
+
+ MAction *temperatureAction = new MAction("icon-m-weather-hot", tr("Temperature"), this);
+ temperatureAction->setLocation(MAction::ToolBarLocation);
+ addAction(temperatureAction);
+ connect(temperatureAction, SIGNAL(triggered()), this, SLOT(temperatureMenuClicked()));
+
+ MAction *aboutAction = new MAction(this);
+ aboutAction->setText(tr("About"));
+ aboutAction->setLocation(MAction::ApplicationMenuLocation);
+ addAction(aboutAction);
+ connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutMenuClicked()));
+}
+#else
void MainWindow::setupMenu()
{
QMenuBar *menu = new QMenuBar();
menu->addAction(aboutAction);
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutMenuClicked()));
}
+#endif
void MainWindow::loadSettings()
{
int forecastType = settings.value("ForecastType").toInt();
m_downloader->setForecastDomain((MedardDownloader::ForecastDomain) forecastDomain);
+#ifdef Q_WS_MAEMO_6
+ m_domainComboBox->setCurrentIndex(forecastDomain);
+#else
m_domainActionGroup->actions().at(forecastDomain)->setChecked(true);
+#endif
switch ((MedardDownloader::ForecastType) forecastType) {
case MedardDownloader::SeaLevelPressure:
void MainWindow::updateNavigationButtons()
{
if ((m_downloader->forecastDateOffset() - 24) < m_downloader->minForecastDateOffset()) {
- m_minusDayButton->setDisabled(true);
- m_plusDayButton->setDisabled(false);
+// m_minusDayButton->setDisabled(true);
+// m_plusDayButton->setDisabled(false);
} else if ((m_downloader->forecastDateOffset() + 24) > m_downloader->maxForecastDateOffset()) {
- m_minusDayButton->setDisabled(false);
- m_plusDayButton->setDisabled(true);
+// m_minusDayButton->setDisabled(false);
+// m_plusDayButton->setDisabled(true);
} else {
- m_minusDayButton->setDisabled(false);
- m_plusDayButton->setDisabled(false);
+// m_minusDayButton->setDisabled(false);
+// m_plusDayButton->setDisabled(false);
}
if ((m_downloader->forecastDateOffset() - 1) < m_downloader->minForecastDateOffset()) {
- m_minusHourButton->setDisabled(true);
- m_plusHourButton->setDisabled(false);
+// m_minusHourButton->setDisabled(true);
+// m_plusHourButton->setDisabled(false);
} else if ((m_downloader->forecastDateOffset() + 1) > m_downloader->maxForecastDateOffset()) {
- m_minusHourButton->setDisabled(false);
- m_plusHourButton->setDisabled(true);
+// m_minusHourButton->setDisabled(false);
+// m_plusHourButton->setDisabled(true);
} else {
- m_minusHourButton->setDisabled(false);
- m_plusHourButton->setDisabled(false);
+// m_minusHourButton->setDisabled(false);
+// m_plusHourButton->setDisabled(false);
}
}
void MainWindow::aboutMenuClicked()
{
AboutDialog *dialog = new AboutDialog();
+#ifdef Q_WS_MAEMO_6
+ dialog->appear(scene(), MSceneWindow::DestroyWhenDismissed);
+#else
dialog->exec();
+#endif
}
void MainWindow::downloadAgainClicked()
m_downloader->downloadImage();
}
+#ifdef Q_WS_MAEMO_6
+void MainWindow::forecastDomainChanged(int index)
+{
+ m_forecast->clearImage(false);
+
+ if (index == 0)
+ m_downloader->setForecastDomain(MedardDownloader::Europe);
+ else
+ m_downloader->setForecastDomain(MedardDownloader::CzechRepublic);
+
+ m_downloader->downloadImage();
+
+ QSettings settings;
+ settings.setValue("ForecastDomain", index);
+}
+#else
void MainWindow::forecastDomainChanged(QAction *action)
{
int forecastDomain = m_domainActionGroup->actions().indexOf(action);
QSettings settings;
settings.setValue("ForecastDomain", forecastDomain);
}
+#endif
void MainWindow::downloadedFinished(const QString &filename, const QDateTime &date)
{