[Marble-commits] KDE/kdeedu/marble/src
Torsten Rahn
tackat at kde.org
Tue Dec 28 11:56:13 CET 2010
SVN commit 1209864 by rahn:
Changes:
- Contextmenu for scalebar plugin by Daniel Marth.
- Context menu and tooltip infrastructure for AbstractFloatItems by
Daniel Marth
http://reviewboard.kde.org/r/6226/
M +33 -0 lib/AbstractFloatItem.cpp
M +5 -0 lib/AbstractFloatItem.h
M +29 -5 plugins/render/mapscale/MapScaleFloatItem.cpp
M +6 -0 plugins/render/mapscale/MapScaleFloatItem.h
--- trunk/KDE/kdeedu/marble/src/lib/AbstractFloatItem.cpp #1209863:1209864
@@ -124,9 +124,42 @@
return false;
}
+ if( e->type() == QEvent::ContextMenu )
+ {
+ QWidget *widget = dynamic_cast<QWidget *>( object );
+ QContextMenuEvent *menuEvent = dynamic_cast<QContextMenuEvent *> ( e );
+ if( widget != NULL && menuEvent != NULL && contains( menuEvent->pos() ) )
+ {
+ contextMenuEvent( widget, menuEvent );
+ return true;
+ }
+ return false;
+ }
+ else if( e->type() == QEvent::ToolTip )
+ {
+ QHelpEvent *helpEvent = dynamic_cast<QHelpEvent *>( e );
+ if( helpEvent != NULL && contains( helpEvent->pos() ) )
+ {
+ toolTipEvent( helpEvent );
+ return true;
+ }
+ return false;
+ }
+ else
return ScreenGraphicsItem::eventFilter( object, e );
}
+void AbstractFloatItem::contextMenuEvent ( QWidget *w, QContextMenuEvent *e )
+{
+ Q_UNUSED( w );
+ Q_UNUSED( e );
+}
+
+void AbstractFloatItem::toolTipEvent ( QHelpEvent *e )
+{
+ Q_UNUSED( e );
+}
+
bool AbstractFloatItem::render( GeoPainter *painter, ViewportParams *viewport,
const QString& renderPos, GeoSceneLayer * layer )
{
--- trunk/KDE/kdeedu/marble/src/lib/AbstractFloatItem.h #1209863:1209864
@@ -18,6 +18,9 @@
#include <QtGui/QPen>
#include <QtGui/QFont>
+#include <QtGui/QContextMenuEvent>
+#include <QtGui/QHelpEvent>
+#include <QtGui/QWidget>
#include "RenderPlugin.h"
#include "FrameGraphicsItem.h"
@@ -70,6 +73,8 @@
protected:
virtual bool eventFilter( QObject *object, QEvent *e );
+ virtual void contextMenuEvent ( QWidget *w, QContextMenuEvent *e );
+ virtual void toolTipEvent( QHelpEvent *e );
private:
Q_DISABLE_COPY( AbstractFloatItem )
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/MapScaleFloatItem.cpp #1209863:1209864
@@ -14,6 +14,8 @@
#include <QtGui/QPixmap>
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
+#include <QtGui/QMenu>
+#include <QtGui/QToolTip>
#include "ui_MapScaleConfigWidget.h"
#include "MarbleDebug.h"
@@ -196,9 +198,8 @@
power *= 10;
}
iRatio *= power;
- QString ratioStr;
- ratioStr.setNum(iRatio);
- ratioStr = "1 : " + ratioStr;
+ m_ratioString.setNum(iRatio);
+ m_ratioString = m_ratioString = "1 : " + m_ratioString;
m_scaleBarDistance = (qreal)(m_scaleBarWidth) * pixel2Length;
@@ -275,8 +276,8 @@
}
}
- int leftRatioIndent = m_leftBarMargin + (m_scaleBarWidth - QFontMetrics( font() ).width(ratioStr) ) / 2;
- painter->drawText( leftRatioIndent, fontHeight + 3 + m_scaleBarHeight + fontHeight + 5, ratioStr );
+ int leftRatioIndent = m_leftBarMargin + (m_scaleBarWidth - QFontMetrics( font() ).width(m_ratioString) ) / 2;
+ painter->drawText( leftRatioIndent, fontHeight + 3 + m_scaleBarHeight + fontHeight + 5, m_ratioString );
painter->restore();
}
@@ -346,6 +347,22 @@
return m_configDialog;
}
+void MapScaleFloatItem::contextMenuEvent( QWidget *w, QContextMenuEvent *e )
+{
+ QMenu menu;
+ QAction *toggleaction = menu.addAction( "&Ratio Scale",
+ this,
+ SLOT( toggleRatioScaleVisibility() ) );
+ toggleaction->setCheckable( true );
+ toggleaction->setChecked( m_showRatioScale );
+ menu.exec( w->mapToGlobal( e->pos() ) );
+}
+
+void MapScaleFloatItem::toolTipEvent( QHelpEvent *e )
+{
+ QToolTip::showText( e->globalPos(), m_ratioString );
+}
+
void MapScaleFloatItem::readSettings() const
{
if ( !m_configDialog )
@@ -370,8 +387,15 @@
emit settingsChanged( nameId() );
}
+void MapScaleFloatItem::toggleRatioScaleVisibility()
+{
+ m_showRatioScale = !m_showRatioScale;
+ readSettings();
+ emit settingsChanged( nameId() );
}
+}
+
Q_EXPORT_PLUGIN2(MapScaleFloatItem, Marble::MapScaleFloatItem)
#include "MapScaleFloatItem.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/MapScaleFloatItem.h #1209863:1209864
@@ -68,9 +68,14 @@
QDialog *configDialog() const;
+ protected:
+ virtual void contextMenuEvent( QWidget *w, QContextMenuEvent *e );
+ virtual void toolTipEvent( QHelpEvent *e );
+
private Q_SLOTS:
void readSettings() const;
void writeSettings();
+ void toggleRatioScaleVisibility();
private:
int invScale() const { return m_invScale; }
@@ -97,6 +102,7 @@
int m_valueInterval;
QString m_unit;
+ QString m_ratioString;
bool m_scaleInitDone;
More information about the Marble-commits
mailing list