• 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
  • lib
  • marble
AbstractFloatItem.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 2008 Torsten Rahn <rahn@kde.org>
9 //
10 
11 // Self
12 #include "AbstractFloatItem.h"
13 
14 // Qt
15 #include <QMenu>
16 #include <QAction>
17 #include <QContextMenuEvent>
18 #include <QDialog>
19 #include <QHelpEvent>
20 
21 // Marble
22 #include "DialogConfigurationInterface.h"
23 #include "GeoPainter.h"
24 #include "MarbleDebug.h"
25 
26 namespace Marble
27 {
28 
29 class AbstractFloatItemPrivate
30 {
31  public:
32  AbstractFloatItemPrivate() : m_contextMenu( 0 )
33  {
34  }
35 
36  ~AbstractFloatItemPrivate()
37  {
38  delete m_contextMenu;
39  }
40 
41 
42  static QPen s_pen;
43  static QFont s_font;
44 
45  QMenu* m_contextMenu;
46 };
47 
48 QPen AbstractFloatItemPrivate::s_pen = QPen( Qt::black );
49 #ifdef Q_OS_MACX
50  QFont AbstractFloatItemPrivate::s_font = QFont( "Sans Serif", 10 );
51 #else
52  QFont AbstractFloatItemPrivate::s_font = QFont( "Sans Serif", 8 );
53 #endif
54 
55 AbstractFloatItem::AbstractFloatItem( const MarbleModel *marbleModel, const QPointF &point, const QSizeF &size )
56  : RenderPlugin( marbleModel ),
57  FrameGraphicsItem(),
58  d( new AbstractFloatItemPrivate() )
59 {
60  setCacheMode( ItemCoordinateCache );
61  setFrame( RectFrame );
62  setPadding( 4.0 );
63  setContentSize( size );
64  setPosition( point );
65 }
66 
67 AbstractFloatItem::~AbstractFloatItem()
68 {
69  delete d;
70 }
71 
72 QHash<QString,QVariant> AbstractFloatItem::settings() const
73 {
74  QHash<QString,QVariant> updated = RenderPlugin::settings();
75  updated["position"] = position();
76  return updated;
77 }
78 
79 void AbstractFloatItem::setSettings(const QHash<QString, QVariant> &settings)
80 {
81  if ( settings.value( "position" ).type() == QVariant::String ) {
82  // work around KConfig turning QPointFs into QStrings
83  const QStringList coordinates = settings.value( "position" ).toString().split( QLatin1Char(',') );
84  setPosition( QPointF( coordinates.at( 0 ).toFloat(), coordinates.at( 1 ).toFloat() ) );
85  }
86  else {
87  setPosition( settings.value( "position", position() ).toPointF() );
88  }
89 
90  RenderPlugin::setSettings(settings);
91 }
92 
93 RenderPlugin::RenderType AbstractFloatItem::renderType() const
94 {
95  return RenderPlugin::PanelRenderType;
96 }
97 
98 QPen AbstractFloatItem::pen() const
99 {
100  return d->s_pen;
101 }
102 
103 void AbstractFloatItem::setPen( const QPen &pen )
104 {
105  d->s_pen = pen;
106  update();
107 }
108 
109 QFont AbstractFloatItem::font() const
110 {
111  return d->s_font;
112 }
113 
114 void AbstractFloatItem::setFont( const QFont &font )
115 {
116  d->s_font = font;
117  update();
118 }
119 
120 QString AbstractFloatItem::renderPolicy() const
121 {
122  return "ALWAYS";
123 }
124 
125 QStringList AbstractFloatItem::renderPosition() const
126 {
127  return QStringList( "FLOAT_ITEM" );
128 }
129 
130 void AbstractFloatItem::setVisible( bool visible )
131 {
132  // Reimplemented since AbstractFloatItem does multiple inheritance
133  // and the (set)Visible() methods are available in both base classes!
134  RenderPlugin::setVisible( visible );
135 }
136 
137 bool AbstractFloatItem::visible() const
138 {
139  // Reimplemented since AbstractFloatItem does multiple inheritance
140  // and the (set)Visible() methods are available in both base classes!
141  return RenderPlugin::visible();
142 }
143 
144 void AbstractFloatItem::setPositionLocked( bool lock )
145 {
146  ScreenGraphicsItem::GraphicsItemFlags flags = this->flags();
147 
148  if ( lock ) {
149  flags &= ~ScreenGraphicsItem::ItemIsMovable;
150  }
151  else {
152  flags |= ScreenGraphicsItem::ItemIsMovable;
153  }
154 
155  setFlags( flags );
156 }
157 
158 bool AbstractFloatItem::positionLocked() const
159 {
160  return ( flags() & ScreenGraphicsItem::ItemIsMovable ) ? false : true;
161 }
162 
163 bool AbstractFloatItem::eventFilter( QObject *object, QEvent *e )
164 {
165  if ( !enabled() || !visible() ) {
166  return false;
167  }
168 
169  if( e->type() == QEvent::ContextMenu )
170  {
171  QWidget *widget = dynamic_cast<QWidget *>( object );
172  QContextMenuEvent *menuEvent = dynamic_cast<QContextMenuEvent *> ( e );
173  if( widget != NULL && menuEvent != NULL && contains( menuEvent->pos() ) )
174  {
175  contextMenuEvent( widget, menuEvent );
176  return true;
177  }
178  return false;
179  }
180  else if( e->type() == QEvent::ToolTip )
181  {
182  QHelpEvent *helpEvent = dynamic_cast<QHelpEvent *>( e );
183  if( helpEvent != NULL && contains( helpEvent->pos() ) )
184  {
185  toolTipEvent( helpEvent );
186  return true;
187  }
188  return false;
189  }
190  else
191  return ScreenGraphicsItem::eventFilter( object, e );
192 }
193 
194 void AbstractFloatItem::contextMenuEvent ( QWidget *w, QContextMenuEvent *e )
195 {
196  contextMenu()->exec( w->mapToGlobal( e->pos() ) );
197 }
198 
199 void AbstractFloatItem::toolTipEvent ( QHelpEvent *e )
200 {
201  Q_UNUSED( e );
202 }
203 
204 bool AbstractFloatItem::render( GeoPainter *painter, ViewportParams *viewport,
205  const QString& renderPos, GeoSceneLayer * layer )
206 {
207  Q_UNUSED( renderPos )
208  Q_UNUSED( layer )
209 
210  paintEvent( painter, viewport );
211 
212  return true;
213 }
214 
215 void AbstractFloatItem::show()
216 {
217  setVisible( true );
218 }
219 
220 void AbstractFloatItem::hide()
221 {
222  setVisible( false );
223 }
224 
225 QMenu* AbstractFloatItem::contextMenu()
226 {
227  if ( !d->m_contextMenu )
228  {
229  d->m_contextMenu = new QMenu;
230 
231  QAction *lockAction = d->m_contextMenu->addAction( QIcon(":/icons/unlock.png"), tr( "&Lock" ) );
232  lockAction->setCheckable( true );
233  lockAction->setChecked( positionLocked() );
234  connect( lockAction, SIGNAL(triggered(bool)), this, SLOT(setPositionLocked(bool)) );
235 
236  if(!(flags() & ItemIsHideable)) {
237  QAction *hideAction = d->m_contextMenu->addAction( tr( "&Hide" ) );
238  connect( hideAction, SIGNAL(triggered()), this, SLOT(hide()) );
239  }
240 
241  DialogConfigurationInterface *configInterface = qobject_cast<DialogConfigurationInterface *>( this );
242  QDialog *dialog = configInterface ? configInterface->configDialog() : 0;
243  if( dialog )
244  {
245  d->m_contextMenu->addSeparator();
246  QAction *configAction = d->m_contextMenu->addAction( QIcon(":/icons/settings-configure.png"), tr( "&Configure..." ) );
247  connect( configAction, SIGNAL(triggered()), dialog, SLOT(exec()) );
248  }
249  }
250 
251  Q_ASSERT( d->m_contextMenu );
252  return d->m_contextMenu;
253 }
254 
255 }
256 
257 #include "AbstractFloatItem.moc"
Marble::AbstractFloatItem::settings
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: AbstractFloatItem.cpp:72
Marble::RenderPlugin::visible
bool visible() const
is visible
QEvent
QWidget
Marble::AbstractFloatItem::visible
bool visible() const
Check visibility of the float item.
Definition: AbstractFloatItem.cpp:137
Marble::FrameGraphicsItem
Definition: FrameGraphicsItem.h:25
QEvent::type
Type type() const
Marble::DialogConfigurationInterface
This interface allows a plugin to provide a QWidget-based configuration dialog which is accessible wi...
Definition: DialogConfigurationInterface.h:31
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
QAction::setChecked
void setChecked(bool)
QFont
AbstractFloatItem.h
QList::at
const T & at(int i) const
Marble::AbstractFloatItem::renderPosition
virtual QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: AbstractFloatItem.cpp:125
Marble::AbstractFloatItem::pen
QPen pen() const
current pen for rendering
Definition: AbstractFloatItem.cpp:98
Marble::AbstractFloatItem::eventFilter
virtual bool eventFilter(QObject *object, QEvent *e)
Definition: AbstractFloatItem.cpp:163
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
Marble::AbstractFloatItem::renderPolicy
virtual QString renderPolicy() const
Return how the plugin settings should be used.
Definition: AbstractFloatItem.cpp:120
Marble::AbstractFloatItem::setSettings
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: AbstractFloatItem.cpp:79
QHelpEvent::pos
const QPoint & pos() const
Marble::AbstractFloatItem::positionLocked
bool positionLocked() const
Check is position locked.
Definition: AbstractFloatItem.cpp:158
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::AbstractFloatItem::show
void show()
Show the item.
Definition: AbstractFloatItem.cpp:215
QPointF
Marble::ScreenGraphicsItem::flags
GraphicsItemFlags flags() const
Returns the flags of the item.
Definition: ScreenGraphicsItem.cpp:59
Marble::RenderPlugin::PanelRenderType
Definition: RenderPlugin.h:62
Marble::AbstractFloatItem::renderType
virtual RenderType renderType() const
Render type of the plugin.
Definition: AbstractFloatItem.cpp:93
Marble::ScreenGraphicsItem::ItemIsHideable
Definition: ScreenGraphicsItem.h:35
Marble::AbstractFloatItem::~AbstractFloatItem
virtual ~AbstractFloatItem()
Definition: AbstractFloatItem.cpp:67
Marble::MarbleGraphicsItem::contains
bool contains(const QPointF &point) const
Returns true if the Item contains point in parent coordinates.
Definition: MarbleGraphicsItem.cpp:110
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
QHash< QString, QVariant >
QContextMenuEvent
QObject
Marble::MarbleGraphicsItem::ItemCoordinateCache
Definition: MarbleGraphicsItem.h:41
Marble::AbstractFloatItem::setPen
void setPen(const QPen &pen)
setting current pen for rendering
Definition: AbstractFloatItem.cpp:103
DialogConfigurationInterface.h
Marble::RenderPlugin::setVisible
void setVisible(bool visible)
settting visible
Definition: RenderPlugin.cpp:151
QString
GeoPainter.h
Marble::AbstractFloatItem::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos="FLOAT_ITEM", GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
Definition: AbstractFloatItem.cpp:204
QMenu::exec
QAction * exec()
QStringList
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
QHash::value
const T value(const Key &key) const
QMenu
QLatin1Char
Marble::ScreenGraphicsItem::setFlags
void setFlags(GraphicsItemFlags flags)
Sets the flags to flags.
Definition: ScreenGraphicsItem.cpp:64
QAction::setCheckable
void setCheckable(bool)
Marble::AbstractFloatItem::AbstractFloatItem
AbstractFloatItem(const MarbleModel *marbleModel, const QPointF &point=QPointF(10.0, 10.0), const QSizeF &size=QSizeF(150.0, 50.0))
Definition: AbstractFloatItem.cpp:55
Marble::ScreenGraphicsItem::eventFilter
virtual bool eventFilter(QObject *, QEvent *)
Definition: ScreenGraphicsItem.cpp:69
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
Marble::AbstractFloatItem::setPositionLocked
void setPositionLocked(bool lock)
Set is position locked.
Definition: AbstractFloatItem.cpp:144
Marble::ScreenGraphicsItem::ItemIsMovable
Definition: ScreenGraphicsItem.h:34
QContextMenuEvent::pos
const QPoint & pos() const
QSizeF
Marble::MarbleGraphicsItem::setCacheMode
void setCacheMode(CacheMode mode)
Set the cache mode of the item.
Definition: MarbleGraphicsItem.cpp:159
Marble::ScreenGraphicsItem::setPosition
void setPosition(const QPointF &position)
Set the position of the ScreenGraphicsItem.
Definition: ScreenGraphicsItem.cpp:44
QAction
Marble::AbstractFloatItem::setFont
void setFont(const QFont &font)
setting current font for rendering
Definition: AbstractFloatItem.cpp:114
Marble::ScreenGraphicsItem
Definition: ScreenGraphicsItem.h:30
Marble::FrameGraphicsItem::setFrame
void setFrame(FrameType type)
Sets the type of the Frame.
Definition: FrameGraphicsItem.cpp:43
Marble::MarbleGraphicsItem::update
void update()
Marks the item and all parent items as invalid.
Definition: MarbleGraphicsItem.cpp:167
Marble::AbstractFloatItem::hide
void hide()
Hide the item.
Definition: AbstractFloatItem.cpp:220
Marble::ScreenGraphicsItem::position
QPointF position() const
Return the position of the ScreenGraphicsItem.
Definition: ScreenGraphicsItem.cpp:39
QPen
QDialog
Marble::AbstractFloatItem::font
QFont font() const
current font for rendering
Definition: AbstractFloatItem.cpp:109
Marble::MarbleGraphicsItem::paintEvent
bool paintEvent(QPainter *painter, const ViewportParams *viewport)
Paints the item on the screen in view coordinates.
Definition: MarbleGraphicsItem.cpp:38
Marble::RenderPlugin::enabled
bool enabled() const
is enabled
Marble::FrameGraphicsItem::RectFrame
Definition: FrameGraphicsItem.h:30
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)
Marble::FrameGraphicsItem::setContentSize
void setContentSize(const QSizeF &size)
Sets the size of the content of the item.
Definition: FrameGraphicsItem.cpp:200
Marble::RenderPlugin::settings
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: RenderPlugin.cpp:185
Marble::AbstractFloatItem::contextMenuEvent
virtual void contextMenuEvent(QWidget *w, QContextMenuEvent *e)
Definition: AbstractFloatItem.cpp:194
QHelpEvent
Marble::RenderPlugin::RenderType
RenderType
A Type of plugin.
Definition: RenderPlugin.h:59
Marble::AbstractFloatItem::contextMenu
QMenu * contextMenu()
Definition: AbstractFloatItem.cpp:225
Marble::AbstractFloatItem::toolTipEvent
virtual void toolTipEvent(QHelpEvent *e)
Definition: AbstractFloatItem.cpp:199
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
Marble::RenderPlugin::setSettings
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: RenderPlugin.cpp:195
QIcon
Marble::DialogConfigurationInterface::configDialog
virtual QDialog * configDialog()=0
Returns a pointer to the configuration dialog of the plugin.
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:38 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