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

List:       kde-commits
Subject:    branches/marble/marble-1.1/src/plugins/render/mapscale
From:       Torsten Rahn <tackat () kde ! org>
Date:       2010-12-28 11:19:17
Message-ID: 20101228111917.74532AC8AD () svn ! kde ! org
[Download RAW message or body]

SVN commit 1209871 by rahn:

Binary Compatible backport of 

rahn * r1209864 trunk/KDE/kdeedu/marble/src/ (4 files in 2 dirs)
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  +47 -5     MapScaleFloatItem.cpp  
 M  +5 -0      MapScaleFloatItem.h  


--- branches/marble/marble-1.1/src/plugins/render/mapscale/MapScaleFloatItem.cpp \
#1209870:1209871 @@ -14,6 +14,9 @@
 #include <QtGui/QPixmap>
 #include <QtGui/QApplication>
 #include <QtGui/QPushButton>
+#include <QtGui/QMenu>
+#include <QtGui/QContextMenuEvent>
+#include <QtGui/QToolTip>
 
 #include "ui_MapScaleConfigWidget.h"
 #include "MarbleDebug.h"
@@ -196,9 +199,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 +277,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 +348,39 @@
     return m_configDialog;
 }
 
+bool MapScaleFloatItem::eventFilter( QObject *object, QEvent *e )
+{
+    if ( !enabled() || !visible() ) {
+        return true;
+    }
+
+    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() ) )
+        {
+            QMenu menu;
+            QAction *toggleaction = menu.addAction( "&Ratio Scale", 
+                                                    this, 
+                                                    SLOT( \
toggleRatioScaleVisibility() ) ); +            toggleaction->setCheckable( true );
+            toggleaction->setChecked( m_showRatioScale );
+            menu.exec( widget->mapToGlobal( menuEvent->pos() ) );
+        }
+        return true;
+    }
+    else if( e->type() == QEvent::ToolTip )
+    {
+        QHelpEvent *helpEvent = dynamic_cast<QHelpEvent *>( e );
+        if( helpEvent != NULL && contains( helpEvent->pos() ) )
+            QToolTip::showText( helpEvent->globalPos(), m_ratioString );
+        return true;
+    }
+    else
+        return AbstractFloatItem::eventFilter( object, e );
+}
+
 void MapScaleFloatItem::readSettings() const
 {    
     if ( !m_configDialog )
@@ -370,8 +405,15 @@
     emit settingsChanged( nameId() );
 }
 
+void MapScaleFloatItem::toggleRatioScaleVisibility()
+{
+    m_showRatioScale = !m_showRatioScale;
+    readSettings();
+    emit settingsChanged( nameId() );
 }
 
+}
+
 Q_EXPORT_PLUGIN2(MapScaleFloatItem, Marble::MapScaleFloatItem)
 
 #include "MapScaleFloatItem.moc"
--- branches/marble/marble-1.1/src/plugins/render/mapscale/MapScaleFloatItem.h \
#1209870:1209871 @@ -68,9 +68,13 @@
 
     QDialog *configDialog() const;
 
+ protected:
+    virtual bool eventFilter( QObject *object, QEvent *e );
+
  private Q_SLOTS:
     void readSettings() const;
     void writeSettings();
+    void toggleRatioScaleVisibility();
 
  private:
     int   invScale() const            { return m_invScale; }
@@ -97,6 +101,7 @@
     int      m_valueInterval;
 
     QString  m_unit;
+    QString m_ratioString;
 
     bool     m_scaleInitDone;
 


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

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