Commit 61ea9ae1 authored by Illya Kovalevskyy's avatar Illya Kovalevskyy Committed by Dennis Nienhüser
Browse files

Render Copyright/License on the Map

REVIEW: 107620
parent 2aad4574
......@@ -2,6 +2,7 @@
<dgml xmlns="http://edu.kde.org/marble/dgml/2.0">
<document>
<head>
<license short="NASA / Public Domain">Source: NASA Goddard Space Flight Center Earth Observatory http://earthobservatory.nasa.gov/Newsroom/BlueMarble, License: Public Domain</license>
<name>Satellite View</name>
<target>earth</target>
<theme>bluemarble</theme>
......
......@@ -2,6 +2,7 @@
<dgml xmlns="http://edu.kde.org/marble/dgml/2.0">
<document>
<head>
<license short="NOAA NGDC, NASA / Public Domain">Source: Marc Imhoff of NASA GSFC; Christopher Elvidge of NOAA NGDC; Craig Mayhew and Robert Simmon, NASA GSFC, License: Public Domain</license>
<name>Earth at Night</name>
<target>earth</target>
<theme>citylights</theme>
......
......@@ -2,6 +2,7 @@
<dgml xmlns="http://edu.kde.org/marble/dgml/2.0">
<document>
<head>
<license short="© OpenStreetMap contributors">Source: © OpenStreetMap contributors, License: Creative Commons Attribution-ShareAlike 2.0 (CC BY-SA)</license>
<name>OpenStreetMap</name>
<target>earth</target>
<theme>openstreetmap</theme>
......
......@@ -2,6 +2,7 @@
<dgml xmlns="http://edu.kde.org/marble/dgml/2.0">
<document>
<head>
<license short="CIA / Public Domain" attribution="always">Source: Micro World Data Bank in Polygons („MWDB-POLY / MWDBII“), CIA; Global Associates, Ltd.; Fred Pospeschil und Antonio Rivera, License: Public Domain</license>
<name>Plain Map</name>
<target>earth</target>
<theme>plain</theme>
......
......@@ -2,6 +2,7 @@
<dgml xmlns="http://edu.kde.org/marble/dgml/2.0">
<document>
<head>
<license short="Legates, Willmott / CC by-SA">Legates, D.R. und Willmott, C.J. 1989. Average Monthly Surface Air Temperature and Precipitation, License: Creative Commons Attribution Share-Alike 2.0 (CC BY-SA)</license>
<name>Temperature (July)</name>
<target>earth</target>
<theme>temp-july</theme>
......
......@@ -215,8 +215,12 @@ QMenu* AbstractFloatItem::contextMenu()
lockAction->setCheckable( true );
lockAction->setChecked( positionLocked() );
connect( lockAction, SIGNAL( triggered( bool ) ), this, SLOT( setPositionLocked( bool ) ) );
QAction *hideAction = d->m_contextMenu->addAction( tr( "&Hide" ) );
connect( hideAction, SIGNAL( triggered() ), this, SLOT( hide() ) );
if(!(flags() & ItemIsHideable)) {
QAction *hideAction = d->m_contextMenu->addAction( tr( "&Hide" ) );
connect( hideAction, SIGNAL( triggered() ), this, SLOT( hide() ) );
}
DialogConfigurationInterface *configInterface = qobject_cast<DialogConfigurationInterface *>( this );
QDialog *dialog = configInterface ? configInterface->configDialog() : 0;
if( dialog )
......
......@@ -8,6 +8,7 @@
// Copyright 2008 Torsten Rahn <rahn@kde.org>
// Copyright 2008 Inge Wallin <inge@lysator.liu.se>
// Copyright 2011,2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
// Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
//
// Self
......@@ -35,7 +36,8 @@ class RenderPlugin::Private
m_action(0),
m_item(),
m_enabled(true),
m_visible(true)
m_visible(true),
m_userCheckable(true)
{
}
......@@ -51,6 +53,7 @@ class RenderPlugin::Private
bool m_enabled;
bool m_visible;
bool m_userCheckable;
};
......@@ -153,6 +156,15 @@ void RenderPlugin::setVisible( bool visible )
emit visibilityChanged( visible, nameId() );
}
void RenderPlugin::setUserCheckable( bool checkable )
{
if ( checkable != d->m_userCheckable ) {
d->m_action.setEnabled( checkable );
d->m_userCheckable = checkable;
emit userCheckableChanged( checkable );
}
}
bool RenderPlugin::enabled() const
{
return d->m_enabled;
......@@ -163,6 +175,11 @@ bool RenderPlugin::visible() const
return d->m_visible;
}
bool RenderPlugin::isUserCheckable() const
{
return d->m_userCheckable;
}
QHash<QString,QVariant> RenderPlugin::settings() const
{
return QHash<QString,QVariant>();
......
......@@ -8,6 +8,7 @@
// Copyright 2008 Torsten Rahn <tackat@kde.org>
// Copyright 2008 Inge Wallin <inge@lysator.liu.se>
// Copyright 2011,2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
// Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
//
#ifndef MARBLE_RENDERPLUGIN_H
......@@ -47,6 +48,7 @@ class MARBLE_EXPORT RenderPlugin : public QObject, public RenderPluginInterface
Q_PROPERTY ( QString description READ description CONSTANT )
Q_PROPERTY ( bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged )
Q_PROPERTY ( bool visible READ visible WRITE setVisible NOTIFY visibilityChanged )
Q_PROPERTY ( bool userCheckable READ isUserCheckable WRITE setUserCheckable NOTIFY userCheckableChanged )
public:
enum RenderType {
......@@ -93,6 +95,7 @@ class MARBLE_EXPORT RenderPlugin : public QObject, public RenderPluginInterface
bool enabled() const;
bool visible() const;
bool isUserCheckable() const;
/**
* @return: The settings of the item.
......@@ -117,6 +120,7 @@ class MARBLE_EXPORT RenderPlugin : public QObject, public RenderPluginInterface
public Q_SLOTS:
void setEnabled( bool enabled );
void setVisible( bool visible );
void setUserCheckable(bool isUserCheckable);
void restoreDefaultSettings();
QStringList settingKeys();
......@@ -134,6 +138,7 @@ class MARBLE_EXPORT RenderPlugin : public QObject, public RenderPluginInterface
void visibilityChanged( bool visible, const QString &nameId );
void enabledChanged( bool enable );
void userCheckableChanged(bool isUserCheckable);
/**
* This signal is emitted if the settings of the RenderPlugin changed.
......
......@@ -31,6 +31,7 @@ namespace dgml
const char* dgmlAttr_nameSpace20 = "http://edu.kde.org/marble/dgml/2.0";
const char* dgmlAttr_attribution = "attribution";
const char* dgmlAttr_backend = "backend";
const char* dgmlAttr_bgcolor = "bgcolor";
const char* dgmlAttr_color = "color";
......
......@@ -33,6 +33,7 @@ namespace dgml
extern const char* dgmlAttr_nameSpace20;
extern const char* dgmlAttr_attribution;
extern const char* dgmlAttr_backend;
extern const char* dgmlAttr_bgcolor;
extern const char* dgmlAttr_color;
......
......@@ -15,6 +15,7 @@
#include "DgmlAttributeDictionary.h"
#include "GeoParser.h"
#include "GeoSceneHead.h"
#include "MarbleDebug.h"
namespace Marble
{
......@@ -29,6 +30,19 @@ GeoNode* DgmlLicenseTagHandler::parse( GeoParser& parser ) const
GeoStackItem parentItem = parser.parentElement();
if( parentItem.represents( dgmlTag_Head ) ) {
QString const attribution = parser.attribute(dgmlAttr_attribution).trimmed().toLower();
if ( attribution == "never" ) {
parentItem.nodeAs<GeoSceneHead>()->license()->setAttribution( GeoSceneLicense::Never );
} else if( attribution == "opt-in" || attribution == "optin" ) {
parentItem.nodeAs<GeoSceneHead>()->license()->setAttribution( GeoSceneLicense::OptIn );
} else if( attribution.isEmpty() || attribution == "opt-out" || attribution == "optout" ) {
parentItem.nodeAs<GeoSceneHead>()->license()->setAttribution( GeoSceneLicense::OptOut );
} else if ( attribution == "always" ) {
parentItem.nodeAs<GeoSceneHead>()->license()->setAttribution( GeoSceneLicense::Always );
} else {
mDebug() << "Unknown license attribution value " << attribution << ", falling back to 'opt-out'.";
parentItem.nodeAs<GeoSceneHead>()->license()->setAttribution( GeoSceneLicense::OptOut );
}
QString const shortLicense = parser.attribute( dgmlAttr_short ).trimmed();
parentItem.nodeAs<GeoSceneHead>()->license()->setShortLicense( shortLicense );
QString const fullLicense = parser.readElementText().trimmed();
......
......@@ -13,6 +13,12 @@
namespace Marble
{
GeoSceneLicense::GeoSceneLicense() :
m_attribution( OptOut )
{
// nothing to do
}
QString GeoSceneLicense::license() const
{
return m_fullLicense;
......@@ -23,7 +29,12 @@ QString GeoSceneLicense::shortLicense() const
return m_shortLicense;
}
void GeoSceneLicense::setLicense( const QString &license )
GeoSceneLicense::Attribution GeoSceneLicense::attribution() const
{
return m_attribution;
}
void GeoSceneLicense::setLicense(const QString &license )
{
m_fullLicense = license;
}
......@@ -33,4 +44,9 @@ void GeoSceneLicense::setShortLicense( const QString &license )
m_shortLicense = license;
}
void GeoSceneLicense::setAttribution(Attribution attr )
{
m_attribution = attr;
}
}
......@@ -23,15 +23,27 @@ namespace Marble
class GEODATA_EXPORT GeoSceneLicense : public GeoNode
{
public:
enum Attribution {
Never,
OptOut,
OptIn,
Always
};
GeoSceneLicense();
QString license() const;
QString shortLicense() const;
Attribution attribution() const;
void setLicense( const QString &license );
void setShortLicense( const QString &license );
void setAttribution(Attribution attr );
private:
QString m_fullLicense;
QString m_shortLicense;
Attribution m_attribution;
};
......
......@@ -31,7 +31,8 @@ class MARBLE_EXPORT ScreenGraphicsItem : public MarbleGraphicsItem
{
public:
enum GraphicsItemFlag {
ItemIsMovable = 0x1
ItemIsMovable = 0x1,
ItemIsHideable = 0x2
};
Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
......
# Example
# add_subdirectory( test )
add_subdirectory( license )
# Display a control or a screen box
add_subdirectory( compass )
add_subdirectory( elevationprofilefloatitem )
......
PROJECT( License )
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${QT_INCLUDE_DIR}
)
INCLUDE(${QT_USE_FILE})
set( license_SRCS License.cpp )
qt4_automoc( ${license_SRCS} )
marble_add_plugin( License ${license_SRCS} )
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2012 Dennis Nienhüser <earthwings@gentoo.org>
// Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
//
#include "License.h"
#include "MarbleModel.h"
#include "MarbleAboutDialog.h"
#include "WidgetGraphicsItem.h"
#include "MarbleGraphicsGridLayout.h"
#include "ViewportParams.h"
#include "GeoSceneDocument.h"
#include "GeoSceneHead.h"
#include "GeoSceneLicense.h"
#include <QtGui/QMessageBox>
#include <QtGui/QCommonStyle>
#include <QtGui/QPainter>
#include <QtGui/QLabel>
namespace Marble
{
class OutlinedStyle : public QCommonStyle {
public:
void drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,bool enabled, const QString& text, QPalette::ColorRole textRole) const {
Q_UNUSED(alignment);
Q_UNUSED(enabled);
if (text.isEmpty()) {
return;
}
QPen savedPen;
if (textRole != QPalette::NoRole) {
savedPen = painter->pen();
painter->setPen(QPen(pal.brush(textRole), savedPen.widthF()));
}
QPainterPath path;
QFontMetricsF metrics(painter->font());
QPointF point(rect.x() + 7.0, rect.y() + metrics.ascent());
path.addText(point, painter->font(), text);
QPen pen(Qt::black);
pen.setWidth(2);
painter->setPen(pen);
painter->setBrush(QBrush(Qt::white));
painter->setRenderHint(QPainter::Antialiasing, true);
painter->drawPath(path);
painter->setPen( Qt::NoPen );
painter->drawPath( path );
if (textRole != QPalette::NoRole) {
painter->setPen(savedPen);
}
}
};
License::License( const MarbleModel *marbleModel )
: AbstractFloatItem( marbleModel, QPointF( -10.0, -5.0 ), QSizeF( 150.0, 20.0 ) ),
m_widgetItem( 0 ),
m_label( 0 )
{
setEnabled( true );
setVisible( true );
setBackground(QBrush(QColor(Qt::transparent)));
setFrame(NoFrame);
}
License::~License()
{
}
QStringList License::backendTypes() const
{
return QStringList( "License" );
}
QString License::name() const
{
return tr("License");
}
QString License::guiString() const
{
return tr("&License");
}
QString License::nameId() const
{
return QString( "license" );
}
QString License::version() const
{
return "1.0";
}
QString License::description() const
{
return tr("This is a float item that provides copyright information.");
}
QString License::copyrightYears() const
{
return "2012";
}
QList<PluginAuthor> License::pluginAuthors() const
{
return QList<PluginAuthor>()
<< PluginAuthor( "Dennis Nienhüser", "earthwings@gentoo.org" )
<< PluginAuthor( "Illya Kovalevskyy", "illya.kovalevskyy@gmail.com" );
}
QIcon License::icon () const
{
return QIcon();
}
void License::initialize ()
{
const GeoSceneLicense *license = marbleModel()->mapTheme()->head()->license();
if (!m_widgetItem && license->attribution() != GeoSceneLicense::Never)
updateLicenseText();
connect(marbleModel(), SIGNAL(themeChanged(QString)), this, SLOT(updateLicenseText()));
}
void License::updateLicenseText()
{
setEnabled(true);
setVisible(true);
const bool firstRun = (m_label == 0);
if(firstRun) {
m_widgetItem = new WidgetGraphicsItem( this );
m_label = new QLabel;
m_label->setStyle(new OutlinedStyle);
m_label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
const GeoSceneLicense *license = marbleModel()->mapTheme()->head()->license();
m_label->setText(license->shortLicense());
m_label->setToolTip(license->license());
m_widgetItem->setWidget(m_label);
if(firstRun) {
MarbleGraphicsGridLayout *layout = new MarbleGraphicsGridLayout( 1, 1 );
layout->addItem( m_widgetItem, 0, 0 );
setLayout( layout );
setPadding( 0 );
}
if(license->attribution() == GeoSceneLicense::Always) {
setUserCheckable(false);
} else if(license->attribution() == GeoSceneLicense::Never) {
setVisible(false);
setUserCheckable(false);
} else if(license->attribution() == GeoSceneLicense::OptIn) {
setUserCheckable(true);
setVisible(false);
} else {
setUserCheckable(true);
setVisible(true);
}
QSizeF const magic(6,0);
m_widgetItem->setSize(m_label->sizeHint()+magic);
setSize(m_label->sizeHint()+magic);
update();
}
bool License::isInitialized () const
{
return m_widgetItem;
}
bool License::eventFilter(QObject *object, QEvent *event)
{
if (!enabled() || !visible())
return false;
if(event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
QRectF floatItemRect = QRectF(positivePosition(), size());
if (mouseEvent->button() == Qt::LeftButton) {
const GeoSceneLicense *license = marbleModel()->mapTheme()->head()->license();
if (floatItemRect.contains(mouseEvent->pos()) && license->attribution() != GeoSceneLicense::Never) {
QMessageBox box;
box.setIcon(QMessageBox::Information);
box.setWindowTitle(tr("Copyright"));
box.setButtonText(0, tr("Read more..."));
box.setButtonText(1, tr("Continue"));
box.setText(tr("This Marble Map is available under the "+
license->shortLicense().toAscii()+
" license."));
box.setDetailedText(license->license());
box.exec();
MarbleAboutDialog dial;
dial.exec();
return true;
}
}
}
return AbstractFloatItem::eventFilter(object, event);
}
}
Q_EXPORT_PLUGIN2( License, Marble::License )
#include "License.moc"
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2012 Dennis Nienhüser <earthwings@gentoo.org>
// Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
//
#ifndef MARBLELICENSE_H
#define MARBLELICENSE_H
#include <QtCore/QObject>
#include "AbstractFloatItem.h"
class QLabel;
namespace Marble
{
class GeoDataCoordinates;
class WidgetGraphicsItem;
class MarbleLocale;
/**
* @short The class that displays copyright info
*
*/
class License : public AbstractFloatItem
{
Q_OBJECT
Q_INTERFACES( Marble::RenderPluginInterface )
MARBLE_PLUGIN( License )
public:
explicit License( const MarbleModel *marbleModel=0 );
~License();
QStringList backendTypes() const;
QString name() const;
QString guiString() const;
QString nameId() const;
QString version() const;
QString description() const;
QString copyrightYears() const;
QList<PluginAuthor> pluginAuthors() const;
QIcon icon () const;
void initialize ();
bool isInitialized () const;
public slots:
void updateLicenseText();
protected:
bool eventFilter(QObject *, QEvent *e);
private:
WidgetGraphicsItem* m_widgetItem;
QLabel* m_label;
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment