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

marble

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