[Marble-commits] KDE/kdeedu/marble

Torsten Rahn tackat at kde.org
Wed Jan 6 01:30:42 CET 2010


SVN commit 1070554 by rahn:


- Native Checkboxes in the LegendBrowser.



 D             data/bitmaps/checkbox_checked.png  
 D             data/bitmaps/checkbox_disabled.png  
 D             data/bitmaps/checkbox_empty.png  
 M  +20 -4     src/lib/MarbleLegendBrowser.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/MarbleLegendBrowser.cpp #1070553:1070554
@@ -21,6 +21,8 @@
 #include <QtGui/QPainter>
 #include <QtGui/QTextFrame>
 #include <QtGui/QScrollBar>
+#include <QtGui/QStyle>
+#include <QtGui/QStyleOptionButton>
 #include <QtCore/QRegExp>
 
 #include "GeoSceneDocument.h"
@@ -305,16 +307,30 @@
     if ( type == QTextDocument::ImageResource
          && name.toString().startsWith("checkbox:", Qt::CaseInsensitive) )
     {
+        QStyleOptionButton option;
+        option.initFrom(this);
+        int width = style()->pixelMetric(QStyle::PM_IndicatorWidth, &option, this );
+        int height = style()->pixelMetric(QStyle::PM_IndicatorHeight, &option, this );
+        option.rect = QRect( 0, 0, width, height );
+        
         QString checkBoxName = name.toString().section(':', 1, -1);
         if ( !d->m_checkBoxMap.contains( checkBoxName ) ) {
-            newName = MarbleDirs::path( "bitmaps/checkbox_disabled.png" );
+            option.state = QStyle::State_None;
         }
         else if ( d->m_checkBoxMap.value( checkBoxName ) )
-            newName = MarbleDirs::path( "bitmaps/checkbox_checked.png" );
+            option.state |= QStyle::State_On;
         else
-            newName = MarbleDirs::path( "bitmaps/checkbox_empty.png" );
+            option.state |= QStyle::State_Off;
+            
+        QPixmap pixmap( width, height );
+        pixmap.fill( Qt::transparent );
 
-        return QTextBrowser::loadResource( type, QUrl::fromLocalFile( newName ) );
+        QPainter painter;
+        painter.begin(&pixmap);
+        style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &option, &painter, this);
+        painter.end();
+
+        return pixmap;
     }
 
     if ( type == QTextDocument::ImageResource


More information about the Marble-commits mailing list