int main(int argc, char** argv) { QApplication app(argc,argv); // Create a Marble QWidget without a parent MarbleWidget *mapWidget = new MarbleWidget(); // Load the OpenStreetMap map mapWidget->setMapThemeId("earth/bluemarble/bluemarble.dgml"); mapWidget->setProjection( Mercator ); // Enable the cloud cover and enable the country borders mapWidget->setShowClouds( true ); mapWidget->setShowBorders( true ); // Hide the FloatItems: Compass and StatusBar mapWidget->setShowOverviewMap(false); mapWidget->setShowScaleBar(false); foreach ( AbstractFloatItem * floatItem, mapWidget->floatItems() ) if ( floatItem && floatItem->nameId() == "compass" ) { // Put the compass onto the left hand side floatItem->setPosition( QPoint( 10, 10 ) ); // Make the content size of the compass smaller floatItem->setContentSize( QSize( 50, 50 ) ); } mapWidget->resize( 400, 300 ); mapWidget->show(); return app.exec(); }
int main(int argc, char** argv) { QApplication app(argc,argv); MarbleWidget *mapWidget = new MarbleWidget; // Create and register our paint layer MyPaintLayer* layer = new MyPaintLayer(mapWidget); // Uncomment for older versions of Marble: // mapWidget->map()->model()->addLayer(layer); mapWidget->addLayer(layer); // Install an event handler: Pressing + will change the layer we paint at mapWidget->installEventFilter(layer); // Finish widget creation. mapWidget->setMapThemeId("earth/bluemarble/bluemarble.dgml"); mapWidget->show(); // Update each second to give the clock second resolution QTimer seconds; seconds.setInterval(1000); QObject::connect(&seconds, SIGNAL(timeout()), mapWidget, SLOT(update())); seconds.start(); return app.exec(); }
PreviewDialog::PreviewDialog( QWidget* parent, const QString& mapThemeId ) : QDialog( parent ), m_mapThemeId( mapThemeId ) { QGridLayout *layout = new QGridLayout(); MarbleWidget *widget = new MarbleWidget(); MarbleNavigator *navigator = new MarbleNavigator(); connect( navigator, SIGNAL(goHome()), widget, SLOT(goHome()) ); connect( navigator, SIGNAL(moveUp()), widget, SLOT(moveUp()) ); connect( navigator, SIGNAL(moveDown()), widget, SLOT(moveDown()) ); connect( navigator, SIGNAL(moveLeft()), widget, SLOT(moveLeft()) ); connect( navigator, SIGNAL(moveRight()), widget, SLOT(moveRight()) ); connect( navigator, SIGNAL(zoomIn()), widget, SLOT(zoomIn()) ); connect( navigator, SIGNAL(zoomOut()), widget, SLOT(zoomOut()) ); connect( navigator, SIGNAL(zoomChanged(int)), widget, SLOT(setZoom(int)) ); widget->setMapThemeId( m_mapThemeId ); widget->setZoom( 1000 ); layout->addWidget( navigator, 1, 1 ); layout->addWidget( widget, 1, 2 ); layout->setMargin( 0 ); layout->setSpacing( 0 ); this->setLayout( layout ); this->setMinimumSize( 640, 480 ); this->setWindowTitle( tr( "Preview Map" ) ); }
void MarbleWidgetTest::mouseMove() { MarbleWidget widget; widget.setMapThemeId("earth/srtm/srtm.dgml"); QTest::mouseMove( &widget ); QThreadPool::globalInstance()->waitForDone(); // wait for all runners to terminate }
void MarbleWidgetTest::setMapTheme() { QFETCH( QString, mapThemeId ); MarbleWidget widget; widget.setMapThemeId( mapThemeId ); QCOMPARE( widget.mapThemeId(), mapThemeId ); QThreadPool::globalInstance()->waitForDone(); // wait for all runners to terminate }
bool PopupItem::eventFilter( QObject *object, QEvent *e ) { MarbleWidget *widget = dynamic_cast<MarbleWidget*> ( object ); if ( !widget ) { return BillboardGraphicsItem::eventFilter( object, e ); } if ( e->type() == QEvent::MouseButtonDblClick || e->type() == QEvent::MouseMove || e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease ) { // Mouse events are forwarded to the underlying widget QMouseEvent *event = static_cast<QMouseEvent*> ( e ); QPoint const shiftedPos = transform( event->pos() ); bool const forcedMouseRelease = m_needMouseRelease && e->type() == QEvent::MouseButtonRelease; if ( !shiftedPos.isNull() || forcedMouseRelease ) { if ( !m_needMouseRelease && e->type() == QEvent::MouseButtonPress ) { m_needMouseRelease = true; } else if ( forcedMouseRelease ) { m_needMouseRelease = false; } widget->setCursor( Qt::ArrowCursor ); // transform to children's coordinates QMouseEvent shiftedEvent = QMouseEvent( e->type(), shiftedPos, event->globalPos(), event->button(), event->buttons(), event->modifiers() ); if ( QApplication::sendEvent( m_webView, &shiftedEvent ) ) { widget->setCursor( m_webView->cursor() ); emit dirty(); return true; } } } else if ( e->type() == QEvent::Wheel ) { // Wheel events are forwarded to the underlying widget QWheelEvent *event = static_cast<QWheelEvent*> ( e ); QPoint const shiftedPos = transform( event->pos() ); if ( !shiftedPos.isNull() ) { widget->setCursor( Qt::ArrowCursor ); QWheelEvent shiftedEvent = QWheelEvent( shiftedPos, event->globalPos(), event->delta(), event->buttons(), event->modifiers() ); if ( QApplication::sendEvent( m_webView, &shiftedEvent ) ) { widget->setCursor( m_webView->cursor() ); emit dirty(); return true; } } } return BillboardGraphicsItem::eventFilter( object, e ); }
void TourWidgetPrivate::captureTour() { MarbleWidget* widget = new MarbleWidget; widget->setMapThemeId( m_widget->mapThemeId() ); widget->resize( 1280, 720 ); m_widget->model()->treeModel()->removeDocument(m_document); widget->model()->treeModel()->addDocument(m_document); GeoDataTour* tour = findTour( m_document ); TourPlayback* playback = new TourPlayback; playback->setMarbleWidget( widget ); playback->setTour( tour ); m_tourUi.m_listView->setModel( widget->model()->treeModel() ); if( tour ){ m_tourUi.m_listView->setRootIndex( widget->model()->treeModel()->index( tour->playlist() ) ); m_tourUi.m_listView->repaint(); TourCaptureDialog* tourCaptureDialog = new TourCaptureDialog( widget, m_widget ); tourCaptureDialog->setDefaultFilename( tour->name() ); tourCaptureDialog->setTourPlayback( playback ); tourCaptureDialog->exec(); } delete playback; widget->model()->treeModel()->removeDocument(m_document); m_widget->model()->treeModel()->addDocument(m_document); updateRootIndex(); delete widget; }
int main(int argc, char** argv) { QApplication app(argc,argv); // Create a Marble QWidget without a parent MarbleWidget *mapWidget = new MarbleWidget(); // Load the OpenStreetMap map mapWidget->setMapThemeId(QStringLiteral("earth/openstreetmap/openstreetmap.dgml")); mapWidget->setProjection( Mercator ); // Access the shared route request (start, destination and parameters) RoutingManager* manager = mapWidget->model()->routingManager(); RouteRequest* request = manager->routeRequest(); // Use default routing settings for cars request->setRoutingProfile( manager->defaultProfile( RoutingProfile::Motorcar ) ); // Set start and destination request->append( GeoDataCoordinates( 8.38942, 48.99738, 0.0, GeoDataCoordinates::Degree ) ); request->append( GeoDataCoordinates( 8.42002, 49.0058, 0.0, GeoDataCoordinates::Degree ) ); // Calculate the route manager->retrieveRoute(); // Center the map on the route start point and show it mapWidget->centerOn( request->at( 0 ) ); mapWidget->setDistance( 0.75 ); mapWidget->show(); return app.exec(); }
Marble::MarbleModel * NavigationPrivate::model() const { if (m_marbleQuickItem != nullptr) { return m_marbleQuickItem->model(); } else if (m_marbleWidget != nullptr) { return m_marbleWidget->model(); } return nullptr; }
bool License::eventFilter( QObject *object, QEvent *event ) { if ( !enabled() || !visible() ) return false; MarbleWidget *widget = dynamic_cast<MarbleWidget*>( object ); if ( !widget ) { return AbstractFloatItem::eventFilter( object,event ); } if( event->type() == QEvent::MouseMove ) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event ); QRectF floatItemRect = QRectF( positivePosition(), size() ); if ( floatItemRect.contains( mouseEvent->pos() ) ) { widget->setCursor( QCursor( Qt::ArrowCursor ) ); return true; } } return AbstractFloatItem::eventFilter( object, event ); }
void MarbleWidgetTest::switchMapThemes() { MarbleWidget widget; widget.setMapThemeId( "earth/plain/plain.dgml" ); QCOMPARE( widget.mapThemeId(), QString( "earth/plain/plain.dgml" ) ); widget.setMapThemeId( "earth/srtm/srtm.dgml" ); QCOMPARE( widget.mapThemeId(), QString( "earth/srtm/srtm.dgml" ) ); widget.setMapThemeId( "earth/openstreetmap/openstreetmap.dgml" ); QCOMPARE( widget.mapThemeId(), QString( "earth/openstreetmap/openstreetmap.dgml" ) ); widget.setMapThemeId( "earth/plain/plain.dgml" ); QCOMPARE( widget.mapThemeId(), QString( "earth/plain/plain.dgml" ) ); QThreadPool::globalInstance()->waitForDone(); // wait for all runners to terminate }
int main(int argc, char** argv) { QApplication app(argc,argv); QFileInfo inputFile( app.arguments().last() ); if ( app.arguments().size() < 2 || !inputFile.exists() ) { qWarning() << "Usage: " << app.arguments().first() << "file.png"; return 1; } // Create a Marble QWidget without a parent MarbleWidget *mapWidget = new MarbleWidget(); // Load the Satellite map mapWidget->setMapThemeId( "earth/bluemarble/bluemarble.dgml" ); // Create a bounding box from the given corner points GeoDataLatLonBox box( 55, 48, 14.5, 6, GeoDataCoordinates::Degree ); box.setRotation( 0, GeoDataCoordinates::Degree ); // Create an overlay and assign the image to render and its bounding box to it GeoDataGroundOverlay *overlay = new GeoDataGroundOverlay; overlay->setLatLonBox( box ); overlay->setIcon( QImage( inputFile.absoluteFilePath() ) ); // Create a document as a container for the overlay GeoDataDocument *document = new GeoDataDocument(); document->append( overlay ); // Add the document to MarbleWidget's tree model mapWidget->model()->treeModel()->addDocument( document ); mapWidget->show(); return app.exec(); }
bool MyPaintLayer::render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer ) { // Have window title reflect the current paint layer m_widget->setWindowTitle(renderPosition().first()); GeoDataCoordinates home(8.4, 48.0, 0.0, GeoDataCoordinates::Degree); QTime now = QTime::currentTime(); painter->setRenderHint(QPainter::Antialiasing, true); // Large circle built by 60 small circles painter->setPen( QPen(QBrush(QColor::fromRgb(255,255,255,200)), 3.0, Qt::SolidLine, Qt::RoundCap ) ); for (int i=0; i<60; ++i) painter->drawEllipse(approximate(home, M_PI * i / 30.0, 1.0), 5, 5); // hour, minute, second hand painter->drawPolyline(GeoDataLineString() << home << approximate(home, M_PI * now.minute() / 30.0, 0.75)); painter->drawPolyline(GeoDataLineString() << home << approximate(home, M_PI * now.hour() / 6.0, 0.5)); painter->setPen(QPen(QBrush(Qt::red), 4.0, Qt::SolidLine, Qt::RoundCap )); painter->drawPolyline(GeoDataLineString() << home << approximate(home, M_PI * now.second() / 30.0, 1.0)); return true; }
bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e ) { MarbleWidget *widget = dynamic_cast<MarbleWidget*>(object); if ( !widget ) { return MarbleGraphicsItem::eventFilter( object, e ); } if ( !p()->m_floatItemMoving ) { if ( MarbleGraphicsItem::eventFilter( object, e ) ) { return true; } if ( !visible() || !p()->isMovable() ) { return false; } if ( e->type() == QEvent::MouseMove ) { return false; } // Move ScreenGraphicsItem if ( e->type() == QEvent::MouseButtonPress ) { QMouseEvent *event = static_cast<QMouseEvent*>(e); // Click and move above a float item triggers moving the float item if ( contains( event->pos() ) ) { if ( event->button() == Qt::LeftButton ) { p()->m_floatItemMoveStartPos = event->pos(); p()->m_floatItemMoving = true; return true; } } } return false; } else { // Move ScreenGraphicsItem bool cursorAboveFloatItem = false; if ( e->type() == QEvent::MouseMove || e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease ) { QMouseEvent *event = static_cast<QMouseEvent*>( e ); // The rect the item was painted on before. We add one pixel as antialiasing could // result into painting on these pixels to. QRectF floatItemRect = QRectF( positivePosition() - QPoint( 1, 1 ), size() + QSize( 2, 2 ) ); // Click and move above a float item triggers moving the float item if ( contains( event->pos() ) ) { cursorAboveFloatItem = true; if ( e->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton ) { p()->m_floatItemMoveStartPos = event->pos(); return true; } } if ( e->type() == QEvent::MouseMove && event->buttons() & Qt::LeftButton && p()->isMovable() ) { p()->m_floatItemMoving = true; const QPoint &point = event->pos(); QPointF position = positivePosition(); qreal newX = position.x()+point.x()-p()->m_floatItemMoveStartPos.x(); qreal newY = position.y()+point.y()-p()->m_floatItemMoveStartPos.y(); if ( newX >= 0 && newY >= 0 ) { // docking behavior const qreal dockArea = 60.0; // Alignment area width/height const qreal dockJump = 30.0; // Alignment indicator jump size if ( widget->width()-size().width()-newX < dockArea ) { newX = qMin( qreal( -1.0 ), size().width() + newX-widget->width() ); if ( p()->m_floatItemMoveStartPos.x() < event->pos().x() ) { // Indicate change to right alignment with a short jump newX = qMax( newX, -(dockArea-dockJump) ); } } if ( widget->height()-size().height()-newY < dockArea ) { newY = qMin( qreal( -1.0 ), size().height() + newY-widget->height() ); if (p()->m_floatItemMoveStartPos.y()<event->pos().y()) { // Indicate change to bottom alignment with a short jump newY = qMax( newY, -( dockArea - dockJump ) ); } } setPosition( QPointF( newX,newY ) ); // The rect the item will be painted on now. We add one pixel as // antialiasing could result into painting on these pixels to. QRect newFloatItemRect = QRectF( positivePosition() - QPoint( 1, 1 ), size() + QSize( 2, 2 ) ).toRect(); p()->m_floatItemMoveStartPos = event->pos(); QRegion dirtyRegion( floatItemRect.toRect() ); dirtyRegion = dirtyRegion.united( newFloatItemRect ); widget->setAttribute( Qt::WA_NoSystemBackground, false ); widget->update(dirtyRegion); widget->setAttribute( Qt::WA_NoSystemBackground, widget->viewport()->mapCoversViewport() ); return true; } } if ( e->type() == QEvent::MouseButtonRelease ) { p()->m_floatItemMoving = false; } // Adjusting Cursor shape if ( cursorAboveFloatItem || p()->m_floatItemMoving ) { widget->setCursor(QCursor(Qt::SizeAllCursor)); return true; } } return MarbleGraphicsItem::eventFilter( object, e ); } }
EditPlacemarkDialog::EditPlacemarkDialog( GeoDataPlacemark *placemark, const QHash<qint64, OsmPlacemarkData> *relations, QWidget *parent ) : QDialog( parent ), d( new Private( placemark ) ) { d->setupUi( this ); // Store initial style so that it can be restored if the 'Cancel' button is pressed. d->m_initialStyle = *placemark->style(); d->m_initialVisualCategory = placemark->visualCategory(); d->m_hadInitialOsmData = placemark->hasOsmData(); if ( d->m_hadInitialOsmData ) { d->m_initialOsmData = placemark->osmData(); } // If the placemark has just been created, assign it a default name. if ( placemark->name().isNull() ) { placemark->setName( tr("Untitled Placemark") ); } // Setup id, name, icon link and latitude/longitude values. d->m_header->setId( placemark->id() ); d->m_initialId = placemark->id(); d->m_header->setName( placemark->name() ); d->m_initialName = placemark->name(); d->m_isPlacemarkVisible->setChecked( placemark->isVisible() ); d->m_initialIsPlacemarkVisible = placemark->isVisible(); d->m_header->setIconLink( placemark->style()->iconStyle().iconPath() ); d->m_header->setTargetId( placemark->targetId() ); d->m_initialTargetId = placemark->targetId(); MarbleWidget* marbleWidget = dynamic_cast<MarbleWidget*>( parent ); if( marbleWidget != 0 ) { const AngleUnit defaultAngleUnit = marbleWidget->defaultAngleUnit(); const GeoDataCoordinates::Notation notation = (defaultAngleUnit == DecimalDegree) ? GeoDataCoordinates::Decimal : (defaultAngleUnit == DMSDegree) ? GeoDataCoordinates::DMS : /* else, UTM */ GeoDataCoordinates::DMS; d->m_header->setNotation( notation ); } connect( d->m_header, SIGNAL(valueChanged()), this, SLOT( updateTextAnnotation()) ); d->m_formattedTextWidget->setText( placemark->description() ); d->m_initialDescription = placemark->description(); d->m_initialDescriptionIsCDATA = placemark->descriptionIsCDATA(); d->m_isBalloonVisible->setChecked( placemark->isBalloonVisible() ); d->m_initialIsBaloonVisible = placemark->isBalloonVisible(); d->m_header->setLatitude( placemark->coordinate().latitude( GeoDataCoordinates::Degree ) ); d->m_header->setLongitude( placemark->coordinate().longitude( GeoDataCoordinates::Degree ) ); d->m_initialCoords = GeoDataCoordinates( d->m_header->longitude(), d->m_header->latitude(), 0, GeoDataCoordinates::Degree ); // There's no point showing Relations and Tags tabs if the editor was not // loaded from the annotate plugin ( loaded from tourWidget.. ) if ( relations ) { // Adding the osm tag editor widget tab d->m_osmTagEditorWidget = new OsmTagEditorWidget( placemark, this ); d->tabWidget->addTab( d->m_osmTagEditorWidget, tr( "Tags" ) ); QObject::connect( d->m_osmTagEditorWidget, SIGNAL( placemarkChanged( GeoDataFeature* ) ), this, SLOT( updateTextAnnotation() ) ); // Adding the osm relation editor widget tab d->m_osmRelationManagerWidget = new OsmRelationManagerWidget( placemark, relations, this ); d->tabWidget->addTab( d->m_osmRelationManagerWidget, tr( "Relations" ) ); QObject::connect( d->m_osmRelationManagerWidget, SIGNAL( relationCreated( const OsmPlacemarkData& ) ), this, SIGNAL( relationCreated( const OsmPlacemarkData& ) ) ); } // Adding the elevation widget tab d->m_elevationWidget = new Ui::ElevationWidget; QWidget *elevationTab = new QWidget; d->m_elevationWidget->setupUi( elevationTab ); d->tabWidget->addTab( elevationTab, tr("Elevation") ); qreal altitude = d->m_placemark->coordinate().altitude(); MarbleLocale *locale = MarbleGlobal::getInstance()->locale(); if ( altitude == 0.0 ) { switch ( locale->measurementSystem() ) { case MarbleLocale::MetricSystem: d->m_elevationUnit = MarbleLocale::Meter; break; case MarbleLocale::ImperialSystem: d->m_elevationUnit = MarbleLocale::Foot; break; case MarbleLocale::NauticalSystem: d->m_elevationUnit = MarbleLocale::NauticalMile; break; } d->m_elevationWidget->elevationSpinBox->setSuffix( locale->unitAbbreviation((d->m_elevationUnit)) ); } else { qreal convertedAltitude; const MarbleLocale::MeasurementSystem currentSystem = locale->measurementSystem(); locale->meterToTargetUnit( altitude, currentSystem, convertedAltitude, d->m_elevationUnit ); d->m_elevationWidget->elevationSpinBox->setValue( convertedAltitude ); d->m_elevationWidget->elevationSpinBox->setSuffix( locale->unitAbbreviation(d->m_elevationUnit) ); } // Adjust icon and label scales. d->m_iconScale->setValue( placemark->style()->iconStyle().scale() ); connect( d->m_iconScale, SIGNAL(valueChanged(double)), this, SLOT(updateTextAnnotation()) ); d->m_labelScale->setValue( placemark->style()->labelStyle().scale() ); connect( d->m_labelScale, SIGNAL(valueChanged(double)), this, SLOT(updateTextAnnotation()) ); // Adjust the current color of the two push buttons' pixmap to resemble the label and icon colors. const GeoDataLabelStyle labelStyle = placemark->style()->labelStyle(); const GeoDataIconStyle iconStyle = placemark->style()->iconStyle(); QPixmap labelPixmap( d->m_labelButton->iconSize().width(), d->m_labelButton->iconSize().height() ); labelPixmap.fill( labelStyle.color() ); d->m_labelButton->setIcon( QIcon( labelPixmap ) ); QPixmap iconPixmap( d->m_iconButton->iconSize().width(), d->m_iconButton->iconSize().height() ); iconPixmap.fill( iconStyle.color() ); d->m_iconButton->setIcon( QIcon( iconPixmap ) ); // Setup the color dialogs. d->m_labelColorDialog = new QColorDialog( this ); d->m_labelColorDialog->setOption( QColorDialog::ShowAlphaChannel ); d->m_labelColorDialog->setCurrentColor( labelStyle.color() ); connect( d->m_labelButton, SIGNAL(clicked()), d->m_labelColorDialog, SLOT(exec()) ); connect( d->m_labelColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateLabelDialog(QColor)) ); connect( d->m_labelColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateTextAnnotation()) ); d->m_iconColorDialog = new QColorDialog( this ); d->m_iconColorDialog->setOption( QColorDialog::ShowAlphaChannel ); d->m_iconColorDialog->setCurrentColor( iconStyle.color() ); connect( d->m_iconButton, SIGNAL(clicked()), d->m_iconColorDialog, SLOT(exec()) ); connect( d->m_iconColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateIconDialog(QColor)) ); connect( d->m_iconColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateTextAnnotation()) ); connect( d->m_isBalloonVisible, SIGNAL(toggled(bool)), this, SLOT(updateTextAnnotation()) ); // Promote "Ok" button to default button. d->buttonBox->button( QDialogButtonBox::Ok )->setDefault( true ); connect( d->buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(pressed()), this, SLOT(checkFields()) ); connect( this, SIGNAL(accepted()), SLOT(updateTextAnnotation()) ); connect( this, SIGNAL(accepted()), SLOT(updatePlacemarkAltitude()) ); connect( this, SIGNAL(finished(int)), SLOT(restoreInitial(int)) ); // Ensure that the dialog gets deleted when closing it (either when clicking OK or // Close). connect( this, SIGNAL(finished(int)), SLOT(deleteLater()) ); }
bool ElevationProfileFloatItem::eventFilter( QObject *object, QEvent *e ) { if ( !enabled() || !visible() ) { return false; } MarbleWidget *widget = dynamic_cast<MarbleWidget*>( object ); if ( !widget ) { return AbstractFloatItem::eventFilter(object,e); } if ( widget && !m_marbleWidget ) { m_marbleWidget = widget; connect( this, SIGNAL(dataUpdated()), this, SLOT(updateVisiblePoints()) ); connect( m_marbleWidget, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), this, SLOT(updateVisiblePoints()) ); connect( this, SIGNAL(settingsChanged(QString)), this, SLOT(updateVisiblePoints()) ); } if ( e->type() == QEvent::MouseButtonDblClick || e->type() == QEvent::MouseMove ) { GeoDataTreeModel *const treeModel = const_cast<MarbleModel *>( marbleModel() )->treeModel(); QMouseEvent *event = static_cast<QMouseEvent*>( e ); QRectF plotRect = QRectF ( m_leftGraphMargin, 0, m_eleGraphWidth, contentSize().height() ); plotRect.translate( positivePosition() ); plotRect.translate( padding(), padding() ); // for antialiasing: increase size by 1 px to each side plotRect.translate(-1, -1); plotRect.setSize(plotRect.size() + QSize(2, 2) ); const bool cursorAboveFloatItem = plotRect.contains(event->pos()); if ( cursorAboveFloatItem ) { const int start = m_zoomToViewport ? m_firstVisiblePoint : 0; const int end = m_zoomToViewport ? m_lastVisiblePoint : m_eleData.size(); // Double click triggers recentering the map at the specified position if ( e->type() == QEvent::MouseButtonDblClick ) { const QPointF mousePosition = event->pos() - plotRect.topLeft(); const int xPos = mousePosition.x(); for ( int i = start; i < end; ++i) { const int plotPos = ( m_eleData.value(i).x() - m_axisX.minValue() ) * m_eleGraphWidth / m_axisX.range(); if ( plotPos >= xPos ) { widget->centerOn( m_points[i], true ); break; } } return true; } if ( e->type() == QEvent::MouseMove && !(event->buttons() & Qt::LeftButton) ) { // Cross hair cursor when moving above the float item // and mark the position on the graph widget->setCursor(QCursor(Qt::CrossCursor)); if ( m_cursorPositionX != event->pos().x() - plotRect.left() ) { m_cursorPositionX = event->pos().x() - plotRect.left(); const qreal xpos = m_axisX.minValue() + ( m_cursorPositionX / m_eleGraphWidth ) * m_axisX.range(); GeoDataCoordinates currentPoint; // invalid coordinates for ( int i = start; i < end; ++i) { if ( m_eleData.value(i).x() >= xpos ) { currentPoint = m_points[i]; currentPoint.setAltitude( m_eleData.value(i).y() ); break; } } m_markerPlacemark->setCoordinate( currentPoint ); if ( m_documentIndex < 0 ) { m_documentIndex = treeModel->addDocument( &m_markerDocument ); } emit repaintNeeded(); } return true; } } else { if ( m_documentIndex >= 0 ) { m_markerPlacemark->setCoordinate( GeoDataCoordinates() ); // set to invalid treeModel->removeDocument( &m_markerDocument ); m_documentIndex = -1; emit repaintNeeded(); } } } return AbstractFloatItem::eventFilter(object,e); }