From 5ac4ae83bbb074ae792abd7f5738a63512d6a68c Mon Sep 17 00:00:00 2001 From: Ariya Hidayat Date: Wed, 19 Aug 2009 13:44:16 +0200 Subject: Import the weather info example. Originally it was published in Qt Labs: http://labs.trolltech.com/blogs/2009/07/22/weather-info-for-qts60/ Reviewed-by: Jason Barron --- demos/embedded/embedded.pro | 3 + demos/embedded/fluidlauncher/config_s60/config.xml | 1 + .../fluidlauncher/screenshots/weatherinfo.png | Bin 0 -> 38521 bytes demos/embedded/weatherinfo/icons/README.txt | 5 + .../weatherinfo/icons/weather-few-clouds.svg | 738 +++ demos/embedded/weatherinfo/icons/weather-fog.svg | 1585 ++++++ demos/embedded/weatherinfo/icons/weather-haze.svg | 1121 +++++ demos/embedded/weatherinfo/icons/weather-icy.svg | 255 + .../weatherinfo/icons/weather-overcast.svg | 3036 ++++++++++++ .../embedded/weatherinfo/icons/weather-showers.svg | 4753 ++++++++++++++++++ demos/embedded/weatherinfo/icons/weather-sleet.svg | 5196 ++++++++++++++++++++ demos/embedded/weatherinfo/icons/weather-snow.svg | 1974 ++++++++ demos/embedded/weatherinfo/icons/weather-storm.svg | 4308 ++++++++++++++++ .../icons/weather-sunny-very-few-clouds.svg | 593 +++ demos/embedded/weatherinfo/icons/weather-sunny.svg | 1330 +++++ .../weatherinfo/icons/weather-thundershower.svg | 4587 +++++++++++++++++ demos/embedded/weatherinfo/weatherinfo.cpp | 511 ++ demos/embedded/weatherinfo/weatherinfo.pro | 11 + demos/embedded/weatherinfo/weatherinfo.qrc | 16 + 19 files changed, 30023 insertions(+) create mode 100644 demos/embedded/fluidlauncher/screenshots/weatherinfo.png create mode 100644 demos/embedded/weatherinfo/icons/README.txt create mode 100644 demos/embedded/weatherinfo/icons/weather-few-clouds.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-fog.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-haze.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-icy.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-overcast.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-showers.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-sleet.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-snow.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-storm.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-sunny-very-few-clouds.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-sunny.svg create mode 100644 demos/embedded/weatherinfo/icons/weather-thundershower.svg create mode 100644 demos/embedded/weatherinfo/weatherinfo.cpp create mode 100644 demos/embedded/weatherinfo/weatherinfo.pro create mode 100644 demos/embedded/weatherinfo/weatherinfo.qrc diff --git a/demos/embedded/embedded.pro b/demos/embedded/embedded.pro index 3fa0e13..e425eb5 100644 --- a/demos/embedded/embedded.pro +++ b/demos/embedded/embedded.pro @@ -10,6 +10,9 @@ contains(QT_CONFIG, svg) { contains(QT_CONFIG, network) { SUBDIRS += lightmaps SUBDIRS += flightinfo + contains(QT_CONFIG, svg) { + SUBDIRS += weatherinfo + } } contains(QT_CONFIG, webkit) { diff --git a/demos/embedded/fluidlauncher/config_s60/config.xml b/demos/embedded/fluidlauncher/config_s60/config.xml index 5957404..08cdb90 100644 --- a/demos/embedded/fluidlauncher/config_s60/config.xml +++ b/demos/embedded/fluidlauncher/config_s60/config.xml @@ -17,6 +17,7 @@ + diff --git a/demos/embedded/fluidlauncher/screenshots/weatherinfo.png b/demos/embedded/fluidlauncher/screenshots/weatherinfo.png new file mode 100644 index 0000000..b18608d Binary files /dev/null and b/demos/embedded/fluidlauncher/screenshots/weatherinfo.png differ diff --git a/demos/embedded/weatherinfo/icons/README.txt b/demos/embedded/weatherinfo/icons/README.txt new file mode 100644 index 0000000..d384153 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/README.txt @@ -0,0 +1,5 @@ +The scalable icons are from: + +http://tango.freedesktop.org/Tango_Icon_Library +http://darkobra.deviantart.com/art/Tango-Weather-Icon-Pack-98024429 + diff --git a/demos/embedded/weatherinfo/icons/weather-few-clouds.svg b/demos/embedded/weatherinfo/icons/weather-few-clouds.svg new file mode 100644 index 0000000..57d45e9 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-few-clouds.svg @@ -0,0 +1,738 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-clear + January 2006 + + + Ryan Collier (pseudo) + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + applet + notification + + + + + + Garrett LeSage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-fog.svg b/demos/embedded/weatherinfo/icons/weather-fog.svg new file mode 100644 index 0000000..a9a4ca8 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-fog.svg @@ -0,0 +1,1585 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-haze.svg b/demos/embedded/weatherinfo/icons/weather-haze.svg new file mode 100644 index 0000000..f2d6671 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-haze.svg @@ -0,0 +1,1121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-icy.svg b/demos/embedded/weatherinfo/icons/weather-icy.svg new file mode 100644 index 0000000..fe42860 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-icy.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-overcast.svg b/demos/embedded/weatherinfo/icons/weather-overcast.svg new file mode 100644 index 0000000..35fb4a4 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-overcast.svg @@ -0,0 +1,3036 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-overcast + January 2006 + + + Ryan Collier (pseudo) + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + applet + notify + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-showers.svg b/demos/embedded/weatherinfo/icons/weather-showers.svg new file mode 100644 index 0000000..c814571 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-showers.svg @@ -0,0 +1,4753 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-showers + January 2006 + + + Ryan collier (pseudo) + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + appplet + notify + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-sleet.svg b/demos/embedded/weatherinfo/icons/weather-sleet.svg new file mode 100644 index 0000000..f1cb9eb --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-sleet.svg @@ -0,0 +1,5196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-showers + January 2006 + + + Ryan collier (pseudo) + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + appplet + notify + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-snow.svg b/demos/embedded/weatherinfo/icons/weather-snow.svg new file mode 100644 index 0000000..6c7b4ad --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-snow.svg @@ -0,0 +1,1974 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-snow + January 2006 + + + Ryan Collier (pseudo) + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + applet + notification + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-storm.svg b/demos/embedded/weatherinfo/icons/weather-storm.svg new file mode 100644 index 0000000..4d8bfec --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-storm.svg @@ -0,0 +1,4308 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-storm + January 2006 + + + Ryan Collier + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + applet + notify + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-sunny-very-few-clouds.svg b/demos/embedded/weatherinfo/icons/weather-sunny-very-few-clouds.svg new file mode 100644 index 0000000..93b0009 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-sunny-very-few-clouds.svg @@ -0,0 +1,593 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-clear + January 2006 + + + Ryan Collier (pseudo) + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + applet + notification + + + + + + Garrett LeSage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-sunny.svg b/demos/embedded/weatherinfo/icons/weather-sunny.svg new file mode 100644 index 0000000..0360ac7 --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-sunny.svg @@ -0,0 +1,1330 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-clear + January 2006 + + + Ryan Collier (pseudo) + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + applet + notification + + + + + + Garrett LeSage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/icons/weather-thundershower.svg b/demos/embedded/weatherinfo/icons/weather-thundershower.svg new file mode 100644 index 0000000..406abfa --- /dev/null +++ b/demos/embedded/weatherinfo/icons/weather-thundershower.svg @@ -0,0 +1,4587 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + weather-storm + January 2006 + + + Ryan Collier + + + + + http://www.tango-project.org + + + http://www.pseudocode.org + + + weather + applet + notify + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/embedded/weatherinfo/weatherinfo.cpp b/demos/embedded/weatherinfo/weatherinfo.cpp new file mode 100644 index 0000000..0762644 --- /dev/null +++ b/demos/embedded/weatherinfo/weatherinfo.cpp @@ -0,0 +1,511 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#if defined (Q_OS_SYMBIAN) +#include "sym_iap_util.h" +#endif + +class WeatherInfo: public QMainWindow +{ + Q_OBJECT + +private: + + QGraphicsView *m_view; + QGraphicsScene m_scene; + QString city; + QGraphicsRectItem *m_statusItem; + QGraphicsTextItem *m_temperatureItem; + QGraphicsTextItem *m_conditionItem; + QGraphicsSvgItem *m_iconItem; + QList m_forecastItems; + QList m_dayItems; + QList m_conditionItems; + QList m_rangeItems; + QTimeLine m_timeLine; + QHash m_icons; + +public: + WeatherInfo(QWidget *parent = 0): QMainWindow(parent) { + + m_view = new QGraphicsView(this); + setCentralWidget(m_view); + + setupScene(); + m_view->setScene(&m_scene); + m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + m_view->setFrameShape(QFrame::NoFrame); + setWindowTitle("Weather Info"); + + QStringList cities; + cities << "Oslo"; + cities << "Berlin"; + cities << "Brisbane"; + cities << "Helsinki"; + cities << "San Diego"; + for (int i = 0; i < cities.count(); ++i) { + QAction *action = new QAction(cities[i], this); + connect(action, SIGNAL(triggered()), SLOT(chooseCity())); + addAction(action); +#if defined(Q_OS_SYMBIAN) + menuBar()->addAction(action); +#endif + } + setContextMenuPolicy(Qt::ActionsContextMenu); + + QTimer::singleShot(0, this, SLOT(delayedInit())); + } + +private slots: + void delayedInit() { +#if defined(Q_OS_SYMBIAN) + qt_SetDefaultIap(); +#else + request("Oslo"); +#endif + } + +private slots: + + void chooseCity() { + QAction *action = qobject_cast(sender()); + if (action) + request(action->text()); + } + + void handleNetworkData(QNetworkReply *networkReply) { + QUrl url = networkReply->url(); + if (!networkReply->error()) + digest(QString::fromUtf8(networkReply->readAll())); + networkReply->deleteLater(); + networkReply->manager()->deleteLater(); + } + + void animate(int frame) { + qreal progress = static_cast(frame) / 100; +#if QT_VERSION >= 0x040500 + m_iconItem->setOpacity(progress); +#endif + qreal hw = width() / 2.0; + m_statusItem->setPos(-hw + hw * progress, 0); + for (int i = 0; i < m_forecastItems.count(); ++i) { + qreal ofs = i * 0.5 / m_forecastItems.count(); + qreal alpha = qBound(qreal(0), 2 * (progress - ofs), qreal(1)); +#if QT_VERSION >= 0x040500 + m_conditionItems[i]->setOpacity(alpha); +#endif + QPointF pos = m_forecastItems[i]->pos(); + if (width() > height()) { + qreal fx = width() - width() * 0.4 * alpha; + m_forecastItems[i]->setPos(fx, pos.y()); + } else { + qreal fx = height() - height() * 0.5 * alpha; + m_forecastItems[i]->setPos(pos.x(), fx); + } + } + } + +private: + + void setupScene() { + + QColor textColor = palette().color(QPalette::WindowText); + QFont textFont = font(); + textFont.setBold(true); + textFont.setPointSize(textFont.pointSize() * 2); + + m_temperatureItem = m_scene.addText(QString(), textFont); + m_temperatureItem->setDefaultTextColor(textColor); + + m_conditionItem = m_scene.addText(QString(), textFont); + m_conditionItem->setDefaultTextColor(textColor); + + m_iconItem = new QGraphicsSvgItem; + m_scene.addItem(m_iconItem); + + m_statusItem = m_scene.addRect(0, 0, 10, 10); + m_statusItem->setPen(Qt::NoPen); + m_statusItem->setBrush(Qt::NoBrush); + m_temperatureItem->setParentItem(m_statusItem); + m_conditionItem->setParentItem(m_statusItem); + m_iconItem->setParentItem(m_statusItem); + + connect(&m_timeLine, SIGNAL(frameChanged(int)), SLOT(animate(int))); + m_timeLine.setDuration(1100); + m_timeLine.setFrameRange(0, 100); + m_timeLine.setCurveShape(QTimeLine::EaseInCurve); + } + + void request(const QString &location) { + QUrl url("http://www.google.com/ig/api"); + url.addEncodedQueryItem("hl", "en"); + url.addEncodedQueryItem("weather", QUrl::toPercentEncoding(location)); + + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + connect(manager, SIGNAL(finished(QNetworkReply*)), + this, SLOT(handleNetworkData(QNetworkReply*))); + manager->get(QNetworkRequest(url)); + + city = QString(); + setWindowTitle("Loading..."); + } + + QString extractIcon(const QString &data) { + if (m_icons.isEmpty()) { + m_icons["mostly_cloudy"] = "weather-few-clouds"; + m_icons["cloudy"] = "weather-overcast"; + m_icons["mostly_sunny"] = "weather-sunny-very-few-clouds"; + m_icons["partly_cloudy"] = "weather-sunny-very-few-clouds"; + m_icons["sunny"] = "weather-sunny"; + m_icons["flurries"] = "weather-snow"; + m_icons["fog"] = "weather-fog"; + m_icons["haze"] = "weather-haze"; + m_icons["icy"] = "weather-icy"; + m_icons["sleet"] = "weather-sleet"; + m_icons["chance_of_sleet"] = "weather-sleet"; + m_icons["snow"] = "weather-snow"; + m_icons["chance_of_snow"] = "weather-snow"; + m_icons["mist"] = "weather-showers"; + m_icons["rain"] = "weather-showers"; + m_icons["chance_of_rain"] = "weather-showers"; + m_icons["storm"] = "weather-storm"; + m_icons["chance_of_storm"] = "weather-storm"; + m_icons["thunderstorm"] = "weather-thundershower"; + m_icons["chance_of_tstorm"] = "weather-thundershower"; + } + QRegExp regex("([\\w]+).gif$"); + if (regex.indexIn(data) != -1) { + QString i = regex.cap(); + i = i.left(i.length() - 4); + QString name = m_icons.value(i); + if (!name.isEmpty()) { + name.prepend(":/icons/"); + name.append(".svg"); + return name; + } + } + return QString(); + } + + static QString toCelcius(QString t, QString unit) { + bool ok = false; + int degree = t.toInt(&ok); + if (!ok) + return QString(); + if (unit != "SI") + degree = ((degree - 32) * 5 + 8)/ 9; + return QString::number(degree) + QChar(176); + } + + +#define GET_DATA_ATTR xml.attributes().value("data").toString() + + void digest(const QString &data) { + + QColor textColor = palette().color(QPalette::WindowText); + QString unitSystem; + + delete m_iconItem; + m_iconItem = new QGraphicsSvgItem(); + m_scene.addItem(m_iconItem); + m_iconItem->setParentItem(m_statusItem); + qDeleteAll(m_dayItems); + qDeleteAll(m_conditionItems); + qDeleteAll(m_rangeItems); + qDeleteAll(m_forecastItems); + m_dayItems.clear(); + m_conditionItems.clear(); + m_rangeItems.clear(); + m_forecastItems.clear(); + + QXmlStreamReader xml(data); + while (!xml.atEnd()) { + xml.readNext(); + if (xml.tokenType() == QXmlStreamReader::StartElement) { + if (xml.name() == "city") { + city = GET_DATA_ATTR; + setWindowTitle(city); + } + if (xml.name() == "unit_system") + unitSystem = xml.attributes().value("data").toString(); + // Parse current weather conditions + if (xml.name() == "current_conditions") { + while (!xml.atEnd()) { + xml.readNext(); + if (xml.name() == "current_conditions") + break; + if (xml.tokenType() == QXmlStreamReader::StartElement) { + if (xml.name() == "condition") { + m_conditionItem->setPlainText(GET_DATA_ATTR); + } + if (xml.name() == "icon") { + QString name = extractIcon(GET_DATA_ATTR); + if (!name.isEmpty()) { + delete m_iconItem; + m_iconItem = new QGraphicsSvgItem(name); + m_scene.addItem(m_iconItem); + m_iconItem->setParentItem(m_statusItem); + } + } + if (xml.name() == "temp_c") { + QString s = GET_DATA_ATTR + QChar(176); + m_temperatureItem->setPlainText(s); + } + } + } + } + // Parse and collect the forecast conditions + if (xml.name() == "forecast_conditions") { + QGraphicsTextItem *dayItem = 0; + QGraphicsSvgItem *statusItem = 0; + QString lowT, highT; + while (!xml.atEnd()) { + xml.readNext(); + if (xml.name() == "forecast_conditions") { + if (dayItem && statusItem && + !lowT.isEmpty() && !highT.isEmpty()) { + m_dayItems << dayItem; + m_conditionItems << statusItem; + QString txt = highT + '/' + lowT; + QGraphicsTextItem* rangeItem; + rangeItem = m_scene.addText(txt); + rangeItem->setDefaultTextColor(textColor); + m_rangeItems << rangeItem; + QGraphicsRectItem *box; + box = m_scene.addRect(0, 0, 10, 10); + box->setPen(Qt::NoPen); + box->setBrush(Qt::NoBrush); + m_forecastItems << box; + dayItem->setParentItem(box); + statusItem->setParentItem(box); + rangeItem->setParentItem(box); + } else { + delete dayItem; + delete statusItem; + } + break; + } + if (xml.tokenType() == QXmlStreamReader::StartElement) { + if (xml.name() == "day_of_week") { + QString s = GET_DATA_ATTR; + dayItem = m_scene.addText(s.left(3)); + dayItem->setDefaultTextColor(textColor); + } + if (xml.name() == "icon") { + QString name = extractIcon(GET_DATA_ATTR); + if (!name.isEmpty()) { + statusItem = new QGraphicsSvgItem(name); + m_scene.addItem(statusItem); + } + } + if (xml.name() == "low") + lowT = toCelcius(GET_DATA_ATTR, unitSystem); + if (xml.name() == "high") + highT = toCelcius(GET_DATA_ATTR, unitSystem); + } + } + } + + } + } + + m_timeLine.stop(); + layoutItems(); + animate(0); + m_timeLine.start(); + } + + void layoutItems() { + m_scene.setSceneRect(0, 0, width() - 1, height() - 1); + m_view->centerOn(width() / 2, height() / 2); + if (width() > height()) + layoutItemsLandscape(); + else + layoutItemsPortrait(); + } + + void layoutItemsLandscape() { + m_statusItem->setRect(0, 0, width() / 2 - 1, height() - 1); + + if (!m_iconItem->boundingRect().isEmpty()) { + qreal dim = qMin(width() * 0.6, height() * 0.8); + qreal pad = (height() - dim) / 2; + qreal sw = dim / m_iconItem->boundingRect().width(); + qreal sh = dim / m_iconItem->boundingRect().height(); + m_iconItem->setTransform(QTransform().scale(sw, sh)); + m_iconItem->setPos(1, pad); + } + + m_temperatureItem->setPos(2, 2); + qreal h = m_conditionItem->boundingRect().height(); + m_conditionItem->setPos(10, height() - h); + + if (m_dayItems.count()) { + qreal left = width() * 0.6; + qreal h = height() / m_dayItems.count(); + QFont textFont = font(); + textFont.setPixelSize(static_cast(h * 0.3)); + qreal statusWidth = 0; + qreal rangeWidth = 0; + for (int i = 0; i < m_dayItems.count(); ++i) { + m_dayItems[i]->setFont(textFont); + QRectF brect = m_dayItems[i]->boundingRect(); + statusWidth = qMax(statusWidth, brect.width()); + brect = m_rangeItems[i]->boundingRect(); + rangeWidth = qMax(rangeWidth, brect.width()); + } + qreal space = width() - left - statusWidth - rangeWidth; + qreal dim = qMin(h, space); + qreal pad = statusWidth + (space - dim) / 2; + for (int i = 0; i < m_dayItems.count(); ++i) { + qreal base = h * i; + m_forecastItems[i]->setPos(left, base); + m_forecastItems[i]->setRect(0, 0, width() - left, h); + QRectF brect = m_dayItems[i]->boundingRect(); + qreal ofs = (h - brect.height()) / 2; + m_dayItems[i]->setPos(0, ofs); + brect = m_rangeItems[i]->boundingRect(); + ofs = (h - brect.height()) / 2; + m_rangeItems[i]->setPos(width() - rangeWidth - left, ofs); + brect = m_conditionItems[i]->boundingRect(); + ofs = (h - dim) / 2; + m_conditionItems[i]->setPos(pad, ofs); + if (brect.isEmpty()) + continue; + qreal sw = dim / brect.width(); + qreal sh = dim / brect.height(); + m_conditionItems[i]->setTransform(QTransform().scale(sw, sh)); + } + } + } + + void layoutItemsPortrait() { + + m_statusItem->setRect(0, 0, width() - 1, height() / 2 - 1); + + if (!m_iconItem->boundingRect().isEmpty()) { + qreal dim = qMin(width() * 0.8, height() * 0.4); + qreal ofsy = (height() / 2 - dim) / 2; + qreal ofsx = (width() - dim) / 3; + qreal sw = dim / m_iconItem->boundingRect().width(); + qreal sh = dim / m_iconItem->boundingRect().height(); + m_iconItem->setTransform(QTransform().scale(sw, sh)); + m_iconItem->setPos(ofsx, ofsy); + } + + m_temperatureItem->setPos(2, 2); + qreal ch = m_conditionItem->boundingRect().height(); + qreal cw = m_conditionItem->boundingRect().width(); + m_conditionItem->setPos(width() - cw , height() / 2 - ch - 20); + + if (m_dayItems.count()) { + qreal top = height() * 0.5; + qreal w = width() / m_dayItems.count(); + qreal statusHeight = 0; + qreal rangeHeight = 0; + for (int i = 0; i < m_dayItems.count(); ++i) { + m_dayItems[i]->setFont(font()); + QRectF brect = m_dayItems[i]->boundingRect(); + statusHeight = qMax(statusHeight, brect.height()); + brect = m_rangeItems[i]->boundingRect(); + rangeHeight = qMax(rangeHeight, brect.height()); + } + qreal space = height() - top - statusHeight - rangeHeight; + qreal dim = qMin(w, space); + + qreal boxh = statusHeight + rangeHeight + dim; + qreal pad = (height() - top - boxh) / 2; + + for (int i = 0; i < m_dayItems.count(); ++i) { + qreal base = w * i; + m_forecastItems[i]->setPos(base, top); + m_forecastItems[i]->setRect(0, 0, w, boxh); + QRectF brect = m_dayItems[i]->boundingRect(); + qreal ofs = (w - brect.width()) / 2; + m_dayItems[i]->setPos(ofs, pad); + + brect = m_rangeItems[i]->boundingRect(); + ofs = (w - brect.width()) / 2; + m_rangeItems[i]->setPos(ofs, pad + statusHeight + dim); + + brect = m_conditionItems[i]->boundingRect(); + ofs = (w - dim) / 2; + m_conditionItems[i]->setPos(ofs, pad + statusHeight); + if (brect.isEmpty()) + continue; + qreal sw = dim / brect.width(); + qreal sh = dim / brect.height(); + m_conditionItems[i]->setTransform(QTransform().scale(sw, sh)); + } + } + } + + + void resizeEvent(QResizeEvent *event) { + Q_UNUSED(event); + layoutItems(); + } + +}; + +#include "weatherinfo.moc" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + WeatherInfo w; +#if defined(Q_OS_SYMBIAN) + w.showMaximized(); +#else + w.resize(520, 288); + w.show(); +#endif + + return app.exec(); +} diff --git a/demos/embedded/weatherinfo/weatherinfo.pro b/demos/embedded/weatherinfo/weatherinfo.pro new file mode 100644 index 0000000..a89acba --- /dev/null +++ b/demos/embedded/weatherinfo/weatherinfo.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = weatherinfo +SOURCES = weatherinfo.cpp +RESOURCES = weatherinfo.qrc +QT += network svg + +symbian { + HEADERS += $$QT_SOURCE_TREE/examples/network/ftp/sym_iap_util.h + LIBS += -lesock -lconnmon + TARGET.CAPABILITY = NetworkServices +} diff --git a/demos/embedded/weatherinfo/weatherinfo.qrc b/demos/embedded/weatherinfo/weatherinfo.qrc new file mode 100644 index 0000000..6e9d224 --- /dev/null +++ b/demos/embedded/weatherinfo/weatherinfo.qrc @@ -0,0 +1,16 @@ + + + icons/weather-few-clouds.svg + icons/weather-fog.svg + icons/weather-haze.svg + icons/weather-icy.svg + icons/weather-overcast.svg + icons/weather-showers.svg + icons/weather-sleet.svg + icons/weather-snow.svg + icons/weather-storm.svg + icons/weather-sunny.svg + icons/weather-sunny-very-few-clouds.svg + icons/weather-thundershower.svg + + -- cgit v0.12