• 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
  • fileview
FileViewFloatItem.cpp
Go to the documentation of this file.
1 
2 //
3 // This file is part of the Marble Virtual Globe.
4 //
5 // This program is free software licensed under the GNU LGPL. You can
6 // find a copy of this license in LICENSE.txt in the top directory of
7 // the source code.
8 //
9 // Copyright 2008 Patrick Spendrin <ps_ml@gmx.de>
10 //
11 
12 #include "FileViewFloatItem.h"
13 
14 #include <QRect>
15 #include <QPoint>
16 #include <QApplication>
17 #include <QFileDialog>
18 #include <QListView>
19 #include <QListWidget>
20 #include <QMenu>
21 #include <QPixmap>
22 #include <QSlider>
23 #include <QMouseEvent>
24 
25 #include "MarbleDebug.h"
26 #include "FileViewModel.h"
27 #include "GeoPainter.h"
28 #include "ViewportParams.h"
29 #include "MarbleWidget.h"
30 
31 
32 using namespace Marble;
33 
34 FileViewFloatItem::FileViewFloatItem(const QPointF &point,
35  const QSizeF &size) :
36  AbstractFloatItem(point, size), m_marbleWidget(0),
37  m_fileView(0), m_fileViewParent(0),
38  m_repaintScheduled(true), m_persIndex(0)
39 {
40  // Plugin is not enabled by default
41  setEnabled(false);
42 }
43 
44 FileViewFloatItem::~FileViewFloatItem()
45 {
46  delete m_fileViewParent;
47 }
48 
49 QStringList FileViewFloatItem::backendTypes() const
50 {
51  return QStringList("fileview");
52 }
53 
54 QString FileViewFloatItem::name() const
55 {
56  return tr("File View");
57 }
58 
59 QString FileViewFloatItem::guiString() const
60 {
61  return tr("&File View");
62 }
63 
64 QString FileViewFloatItem::nameId() const
65 {
66  return QString("fileview");
67 }
68 
69 QString FileViewFloatItem::description() const
70 {
71  return tr("A list of currently opened files");
72 }
73 
74 QIcon FileViewFloatItem::icon() const
75 {
76  return QIcon();
77 }
78 
79 void FileViewFloatItem::initialize()
80 {
81  m_fileViewParent = new QWidget(0);
82  m_fileViewParent->setFixedSize(size().toSize() - QSize(2 * padding(), 2
83  * padding()));
84  m_fileView = new QListView(m_fileViewParent);
85  m_fileView->resize(100, 240);
86  m_fileView->setResizeMode(QListView::Adjust);
87  m_fileView->setContextMenuPolicy( Qt::CustomContextMenu );
88  connect(m_fileView, SIGNAL(customContextMenuRequested(QPoint)),
89  this, SLOT(contextMenu(QPoint)));
90 }
91 
92 bool FileViewFloatItem::isInitialized() const
93 {
94  return m_fileViewParent != 0;
95 }
96 
97 QPainterPath FileViewFloatItem::backgroundShape() const
98 {
99  QPainterPath path;
100  QSizeF paintedSize = paintedRect().size();
101  path.addRoundedRect( QRectF( 0.0, 0.0, paintedSize.width() - 1, paintedSize.height() - 1 ), 6, 6 );
102  return path;
103 }
104 
105 void FileViewFloatItem::changeViewport( ViewportParams *viewport )
106 {
107  Q_UNUSED( viewport );
108  update();
109 }
110 
111 void FileViewFloatItem::paintContent( GeoPainter *painter, ViewportParams *viewport,
112  const QString& renderPos, GeoSceneLayer * layer)
113 {
114  Q_UNUSED( viewport );
115  Q_UNUSED( layer );
116  Q_UNUSED( renderPos );
117 
118  if( !m_fileView->model() ) {
119  m_fileView->setModel(marbleModel()->fileViewModel());
120  }
121  painter->end();
122  // Paint widget without a background
123  m_fileViewParent->render( painter->device(),
124  QPoint( padding(), padding() ), QRegion(),QWidget::RenderFlags(QWidget::DrawChildren));
125 
126  painter->begin( painter->device() );
127  m_fileView->update();
128 }
129 
130 bool FileViewFloatItem::eventFilter(QObject *object, QEvent *e)
131 {
132  if ( !enabled() || !visible() ) {
133  return false;
134  }
135 
136  MarbleWidget *widget = dynamic_cast<MarbleWidget*> (object);
137  if ( !widget ) {
138  return AbstractFloatItem::eventFilter(object, e);
139  }
140 
141  if ( m_marbleWidget != widget ) {
142  // Delayed initialization
143  m_marbleWidget = widget;
144  }
145 
146  Q_ASSERT( m_marbleWidget );
147  // Mouse events are forwarded to the underlying widget
148  QMouseEvent *event = static_cast<QMouseEvent*> (e);
149  QRectF floatItemRect = QRectF( positivePosition(), size() );
150 
151  QPoint shiftedPos = event->pos() - floatItemRect.topLeft().toPoint()
152  - QPoint( padding(), padding() );
153  if( e->type() == QEvent::MouseMove ) {
154  m_itemPosition = event->globalPos();
155  }
156 
157  if( floatItemRect.contains( event->pos() ) ) {
158  QWidget *child = m_fileViewParent->childAt( shiftedPos );
159 
160  if( child ) {
161  m_marbleWidget->setCursor( Qt::ArrowCursor );
162 
163  // there needs to be some extra handling for the scrollbars
164  // these need some special treatment due to them not forwarding
165  // their mouseevents to their scrollbars.
166  if( reinterpret_cast<QScrollBar*>( child ) == m_fileView->horizontalScrollBar() ) {
167  shiftedPos -= QPoint( 0, m_fileView->viewport()->size().height() );
168  } else if( reinterpret_cast<QScrollBar*>( child ) == m_fileView->verticalScrollBar() ) {
169  shiftedPos -= QPoint( m_fileView->viewport()->size().width(), 0 );
170  }
171  QMouseEvent shiftedEvent( e->type(), shiftedPos,
172  event->globalPos(), event->button(), event->buttons(),
173  event->modifiers() );
174  if( QApplication::sendEvent(child, &shiftedEvent) ) {
175  if( e->type() == QEvent::MouseButtonPress ||
176  e->type() == QEvent::MouseButtonRelease ||
177  e->type() == QEvent::MouseButtonDblClick ||
178  e->type() == QEvent::MouseMove )
179  updateFileView();
180  return true;
181  }
182 
183  }
184  }
185 
186  return AbstractFloatItem::eventFilter(object, e);
187 }
188 
189 void FileViewFloatItem::selectTheme(QString theme)
190 {
191  Q_UNUSED(theme);
192 
193  if ( m_marbleWidget ) {
194  }
195 }
196 
197 void FileViewFloatItem::updateFileView()
198 {
199  if (m_marbleWidget)
200  {
201  // Trigger a repaint of the float item. Otherwise button state updates
202  // are delayed
203  QRectF floatItemRect = QRectF(positivePosition(), size()).toRect();
204  QRegion dirtyRegion(floatItemRect.toRect());
205 
206  m_marbleWidget->update(dirtyRegion);
207  }
208 }
209 
210 void FileViewFloatItem::contextMenu( const QPoint& pos )
211 {
212  if( !m_marbleWidget )
213  return;
214 
215  QPointer<QMenu> test = new QMenu( m_fileView );
216  // We need the global position to move the menu.
217  // pos contains the relative position.
218  test->move( m_itemPosition );
219  connect( test->addAction( tr( "Open file..." ) ), SIGNAL(triggered()),
220  this, SLOT(addFile()) );
221  connect( test->addAction( tr( "Close this file" ) ), SIGNAL(triggered()),
222  this, SLOT(removeFile()) );
223  m_persIndex = new QPersistentModelIndex( m_fileView->indexAt( pos ) );
224  test->exec();
225  delete test;
226 }
227 
228 void FileViewFloatItem::addFile()
229 {
230  QString fileName;
231  fileName = QFileDialog::getOpenFileName(m_marbleWidget, tr("Open File"),
232  QString(),
233  tr("All Supported Files (*.gpx *.kml *.pnt);;GPS Data (*.gpx);;Google Earth KML (*.kml);PNT Data (*.pnt)"));
234 
235  if ( ! fileName.isEmpty() ) {
236  m_marbleWidget->model()->addGeoDataFile( fileName );
237  }
238 }
239 
240 void FileViewFloatItem::removeFile()
241 {
242  //reinterpret_cast<FileViewModel*>(m_fileView->model())->setSelectedIndex( *m_persIndex );
243  mDebug() << m_fileView->model()->data( *m_persIndex, Qt::DisplayRole ).toString();
244  // close selected file
245  reinterpret_cast<FileViewModel*>(m_fileView->model())->closeFile();
246 }
247 
248 
249 Q_EXPORT_PLUGIN2(FileViewFloatItem, FileViewFloatItem)
250 
251 #include "FileViewFloatItem.moc"
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
Marble::FileViewFloatItem::paintContent
void paintContent(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Definition: FileViewFloatItem.cpp:111
QEvent
QWidget
Marble::FileViewFloatItem::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: FileViewFloatItem.cpp:64
Marble::AbstractFloatItem::visible
bool visible() const
Check visibility of the float item.
Definition: AbstractFloatItem.cpp:137
QEvent::type
Type type() const
QRectF::toRect
QRect toRect() const
QPainter::end
bool end()
QWidget::setCursor
void setCursor(const QCursor &)
Marble::FileViewFloatItem::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: FileViewFloatItem.cpp:59
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
QAbstractItemView::setModel
virtual void setModel(QAbstractItemModel *model)
QWidget::childAt
QWidget * childAt(int x, int y) const
QRectF::size
QSizeF size() const
QPainterPath::addRoundedRect
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
Marble::AbstractFloatItem::eventFilter
virtual bool eventFilter(QObject *object, QEvent *e)
Definition: AbstractFloatItem.cpp:163
QPointer< QMenu >
QAbstractScrollArea::viewport
QWidget * viewport() const
Marble::MarbleGraphicsItem::size
QSizeF size() const
Returns the size of the item.
Definition: MarbleGraphicsItem.cpp:136
QPoint
QMouseEvent
QWidget::RenderFlags
typedef RenderFlags
Marble::FileViewFloatItem::backgroundShape
virtual QPainterPath backgroundShape() const
Returns the shape of the background.
Definition: FileViewFloatItem.cpp:97
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QWidget::update
void update()
Marble::FileViewFloatItem::name
QString name() const
Returns the user-visible name of the plugin.
Definition: FileViewFloatItem.cpp:54
QPointF
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
QObject::event
virtual bool event(QEvent *e)
QListView
QWidget::resize
void resize(int w, int h)
Marble::MarbleModel::addGeoDataFile
void addGeoDataFile(const QString &filename)
Handle file loading into the treeModel.
Definition: MarbleModel.cpp:725
Marble::FileViewFloatItem::eventFilter
bool eventFilter(QObject *object, QEvent *e)
Definition: FileViewFloatItem.cpp:130
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
QAbstractItemView::update
void update(const QModelIndex &index)
Marble::FrameGraphicsItem::paintedRect
QRectF paintedRect() const
Definition: FrameGraphicsItem.cpp:185
Marble::FileViewFloatItem::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: FileViewFloatItem.cpp:74
QObject
Marble::AbstractFloatItem
The abstract class for float item plugins.
Definition: AbstractFloatItem.h:45
Marble::MarbleWidget::model
MarbleModel * model()
Return the model that this view shows.
Definition: MarbleWidget.cpp:289
QRectF::topLeft
QPointF topLeft() const
QString::isEmpty
bool isEmpty() const
QCoreApplication::sendEvent
bool sendEvent(QObject *receiver, QEvent *event)
Marble::FileViewFloatItem::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: FileViewFloatItem.cpp:49
QPainter::device
QPaintDevice * device() const
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
QString
GeoPainter.h
QAbstractScrollArea::verticalScrollBar
QScrollBar * verticalScrollBar() const
Marble::FrameGraphicsItem::padding
qreal padding() const
Returns the padding of the item.
Definition: FrameGraphicsItem.cpp:121
QStringList
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::ScreenGraphicsItem::positivePosition
QPointF positivePosition() const
Return the positive position of the ScreenGraphicsItem.
Definition: ScreenGraphicsItem.cpp:49
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::FileViewFloatItem::~FileViewFloatItem
~FileViewFloatItem()
Definition: FileViewFloatItem.cpp:44
QMenu
QSize
QWidget::setFixedSize
void setFixedSize(const QSize &s)
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
ViewportParams.h
This file contains the headers for ViewportParams.
QPersistentModelIndex
QPainterPath
QListView::indexAt
virtual QModelIndex indexAt(const QPoint &p) const
Marble::RenderPlugin::setEnabled
void setEnabled(bool enabled)
settting enabled
Definition: RenderPlugin.cpp:139
QSizeF
QPointF::toPoint
QPoint toPoint() const
Marble::FileViewFloatItem::FileViewFloatItem
FileViewFloatItem(const QPointF &point=QPointF(-1, 10), const QSizeF &size=QSizeF(110.0, 250.0))
Definition: FileViewFloatItem.cpp:34
QRectF
Marble::FileViewFloatItem::description
QString description() const
Returns a user description of the plugin.
Definition: FileViewFloatItem.cpp:69
FileViewFloatItem.h
Marble::FileViewFloatItem
Provides a float item with a list of opened files.
Definition: FileViewFloatItem.h:31
Marble::MarbleGraphicsItem::update
void update()
Marks the item and all parent items as invalid.
Definition: MarbleGraphicsItem.cpp:167
QAbstractScrollArea::horizontalScrollBar
QScrollBar * horizontalScrollBar() const
MarbleWidget.h
This file contains the headers for MarbleWidget.
QRectF::contains
bool contains(const QPointF &point) const
Marble::RenderPlugin::enabled
bool enabled() const
is enabled
QFileDialog::getOpenFileName
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
Marble::FileViewFloatItem::changeViewport
void changeViewport(ViewportParams *viewport)
Definition: FileViewFloatItem.cpp:105
QAbstractItemView::model
QAbstractItemModel * model() const
Marble::FileViewFloatItem::isInitialized
bool isInitialized() const
Definition: FileViewFloatItem.cpp:92
QSizeF::height
qreal height() const
Marble::RenderPlugin::marbleModel
const MarbleModel * marbleModel() const
Access to the MarbleModel.
Definition: RenderPlugin.cpp:83
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QPainter::begin
bool begin(QPaintDevice *device)
QListView::setResizeMode
void setResizeMode(ResizeMode mode)
Marble::AbstractFloatItem::contextMenu
QMenu * contextMenu()
Definition: AbstractFloatItem.cpp:225
QVariant::toString
QString toString() const
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::FileViewFloatItem::initialize
void initialize()
Definition: FileViewFloatItem.cpp:79
QSizeF::width
qreal width() const
QRegion
QWidget::render
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QFlags< QWidget::RenderFlag > renderFlags)
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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