[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [marble] src/plugins/render/weather: Weather Plugin was migrated to usage of MapInfoDialog
From: Illya Kovalevskyy <illya.kovalevskyy () gmail ! com>
Date: 2012-12-30 12:12:44
Message-ID: 20121230121244.6E2EBA6091 () git ! kde ! org
[Download RAW message or body]
Git commit fd773f2fa55d2a947baf2ea6cb4173893e9381d4 by Illya Kovalevskyy.
Committed on 30/12/2012 at 13:10.
Pushed by kovalevskyy into branch 'master'.
Weather Plugin was migrated to usage of MapInfoDialog
REVIEW: 108021
M +12 -1 src/plugins/render/weather/AbstractWeatherService.cpp
M +6 -0 src/plugins/render/weather/AbstractWeatherService.h
M +1 -0 src/plugins/render/weather/BBCWeatherService.cpp
M +1 -0 src/plugins/render/weather/CMakeLists.txt
M +1 -0 src/plugins/render/weather/GeoNamesWeatherService.cpp
M +72 -38 src/plugins/render/weather/WeatherItem.cpp
M +6 -2 src/plugins/render/weather/WeatherItem.h
M +7 -0 src/plugins/render/weather/WeatherModel.cpp
M +3 -0 src/plugins/render/weather/WeatherModel.h
M +14 -0 src/plugins/render/weather/WeatherPlugin.cpp
M +3 -0 src/plugins/render/weather/WeatherPlugin.h
A +- -- src/plugins/render/weather/data/marble_deco.png
A +107 -0 src/plugins/render/weather/data/weather.html
A +78 -0 src/plugins/render/weather/data/weatherscreen.css
A +7 -0 src/plugins/render/weather/weather.qrc
http://commits.kde.org/marble/fd773f2fa55d2a947baf2ea6cb4173893e9381d4
diff --git a/src/plugins/render/weather/AbstractWeatherService.cpp \
b/src/plugins/render/weather/AbstractWeatherService.cpp index 251fe4d..a6c7318 100644
--- a/src/plugins/render/weather/AbstractWeatherService.cpp
+++ b/src/plugins/render/weather/AbstractWeatherService.cpp
@@ -15,7 +15,8 @@ namespace Marble
{
AbstractWeatherService::AbstractWeatherService( QObject *parent )
- : QObject( parent )
+ : QObject( parent ),
+ m_marbleWidget(0)
{
}
@@ -23,6 +24,16 @@ AbstractWeatherService::~AbstractWeatherService()
{
}
+void AbstractWeatherService::setMarbleWidget( MarbleWidget *widget )
+{
+ m_marbleWidget = widget;
+}
+
+MarbleWidget* AbstractWeatherService::marbleWidget()
+{
+ return m_marbleWidget;
+}
+
void AbstractWeatherService::setFavoriteItems( const QStringList& favorite )
{
if ( m_favoriteItems != favorite) {
diff --git a/src/plugins/render/weather/AbstractWeatherService.h \
b/src/plugins/render/weather/AbstractWeatherService.h index 8c8ce0e..fa4dc74 100644
--- a/src/plugins/render/weather/AbstractWeatherService.h
+++ b/src/plugins/render/weather/AbstractWeatherService.h
@@ -17,6 +17,7 @@
namespace Marble
{
+class MarbleWidget;
class AbstractWeatherService : public QObject
{
@@ -25,6 +26,7 @@ class AbstractWeatherService : public QObject
public:
explicit AbstractWeatherService( QObject *parent );
virtual ~AbstractWeatherService();
+ void setMarbleWidget( MarbleWidget* widget );
public Q_SLOTS:
virtual void setFavoriteItems( const QStringList& favorite );
@@ -41,8 +43,12 @@ class AbstractWeatherService : public QObject
void createdItems( QList<AbstractDataPluginItem*> items );
void downloadDescriptionFileRequested( const QUrl& );
+protected:
+ MarbleWidget* marbleWidget();
+
private:
QStringList m_favoriteItems;
+ MarbleWidget* m_marbleWidget;
};
} // namespace Marble
diff --git a/src/plugins/render/weather/BBCWeatherService.cpp \
b/src/plugins/render/weather/BBCWeatherService.cpp index 02898c1..2952d91 100644
--- a/src/plugins/render/weather/BBCWeatherService.cpp
+++ b/src/plugins/render/weather/BBCWeatherService.cpp
@@ -101,6 +101,7 @@ void BBCWeatherService::fetchStationList()
void BBCWeatherService::createItem( BBCStation station )
{
BBCWeatherItem *item = new BBCWeatherItem( this );
+ item->setMarbleWidget( marbleWidget() );
item->setBbcId( station.bbcId() );
item->setCoordinate( station.coordinate() );
item->setPriority( station.priority() );
diff --git a/src/plugins/render/weather/CMakeLists.txt \
b/src/plugins/render/weather/CMakeLists.txt index 7b48dc9..df2b79a 100644
--- a/src/plugins/render/weather/CMakeLists.txt
+++ b/src/plugins/render/weather/CMakeLists.txt
@@ -25,6 +25,7 @@ set( weather_SRCS WeatherData.cpp
set( weather_UI WeatherConfigWidget.ui )
qt4_wrap_ui( weather_SRCS ${weather_UI} )
+qt4_add_resources( weather_SRCS weather.qrc )
marble_add_plugin( Weather ${weather_SRCS} )
target_link_libraries( Weather ${QT_QTWEBKIT_LIBRARY} )
diff --git a/src/plugins/render/weather/GeoNamesWeatherService.cpp \
b/src/plugins/render/weather/GeoNamesWeatherService.cpp index 202a9c3..94af39c 100644
--- a/src/plugins/render/weather/GeoNamesWeatherService.cpp
+++ b/src/plugins/render/weather/GeoNamesWeatherService.cpp
@@ -165,6 +165,7 @@ AbstractDataPluginItem *GeoNamesWeatherService::parse( const \
QScriptValue &value
GeoDataCoordinates coordinates( longitude, latitude, 0.0, \
GeoDataCoordinates::Degree ); GeoNamesWeatherItem *item = new GeoNamesWeatherItem( \
this ); + item->setMarbleWidget( marbleWidget() );
item->setId( id );
item->setCoordinate( coordinates );
item->setTarget( "earth" );
diff --git a/src/plugins/render/weather/WeatherItem.cpp \
b/src/plugins/render/weather/WeatherItem.cpp index ae80079..46faab7 100644
--- a/src/plugins/render/weather/WeatherItem.cpp
+++ b/src/plugins/render/weather/WeatherItem.cpp
@@ -6,6 +6,7 @@
// the source code.
//
// Copyright 2009 Bastian Holst <bastianholst@gmx.de>
+// Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
//
// Self
@@ -22,6 +23,8 @@
#include "WidgetGraphicsItem.h"
#include "TinyWebBrowser.h"
#include "MarbleDebug.h"
+#include "MarbleWidget.h"
+#include "MapInfoDialog.h"
// Qt
#include <QtCore/QCoreApplication>
@@ -51,7 +54,8 @@ class WeatherItemPrivate
public:
WeatherItemPrivate( WeatherItem *parent )
- : m_priority( 0 ),
+ : m_marbleWidget( 0 ),
+ m_priority( 0 ),
m_browserAction( tr( "Weather" ), parent ),
m_favoriteAction( parent ),
m_browser( 0 ),
@@ -290,6 +294,8 @@ class WeatherItemPrivate
\
WeatherData::HectoPascal ).toInt(); }
+ MarbleWidget *m_marbleWidget;
+
WeatherData m_currentWeather;
QMap<QDate, WeatherData> m_forecastWeather;
@@ -320,11 +326,19 @@ class WeatherItemPrivate
QFont WeatherItemPrivate::s_font = QFont( "Sans Serif", 8 );
#endif
-WeatherItem::WeatherItem( QObject *parent )
+WeatherItem::WeatherItem(QObject *parent )
+ : AbstractDataPluginItem( parent ),
+ d( new WeatherItemPrivate( this ) )
+{
+ setCacheMode( MarbleGraphicsItem::ItemCoordinateCache );
+}
+
+WeatherItem::WeatherItem(MarbleWidget* widget, QObject *parent )
: AbstractDataPluginItem( parent ),
d( new WeatherItemPrivate( this ) )
{
setCacheMode( MarbleGraphicsItem::ItemCoordinateCache );
+ d->m_marbleWidget = widget;
}
WeatherItem::~WeatherItem()
@@ -458,11 +472,6 @@ void WeatherItem::setPriority( quint8 priority )
d->m_priority = priority;
}
-QString WeatherItem::creditHtml() const
-{
- return QString();
-}
-
void WeatherItem::setSettings( const QHash<QString, QVariant>& settings )
{
if ( d->m_settings == settings ) {
@@ -476,43 +485,68 @@ void WeatherItem::setSettings( const QHash<QString, QVariant>& \
settings ) d->updateFavorite();
}
+void WeatherItem::setMarbleWidget(MarbleWidget *widget)
+{
+ d->m_marbleWidget = widget;
+}
+
void WeatherItem::openBrowser()
{
- QLocale locale = QLocale::system();
- if( !d->m_browser ) {
- d->m_browser = new TinyWebBrowser();
- }
- QString html;
- html += "<html>";
- html += "<body>";
- html += "<h1>" + tr( "Weather for %1" ).arg( stationName() ) + "</h1>";
- if ( d->m_currentWeather.isValid() ) {
- html += "<h2>" + tr( "Current Observation" ) + "</h2>";
- html += d->m_currentWeather.toHtml( d->temperatureUnit(),
- d->speedUnit(),
- d->pressureUnit() );
- }
- if ( !d->m_forecastWeather.isEmpty() ) {
- html += "<h2>" + tr( "Forecasts" ) + "</h2>";
+ if (d->m_marbleWidget) {
+ MapInfoDialog *popup = d->m_marbleWidget->mapInfoDialog();
+ popup->setCoordinates( coordinate(), Qt::AlignRight | Qt::AlignVCenter );
+ popup->setSize( QSizeF( 610, 550 ) ); // +10 pixels for the width
+ popup->setVisible( true );
+
+ QFile weatherHtmlFile(":/marble/weather/weather.html");
+ if ( !weatherHtmlFile.open(QIODevice::ReadOnly) ) {
+ return;
+ }
+
+ QString templateHtml = weatherHtmlFile.readAll();
+ popup->setContent( createFromTemplate(templateHtml) );
}
- foreach ( const WeatherData& data, d->m_forecastWeather ) {
- QDate date = data.dataDate();
- html += "<h3>" + locale.standaloneDayName( date.dayOfWeek() ) + "</h3>";
- html += data.toHtml( d->temperatureUnit(),
- d->speedUnit(),
- d->pressureUnit() );
+}
+
+QString WeatherItem::createFromTemplate(const QString &templateHtml)
+{
+ QString html = templateHtml;
+ QLocale locale = QLocale::system();
+ html.replace("%city_name%", stationName());
+ html.replace("%weather_situation%", "file://"+d->m_currentWeather.iconSource());
+ html.replace("%current_temp%", d->temperatureString());
+ html.replace("%current_condition%", d->m_currentWeather.conditionString());
+ html.replace("%wind_direction%", d->m_currentWeather.windDirectionString());
+ html.replace("%wind_speed%", d->m_currentWeather.windSpeedString());
+ html.replace("%humidity_level%", d->m_currentWeather.humidityString());
+ html.replace("%publish_time%", d->m_currentWeather.publishingTime().toString());
+
+ if(d->m_forecastWeather.size() < 1) {
+ html.replace("%forecast_available%", "none");
+ } else {
+ html.replace("%forecast_available%", "block");
}
- QString credit = creditHtml();
- if ( !credit.isEmpty() ) {
- html += "<p>";
- html += creditHtml();
- html += "</p>";
+
+ int forecastNumber = 0;
+
+ foreach ( const WeatherData &forecast, d->m_forecastWeather ) {
+ forecastNumber++;
+ const QString suffix = QString::number(forecastNumber);
+ QDate date = forecast.dataDate();
+ html.replace("%day_f"+suffix+"%", \
locale.standaloneDayName(date.dayOfWeek())); + \
html.replace("%weather_situation_f"+suffix+"%", "file://"+forecast.iconSource()); + \
qDebug() << "%weather_situation_"+suffix+"%" << "file://"+forecast.iconSource(); + \
html.replace("%max_temp_f"+suffix+"%", + \
forecast.maxTemperatureString(WeatherData::Celsius)); + \
html.replace("%min_temp_f"+suffix+"%", + \
forecast.minTemperatureString(WeatherData::Celsius)); + \
html.replace("%condition_f"+suffix+"%", forecast.conditionString()); + \
html.replace("%wind_direction_f"+suffix+"%", forecast.windDirectionString()); + \
html.replace("%wind_speed_f"+suffix+"%", forecast.windSpeedString()); + \
html.replace("%publish_time_f"+suffix+"%", forecast.publishingTime().toString()); }
- html += "</body>";
- html += "</html>";
- d->m_browser->setHtml( html );
- d->m_browser->show();
+ return html;
}
QList<QAction*> WeatherItem::actions()
diff --git a/src/plugins/render/weather/WeatherItem.h \
b/src/plugins/render/weather/WeatherItem.h index 09829f9..2b88905 100644
--- a/src/plugins/render/weather/WeatherItem.h
+++ b/src/plugins/render/weather/WeatherItem.h
@@ -6,6 +6,7 @@
// the source code.
//
// Copyright 2009 Bastian Holst <bastianholst@gmx.de>
+// Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
//
#ifndef WEATHERITEM_H
@@ -13,6 +14,7 @@
// Marble
#include "AbstractDataPluginItem.h"
+#include "MarbleWidget.h"
// Qt
#include <QtCore/QMap>
@@ -43,6 +45,7 @@ class WeatherItem : public AbstractDataPluginItem
public:
WeatherItem( QObject *parent = 0 );
+ WeatherItem( MarbleWidget* widget, QObject *parent = 0 );
~WeatherItem();
QAction *action();
@@ -83,10 +86,10 @@ class WeatherItem : public AbstractDataPluginItem
quint8 priority() const;
void setPriority( quint8 priority );
- virtual QString creditHtml() const;
-
void setSettings( const QHash<QString, QVariant>& settings );
+ void setMarbleWidget( MarbleWidget *widget );
+
virtual QList<QAction*> actions();
QString description() const;
@@ -111,6 +114,7 @@ Q_SIGNALS:
Q_DISABLE_COPY(WeatherItem)
WeatherItemPrivate * const d;
friend class WeatherItemPrivate;
+ QString createFromTemplate(const QString &templateHtml);
};
} // namespace Marble
diff --git a/src/plugins/render/weather/WeatherModel.cpp \
b/src/plugins/render/weather/WeatherModel.cpp index e6580d3..ea18208 100644
--- a/src/plugins/render/weather/WeatherModel.cpp
+++ b/src/plugins/render/weather/WeatherModel.cpp
@@ -134,6 +134,13 @@ void WeatherModel::downloadDescriptionFileRequested( const QUrl& \
url ) downloadDescriptionFile( url );
}
+void WeatherModel::setMarbleWidget(MarbleWidget *widget)
+{
+ foreach ( AbstractWeatherService* service, m_services ) {
+ service->setMarbleWidget( widget );
+ }
+}
+
void WeatherModel::addService( AbstractWeatherService *service )
{
service->setFavoriteItems( favoriteItems() );
diff --git a/src/plugins/render/weather/WeatherModel.h \
b/src/plugins/render/weather/WeatherModel.h index 7613b5f..3bdb7f6 100644
--- a/src/plugins/render/weather/WeatherModel.h
+++ b/src/plugins/render/weather/WeatherModel.h
@@ -15,6 +15,7 @@
#include "WeatherData.h"
#include "GeoDataLatLonAltBox.h"
+#include "MarbleWidget.h"
#include <QtCore/QStringList>
@@ -51,6 +52,8 @@ class WeatherModel : public AbstractDataPluginModel
void downloadDescriptionFileRequested( const QUrl& url );
+ void setMarbleWidget(MarbleWidget *widget);
+
Q_SIGNALS:
void additionalItemsRequested( const GeoDataLatLonAltBox &,
const MarbleModel *,
diff --git a/src/plugins/render/weather/WeatherPlugin.cpp \
b/src/plugins/render/weather/WeatherPlugin.cpp index dd5e3de..bb9bf02 100644
--- a/src/plugins/render/weather/WeatherPlugin.cpp
+++ b/src/plugins/render/weather/WeatherPlugin.cpp
@@ -210,6 +210,20 @@ void WeatherPlugin::setSettings( const QHash<QString,QVariant> \
&settings ) updateSettings();
}
+bool WeatherPlugin::eventFilter(QObject *object, QEvent *event)
+{
+ if ( isInitialized() ) {
+ WeatherModel *weatherModel = dynamic_cast<WeatherModel*>( model() );
+ Q_ASSERT(weatherModel);
+ MarbleWidget* widget = dynamic_cast<MarbleWidget*>( object );
+ if ( widget ) {
+ weatherModel->setMarbleWidget(widget);
+ }
+ }
+
+ return AbstractDataPlugin::eventFilter( object, event );
+}
+
void WeatherPlugin::readSettings()
{
if ( !m_configDialog ) {
diff --git a/src/plugins/render/weather/WeatherPlugin.h \
b/src/plugins/render/weather/WeatherPlugin.h index 844f5b6..02ca62a 100644
--- a/src/plugins/render/weather/WeatherPlugin.h
+++ b/src/plugins/render/weather/WeatherPlugin.h
@@ -67,6 +67,9 @@ class WeatherPlugin : public AbstractDataPlugin, public \
DialogConfigurationInter
void setSettings( const QHash<QString,QVariant> &settings );
+protected:
+ bool eventFilter(QObject *object, QEvent *event);
+
private Q_SLOTS:
void readSettings();
void writeSettings();
diff --git a/src/plugins/render/weather/data/marble_deco.png \
b/src/plugins/render/weather/data/marble_deco.png new file mode 100644
index 0000000..1f9c2da
Binary files /dev/null and b/src/plugins/render/weather/data/marble_deco.png differ
diff --git a/src/plugins/render/weather/data/weather.html \
b/src/plugins/render/weather/data/weather.html new file mode 100644
index 0000000..c49b7e3
--- /dev/null
+++ b/src/plugins/render/weather/data/weather.html
@@ -0,0 +1,107 @@
+<html>
+<head>
+<title>Weather for %city_name%</title>
+<link rel="stylesheet" media="screen" href="qrc:/marble/weather/weatherscreen.css">
+<link rel="stylesheet" media="print, embossed" \
href="qrc:/marble/weather/weatherprint.css"></head> +<body>
+<div id="Marblelogo">
+<h1>Current Observation</h1>
+<img src="%weather_situation%">
+<p>
+<table>
+<tr class="blue">
+ <td>Temperature</td><td>%current_temp%</td>
+</tr>
+<tr>
+ <td>Condition</td><td>%current_condition%</td>
+</tr>
+<tr>
+ <td>Wind direction</td><td>%wind_direction%</td>
+</tr>
+<tr>
+ <td>Wind speed</td><td>%wind_speed%</td>
+</tr>
+<tr>
+ <td>Humidity</td><td>%humidity_level%</td>
+</tr>
+</table>
+<p class="gray">Publishing time: %publish_time%
+
+<div style="display: %forecast_available%;">
+<h2>Forecasts</h2>
+
+<h3>%day_f1%</h3>
+
+<img src="%weather_situation_f1%">
+<p>
+<table>
+<tr class="blue">
+ <td>Max temperature</td><td>%max_temp_f1%</td>
+</tr>
+<tr>
+ <td>Min temperature</td><td>%min_temp_f1%</td>
+</tr>
+<tr>
+ <td>Condition</td><td>%condition_f1%</td>
+</tr>
+<tr>
+ <td>Wind direction</td><td>%wind_direction_f1%</td>
+</tr>
+<tr>
+ <td>Wind speed</td><td>%wind_speed_f1%</td>
+</tr>
+</table>
+<p class="gray">Publishing time: %publish_time_f1%
+
+<h3>%day_f2%</h3>
+
+<img src="%weather_situation_f2%">
+<p>
+<table>
+<tr class="blue">
+ <td>Max temperature</td><td>%max_temp_f2%</td>
+</tr>
+<tr>
+ <td>Min temperature</td><td>%min_temp_f2%</td>
+</tr>
+<tr>
+ <td>Condition</td><td>%condition_f2%</td>
+</tr>
+<tr>
+ <td>Wind direction</td><td>%wind_direction_f2%</td>
+</tr>
+<tr>
+ <td>Wind speed</td><td>%wind_speed_f2%</td>
+</tr>
+</table>
+<p class="gray">Publishing time: %publish_time_f2%
+
+<h3>%day_f3%</h3>
+
+<img src="%weather_situation_f3%">
+<p>
+<table>
+<tr class="blue">
+ <td>Max temperature</td><td>%max_temp_f3%</td>
+</tr>
+<tr>
+ <td>Min temperature</td><td>%min_temp_f3%</td>
+</tr>
+<tr>
+ <td>Condition</td><td>%condition_f3%</td>
+</tr>
+<tr>
+ <td>Wind direction</td><td>%wind_direction_f3%</td>
+</tr>
+<tr>
+ <td>Wind speed</td><td>%wind_speed_f3%</td>
+</tr>
+</table>
+<p class="gray">Publishing time: %publish_time_f3%
+</div>
+<hr>
+<p>Supported by <a href="http://backstage.bbc.co.uk">backstage.bbc.co.uk</a></p>
+<p>Weather data from <a href="http://www.metoffice.gov.uk/">UK MET Office</a></p>
+<p>Cloud image stripe by Soenke Rahn</p>
+</body>
+</html>
diff --git a/src/plugins/render/weather/data/weatherscreen.css \
b/src/plugins/render/weather/data/weatherscreen.css new file mode 100644
index 0000000..3c93964
--- /dev/null
+++ b/src/plugins/render/weather/data/weatherscreen.css
@@ -0,0 +1,78 @@
+/*
+ * Style sheet for weather plugin
+ */
+
+body {
+ margin-top: 70px;
+ background-image: url('qrc:/marble/weather/marble_deco.png');
+ background-repeat: no-repeat;
+ background-position: 0px 0px;
+}
+
+h1 {
+ color: #a4c0e4;
+ font: bold 1.8em "Linux Biolinum O", Tahoma, Arial, Helvetica, sans-serif;
+ margin-top: 80px;
+}
+
+h2 {
+ color: #888a85;
+ font-size: 24px;
+ margin-top: 20px;
+}
+
+h3 {
+ color: #6193cf;
+ font-size: 18px;
+ margin-top: 25px;
+}
+
+table {
+ font: 11px/24px Tahoma, Arial, Helvetica, sans-serif;
+ border-collapse: collapse;
+ width: 400px;
+}
+
+tr.blue td {
+ border-top: 1px solid #00438a;
+ border-bottom: 1px solid #00438a;
+ background: #a4c0e4;
+ color: white;
+ font: bold 12px/26px Tahoma, Arial, Helvetica, sans-serif;
+}
+
+td {
+ border-bottom: 1px solid #CCC;
+ padding: 0 0.5em;
+}
+
+td+td {
+ border-left: 1px solid #CCC;
+ text-align: center;
+}
+
+p.gray {
+ color: #888a85;
+ font-size: 12px;
+ margin-top: 20px;
+}
+
+p {
+ color: black;
+ font-size: 12px;
+ margin-top: 20px;
+ font: 11px/24px Tahoma, Arial, Helvetica, sans-serif;
+}
+
+hr {
+ margin-left: 0px;
+ width: 400px;
+ margin-top: 25px;
+}
+
+a { color: #2c72c7 }
+
+img {
+ width: 64px;
+ height: 64px;
+}
diff --git a/src/plugins/render/weather/weather.qrc \
b/src/plugins/render/weather/weather.qrc new file mode 100644
index 0000000..5662afe
--- /dev/null
+++ b/src/plugins/render/weather/weather.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file alias="marble/weather/marble_deco.png">data/marble_deco.png</file>
+ <file alias="marble/weather/weather.html">data/weather.html</file>
+ <file alias="marble/weather/weatherscreen.css">data/weatherscreen.css</file>
+ </qresource>
+</RCC>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic