32 class AutoNavigation::Private
37 const MarbleModel *
const m_model;
38 const ViewportParams *
const m_viewport;
39 const PositionTracking *
const m_tracking;
42 QTimer m_lastWidgetInteraction;
43 bool m_selfInteraction;
53 void moveOnBorderToCenter(
const GeoDataCoordinates &position, qreal speed );
60 GeoDataCoordinates findIntersection( qreal currentX, qreal currentY )
const;
66 void adjustZoom(
const GeoDataCoordinates ¤tPosition, qreal speed );
71 void centerOn(
const GeoDataCoordinates &position );
74 AutoNavigation::Private::Private( MarbleModel *model,
const ViewportParams *viewport, AutoNavigation *parent ) :
77 m_viewport( viewport ),
78 m_tracking( model->positionTracking() ),
79 m_recenterMode( AutoNavigation::DontRecenter ),
81 m_selfInteraction( false )
83 m_lastWidgetInteraction.setInterval( 10 * 1000 );
84 m_lastWidgetInteraction.setSingleShot(
true );
87 void AutoNavigation::Private::moveOnBorderToCenter(
const GeoDataCoordinates &position, qreal )
97 if(!( m_viewport->screenCoordinates( lon, lat, x, y ) ) ) {
100 qreal centerLon = m_viewport->centerLongitude();
101 qreal centerLat = m_viewport->centerLatitude();
106 m_viewport->screenCoordinates( centerLon, centerLat, centerX, centerY );
108 const qreal borderRatio = 0.25;
110 int shiftX = qRound( centerX * borderRatio );
111 int shiftY = qRound( centerY * borderRatio );
113 QRect recenterBorderBound;
114 recenterBorderBound.
setCoords( centerX-shiftX, centerY-shiftY, centerX+shiftX, centerY+shiftY );
116 if( !recenterBorderBound.
contains( x,y ) ) {
117 centerOn( position );
121 GeoDataCoordinates AutoNavigation::Private::findIntersection( qreal currentX, qreal currentY )
const
123 qreal
direction = m_tracking->direction();
124 if ( direction >= 360 ) {
125 direction = fmod( direction,360.0 );
128 const qreal width = m_viewport->width();
129 const qreal height = m_viewport->height();
136 bool crossHorizontal =
false;
137 bool crossVertical =
false;
140 if( 0 < direction && direction < 90 ) {
144 intercept.
setX( width - currentX );
145 intercept.
setY( intercept.
x() / tan( angle ) );
146 destinationVertical.
setX( width );
147 destinationVertical.
setY( currentY-intercept.
y() );
150 intercept.
setY( currentY );
151 intercept.
setX( intercept.
y() * tan( angle ) );
152 destinationHorizontal.
setX( currentX + intercept.
x() );
153 destinationHorizontal.
setY( 0 );
155 if ( destinationVertical.
y() < 0 ) {
156 crossHorizontal =
true;
158 else if( destinationHorizontal.
x() > width ) {
159 crossVertical =
true;
163 else if( 270 < direction && direction < 360 ) {
164 const qreal angle = direction - 270;
167 intercept.
setY( currentY );
168 intercept.
setX( intercept.
y() / tan( angle ) );
169 destinationHorizontal.
setX( currentX - intercept.
x() );
170 destinationHorizontal.
setY( 0 );
173 intercept.
setX( currentX );
174 intercept.
setY( intercept.
x() * tan( angle ) );
175 destinationVertical.
setY( currentY - intercept.
y() );
176 destinationVertical.
setX( 0 );
178 if( destinationHorizontal.
x() > width ) {
179 crossVertical =
true;
181 else if( destinationVertical.
y() < 0 ) {
182 crossHorizontal =
true;
186 else if( 180 < direction && direction < 270 ) {
187 const qreal angle = direction - 180;
190 intercept.
setX( currentX );
191 intercept.
setY( intercept.
x() / tan( angle ) );
192 destinationVertical.
setY( currentY + intercept.
y() );
193 destinationVertical.
setX( 0 );
196 intercept.
setY( currentY );
197 intercept.
setX( intercept.
y() * tan( angle ) );
198 destinationHorizontal.
setX( currentX - intercept.
x() );
199 destinationHorizontal.
setY( height );
201 if ( destinationVertical.
y() > height ) {
202 crossHorizontal =
true;
204 else if ( destinationHorizontal.
x() < 0 ) {
205 crossVertical =
true;
209 else if( 90 < direction && direction < 180 ) {
210 const qreal angle = direction - 90;
213 intercept.
setY( height - currentY );
214 intercept.
setX( intercept.
y() / tan( angle ) );
215 destinationHorizontal.
setX( currentX + intercept.
x() );
216 destinationHorizontal.
setY( height );
219 intercept.
setX( width - currentX );
220 intercept.
setY( intercept.
x() * tan( angle ) );
221 destinationVertical.
setX( width );
222 destinationVertical.
setY( currentY + intercept.
y() );
224 if ( destinationHorizontal.
x() > width ) {
225 crossVertical =
true;
227 else if( destinationVertical.
y() > height ) {
228 crossHorizontal =
true;
232 else if( direction == 0 ) {
233 destinationHorizontal.
setX( currentX );
234 destinationHorizontal.
setY( 0 );
235 crossHorizontal =
true;
237 else if( direction == 90 ) {
238 destinationVertical.
setX( width );
239 destinationVertical.
setY( currentY );
240 crossVertical =
true;
242 else if( direction == 190 ) {
243 destinationHorizontal.
setX( currentX );
244 destinationHorizontal.
setY( height );
245 crossHorizontal =
true;
247 else if( direction == 270 ) {
248 destinationVertical.
setX( 0 );
249 destinationVertical.
setY( currentY );
250 crossVertical =
true;
253 if ( crossHorizontal ==
true && crossVertical ==
false ) {
254 destination.
setX( destinationHorizontal.
x() );
255 destination.
setY( destinationHorizontal.
y() );
257 else if ( crossVertical ==
true && crossHorizontal ==
false ) {
258 destination.
setX( destinationVertical.
x() );
259 destination.
setY( destinationVertical.
y() );
262 qreal destinationLon = 0.0;
263 qreal destinationLat = 0.0;
264 m_viewport->geoCoordinates( destination.
x(), destination.
y(), destinationLon, destinationLat,
268 return destinationCoord;
271 void AutoNavigation::Private::adjustZoom(
const GeoDataCoordinates ¤tPosition, qreal speed )
279 if( !m_viewport->screenCoordinates( lon, lat, currentX, currentY ) ) {
283 const GeoDataCoordinates destination = findIntersection( currentX, currentY );
285 qreal greatCircleDistance =
distanceSphere( currentPosition, destination );
286 qreal
radius = m_model->planetRadius();
287 qreal distance = greatCircleDistance *
radius;
291 qreal remainingTime = ( distance / speed ) *
SEC2MIN;
294 qreal thresholdLow = 1.0;
295 qreal thresholdHigh = 12.0 * thresholdLow;
297 m_selfInteraction =
true;
298 if ( remainingTime < thresholdLow ) {
299 emit m_parent->zoomOut(
Instant );
301 else if ( remainingTime < thresholdHigh ) {
305 emit m_parent->zoomIn(
Instant );
307 m_selfInteraction =
false;
311 void AutoNavigation::Private::centerOn(
const GeoDataCoordinates &position )
313 m_selfInteraction =
true;
314 emit m_parent->centerOn( position,
false );
315 m_selfInteraction =
false;
333 if ( d->m_lastWidgetInteraction.isActive() ) {
337 switch( d->m_recenterMode ) {
342 d->centerOn( position );
345 d->moveOnBorderToCenter( position, speed );
349 if ( d->m_adjustZoom ) {
350 switch( d->m_recenterMode ) {
356 d->adjustZoom( position, speed );
376 if ( !d->m_selfInteraction ) {
377 d->m_lastWidgetInteraction.start();
383 return d->m_recenterMode;
388 return d->m_adjustZoom;
393 #include "AutoNavigation.moc"
A 3d point representation.
Enum Value AlwaysRecenter.
double angle(double vec1[3], double vec2[3])
void inhibitAutoAdjustments()
Temporarily inhibits auto-centering and auto-zooming.
This file contains the headers for MarbleModel.
Enum Value RecenterOnBorder.
qreal distanceSphere(qreal lon1, qreal lat1, qreal lon2, qreal lat2)
This method calculates the shortest distance between two points on a sphere.
void autoZoomToggled(bool enabled)
signal emitted when auto zoom is toggled
void recenterModeChanged(AutoNavigation::CenterMode mode)
signal emitted when auto center is turned on (Always re-center, re-center when required ) or off(Disa...
void setRecenter(CenterMode recenterMode)
For Auto Centering adjustment of map in Navigation Mode.
void setCoords(int x1, int y1, int x2, int y2)
static qreal radius(qreal zoom)
void adjust(const GeoDataCoordinates &position, qreal speed)
For adjusting the gps location (recentering) or map(autozooming)
void setAutoZoom(bool activate)
For Auto Zooming adjustment of map in Navigation Mode.
bool contains(const QPoint &point, bool proper) const
~AutoNavigation()
Destructor.
A public class that controls what is visible in the viewport of a Marble map.
This file contains the headers for ViewportParams.
The data model (not based on QAbstractModel) for a MarbleWidget.
AutoNavigation(MarbleModel *model, const ViewportParams *viewport, QObject *parent=0)
Constructor.
Change camera position immediately (no interpolation)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
CenterMode
An enum type Represents which recentering method is selected.
void centerOn(const GeoDataCoordinates &position, bool animated)
AutoNavigation::CenterMode recenterMode() const