[Marble-commits] KDE/kdeedu/marble/src/plugins/render/positionmarker
Torsten Rahn
tackat at kde.org
Thu Dec 30 01:19:18 CET 2010
SVN commit 1210186 by rahn:
- Config Dialog for PositionMarker Plugin by Daniel Marth:
Adds a configuration dialog to the position marker plugin to load a
custom image as marker.
GCI task:
http://www.google-melange.com/gci/task/show/google/gci2010/kde/t129347413457
M +3 -0 CMakeLists.txt
M +82 -0 PositionMarker.cpp
M +16 -0 PositionMarker.h
--- trunk/KDE/kdeedu/marble/src/plugins/render/positionmarker/CMakeLists.txt #1210185:1210186
@@ -8,5 +8,8 @@
INCLUDE(${QT_USE_FILE})
set( positionmarker_SRCS PositionMarker.cpp )
+set( positionmarker_UI PositionMarkerConfigWidget.ui )
+qt4_wrap_ui(positionmarker_SRCS ${positionmarker_UI})
+
marble_add_plugin( PositionMarker ${positionmarker_SRCS} )
--- trunk/KDE/kdeedu/marble/src/plugins/render/positionmarker/PositionMarker.cpp #1210185:1210186
@@ -16,7 +16,11 @@
#include "MarbleDebug.h"
#include <QtCore/QRect>
#include <QtGui/QColor>
+#include <QtGui/QFileDialog>
+#include <QtGui/QMessageBox>
+#include <QtGui/QPushButton>
+#include "ui_PositionMarkerConfigWidget.h"
#include "AbstractProjection.h"
#include "MarbleDataFacade.h"
#include "GeoPainter.h"
@@ -29,7 +33,10 @@
PositionMarker::PositionMarker ()
: RenderPlugin(),
m_isInitialized( false ),
+ m_useCustomCursor( false ),
+ ui_configWidget( 0 ),
m_aboutDialog( 0 ),
+ m_configDialog( 0 ),
m_viewport( 0 )
{
}
@@ -110,6 +117,27 @@
return m_aboutDialog;
}
+QDialog *PositionMarker::configDialog() const
+{
+ if ( !m_configDialog ) {
+ // Initializing configuration dialog
+ m_configDialog = new QDialog();
+ ui_configWidget = new Ui::PositionMarkerConfigWidget;
+ ui_configWidget->setupUi( m_configDialog );
+ readSettings();
+ connect( ui_configWidget->m_buttonBox, SIGNAL( accepted() ),
+ SLOT( writeSettings() ) );
+ connect( ui_configWidget->m_buttonBox, SIGNAL( rejected() ),
+ SLOT( readSettings() ) );
+ QPushButton *applyButton = ui_configWidget->m_buttonBox->button( QDialogButtonBox::Apply );
+ connect( applyButton, SIGNAL( clicked() ),
+ SLOT( writeSettings() ) );
+ connect( ui_configWidget->m_fileChooserButton, SIGNAL( clicked() ),
+ SLOT( chooseCustomCursor() ) );
+ }
+ return m_configDialog;
+}
+
void PositionMarker::initialize()
{
if ( dataFacade() ) {
@@ -202,9 +230,18 @@
painter->drawEllipse( m_currentPosition, width, width );
}
+ if( m_useCustomCursor)
+ {
+ QRectF rect = m_arrow.boundingRect().toAlignedRect();
+ if( rect.isValid() )
+ painter->drawPixmap( rect.topLeft(), m_customCursor );
+ }
+ else
+ {
painter->setPen( Qt::black );
painter->setBrush( Qt::white );
painter->drawPolygon( m_arrow );
+ }
painter->restore();
m_previousArrow = m_arrow;
@@ -212,6 +249,27 @@
return true;
}
+void PositionMarker::readSettings() const
+{
+ if(m_useCustomCursor)
+ ui_configWidget->m_customCursor->click();
+ else
+ ui_configWidget->m_originalCursor->click();
+}
+
+void PositionMarker::writeSettings()
+{
+ if( ui_configWidget->m_customCursor->isChecked() &&
+ ui_configWidget->m_fileChooserButton->icon().isNull() )
+ {
+ QMessageBox::warning( NULL, tr( "Error" ), tr( "No cursor selected, the default cursor will be used." ), QMessageBox::Ok );
+ m_useCustomCursor = false;
+ readSettings();
+ return;
+ }
+ m_useCustomCursor = ui_configWidget->m_customCursor->isChecked();
+}
+
void PositionMarker::setPosition( const GeoDataCoordinates &position )
{
m_previousPosition = m_currentPosition;
@@ -222,6 +280,30 @@
}
}
+void PositionMarker::chooseCustomCursor()
+{
+ QString filename = QFileDialog::getOpenFileName( NULL, tr( "Choose Custom Cursor" ) );
+ if( !filename.isEmpty() )
+ loadCustomCursor( filename );
+}
+
+int PositionMarker::loadCustomCursor( const QString& filename )
+{
+ m_customCursor = QPixmap( filename ).scaled( 22, 22, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+ if( !m_customCursor.isNull() )
+ {
+ ui_configWidget->m_customCursor->click();
+ ui_configWidget->m_fileChooserButton->setIcon( QIcon( m_customCursor ) );
+ return 0;
+ }
+ else
+ {
+ QMessageBox::warning( NULL, tr( "Error" ), tr( "Unable to load custom cursor. Make sure this is a valid image file." ), QMessageBox::Ok );
+ ui_configWidget->m_fileChooserButton->setIcon( QIcon() );
+ return 1;
+ }
+}
+
qreal PositionMarker::zValue() const
{
return 1.0;
--- trunk/KDE/kdeedu/marble/src/plugins/render/positionmarker/PositionMarker.h #1210185:1210186
@@ -19,6 +19,11 @@
#include "GeoDataCoordinates.h"
#include "PluginAboutDialog.h"
+namespace Ui
+{
+ class PositionMarkerConfigWidget;
+}
+
namespace Marble
{
@@ -49,6 +54,8 @@
QDialog *aboutDialog() const;
+ QDialog *configDialog() const;
+
void initialize ();
bool isInitialized () const;
@@ -62,14 +69,20 @@
virtual qreal zValue() const;
public slots:
+ void readSettings() const;
+ void writeSettings();
void setPosition( const GeoDataCoordinates &position );
+ void chooseCustomCursor();
private:
Q_DISABLE_COPY( PositionMarker )
bool m_isInitialized;
+ bool m_useCustomCursor;
+ mutable Ui::PositionMarkerConfigWidget *ui_configWidget;
mutable PluginAboutDialog *m_aboutDialog;
+ mutable QDialog *m_configDialog;
ViewportParams *m_viewport;
GeoDataCoordinates m_currentPosition;
@@ -78,6 +91,9 @@
QPolygonF m_arrow;
QPolygonF m_previousArrow;
QRegion m_dirtyRegion;
+ QPixmap m_customCursor;
+
+ int loadCustomCursor( const QString& filename );
};
}
More information about the Marble-commits
mailing list