[Marble-commits] KDE/kdeedu/marble/src
Dennis Nienhüser
earthwings at gentoo.org
Thu Mar 31 20:43:00 CEST 2011
SVN commit 1226652 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.
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
--- trunk/KDE/kdeedu/marble/src/lib/AbstractFloatItem.cpp #1226651:1226652
@@ -25,17 +25,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 );
@@ -160,25 +163,8 @@
void AbstractFloatItem::contextMenuEvent ( QWidget *w, QContextMenuEvent *e )
{
- 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() ) );
+ contextMenu()->exec( w->mapToGlobal( e->pos() ) );
}
- menu.exec( w->mapToGlobal( e->pos() ) );
-}
void AbstractFloatItem::toolTipEvent ( QHelpEvent *e )
{
@@ -227,6 +213,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"
--- trunk/KDE/kdeedu/marble/src/lib/AbstractFloatItem.h #1226651:1226652
@@ -27,12 +27,13 @@
#include "marble_export.h"
+class QMenu;
+
namespace Marble
{
class AbstractFloatItemPrivate;
-
/**
* @short The abstract class that creates an "empty" float item.
*
@@ -78,6 +79,7 @@
virtual bool eventFilter( QObject *object, QEvent *e );
virtual void contextMenuEvent ( QWidget *w, QContextMenuEvent *e );
virtual void toolTipEvent( QHelpEvent *e );
+ QMenu* contextMenu();
private:
Q_DISABLE_COPY( AbstractFloatItem )
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/MapScaleFloatItem.cpp #1226651:1226652
@@ -47,7 +47,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 ) {
@@ -356,15 +357,26 @@
void MapScaleFloatItem::contextMenuEvent( QWidget *w, QContextMenuEvent *e )
{
- QMenu menu;
- QAction *toggleaction = menu.addAction( tr("&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( w->mapToGlobal( e->pos() ) );
+ toggleAction->setCheckable( true );
+ toggleAction->setChecked( m_showRatioScale );
}
+ Q_ASSERT( m_contextMenu );
+ m_contextMenu->exec( w->mapToGlobal( e->pos() ) );
+}
+
void MapScaleFloatItem::toolTipEvent( QHelpEvent *e )
{
QToolTip::showText( e->globalPos(), m_ratioString );
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/MapScaleFloatItem.h #1226651:1226652
@@ -108,6 +108,8 @@
bool m_showRatioScale;
+ QMenu* m_contextMenu;
+
void calcScaleBar();
};
More information about the Marble-commits
mailing list