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

List:       kde-commits
Subject:    branches/marble/marble-1.1/src
From:       Dennis Nienhüser <earthwings () gentoo ! org>
Date:       2011-03-31 19:18:08
Message-ID: 20110331191808.6FA36AC8CD () svn ! kde ! org
[Download RAW message or body]

SVN commit 1226653 by nienhueser:

Share the context menu with children. Use an extended one in the map scale plugin. \
Fixes 'Hide' and 'Lock' options missing in the map scale infobox context menu. \
Backport of commit 1226652.

 M  +30 -19    lib/AbstractFloatItem.cpp  
 M  +3 -1      lib/AbstractFloatItem.h  
 M  +19 -7     plugins/render/mapscale/MapScaleFloatItem.cpp  
 M  +2 -0      plugins/render/mapscale/MapScaleFloatItem.h  


--- branches/marble/marble-1.1/src/lib/AbstractFloatItem.cpp #1226652:1226653
@@ -26,17 +26,20 @@
 class AbstractFloatItemPrivate
 {
   public:
-    AbstractFloatItemPrivate()
+    AbstractFloatItemPrivate() : m_contextMenu( 0 )
     {
     }
 
     ~AbstractFloatItemPrivate()
     {
+        delete m_contextMenu;
     }
 
 
     static QPen         s_pen;
     static QFont        s_font;
+
+    QMenu* m_contextMenu;
 };
 
 QPen         AbstractFloatItemPrivate::s_pen = QPen( Qt::black );
@@ -140,24 +143,7 @@
         QContextMenuEvent *menuEvent = dynamic_cast<QContextMenuEvent *> ( e );
         if( widget != NULL && menuEvent != NULL && contains( menuEvent->pos() ) )
         {
-	    QMenu menu;
-	    QAction *lockaction = menu.addAction( tr( "&Lock" ) );
-	    lockaction->setCheckable( true );
-	    lockaction->setChecked( positionLocked() );
-	    connect( lockaction, SIGNAL( triggered( bool ) ),
-		    this, SLOT( setPositionLocked( bool ) ) );
-	    QAction *hideaction = menu.addAction( tr( "&Hide" ) );
-	    connect( hideaction, SIGNAL( triggered() ),
-		    this, SLOT( hide() ) );
-	    QDialog *dialog = configDialog();
-	    if( dialog != NULL )
-	    {
-		menu.addSeparator();
-		QAction *configaction = menu.addAction( tr( "&Configure..." ) );
-		connect( configaction, SIGNAL( triggered() ),
-			dialog, SLOT( exec() ) );
-	    }
-	    menu.exec( widget->mapToGlobal( menuEvent->pos() ) );
+            contextMenu()->exec( widget->mapToGlobal( menuEvent->pos() ) );
             return true;
         }
         return false;
@@ -208,6 +194,31 @@
     setVisible( false );
 }
 
+QMenu* AbstractFloatItem::contextMenu()
+{
+    if ( !d->m_contextMenu )
+    {
+        d->m_contextMenu = new QMenu;
 }
 
+    QAction *lockAction = d->m_contextMenu->addAction( tr( "&Lock" ) );
+    lockAction->setCheckable( true );
+    lockAction->setChecked( positionLocked() );
+    connect( lockAction, SIGNAL( triggered( bool ) ), this, SLOT( setPositionLocked( \
bool ) ) ); +    QAction *hideAction = d->m_contextMenu->addAction( tr( "&Hide" ) );
+    connect( hideAction, SIGNAL( triggered() ), this, SLOT( hide() ) );
+    QDialog *dialog = configDialog();
+    if( dialog )
+    {
+        d->m_contextMenu->addSeparator();
+        QAction *configAction = d->m_contextMenu->addAction( tr( "&Configure..." ) \
); +        connect( configAction, SIGNAL( triggered() ), dialog, SLOT( exec() ) );
+    }
+
+    Q_ASSERT( d->m_contextMenu );
+    return d->m_contextMenu;
+}
+
+}
+
 #include "AbstractFloatItem.moc"
--- branches/marble/marble-1.1/src/lib/AbstractFloatItem.h #1226652:1226653
@@ -24,12 +24,13 @@
 #include "marble_export.h"
 
 
+class QMenu;
+
 namespace Marble
 {
 
 class AbstractFloatItemPrivate;
 
-
 /**
  * @short The abstract class that creates an "empty" float item.
  *
@@ -73,6 +74,7 @@
 
  protected:
     virtual bool eventFilter( QObject *object, QEvent *e );
+    QMenu* contextMenu();
 
  private:
     Q_DISABLE_COPY( AbstractFloatItem )
--- branches/marble/marble-1.1/src/plugins/render/mapscale/MapScaleFloatItem.cpp \
#1226652:1226653 @@ -48,7 +48,8 @@
       m_valueInterval(0),
       m_unit(tr("km")),
       m_scaleInitDone( false ),
-      m_showRatioScale( false )
+      m_showRatioScale( false ),
+      m_contextMenu( 0 )
 {
     bool const smallScreen = MarbleGlobal::getInstance()->profiles() & \
MarbleGlobal::SmallScreen;  if ( smallScreen ) {
@@ -367,14 +368,25 @@
         QContextMenuEvent *menuEvent = dynamic_cast<QContextMenuEvent *> ( e );
         if( widget != NULL && menuEvent != NULL && contains( menuEvent->pos() ) )
         {
-            QMenu menu;
-            QAction *toggleaction = menu.addAction( "&Ratio Scale", 
-                                                    this, 
+            if ( !m_contextMenu ) {
+                m_contextMenu = contextMenu();
+
+                foreach( QAction *action, m_contextMenu->actions() ) {
+                    if ( action->text() == tr( "&Configure..." ) ) {
+                        m_contextMenu->removeAction( action );
+                        break;
+                    }
+                }
+
+                QAction *toggleAction = m_contextMenu->addAction( tr("&Ratio \
                Scale"), this,
                                                     SLOT( \
                toggleRatioScaleVisibility() ) );
-            toggleaction->setCheckable( true );
-            toggleaction->setChecked( m_showRatioScale );
-            menu.exec( widget->mapToGlobal( menuEvent->pos() ) );
+                toggleAction->setCheckable( true );
+                toggleAction->setChecked( m_showRatioScale );
         }
+
+            Q_ASSERT( m_contextMenu );
+            m_contextMenu->exec( widget->mapToGlobal( menuEvent->pos() ) );
+        }
         return true;
     }
     else if( e->type() == QEvent::ToolTip )
--- branches/marble/marble-1.1/src/plugins/render/mapscale/MapScaleFloatItem.h \
#1226652:1226653 @@ -107,6 +107,8 @@
 
     bool     m_showRatioScale;
 
+    QMenu*   m_contextMenu;
+
     void calcScaleBar();
 };
 


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

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