[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/marble/marble-1.1
From:       Dennis Nienhüser <earthwings () gentoo ! org>
Date:       2011-01-01 14:05:36
Message-ID: 20110101140536.67865AC8AE () svn ! kde ! org
[Download RAW message or body]

SVN commit 1210637 by nienhueser:

Themable compass plugin. Patch by me, artwork by professorpi in \
http://www.google-melange.com/gci/task/show/google/gci2010/kde/t128906507346 Backport \
of commit 1210634.

 M  +0 -1      data/CMakeLists.txt  
 M  +3 -0      src/plugins/render/compass/CMakeLists.txt  
 A             src/plugins/render/compass/CompassConfigWidget.ui  
 M  +79 -9     src/plugins/render/compass/CompassFloatItem.cpp  
 M  +22 -7     src/plugins/render/compass/CompassFloatItem.h  
 A             src/plugins/render/compass/compass-arrows.svg  
 A             src/plugins/render/compass/compass-atom.svg  
 A             src/plugins/render/compass/compass-magnet.svg  
 A             src/plugins/render/compass/compass.qrc  
 A             src/plugins/render/compass/compass.svg  


--- branches/marble/marble-1.1/data/CMakeLists.txt #1210636:1210637
@@ -22,7 +22,6 @@
 DESTINATION ${MARBLE_DATA_INSTALL_PATH}/bitmaps)
 
 install (FILES 
-svg/compass.svg
 svg/marble-logo.svg
 svg/marble-logo.png
 svg/marble-logo-32dpi.png
--- branches/marble/marble-1.1/src/plugins/render/compass/CMakeLists.txt \
#1210636:1210637 @@ -8,5 +8,8 @@
 INCLUDE(${QT_USE_FILE})
 
 set( compass_SRCS CompassFloatItem.cpp )
+set( compass_UI CompassConfigWidget.ui )
+qt4_wrap_ui( compass_SRCS ${compass_UI} )
+qt4_add_resources( compass_SRCS compass.qrc )
 
 marble_add_plugin( CompassFloatItem ${compass_SRCS} )
--- branches/marble/marble-1.1/src/plugins/render/compass/CompassFloatItem.cpp \
#1210636:1210637 @@ -6,20 +6,23 @@
 // the source code.
 //
 // Copyright 2008 Torsten Rahn <tackat@kde.org>
+// Copyright 2010 Dennis Nienhüser <earthwings@gentoo.org>
 //
 
 #include "CompassFloatItem.h"
+#include "ui_CompassConfigWidget.h"
 
 #include "MarbleDebug.h"
+#include "MarbleDirs.h"
+#include "GeoPainter.h"
+#include "ViewportParams.h"
+
 #include <QtCore/QRect>
 #include <QtGui/QColor>
 #include <QtGui/QPixmap>
+#include <QtGui/QPushButton>
 #include <QtSvg/QSvgRenderer>
 
-#include "MarbleDirs.h"
-#include "GeoPainter.h"
-#include "ViewportParams.h"
-
 namespace Marble
 {
 
@@ -28,7 +31,9 @@
       m_isInitialized( false ),
       m_svgobj( 0 ),
       m_compass(),
-      m_polarity( 0 )
+      m_polarity( 0 ),
+      m_configDialog( 0 ),
+      m_uiConfigWidget( 0 )
 {
 }
 
@@ -67,11 +72,9 @@
     return QIcon();
 }
 
-
 void CompassFloatItem::initialize()
 {
-    m_svgobj = new QSvgRenderer( MarbleDirs::path( "svg/compass.svg" ),
-                                 this );
+    readSettings();
     m_isInitialized = true;
 }
 
@@ -149,7 +152,7 @@
     QSize compassSize( compassLength, compassLength ); 
 
     // Rerender compass pixmap if the size has changed
-    if ( m_compass.size() != compassSize ) {
+    if ( m_compass.isNull() || m_compass.size() != compassSize ) {
         m_compass = QPixmap( compassSize );
         m_compass.fill( Qt::transparent );
         QPainter mapPainter( &m_compass );
@@ -162,8 +165,75 @@
     painter->restore();
 }
 
+QDialog *CompassFloatItem::configDialog() const
+{
+    if ( !m_configDialog ) {
+        m_configDialog = new QDialog();
+        m_uiConfigWidget = new Ui::CompassConfigWidget;
+        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> CompassFloatItem::settings() const
+{
+    return m_settings;
+}
+
+void CompassFloatItem::setSettings( QHash<QString,QVariant> settings )
+{
+    m_settings = settings;
+    readSettings();
+}
+
+void CompassFloatItem::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 = ":/compass.svg";
+    switch( index ) {
+    case 1:
+        theme = ":/compass-arrows.svg";
+        break;
+    case 2:
+        theme = ":/compass-atom.svg";
+        break;
+    case 3:
+        theme = ":/compass-magnet.svg";
+        break;
+    }
+
+    delete m_svgobj;
+    /** @todo FIXME we really need to change the configDialog() const API */
+    CompassFloatItem * me = const_cast<CompassFloatItem*>( this );
+    m_svgobj = new QSvgRenderer( theme, me );
+    m_compass = QPixmap();
+}
+
+void CompassFloatItem::writeSettings()
+{
+    if ( m_uiConfigWidget ) {
+        m_settings["theme"] = m_uiConfigWidget->m_themeList->currentRow();
+    }
+    readSettings();
+    update();
+    emit settingsChanged( nameId() );
+}
+
+}
+
 Q_EXPORT_PLUGIN2( CompassFloatItem, Marble::CompassFloatItem )
 
 #include "CompassFloatItem.moc"
--- branches/marble/marble-1.1/src/plugins/render/compass/CompassFloatItem.h \
#1210636:1210637 @@ -8,10 +8,6 @@
 // Copyright 2008 Torsten Rahn <tackat@kde.org>
 //
 
-//
-// This class is a test plugin.
-//
-
 #ifndef COMPASS_FLOAT_ITEM_H
 #define COMPASS_FLOAT_ITEM_H
 
@@ -21,6 +17,10 @@
 
 class QSvgRenderer;
 
+namespace Ui {
+    class CompassConfigWidget;
+}
+
 namespace Marble
 {
 
@@ -51,7 +51,6 @@
 
     QIcon icon () const;
 
-
     void initialize ();
 
     bool isInitialized () const;
@@ -63,16 +62,32 @@
     void paintContent( 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( CompassFloatItem )
 
     bool           m_isInitialized;
 
-    QSvgRenderer  *m_svgobj;
-    QPixmap        m_compass;
+    mutable QSvgRenderer  *m_svgobj;
+    mutable QPixmap        m_compass;
 
     /// allowed values: -1, 0, 1; default here: 0. FIXME: Declare enum
     int            m_polarity;
+
+    QHash<QString,QVariant> m_settings;
+    /** @todo: Refactor plugin interface to have configDialog() non-const */
+    mutable QDialog * m_configDialog;
+    mutable Ui::CompassConfigWidget * m_uiConfigWidget;
 };
 
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic