[Marble-commits] KDE/kdeedu/marble/src

Andrew Manson g.real.ate at gmail.com
Tue Jul 14 17:52:30 CEST 2009


SVN commit 996649 by mansona:

Moving towards a better Toolbar implementation for Marble Plugins


 M  +2 -15     lib/MarbleWidget.cpp  
 M  +2 -2      lib/MarbleWidget.h  
 M  +50 -16    plugins/render/osmannotate/OsmAnnotatePlugin.cpp  
 M  +9 -9      plugins/render/osmannotate/OsmAnnotatePlugin.h  


--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidget.cpp #996648:996649
@@ -113,7 +113,6 @@
     MarblePhysics    *m_physics;
     
     QToolBar        *m_mainToolbar;
-    QAction         *m_enableInputAction;
 
     //This stuff is NEVER used. Needs to be deleted
     QString          m_proxyHost;
@@ -134,8 +133,6 @@
     if( parent && parent->parent() && parent->parent()->inherits( "QMainWindow" ) ) {
         ((QMainWindow*) parent->parent())->addToolBar(d->m_mainToolbar);
     }
-
-    registerAction( d->m_enableInputAction );
 }
 
 
@@ -223,16 +220,6 @@
 
     m_mainToolbar = new QToolBar(0);
 
-    m_enableInputAction = new QAction(m_mainToolbar);
-//    m_enableInputAction->setText("Enable Marble Input");
-    m_enableInputAction->setCheckable(true);
-    m_enableInputAction->setChecked( true );
-    m_enableInputAction->setIcon( QIcon( MarbleDirs::path("bitmaps/hand.png") ) );
-//    m_enableInputAction->set
-
-    m_widget->connect( m_enableInputAction, SIGNAL(toggled(bool)),
-                       m_widget, SLOT( setInputEnabled(bool)) );
-
     m_widget->connect( m_model, SIGNAL( pluginSettingsChanged() ),
                        m_widget, SIGNAL( pluginSettingsChanged() ) );
 }
@@ -1297,9 +1284,9 @@
     return d->m_password;
 }
 
-void MarbleWidget::registerAction( QAction *action )
+void MarbleWidget::registerActions( QActionGroup* actions)
 {
-    d->m_mainToolbar->addAction( action );
+    d->m_mainToolbar->addActions( actions->actions() );
 }
 
 void MarbleWidget::removeAction( QAction *action )
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidget.h #996648:996649
@@ -21,7 +21,7 @@
  * @author Inge Wallin  <inge at lysator.liu.se>
  */
 
-
+#include <QtGui/QActionGroup>
 #include <QtCore/QTimer>
 #include <QtGui/QWidget>
 #include <QtGui/QImage>
@@ -478,7 +478,7 @@
      * Regestering an action with the marble Widget activates it and places it in
      * the main toolbar.
      */
-    void registerAction( QAction* action );
+    void registerActions( QActionGroup* actions );
 
     /**
      * Disables an action and removes it from the main toolbar.
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/OsmAnnotatePlugin.cpp #996648:996649
@@ -112,8 +112,6 @@
     widgetInitalised= false;
     tmp_lineString = 0;
     m_itemModel = 0;
-    m_addPlacemark =0;
-    m_drawPolygon = 0;
 }
 
 bool OsmAnnotatePlugin::isInitialized () const
@@ -125,8 +123,14 @@
 {
     if( !widgetInitalised ) {
         MarbleWidget* marbleWidget = (MarbleWidget*) painter->device();
-        setupActions( marbleWidget );
+        QList<QActionGroup*> actionGroups = setupActions( marbleWidget );
 
+        QListIterator<QActionGroup*> it(actionGroups);
+
+        while( it.hasNext() ) {
+            marbleWidget->registerActions( it.next() );
+        }
+
         connect(this, SIGNAL(redraw()),
                 marbleWidget, SLOT(repaint()) );
 
@@ -190,8 +194,14 @@
     return true;
 }
 
-void OsmAnnotatePlugin::drawPolygon(bool b)
+void OsmAnnotatePlugin::setAddingPlacemark( bool b)
 {
+    m_addingPlacemark = b;
+}
+
+void OsmAnnotatePlugin::setDrawingPolygon(bool b)
+{
+    m_drawingPolygon = b;
     if( !b ) {
         //stopped drawing the polygon
         if ( tmp_lineString != 0 ) {
@@ -259,8 +269,7 @@
 
         // deal with adding a placemark
         if ( mouseEvent->button() == Qt::LeftButton
-             && m_addPlacemark
-             && m_addPlacemark->isChecked() )
+             && m_addingPlacemark )
         {
             //Add a placemark on the screen
             qreal lon, lat;
@@ -276,7 +285,9 @@
 
                 //FIXME only repaint the new placemark
                 ( ( MarbleWidget* ) watched)->repaint();
-                m_addPlacemark->setChecked( false );
+                //FIXME: enable a way to disable adding a placemark
+                //using signals and slots
+//                m_addPlacemark->setChecked( false );
                 return true;
             }
 
@@ -285,8 +296,7 @@
 
         // deal with drawing a polygon
         if ( mouseEvent->button() == Qt::LeftButton
-             && m_drawPolygon
-             && m_drawPolygon->isChecked() )
+             && m_drawingPolygon )
         {
             qreal lon, lat;
 
@@ -349,17 +359,29 @@
     return false;
 }
 
-void OsmAnnotatePlugin::setupActions(MarbleWidget* widget)
+QList<QActionGroup*> OsmAnnotatePlugin::setupActions(MarbleWidget* widget)
 {
+    QList<QActionGroup*> result;
+    QActionGroup* group = new QActionGroup(0);
+    QAction*    m_addPlacemark;
+    QAction*    m_drawPolygon;
+    QAction*    m_drawLine;
+    QAction*    m_beginSeperator;
+    QAction*    m_endSeperator;
+    QAction*    m_loadOsmFile;
+    QAction*    m_enableInputAction;
+
     m_addPlacemark = new QAction(this);
     m_addPlacemark->setText( "Add Placemark" );
     m_addPlacemark->setCheckable( true );
+    connect( m_addPlacemark, SIGNAL( toggled(bool)),
+             this, SLOT(setAddingPlacemark(bool)) );
 
     m_drawPolygon = new QAction( this );
     m_drawPolygon->setText( "Draw Polygon" );
     m_drawPolygon->setCheckable( true );
     connect( m_drawPolygon, SIGNAL(toggled(bool)),
-             this, SLOT(drawPolygon(bool)) );
+             this, SLOT(setDrawingPolygon(bool)) );
 
     m_loadOsmFile = new QAction( this );
     m_loadOsmFile->setText( "Load Osm File" );
@@ -371,12 +393,24 @@
     m_endSeperator = new QAction ( this );
     m_endSeperator->setSeparator( true );
 
-    widget->registerAction( m_beginSeperator );
-    widget->registerAction( m_addPlacemark );
-    widget->registerAction( m_drawPolygon );
-    widget->registerAction( m_loadOsmFile );
-    widget->registerAction( m_endSeperator );
+        m_enableInputAction = new QAction(this);
+//    m_enableInputAction->setText("Enable Marble Input");
+    m_enableInputAction->setCheckable(true);
+    m_enableInputAction->setChecked( true );
+    m_enableInputAction->setIcon( QIcon( MarbleDirs::path("bitmaps/hand.png") ) );
+//    m_enableInputAction->set
+    connect( m_enableInputAction, SIGNAL(toggled(bool)),
+                       widget, SLOT( setInputEnabled(bool)) );
 
+    group->addAction( m_enableInputAction );
+    group->addAction( m_beginSeperator );
+    group->addAction( m_addPlacemark );
+    group->addAction( m_drawPolygon );
+    group->addAction( m_loadOsmFile );
+    group->addAction( m_endSeperator );
+
+    result.append( group );
+    return result;
 }
 
 }
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/OsmAnnotatePlugin.h #996648:996649
@@ -16,6 +16,7 @@
 #define MARBLEOSMANNOTATEPLUGIN_H
 
 #include <QtCore/QObject>
+#include <QtGui/QActionGroup>
 #include <QtGui/QToolBar>
 #include <QtGui/QGroupBox>
 
@@ -62,8 +63,8 @@
     bool isInitialized () const;
 
 
+    QList<QActionGroup*> actionGroups();
 
-
     bool render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer = 0 );
 
     //Intended to be replaced by an actual model system
@@ -75,25 +76,24 @@
 
     bool    widgetInitalised;
 
-    QAction*    m_addPlacemark;
-    QAction*    m_drawPolygon;
-    QAction*    m_drawLine;
-    QAction*    m_beginSeperator;
-    QAction*    m_endSeperator;
-    QAction*    m_loadOsmFile;
 
 signals:
     void redraw();
 public slots:
-    void drawPolygon(bool);
     void loadOsmFile();
+
+    void setAddingPlacemark( bool );
+    void setDrawingPolygon( bool );
  protected:
     bool eventFilter(QObject* watched, QEvent* event);
 private:
-    void setupActions(MarbleWidget* m);
+    QList<QActionGroup*> setupActions(MarbleWidget* m);
 
     GeoDataLineString* tmp_lineString;
     QList<GeoGraphicsItem*>* m_itemModel;
+
+    bool m_addingPlacemark;
+    bool m_drawingPolygon;
 };
 
 }


More information about the Marble-commits mailing list