[Marble-commits] KDE/kdeedu/marble/src/plugins/render/crosshairs
Dennis Nienhüser
earthwings at gentoo.org
Sat Jan 1 14:58:44 CET 2011
SVN commit 1210633 by nienhueser:
Cross hair theme configuration. Patch by Cezar Mocan in http://www.google-melange.com/gci/task/show/google/gci2010/kde/t129071957351
Artwork by professorpi in http://www.google-melange.com/gci/task/show/google/gci2010/kde/t128906507346
Minor adjustments by me.
CCMAIL: mocancezar at gmail.com
M +4 -0 CMakeLists.txt
A CrosshairsConfigWidget.ui
M +113 -25 CrosshairsPlugin.cpp
M +39 -5 CrosshairsPlugin.h
A crosshairs-circled.svg
A crosshairs-german.svg
A crosshairs-gun1.svg
A crosshairs-gun2.svg
A crosshairs-pointed.svg
A crosshairs.qrc
--- trunk/KDE/kdeedu/marble/src/plugins/render/crosshairs/CMakeLists.txt #1210632:1210633
@@ -8,5 +8,9 @@
INCLUDE(${QT_USE_FILE})
set( crosshairs_SRCS CrosshairsPlugin.cpp )
+set( crosshairs_UI CrosshairsConfigWidget.ui )
+qt4_wrap_ui( crosshairs_SRCS ${crosshairs_UI} )
+qt4_add_resources( crosshairs_SRCS crosshairs.qrc )
+
marble_add_plugin( CrosshairsPlugin ${crosshairs_SRCS} )
--- trunk/KDE/kdeedu/marble/src/plugins/render/crosshairs/CrosshairsPlugin.cpp #1210632:1210633
@@ -6,19 +6,43 @@
// the source code.
//
// Copyright 2008 Torsten Rahn <tackat at kde.org>
+// Copyright 2010 Cezar Mocan <mocancezar at gmail.com>
//
#include "CrosshairsPlugin.h"
+#include "ui_CrosshairsConfigWidget.h"
#include "AbstractProjection.h"
+#include "GeoPainter.h"
#include "MarbleDebug.h"
-#include "GeoPainter.h"
-
+#include "MarbleDirs.h"
#include "ViewportParams.h"
+#include <QtCore/QRect>
+#include <QtGui/QColor>
+#include <QtGui/QPixmap>
+#include <QtGui/QPushButton>
+#include <QtSvg/QSvgRenderer>
+
+
namespace Marble
{
+CrosshairsPlugin::CrosshairsPlugin ( )
+ : m_isInitialized( false ),
+ m_svgobj( 0 ),
+ m_configDialog( 0 ),
+ m_uiConfigWidget( 0 )
+{
+ // nothing to do
+}
+
+CrosshairsPlugin::~CrosshairsPlugin ()
+{
+ delete m_svgobj;
+}
+
+
QStringList CrosshairsPlugin::backendTypes() const
{
return QStringList( "crosshairs" );
@@ -61,13 +85,85 @@
void CrosshairsPlugin::initialize ()
{
+ readSettings();
+ m_isInitialized = true;
}
bool CrosshairsPlugin::isInitialized () const
{
- return true;
+ return m_isInitialized;
}
+QDialog *CrosshairsPlugin::configDialog() const
+{
+ if ( !m_configDialog ) {
+ m_configDialog = new QDialog();
+ m_uiConfigWidget = new Ui::CrosshairsConfigWidget;
+ m_uiConfigWidget->setupUi( m_configDialog );
+ readSettings();
+ connect( m_uiConfigWidget->m_buttonBox, SIGNAL( accepted() ),
+ SLOT( writeSettings() ) );
+ connect( m_uiConfigWidget->m_buttonBox, SIGNAL( rejected() ),
+ SLOT( readSettings() ) );
+ QPushButton *applyButton = m_uiConfigWidget->m_buttonBox->button( QDialogButtonBox::Apply );
+ connect( applyButton, SIGNAL( clicked() ),
+ this, SLOT( writeSettings() ) );
+ }
+
+ return m_configDialog;
+}
+
+QHash<QString,QVariant> CrosshairsPlugin::settings() const
+{
+ return m_settings;
+}
+
+void CrosshairsPlugin::setSettings( QHash<QString,QVariant> settings )
+{
+ m_settings = settings;
+ readSettings();
+}
+
+
+void CrosshairsPlugin::readSettings() const
+{
+ int index = m_settings.value( "theme", 0 ).toInt();
+ if ( m_uiConfigWidget && index >= 0 && index < m_uiConfigWidget->m_themeList->count() ) {
+ m_uiConfigWidget->m_themeList->setCurrentRow( index );
+ }
+
+ QString theme = ":/crosshairs-pointed.svg";
+ switch( index ) {
+ case 1:
+ theme = ":/crosshairs-gun1.svg";
+ break;
+ case 2:
+ theme = ":/crosshairs-gun2.svg";
+ break;
+ case 3:
+ theme = ":/crosshairs-circled.svg";
+ break;
+ case 4:
+ theme = ":/crosshairs-german.svg";
+ break;
+ }
+
+ delete m_svgobj;
+ /** @todo FIXME we really need to change the configDialog() const API */
+ CrosshairsPlugin * me = const_cast<CrosshairsPlugin*>( this );
+ m_svgobj = new QSvgRenderer( theme, me );
+ m_crosshairs = QPixmap();
+}
+
+void CrosshairsPlugin::writeSettings()
+{
+ if ( m_uiConfigWidget ) {
+ m_settings["theme"] = m_uiConfigWidget->m_themeList->currentRow();
+ }
+ readSettings();
+ emit settingsChanged( nameId() );
+}
+
bool CrosshairsPlugin::render( GeoPainter *painter, ViewportParams *viewport,
const QString& renderPos,
GeoSceneLayer * layer )
@@ -75,33 +171,25 @@
Q_UNUSED( layer )
if ( renderPos == "ALWAYS_ON_TOP" ) {
- const int boxwidth = 6;
- const int boxheight = 2;
- const int boxoffset = 4;
+ const int width = 21;
+ const int height = 21;
+ if ( m_crosshairs.isNull() ) {
+ painter->setRenderHint( QPainter::Antialiasing, true );
+ m_crosshairs = QPixmap( QSize( width, height ) );
+ m_crosshairs.fill( Qt::transparent );
+ QPainter mapPainter( &m_crosshairs );
+ mapPainter.setViewport( m_crosshairs.rect() );
+ m_svgobj->render( &mapPainter );
+ mapPainter.setViewport( QRect( QPoint( 0, 0 ), viewport->size() ) );
+ }
+
qreal centerx = 0.0;
qreal centery = 0.0;
viewport->currentProjection()->screenCoordinates(viewport->focusPoint(), viewport, centerx, centery);
+ painter->drawPixmap( QPoint ( centerx - width / 2, centery - height / 2 ), m_crosshairs );
+ }
- painter->save();
-
- painter->setRenderHint( QPainter::Antialiasing, false );
- painter->setPen( QColor( Qt::black ) );
- painter->setBrush( QColor( Qt::white ) );
- painter->drawRect( centerx - boxoffset - boxwidth, centery - 1, boxwidth, boxheight );
- painter->drawRect( centerx + boxoffset, centery - 1, boxwidth, boxheight );
-
- 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 );
- painter->drawLine( centerx, centery - halfsize,
- centerx, centery + halfsize );
- */
- painter->restore();
- }
return true;
}
--- trunk/KDE/kdeedu/marble/src/plugins/render/crosshairs/CrosshairsPlugin.h #1210632:1210633
@@ -6,20 +6,28 @@
// the source code.
//
// Copyright 2008 Torsten Rahn <tackat at kde.org>
+// Copyright 2010 Cezar Mocan <mocancezar at gmail.com>
//
//
// This class is a crosshairs plugin.
//
-#ifndef MARBLECROSSHAIRSPLUGIN_H
-#define MARBLECROSSHAIRSPLUGIN_H
+#ifndef MARBLE_CROSSHAIRSPLUGIN_H
+#define MARBLE_CROSSHAIRSPLUGIN_H
#include <QtCore/QObject>
+#include "AbstractFloatItem.h"
+
#include "RenderPlugin.h"
+class QSvgRenderer;
+namespace Ui {
+ class CrosshairsConfigWidget;
+}
+
namespace Marble
{
@@ -36,6 +44,10 @@
MARBLE_PLUGIN(CrosshairsPlugin)
public:
+ CrosshairsPlugin();
+
+ ~CrosshairsPlugin();
+
QStringList backendTypes() const;
QString renderPolicy() const;
@@ -52,15 +64,37 @@
QIcon icon () const;
-
void initialize ();
bool isInitialized () const;
+ bool render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer = 0 );
- bool render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer = 0 );
+ QDialog *configDialog() const;
+
+ QHash<QString,QVariant> settings() const;
+
+ void setSettings( QHash<QString,QVariant> settings );
+
+private Q_SLOTS:
+ void readSettings() const;
+
+ void writeSettings();
+
+ private:
+ Q_DISABLE_COPY( CrosshairsPlugin )
+
+ bool m_isInitialized;
+
+ mutable QSvgRenderer *m_svgobj;
+ mutable QPixmap m_crosshairs;
+
+ QHash<QString,QVariant> m_settings;
+ /** @todo: Refactor plugin interface to have configDialog() non-const */
+ mutable QDialog * m_configDialog;
+ mutable Ui::CrosshairsConfigWidget * m_uiConfigWidget;
};
}
-#endif // MARBLECROSSHAIRSPLUGIN_H
+#endif // MARBLE_CROSSHAIRSPLUGIN_H
More information about the Marble-commits
mailing list