• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • license
License.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2012 Dennis Nienhüser <earthwings@gentoo.org>
9 // Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
10 //
11 
12 #include "License.h"
13 #include "MarbleWidget.h"
14 #include "MarbleModel.h"
15 #include "MarbleAboutDialog.h"
16 #include "WidgetGraphicsItem.h"
17 #include "MarbleGraphicsGridLayout.h"
18 #include "ViewportParams.h"
19 #include "GeoSceneDocument.h"
20 #include "GeoSceneHead.h"
21 #include "GeoSceneLicense.h"
22 
23 #include <QMessageBox>
24 #include <QCommonStyle>
25 #include <QPainter>
26 #include <QLabel>
27 #include <QMenu>
28 
29 namespace Marble
30 {
31 
32 class OutlinedStyle : public QCommonStyle {
33 public:
34  void drawItemText( QPainter *painter, const QRect &rect, int alignment, const QPalette &palette,
35  bool enabled, const QString& text, QPalette::ColorRole textRole ) const {
36  Q_UNUSED( alignment );
37  Q_UNUSED( enabled );
38 
39  if ( text.isEmpty() ) {
40  return;
41  }
42 
43  QPen savedPen;
44  if ( textRole != QPalette::NoRole ) {
45  savedPen = painter->pen();
46  painter->setPen( QPen( palette.brush( textRole ), savedPen.widthF() ) );
47  }
48 
49  QPainterPath path;
50  QFontMetricsF metrics( painter->font() );
51  QPointF point( rect.x() + 7.0, rect.y() + metrics.ascent() );
52  path.addText( point, painter->font(), text );
53  QPen pen( Qt::white );
54  pen.setWidth( 3 );
55  painter->setPen( pen );
56  painter->setBrush( QBrush( Qt::black ) );
57  painter->setRenderHint( QPainter::Antialiasing, true );
58  painter->drawPath( path );
59 
60  painter->setPen( Qt::NoPen );
61  painter->drawPath( path );
62 
63  if ( textRole != QPalette::NoRole ) {
64  painter->setPen( savedPen );
65  }
66  }
67 };
68 
69 License::License( const MarbleModel *marbleModel )
70  : AbstractFloatItem( marbleModel, QPointF( -10.0, -5.0 ), QSizeF( 150.0, 20.0 ) ),
71  m_widgetItem( 0 ),
72  m_label( 0 ),
73  m_showFullLicense( false ),
74  m_contextMenu( 0 )
75 {
76  setEnabled( true );
77  setVisible( true );
78  setBackground( QBrush( QColor( Qt::transparent ) ) );
79  setFrame( NoFrame );
80 }
81 
82 License::~License()
83 {
84 }
85 
86 QStringList License::backendTypes() const
87 {
88  return QStringList( "License" );
89 }
90 
91 QString License::name() const
92 {
93  return tr( "License" );
94 }
95 
96 QString License::guiString() const
97 {
98  return tr( "&License" );
99 }
100 
101 QString License::nameId() const
102 {
103  return QString( "license" );
104 }
105 
106 QString License::version() const
107 {
108  return "1.0";
109 }
110 
111 QString License::description() const
112 {
113  return tr( "This is a float item that provides copyright information." );
114 }
115 
116 QString License::copyrightYears() const
117 {
118  return "2012";
119 }
120 
121 QList<PluginAuthor> License::pluginAuthors() const
122 {
123  return QList<PluginAuthor>()
124  << PluginAuthor( QString::fromUtf8( "Dennis Nienhüser" ), "earthwings@gentoo.org" )
125  << PluginAuthor( "Illya Kovalevskyy", "illya.kovalevskyy@gmail.com" );
126 }
127 
128 QIcon License::icon () const
129 {
130  return QIcon(":/icons/license.png");
131 }
132 
133 void License::initialize ()
134 {
135  m_widgetItem = new WidgetGraphicsItem( this );
136  m_label = new QLabel;
137  m_label->setStyle( new OutlinedStyle );
138  m_label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
139  m_widgetItem->setWidget( m_label );
140 
141  MarbleGraphicsGridLayout *layout = new MarbleGraphicsGridLayout( 1, 1 );
142  layout->addItem( m_widgetItem, 0, 0 );
143  setLayout( layout );
144  setPadding( 0 );
145 
146  updateLicenseText();
147  connect( marbleModel(), SIGNAL(themeChanged(QString)), this, SLOT(updateLicenseText()) );
148 }
149 
150 void License::updateLicenseText()
151 {
152  const GeoSceneDocument *const mapTheme = marbleModel()->mapTheme();
153  if ( !mapTheme )
154  return;
155 
156  const GeoSceneHead *const head = mapTheme->head();
157  if ( !head )
158  return;
159 
160  const GeoSceneLicense *license = marbleModel()->mapTheme()->head()->license();
161  m_label->setText( m_showFullLicense ? license->license() : license->shortLicense() );
162  m_label->setToolTip( license->license() );
163  if( license->attribution() == GeoSceneLicense::Always ) {
164  setUserCheckable( false );
165  } else if( license->attribution() == GeoSceneLicense::Never ) {
166  setVisible( false );
167  setUserCheckable( false );
168  } else if( license->attribution() == GeoSceneLicense::OptIn ) {
169  setUserCheckable( true );
170  setVisible( false );
171  } else {
172  setUserCheckable( true );
173  setVisible( true );
174  }
175  QSizeF const magic( 6,0 );
176  m_widgetItem->setSize( m_label->sizeHint()+magic );
177  setSize( m_label->sizeHint()+magic );
178  update();
179  emit repaintNeeded();
180 }
181 
182 void License::toggleLicenseSize()
183 {
184  m_showFullLicense = !m_showFullLicense;
185  updateLicenseText();
186 }
187 
188 void License::showAboutDialog()
189 {
190  QPointer<MarbleAboutDialog> aboutDialog = new MarbleAboutDialog;
191  aboutDialog->setInitialTab( MarbleAboutDialog::Data );
192  aboutDialog->exec();
193  delete aboutDialog;
194 }
195 
196 bool License::isInitialized () const
197 {
198  return m_widgetItem;
199 }
200 
201 bool License::eventFilter( QObject *object, QEvent *event )
202 {
203  if ( !enabled() || !visible() )
204  return false;
205 
206  MarbleWidget *widget = dynamic_cast<MarbleWidget*>( object );
207  if ( !widget ) {
208  return AbstractFloatItem::eventFilter( object,event );
209  }
210 
211  if( event->type() == QEvent::MouseMove ) {
212  QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event );
213  QRectF floatItemRect = QRectF( positivePosition(), size() );
214  if ( floatItemRect.contains( mouseEvent->pos() ) ) {
215  widget->setCursor( QCursor( Qt::ArrowCursor ) );
216  return true;
217  }
218  }
219 
220  return AbstractFloatItem::eventFilter( object, event );
221 }
222 
223 void License::contextMenuEvent( QWidget *w, QContextMenuEvent *e )
224 {
225  if ( !m_contextMenu ) {
226  m_contextMenu = contextMenu();
227 
228  QAction *toggleAction = m_contextMenu->addAction( tr("&Full License"), this,
229  SLOT(toggleLicenseSize()) );
230  toggleAction->setCheckable( true );
231  toggleAction->setChecked( m_showFullLicense );
232 
233  m_contextMenu->addAction( tr("&Show Details"), this, SLOT(showAboutDialog()) );
234  }
235 
236  Q_ASSERT( m_contextMenu );
237  m_contextMenu->exec( w->mapToGlobal( e->pos() ) );
238 }
239 
240 }
241 
242 Q_EXPORT_PLUGIN2( License, Marble::License )
243 
244 #include "License.moc"
GeoSceneHead.h
QPainter
Marble::AbstractFloatItem::visible
bool visible() const
Check visibility of the float item.
Definition: AbstractFloatItem.cpp:135
Marble::License::~License
~License()
Definition: License.cpp:82
Marble::GeoSceneHead::license
const GeoSceneLicense * license() const
Definition: GeoSceneHead.cpp:176
Marble::WidgetGraphicsItem::setWidget
void setWidget(QWidget *widget)
Definition: WidgetGraphicsItem.cpp:48
Marble::License::isInitialized
bool isInitialized() const
Definition: License.cpp:196
Marble::MarbleModel::mapTheme
GeoSceneDocument * mapTheme()
Definition: MarbleModel.cpp:221
Marble::MarbleGraphicsItem::setSize
void setSize(const QSizeF &size)
Set the size of the item.
Definition: MarbleGraphicsItem.cpp:197
Marble::RenderPlugin::repaintNeeded
void repaintNeeded(QRegion dirtyRegion=QRegion())
This signal is emitted if an update of the view is needed.
Marble::GeoSceneHead
General properties and identifiers of a GeoScene document.
Definition: GeoSceneHead.h:42
MarbleModel.h
This file contains the headers for MarbleModel.
QWidget
Marble::PluginAuthor
Definition: PluginInterface.h:28
Marble::AbstractFloatItem::eventFilter
virtual bool eventFilter(QObject *object, QEvent *e)
Definition: AbstractFloatItem.cpp:161
Marble::FrameGraphicsItem::setBackground
void setBackground(const QBrush &background)
Changes the background brush of the item.
Definition: FrameGraphicsItem.cpp:165
Marble::GeoSceneLicense::shortLicense
QString shortLicense() const
Definition: GeoSceneLicense.cpp:27
GeoSceneDocument.h
Marble::MarbleGraphicsItem::size
QSizeF size() const
Returns the size of the item.
Definition: MarbleGraphicsItem.cpp:136
Marble::License::contextMenuEvent
void contextMenuEvent(QWidget *w, QContextMenuEvent *e)
Definition: License.cpp:223
MarbleAboutDialog.h
Marble::MarbleGraphicsItem::setLayout
void setLayout(AbstractMarbleGraphicsLayout *layout)
Set the layout of the graphics item.
Definition: MarbleGraphicsItem.cpp:146
Marble::MarbleGraphicsGridLayout::addItem
void addItem(ScreenGraphicsItem *item, int row, int column)
Definition: MarbleGraphicsGridLayout.cpp:74
QObject
Marble::GeoSceneLicense::attribution
Attribution attribution() const
Definition: GeoSceneLicense.cpp:32
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:102
Marble::License::eventFilter
bool eventFilter(QObject *, QEvent *e)
Definition: License.cpp:201
Marble::FrameGraphicsItem::NoFrame
Definition: FrameGraphicsItem.h:29
Marble::AbstractFloatItem
The abstract class for float item plugins.
Definition: AbstractFloatItem.h:48
Marble::License::initialize
void initialize()
Definition: License.cpp:133
Marble::MarbleGraphicsGridLayout
Definition: MarbleGraphicsGridLayout.h:27
Marble::License::backendTypes
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
Definition: License.cpp:86
Marble::WidgetGraphicsItem
Definition: WidgetGraphicsItem.h:28
Marble::License::copyrightYears
QString copyrightYears() const
Definition: License.cpp:116
WidgetGraphicsItem.h
Marble::GeoSceneDocument::head
const GeoSceneHead * head() const
Definition: GeoSceneDocument.cpp:86
Marble::ScreenGraphicsItem::positivePosition
QPointF positivePosition() const
Return the positive position of the ScreenGraphicsItem.
Definition: ScreenGraphicsItem.cpp:49
Marble::License::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: License.cpp:121
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::License::description
QString description() const
Returns a user description of the plugin.
Definition: License.cpp:111
Marble::License::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: License.cpp:128
Marble::GeoSceneDocument
A container for features parsed from the DGML file.
Definition: GeoSceneDocument.h:44
MarbleGraphicsGridLayout.h
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::GeoSceneLicense::Always
Definition: GeoSceneLicense.h:30
Marble::RenderPlugin::setUserCheckable
void setUserCheckable(bool isUserCheckable)
settting user checkable
Definition: RenderPlugin.cpp:159
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
Marble::GeoSceneLicense::license
QString license() const
Definition: GeoSceneLicense.cpp:22
Marble::RenderPlugin::setEnabled
void setEnabled(bool enabled)
settting enabled
Definition: RenderPlugin.cpp:137
Marble::License::name
QString name() const
Returns the user-visible name of the plugin.
Definition: License.cpp:91
Marble::License::License
License(const MarbleModel *marbleModel=0)
Definition: License.cpp:69
License.h
Marble::FrameGraphicsItem::setFrame
void setFrame(FrameType type)
Sets the type of the Frame.
Definition: FrameGraphicsItem.cpp:47
Marble::MarbleGraphicsItem::update
void update()
Marks the item and all parent items as invalid.
Definition: MarbleGraphicsItem.cpp:167
MarbleWidget.h
This file contains the headers for MarbleWidget.
Marble::License::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: License.cpp:101
Marble::MarbleGraphicsItem::layout
AbstractMarbleGraphicsLayout * layout() const
Returns the layout of the MarbleGraphicsItem.
Definition: MarbleGraphicsItem.cpp:141
Marble::RenderPlugin::enabled
bool enabled() const
is enabled
Marble::MarbleAboutDialog::Data
Definition: MarbleAboutDialog.h:38
GeoSceneLicense.h
Marble::License::version
QString version() const
Definition: License.cpp:106
Marble::License
The class that displays copyright info.
Definition: License.h:33
Marble::RenderPlugin::marbleModel
const MarbleModel * marbleModel() const
Access to the MarbleModel.
Definition: RenderPlugin.cpp:81
Marble::FrameGraphicsItem::setPadding
void setPadding(qreal width)
Set the padding of the item.
Definition: FrameGraphicsItem.cpp:130
Marble::License::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: License.cpp:96
Marble::AbstractFloatItem::contextMenu
QMenu * contextMenu()
Definition: AbstractFloatItem.cpp:230
Marble::GeoSceneLicense
Definition: GeoSceneLicense.h:23
Marble::GeoSceneLicense::Never
Definition: GeoSceneLicense.h:27
Marble::GeoSceneLicense::OptIn
Definition: GeoSceneLicense.h:29
Marble::AbstractFloatItem::setVisible
void setVisible(bool visible)
Set visibility of the float item.
Definition: AbstractFloatItem.cpp:128
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal