[Marble-commits] KDE/kdeedu/marble/src/plugins/render/positionmarker
Thibaut Gridel
tgridel at free.fr
Thu Jan 27 22:24:20 CET 2011
SVN commit 1217552 by tgridel:
Position Marker trail by Daniel Marth
Adds a trail to the position marker.
GCI-task: http://www.google-melange.com/gci/task/show/google/gci2010/kde/t129364719879
M +86 -8 PositionMarker.cpp
M +7 -1 PositionMarker.h
M +41 -2 PositionMarkerConfigWidget.ui
--- trunk/KDE/kdeedu/marble/src/plugins/render/positionmarker/PositionMarker.cpp #1217551:1217552
@@ -47,8 +47,15 @@
ui_configWidget( 0 ),
m_aboutDialog( 0 ),
m_configDialog( 0 ),
- m_settings()
+ m_settings(),
+ m_visibleTrailPoints( 0 )
{
+ // Create list of rects for trail with increasing size.
+ // Last element is not drawn, it only stores the next position.
+ GeoDataCoordinates coordinates;
+ for( int i = 0; i < sm_numTrailPoints + 1; ++i ) {
+ m_trail.push_back( coordinates );
+ }
connect( this, SIGNAL( settingsChanged( QString ) ),
this, SLOT( updateSettings() ) );
}
@@ -155,7 +162,9 @@
connect( ui_configWidget->m_resizeSlider, SIGNAL( valueChanged( int ) ),
SLOT( resizeCursor( int ) ) );
connect( ui_configWidget->m_acColorChooserButton, SIGNAL( clicked() ),
- SLOT( chooseAccuracyCircleColor() ) );
+ SLOT( chooseColor() ) );
+ connect( ui_configWidget->m_trailColorChooserButton, SIGNAL( clicked() ),
+ SLOT( chooseColor() ) );
}
return m_configDialog;
}
@@ -216,9 +225,24 @@
m_dirtyRegion = QRegion();
m_dirtyRegion += ( m_arrow.boundingRect().toRect() );
m_dirtyRegion += ( m_previousArrow.boundingRect().toRect() );
+
+ // Check if position has changed.
+ if( !( m_currentPosition == m_trail[sm_numTrailPoints] ) ) {
+ // Move trail forward and add new point.
+ for( int i = 0; i < sm_numTrailPoints; ++i ) {
+ m_trail[i] = m_trail[i + 1];
}
+ m_trail[sm_numTrailPoints] = m_currentPosition;
+ if( m_visibleTrailPoints == 0 ) {
+ m_trail[sm_numTrailPoints - 1] = m_trail[sm_numTrailPoints];
}
+ if( m_visibleTrailPoints < sm_numTrailPoints ) {
+ ++m_visibleTrailPoints;
}
+ }
+ }
+ }
+}
bool PositionMarker::render( GeoPainter *painter,
ViewportParams *viewport,
@@ -250,6 +274,30 @@
painter->drawEllipse( m_currentPosition, width, width );
}
+ // Draw trail if requested.
+ if( m_showTrail ) {
+ painter->save();
+ // Use selected color to draw trail.
+ painter->setBrush( m_trailColor );
+ painter->setPen( m_trailColor );
+ QRectF trailRect;
+ QPointF trailPoint;
+ float opacity = 1.0;
+ for( int i = sm_numTrailPoints - 1; i >= 0 && i >= sm_numTrailPoints - m_visibleTrailPoints; --i ) {
+ // Get screen coordinates from coordinates on the map.
+ m_viewport->currentProjection()->screenCoordinates( m_trail[i], m_viewport, trailPoint );
+ int size = ( i + 1 ) * 5;
+ trailRect.setX( trailPoint.x() - size / 2.0 );
+ trailRect.setY( trailPoint.y() - size / 2.0 );
+ trailRect.setWidth( size );
+ trailRect.setHeight( size );
+ painter->setOpacity( opacity );
+ painter->drawEllipse( trailRect );
+ opacity -= 0.15;
+ }
+ painter->restore();
+ }
+
if( m_useCustomCursor)
{
QRect rect = m_arrow.boundingRect().toRect();
@@ -297,6 +345,12 @@
if( !settings.contains( "acColor" ) ) {
settings.insert( "acColor", oxygenBrickRed4 );
}
+ if( !settings.contains( "trailColor" ) ) {
+ settings.insert( "trailColor", QColor( 0, 0, 255 ) );
+ }
+ if( !settings.contains( "showTrail" ) ) {
+ settings.insert( "showTrail", true );
+ }
m_settings = settings;
readSettings();
@@ -334,6 +388,10 @@
QPalette palette = ui_configWidget->m_acColorChooserButton->palette();
palette.setColor( QPalette::Button, QColor( m_settings.value( "acColor" ).value<QColor>()) );
ui_configWidget->m_acColorChooserButton->setPalette( palette );
+ palette = ui_configWidget->m_trailColorChooserButton->palette();
+ palette.setColor( QPalette::Button, QColor( m_settings.value( "trailColor" ).value<QColor>()) );
+ ui_configWidget->m_trailColorChooserButton->setPalette( palette );
+ ui_configWidget->m_trailCheckBox->setChecked( m_settings.value( "showTrail" ).toBool() );
}
void PositionMarker::writeSettings()
@@ -346,6 +404,8 @@
m_settings.insert( "cursorPath", m_cursorPath );
m_settings.insert( "cursorSize", sm_resizeSteps[ui_configWidget->m_resizeSlider->value()] );
m_settings.insert( "acColor", m_acColor );
+ m_settings.insert( "trailColor", m_trailColor );
+ m_settings.insert( "showTrail", ui_configWidget->m_trailCheckBox->isChecked() );
emit settingsChanged( nameId() );
}
@@ -357,6 +417,8 @@
m_cursorSize = m_settings.value( "cursorSize" ).toFloat();
loadCustomCursor( m_cursorPath, m_useCustomCursor );
m_acColor = m_settings.value( "acColor" ).value<QColor>();
+ m_trailColor = m_settings.value( "trailColor" ).value<QColor>();
+ m_showTrail = m_settings.value( "showTrail" ).toBool();
}
void PositionMarker::setPosition( const GeoDataCoordinates &position )
@@ -406,19 +468,35 @@
m_defaultCursor = QPixmap( m_defaultCursorPath ).scaled( 22 * m_cursorSize, 22 * m_cursorSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
}
-void PositionMarker::chooseAccuracyCircleColor()
+void PositionMarker::chooseColor()
{
- QColor c = QColorDialog::getColor( m_acColor, 0,
- tr( "Please choose the color for the accuracy circle" ),
+ QColor initialColor;
+ if( sender() == ui_configWidget->m_acColorChooserButton ) {
+ initialColor = m_acColor;
+ }
+ else if( sender() == ui_configWidget->m_trailColorChooserButton ) {
+ initialColor = m_trailColor;
+ }
+ QColor color = QColorDialog::getColor( initialColor, NULL,
+ tr( "Please choose a color" ),
QColorDialog::ShowAlphaChannel );
- if( c.isValid() )
+ if( color.isValid() )
{
- m_acColor = c;
- QPalette palette = ui_configWidget->m_acColorChooserButton->palette();
+ QPalette palette;
+ if( sender() == ui_configWidget->m_acColorChooserButton ) {
+ m_acColor = color;
+ palette = ui_configWidget->m_acColorChooserButton->palette();
palette.setColor( QPalette::Button, m_acColor );
ui_configWidget->m_acColorChooserButton->setPalette( palette );
}
+ else if( sender() == ui_configWidget->m_trailColorChooserButton ) {
+ m_trailColor = color;
+ palette = ui_configWidget->m_trailColorChooserButton->palette();
+ palette.setColor( QPalette::Button, m_trailColor );
+ ui_configWidget->m_trailColorChooserButton->setPalette( palette );
}
+ }
+}
void PositionMarker::resizeCursor( int step )
{
--- trunk/KDE/kdeedu/marble/src/plugins/render/positionmarker/PositionMarker.h #1217551:1217552
@@ -15,6 +15,7 @@
#include <QtCore/QObject>
#include <QtCore/QHash>
+#include <QtCore/QVector>
#include <QtGui/QColor>
#include <QtGui/QAbstractButton>
@@ -88,7 +89,7 @@
void updateSettings();
void setPosition( const GeoDataCoordinates &position );
void chooseCustomCursor();
- void chooseAccuracyCircleColor();
+ void chooseColor();
void resizeCursor( int step );
private:
@@ -115,7 +116,12 @@
QHash<QString,QVariant> m_settings;
float m_cursorSize;
QColor m_acColor;
+ QColor m_trailColor;
qreal m_heading;
+ QVector<GeoDataCoordinates> m_trail;
+ static const int sm_numTrailPoints = 5;
+ int m_visibleTrailPoints;
+ bool m_showTrail;
static const int sm_defaultSizeStep;
static const int sm_numResizeSteps;
--- trunk/KDE/kdeedu/marble/src/plugins/render/positionmarker/PositionMarkerConfigWidget.ui #1217551:1217552
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>433</width>
- <height>297</height>
+ <width>470</width>
+ <height>352</height>
</rect>
</property>
<property name="windowTitle">
@@ -144,6 +144,16 @@
</item>
</layout>
</item>
+ <item>
+ <widget class="QCheckBox" name="m_trailCheckBox">
+ <property name="text">
+ <string>Trail</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
@@ -185,6 +195,35 @@
</property>
</widget>
</item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Trail:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="m_trailColorChooserButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>25</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>Color of the position marker's trail.</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
More information about the Marble-commits
mailing list