[Marble-commits] KDE/kdeedu/marble/src/lib
Dennis Nienhüser
earthwings at gentoo.org
Wed Apr 28 21:14:14 CEST 2010
SVN commit 1120278 by nienhueser:
Support adding actions to the context menu (not public api). Move measure tool stuff from popup menu to default input handler.
M +45 -7 MarbleWidgetInputHandler.cpp
M +4 -0 MarbleWidgetInputHandler.h
M +4 -43 MarbleWidgetPopupMenu.cpp
M +8 -12 MarbleWidgetPopupMenu.h
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetInputHandler.cpp #1120277:1120278
@@ -17,6 +17,7 @@
#include <QtCore/QPointer>
#include <QtCore/QTime>
#include <QtCore/QTimer>
+#include <QtGui/QAction>
#include <QtGui/QCursor>
#include <QtGui/QMouseEvent>
#include <QtGui/QPixmap>
@@ -176,6 +177,10 @@
QPoint m_toolTipPosition;
MarbleWidgetPopupMenu *m_popupmenu;
+
+ QAction *m_addMeasurePointAction;
+ QAction *m_removeLastMeasurePointAction;
+ QAction *m_removeMeasurePointsAction;
};
MarbleWidgetDefaultInputHandler::Private::Private()
@@ -338,16 +343,29 @@
d->m_popupmenu = new MarbleWidgetPopupMenu( MarbleWidgetInputHandler::d->m_widget,
MarbleWidgetInputHandler::d->m_model );
}
+
+ d->m_addMeasurePointAction = new QAction( tr( "Add &Measure Point" ), this);
+ d->m_popupmenu->addAction( Qt::RightButton, d->m_addMeasurePointAction );
+ d->m_removeLastMeasurePointAction = new QAction( tr( "Remove &Last Measure Point" ),
+ this);
+ d->m_removeLastMeasurePointAction->setEnabled(false);
+ d->m_popupmenu->addAction( Qt::RightButton, d->m_removeLastMeasurePointAction );
+ d->m_removeMeasurePointsAction = new QAction( tr( "&Remove Measure Points" ),
+ this);
+ d->m_removeMeasurePointsAction->setEnabled(false);
+ d->m_popupmenu->addAction( Qt::RightButton, d->m_removeMeasurePointsAction );
+
+ connect( d->m_addMeasurePointAction, SIGNAL( triggered() ),
+ SLOT( addMeasurePoint() ) );
+ connect( d->m_removeLastMeasurePointAction, SIGNAL(triggered() ),
+ measureTool, SLOT( removeLastMeasurePoint() ) );
+ connect( d->m_removeMeasurePointsAction, SIGNAL( triggered() ),
+ measureTool, SLOT( removeMeasurePoints() ) );
+
connect( this, SIGNAL( rmbRequest( int, int ) ),
this, SLOT( showRmbMenu( int, int ) ) );
- connect( d->m_popupmenu, SIGNAL( addMeasurePoint( qreal, qreal ) ),
- measureTool, SLOT( addMeasurePoint( qreal, qreal ) ) );
- connect( d->m_popupmenu, SIGNAL( removeLastMeasurePoint() ),
- measureTool, SLOT( removeLastMeasurePoint() ) );
- connect( d->m_popupmenu, SIGNAL( removeMeasurePoints() ),
- measureTool, SLOT( removeMeasurePoints( ) ) );
connect( measureTool, SIGNAL( numberOfMeasurePointsChanged( int ) ),
- d->m_popupmenu, SLOT( slotNumberOfMeasurePointsChanged( int ) ) );
+ this, SLOT( setNumberOfMeasurePoints( int ) ) );
connect( this, SIGNAL( lmbRequest( int, int ) ),
this, SLOT( showLmbMenu( int, int ) ) );
}
@@ -362,6 +380,7 @@
void MarbleWidgetDefaultInputHandler::showRmbMenu( int x, int y )
{
if ( isMouseButtonPopupEnabled( Qt::RightButton ) ) {
+ d->m_addMeasurePointAction->setData( QPoint( x, y ) );
d->m_popupmenu->showRmbMenu( x, y );
}
}
@@ -794,5 +813,24 @@
return false;
}
+void MarbleWidgetDefaultInputHandler::addMeasurePoint()
+{
+ QPoint p = d->m_addMeasurePointAction->data().toPoint();
+ qreal lat;
+ qreal lon;
+
+ MarbleWidgetInputHandler::d->m_widget->geoCoordinates( p.x(), p.y(), lon, lat, GeoDataCoordinates::Radian );
+ MeasureTool *measureTool = MarbleWidgetInputHandler::d->m_widget->map()->measureTool();
+ measureTool->addMeasurePoint( lon, lat );
+}
+
+void MarbleWidgetDefaultInputHandler::setNumberOfMeasurePoints( int newNumber )
+{
+ const bool enableMeasureActions = ( newNumber > 0 );
+ d->m_removeMeasurePointsAction->setEnabled(enableMeasureActions);
+ d->m_removeLastMeasurePointAction->setEnabled(enableMeasureActions);
+}
+
+
#include "MarbleWidgetInputHandler.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetInputHandler.h #1120277:1120278
@@ -107,6 +107,10 @@
void lmbTimeout();
+ void addMeasurePoint();
+
+ void setNumberOfMeasurePoints( int number );
+
private:
Q_DISABLE_COPY( MarbleWidgetDefaultInputHandler )
class Private;
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetPopupMenu.cpp #1120277:1120278
@@ -54,17 +54,7 @@
m_copyCoordinateAction = new QAction( tr( "0 N 0 W" ), this );
// Tool actions (Right mouse button)
- m_addMeasurePointAction = new QAction( tr( "Add &Measure Point" ), this);
- m_rmbMenu->addAction( m_addMeasurePointAction );
- m_removeLastMeasurePointAction = new QAction( tr( "Remove &Last Measure Point" ),
- this);
- m_removeLastMeasurePointAction->setEnabled(false);
- m_rmbMenu->addAction( m_removeLastMeasurePointAction );
- m_removeMeasurePointsAction = new QAction( tr( "&Remove Measure Points" ),
- this);
- m_removeMeasurePointsAction->setEnabled(false);
- m_rmbMenu->addAction( m_removeMeasurePointsAction );
- m_rmbMenu->addSeparator();
+ m_rmbExtensionPoint = m_rmbMenu->addSeparator();
m_setHomePointAction = new QAction( tr( "&Set Home Location" ), this);
m_rmbMenu->addAction( m_setHomePointAction );
m_rmbMenu->addSeparator();
@@ -78,12 +68,6 @@
connect( m_setHomePointAction, SIGNAL( triggered() ),
SLOT( slotSetHomePoint() ) );
- connect( m_addMeasurePointAction, SIGNAL( triggered() ),
- SLOT( slotAddMeasurePoint() ) );
- connect( m_removeLastMeasurePointAction, SIGNAL(triggered() ),
- SLOT( slotRemoveLastMeasurePoint() ) );
- connect( m_removeMeasurePointsAction, SIGNAL( triggered() ),
- SLOT( slotRemoveMeasurePoints() ) );
connect( m_aboutDialogAction, SIGNAL( triggered() ),
SLOT( slotAboutDialog() ) );
connect( m_copyCoordinateAction,SIGNAL( triggered() ),
@@ -156,7 +140,6 @@
{
QPoint curpos = QPoint( xpos, ypos );
m_setHomePointAction->setData( curpos );
- m_addMeasurePointAction->setData( curpos );
m_rmbMenu->popup( m_widget->mapToGlobal( curpos ) );
}
@@ -246,39 +229,17 @@
}
}
-void MarbleWidgetPopupMenu::slotAddMeasurePoint()
-{
- QPoint p = m_addMeasurePointAction->data().toPoint();
-
- qreal lat;
- qreal lon;
-
- m_widget->geoCoordinates( p.x(), p.y(), lon, lat, GeoDataCoordinates::Radian );
-
- emit addMeasurePoint( lon, lat );
-}
-
-void MarbleWidgetPopupMenu::slotRemoveMeasurePoints()
-{
- emit removeMeasurePoints();
-}
-
void MarbleWidgetPopupMenu::slotAboutDialog()
{
MarbleAboutDialog dlg( m_widget );
dlg.exec();
}
-void MarbleWidgetPopupMenu::slotRemoveLastMeasurePoint()
+void MarbleWidgetPopupMenu::addAction( Qt::MouseButton button, QAction* action )
{
- emit removeLastMeasurePoint();
+ if ( button == Qt::RightButton ) {
+ m_rmbMenu->insertAction( m_rmbExtensionPoint, action );
}
-
-void MarbleWidgetPopupMenu::slotNumberOfMeasurePointsChanged( int newNumber )
-{
- const bool enableMeasureActions = ( newNumber > 0 );
- m_removeMeasurePointsAction->setEnabled(enableMeasureActions);
- m_removeLastMeasurePointAction->setEnabled(enableMeasureActions);
}
#include "MarbleWidgetPopupMenu.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetPopupMenu.h #1120277:1120278
@@ -41,23 +41,20 @@
MarbleWidgetPopupMenu(MarbleWidget*, MarbleModel*);
virtual ~MarbleWidgetPopupMenu(){}
+ /**
+ * Adds the action to the menu associated with the specified
+ * mouse button
+ */
+ void addAction( Qt::MouseButton button, QAction* action );
+
public Q_SLOTS:
void showLmbMenu( int, int );
void showRmbMenu( int, int );
void showFeatureInfo( QAction* );
- void slotNumberOfMeasurePointsChanged( int newNumber );
- Q_SIGNALS:
- void addMeasurePoint( qreal, qreal );
- void removeLastMeasurePoint();
- void removeMeasurePoints();
-
protected Q_SLOTS:
void slotSetHomePoint();
void slotCopyCoordinates();
- void slotAddMeasurePoint();
- void slotRemoveLastMeasurePoint();
- void slotRemoveMeasurePoints();
void slotAboutDialog();
private:
@@ -77,10 +74,9 @@
QAction *m_copyCoordinateAction;
QAction *m_setHomePointAction;
- QAction *m_addMeasurePointAction;
- QAction *m_removeLastMeasurePointAction;
- QAction *m_removeMeasurePointsAction;
QAction *m_aboutDialogAction;
+
+ QAction *m_rmbExtensionPoint;
};
}
More information about the Marble-commits
mailing list