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

List:       kde-commits
Subject:    KDE/kdeedu/marble/src
From:       Torsten Rahn <tackat () kde ! org>
Date:       2010-12-25 21:50:18
Message-ID: 20101225215018.98242AC80E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1209214 by rahn:

Patch by Khanh-Nhan Nguyen

- About dialog for scale bar plugin
- Settings dialog for scale bar plugin
- toggable ratio scale feature

See: http://svn.reviewboard.kde.org/r/6153
and  http://svn.reviewboard.kde.org/r/6136



 M  +4 -0      lib/global.h  
 M  +4 -0      plugins/render/mapscale/CMakeLists.txt  
 A             plugins/render/mapscale/MapScaleConfigWidget.ui  
 M  +106 -1    plugins/render/mapscale/MapScaleFloatItem.cpp  
 M  +23 -0     plugins/render/mapscale/MapScaleFloatItem.h  


--- trunk/KDE/kdeedu/marble/src/lib/global.h #1209213:1209214
@@ -200,6 +200,10 @@
 const qreal M2FT = 3.2808;
 const qreal FT2M = 1.0 / M2FT;
 
+// Conversion meter vs millimeter
+const qreal M2MM = 1000;
+const qreal MM2M = 1.0 / M2MM;
+
 // Conversion degree vs. radians
 const qreal DEG2RAD = M_PI / 180.0;
 const qreal RAD2DEG = 180.0 / M_PI;
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/CMakeLists.txt \
#1209213:1209214 @@ -2,11 +2,15 @@
 
 INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/render/mapscale
+ ${CMAKE_CURRENT_BUILD_DIR}/src/plugins/render/mapscale
  ${CMAKE_BINARY_DIR}/src/plugins/render/mapscale
  ${QT_INCLUDE_DIR}
 )
 INCLUDE(${QT_USE_FILE})
 
 set( mapscale_SRCS MapScaleFloatItem.cpp )
+set( mapscale_UI MapScaleConfigWidget.ui )
 
+qt4_wrap_ui(mapscale_SRCS ${mapscale_UI})
+
 marble_add_plugin( MapScaleFloatItem ${mapscale_SRCS} )
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/MapScaleFloatItem.cpp \
#1209213:1209214 @@ -12,7 +12,10 @@
 
 #include <QtCore/QRect>
 #include <QtGui/QPixmap>
+#include <QtGui/QApplication>
+#include <QtGui/QPushButton>
 
+#include "ui_MapScaleConfigWidget.h"
 #include "MarbleDebug.h"
 #include "global.h"
 #include "Projections/AbstractProjection.h"
@@ -26,6 +29,8 @@
 
 MapScaleFloatItem::MapScaleFloatItem( const QPointF &point, const QSizeF &size )
     : AbstractFloatItem( point, size ),
+      m_aboutDialog(0),
+      m_configDialog(0),
       m_radius(0),
       m_invScale(0.0),
       m_target(QString()),
@@ -39,7 +44,8 @@
       m_pixelInterval(0),
       m_valueInterval(0),
       m_unit(tr("km")),
-      m_scaleInitDone( false )
+      m_scaleInitDone( false ),
+      m_showRatioScale( false )
 {
     bool const smallScreen = MarbleGlobal::getInstance()->profiles() & \
MarbleGlobal::SmallScreen;  if ( smallScreen ) {
@@ -90,6 +96,34 @@
     return true;
 }
 
+QDialog *MapScaleFloatItem::aboutDialog() const
+{
+    if ( !m_aboutDialog ) {
+        // Initializing about dialog
+        m_aboutDialog = new PluginAboutDialog();
+        m_aboutDialog->setName( "Scale Bar Plugin" );
+        m_aboutDialog->setVersion( "0.1" );
+        // FIXME: Can we store this string for all of Marble
+        m_aboutDialog->setAboutText( tr( "<br />(c) 2009 The Marble Project<br /><br \
/><a href=\"http://edu.kde.org/marble\">http://edu.kde.org/marble</a>" ) ); +        \
QList<Author> authors; +        Author rahn;
+        rahn.name = "Torsten Rahn";
+        rahn.task = tr( "Original Developer" );
+        rahn.email = "tackat@kde.org";
+        Author nhan;
+        nhan.name = "Khanh-Nhan Nguyen";
+        nhan.task = tr( "Developer" );
+        nhan.email = "khanh.nhan@wpi.edu";
+        authors.append( nhan );
+        m_aboutDialog->setAuthors( authors );
+        //TODO: add data text
+        m_aboutDialog->setDataText( tr( "None" ) );
+//        m_aboutDialog->setPixmap( m_icon.pixmap( 62, 53 ) );
+    }
+    return m_aboutDialog;
+}
+
+
 void MapScaleFloatItem::changeViewport( ViewportParams *viewport )
 {
     int viewportWidth = viewport->width();
@@ -102,8 +136,13 @@
             && m_scaleInitDone ) )
     {
         int fontHeight     = QFontMetrics( font() ).ascent();
+        if (m_showRatioScale) {
         setContentSize( QSizeF( viewport->width() / 2,
+                                    fontHeight + 3 + m_scaleBarHeight + fontHeight + \
7 ) ); +        } else {
+            setContentSize( QSizeF( viewport->width() / 2,
                                 fontHeight + 3 + m_scaleBarHeight ) );
+        }
 
         m_leftBarMargin  = QFontMetrics( font() ).boundingRect( "0" ).width() / 2;
         m_rightBarMargin = QFontMetrics( font() ).boundingRect( "0000" ).width() / \
2; @@ -122,6 +161,7 @@
                                       const QString& renderPos,
                                       GeoSceneLayer * layer )
 {
+
     Q_UNUSED( layer )
     Q_UNUSED( renderPos )
 
@@ -143,6 +183,23 @@
         pixel2Length *= M_PI / 2 * cos( centerLatitude );
     }
 
+    //calculate scale ratio
+    qreal displayMMPerPixel = 1.0 * painter->device()->widthMM() / \
painter->device()->width(); +    qreal ratio = pixel2Length / (displayMMPerPixel * \
MM2M); +
+    //round ratio to 3 most significant digits, assume that ratio >= 1, otherwise it \
may display "1 : 0" +    //i made this assumption because as the primary use case we \
dont need to zoom in that much +    qreal power = 1;
+    int iRatio = (int)(ratio + 0.5); //round ratio to the nearest integer
+    while (iRatio >= 1000) {
+        iRatio /= 10;
+        power *= 10;
+    }
+    iRatio *= power;
+    QString ratioStr;
+    ratioStr.setNum(iRatio);
+    ratioStr = "1 : " + ratioStr;
+
     m_scaleBarDistance = (qreal)(m_scaleBarWidth) * pixel2Length;
 
     DistanceUnit distanceUnit;
@@ -218,6 +275,9 @@
         }
     }
 
+    int leftRatioIndent = m_leftBarMargin + (m_scaleBarWidth - QFontMetrics( font() \
).width(ratioStr) ) / 2; +    painter->drawText( leftRatioIndent, fontHeight + 3 + \
m_scaleBarHeight + fontHeight + 5, ratioStr ); +
     painter->restore();
 }
 
@@ -265,8 +325,53 @@
     m_valueInterval = (int)( bestMagValue * magnitude / m_bestDivisor );
 }
 
+QDialog *MapScaleFloatItem::configDialog() const
+{
+    if ( !m_configDialog ) {
+        // Initializing configuration dialog
+        m_configDialog = new QDialog();
+        ui_configWidget = new Ui::MapScaleConfigWidget;
+        ui_configWidget->setupUi( m_configDialog );
+    
+        readSettings();
+
+        connect( ui_configWidget->m_buttonBox, SIGNAL( accepted() ),
+                                            SLOT( writeSettings() ) );
+        connect( ui_configWidget->m_buttonBox, SIGNAL( rejected() ),
+                                            SLOT( readSettings() ) );
+        QPushButton *applyButton = ui_configWidget->m_buttonBox->button( \
QDialogButtonBox::Apply ); +        connect( applyButton, SIGNAL( clicked()) ,
+                this,        SLOT( writeSettings() ) );
 }
+    return m_configDialog;
+}
 
+void MapScaleFloatItem::readSettings() const
+{    
+    if ( !m_configDialog )
+        return;
+    
+    if ( m_showRatioScale ) {
+        ui_configWidget->m_showRatioScaleCheckBox->setCheckState( Qt::Checked );
+    }
+    else {
+        ui_configWidget->m_showRatioScaleCheckBox->setCheckState( Qt::Unchecked );
+    }
+}
+
+void MapScaleFloatItem::writeSettings()
+{
+    if ( ui_configWidget->m_showRatioScaleCheckBox->checkState() == Qt::Checked ) {
+        m_showRatioScale = true;
+    } else {
+        m_showRatioScale = false;
+    }
+
+    emit settingsChanged( nameId() );
+}
+
+}
+
 Q_EXPORT_PLUGIN2(MapScaleFloatItem, Marble::MapScaleFloatItem)
 
 #include "MapScaleFloatItem.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/MapScaleFloatItem.h \
#1209213:1209214 @@ -14,10 +14,18 @@
 #include <QtCore/QObject>
 
 #include "AbstractFloatItem.h"
+#include "PluginAboutDialog.h"
 
+namespace Ui
+{
+    class MapScaleConfigWidget;
+}
+
 namespace Marble
 {
 
+class PluginAboutDialog;
+
 /**
  * @short The class that creates a map scale.
  *
@@ -45,7 +53,9 @@
 
     QIcon icon () const;
 
+    QDialog *aboutDialog() const;
 
+
     void initialize ();
 
     bool isInitialized () const;
@@ -55,10 +65,21 @@
     void paintContent( GeoPainter *painter, ViewportParams *viewport,
                        const QString& renderPos, GeoSceneLayer * layer = 0 );
 
+
+    QDialog *configDialog() const;
+
+ private Q_SLOTS:
+    void readSettings() const;
+    void writeSettings();
+
  private:
     int   invScale() const            { return m_invScale; }
     void  setInvScale( int invScale ) { m_invScale = invScale; }
 
+    mutable PluginAboutDialog *m_aboutDialog;
+    mutable QDialog *m_configDialog;
+    mutable Ui::MapScaleConfigWidget *ui_configWidget;
+
     int      m_radius;
     int      m_invScale;
 
@@ -79,6 +100,8 @@
 
     bool     m_scaleInitDone;
 
+    bool     m_showRatioScale;
+
     void calcScaleBar();
 };
 


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

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