[Marble-commits] branches/KDE/4.4/kdeedu/marble/src
Dennis Nienhüser
earthwings at gentoo.org
Thu Jan 7 23:28:57 CET 2010
SVN commit 1071394 by nienhueser:
Backport of commits 1070837, 1071370 and 1071389:
- Initial fix by Mattias Dalkvist and Dennis Nienhüser. This is neat! :-)
- Introduce a focus point (move-invariant point when zooming) in ViewportParams, used by the default input handler and the crosshair plugin to indicate a non screen-centric zoom action to the user.
- Export class AbstractProjection since it is now used by the CrosshairsPlugin.
BUG: 177591
M +29 -2 lib/MarbleWidgetInputHandler.cpp
M +2 -1 lib/Projections/AbstractProjection.h
M +34 -1 lib/ViewportParams.cpp
M +29 -0 lib/ViewportParams.h
M +9 -3 plugins/render/crosshairs/CrosshairsPlugin.cpp
--- branches/KDE/4.4/kdeedu/marble/src/lib/MarbleWidgetInputHandler.cpp #1071393:1071394
@@ -221,6 +221,8 @@
{
d->m_widget->updateChangedMap();
}
+
+ d->m_widget->map()->viewParams()->viewport()->resetFocusPoint();
}
void MarbleWidgetInputHandler::installPluginEventFilter( RenderPlugin *renderPlugin )
@@ -591,11 +593,36 @@
}
else {
if ( e->type() == QEvent::Wheel ) {
+ MarbleWidget *marbleWidget = MarbleWidgetInputHandler::d->m_widget;
// FIXME: disable animation quality after some time
- MarbleWidgetInputHandler::d->m_widget->setViewContext( Marble::Animation );
+ marbleWidget->setViewContext( Marble::Animation );
QWheelEvent *wheelevt = static_cast<QWheelEvent*>( e );
- MarbleWidgetInputHandler::d->m_widget->zoomViewBy( (int)(wheelevt->delta() / 3) );
+
+ qreal destLat;
+ qreal destLon;
+ bool isValid = marbleWidget->geoCoordinates(wheelevt->x(), wheelevt->y(),
+ destLon, destLat, GeoDataCoordinates::Radian );
+
+ marbleWidget->setUpdatesEnabled( false );
+ marbleWidget->zoomViewBy( (int)(wheelevt->delta() / 3) );
+
+ qreal mouseLat;
+ qreal mouseLon;
+ isValid = isValid && marbleWidget->geoCoordinates(wheelevt->x(), wheelevt->y(),
+ mouseLon, mouseLat, GeoDataCoordinates::Radian );
+
+ qreal centerLat = DEG2RAD * marbleWidget->centerLatitude();
+ qreal centerLon = DEG2RAD * marbleWidget->centerLongitude();
+
+ if ( isValid ) {
+ qreal lon = destLon - (mouseLon - centerLon);
+ qreal lat = destLat - (mouseLat - centerLat);
+ marbleWidget->centerOn( RAD2DEG * lon, RAD2DEG * lat );
+ }
+ marbleWidget->map()->viewParams()->viewport()->setFocusPoint(GeoDataCoordinates(destLon, destLat));
+ marbleWidget->setUpdatesEnabled( true );
+
MarbleWidgetInputHandler::d->m_mouseWheelTimer->start( 400 );
return true;
}
--- branches/KDE/4.4/kdeedu/marble/src/lib/Projections/AbstractProjection.h #1071393:1071394
@@ -28,6 +28,7 @@
#include "GeoDataLatLonAltBox.h"
#include "GeoDataCoordinates.h"
+#include "marble_export.h"
namespace Marble
{
@@ -45,7 +46,7 @@
* @short A base class for all projections in Marble.
*/
-class AbstractProjection
+class MARBLE_EXPORT AbstractProjection
{
// Not a QObject so far because we don't need to send signals.
public:
--- branches/KDE/4.4/kdeedu/marble/src/lib/ViewportParams.cpp #1071393:1071394
@@ -54,6 +54,10 @@
static SphericalProjection s_sphericalProjection;
static EquirectProjection s_equirectProjection;
static MercatorProjection s_mercatorProjection;
+
+ GeoDataCoordinates m_focusPoint;
+ bool m_hasFocusPoint;
+
};
ViewportParamsPrivate::ViewportParamsPrivate()
@@ -66,7 +70,8 @@
m_dirtyBox( true ),
m_viewLatLonAltBox(),
m_dirtyRegion( true ),
- m_activeRegion()
+ m_activeRegion(),
+ m_hasFocusPoint(false)
{
}
@@ -386,5 +391,33 @@
return d->m_activeRegion;
}
+GeoDataCoordinates ViewportParams::focusPoint() const
+{
+ if (d->m_hasFocusPoint) {
+ return d->m_focusPoint;
+ }
+ else {
+ qreal lon, lat;
+ centerCoordinates(lon, lat);
+ return GeoDataCoordinates(lon, lat, 0.0, GeoDataCoordinates::Radian);
+ }
}
+
+void ViewportParams::setFocusPoint(const GeoDataCoordinates &focusPoint)
+{
+ d->m_focusPoint = focusPoint;
+ d->m_hasFocusPoint = true;
+}
+
+void ViewportParams::resetFocusPoint()
+{
+ d->m_hasFocusPoint = false;
+}
+
+bool ViewportParams::focusPointIsCenter() const
+{
+ return !d->m_hasFocusPoint;
+}
+
+}
--- branches/KDE/4.4/kdeedu/marble/src/lib/ViewportParams.h #1071393:1071394
@@ -103,6 +103,35 @@
QRegion activeRegion() const;
+ /**
+ * @return The current point of focus, e.g. the point that is not moved
+ * when changing the zoom level. If not set, it defaults to the
+ * center point.
+ * @see centerCoordinates setFocusPoint resetFocusPoint focusPointIsCenter
+ */
+ GeoDataCoordinates focusPoint() const;
+
+ /**
+ * @brief Change the point of focus, overridding any previously set focus point.
+ * @param focusPoint New focus point
+ * @see focusPoint resetFocusPoint focusPointIsCenter
+ */
+ void setFocusPoint(const GeoDataCoordinates &focusPoint);
+
+ /**
+ * @brief Invalidate any focus point set with @ref setFocusPoint.
+ * @see focusPoint setFocusPoint focusPointIsCenter
+ */
+ void resetFocusPoint();
+
+ /**
+ * @brief Determine whether the focus point is different from the center point
+ * @return False iff an explicit focus point was set with @ref setFocusPoint
+ * and @ref resetFocusPoint has not been called afterwards
+ * @see focusPoint setFocusPoint resetFocusPoint
+ */
+ bool focusPointIsCenter() const;
+
private:
Q_DISABLE_COPY( ViewportParams )
ViewportParamsPrivate * const d;
--- branches/KDE/4.4/kdeedu/marble/src/plugins/render/crosshairs/CrosshairsPlugin.cpp #1071393:1071394
@@ -10,6 +10,7 @@
#include "CrosshairsPlugin.h"
+#include "AbstractProjection.h"
#include "MarbleDebug.h"
#include "GeoPainter.h"
@@ -74,12 +75,17 @@
Q_UNUSED( layer )
if ( renderPos == "ALWAYS_ON_TOP" ) {
- int centerx = viewport->width() / 2;
- int centery = viewport->height() / 2;
+ qreal centerx = viewport->width() / 2;
+ qreal centery = viewport->height() / 2;
int boxwidth = 6;
int boxheight = 2;
int boxoffset = 4;
+ GeoDataCoordinates focusPoint = viewport->focusPoint();
+ if (!viewport->focusPointIsCenter()) {
+ viewport->currentProjection()->screenCoordinates(focusPoint, viewport, centerx, centery);
+ }
+
painter->save();
painter->setRenderHint( QPainter::Antialiasing, false );
@@ -90,7 +96,7 @@
painter->drawRect( centerx - 1, centery - boxoffset - boxwidth, boxheight, boxwidth );
painter->drawRect( centerx - 1, centery + boxoffset, boxheight, boxwidth );
-
+
/*
painter->drawLine( centerx - halfsize, centery,
centerx + halfsize, centery );
More information about the Marble-commits
mailing list