[Marble-commits] KDE/kdeedu/marble/src/lib

Bastian Holst bastianholst at gmx.de
Mon Aug 3 22:38:09 CEST 2009


SVN commit 1006502 by bholst:

Adding image and icon support to Marble's LabelGraphicsItem


 M  +12 -0     GeoPainter.cpp  
 M  +2 -0      GeoPainter.h  
 M  +37 -4     graphicsview/LabelGraphicsItem.cpp  
 M  +6 -0      graphicsview/LabelGraphicsItem.h  
 M  +4 -0      graphicsview/LabelGraphicsItem_p.h  


--- trunk/KDE/kdeedu/marble/src/lib/GeoPainter.cpp #1006501:1006502
@@ -935,6 +935,18 @@
     QPainter::drawImage( target, image, source, flags );
 }
 
+void GeoPainter::drawImage( const QRect& rect,
+                            const QImage& image )
+{
+    QPainter::drawImage( rect, image );
+}
+
+void GeoPainter::drawImage( const QRectF& rect,
+                            const QImage& image )
+{
+    QPainter::drawImage( rect, image );
+}
+
 void GeoPainter::drawPixmap( int x, int y, const QPixmap &pixmap )
 {
     QPainter::drawPixmap( x, y, pixmap );
--- trunk/KDE/kdeedu/marble/src/lib/GeoPainter.h #1006501:1006502
@@ -518,6 +518,8 @@
     void drawImage ( const QRect & target, const QImage & image,
                      const QRect & source,
                      Qt::ImageConversionFlags flags = Qt::AutoColor );
+    void drawImage ( const QRect& rect, const QImage& image );
+    void drawImage ( const QRectF& rect, const QImage& image );
     void drawPixmap ( int x, int y, const QPixmap & pixmap );
     void drawPixmap ( const QPointF & point, const QPixmap & pixmap );
     void drawPixmap ( const QPoint & point, const QPixmap & pixmap );
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/LabelGraphicsItem.cpp #1006501:1006502
@@ -43,14 +43,36 @@
 
 void LabelGraphicsItem::setText( const QString& text )
 {
+    clear();
     d->m_text = text;
     QFontMetrics metrics( d->font() );
     setContentSize( metrics.boundingRect( text ).size() );
 }
 
+void LabelGraphicsItem::setImage( const QImage& image, const QSize& size )
+{
+    clear();
+    d->m_image = image;
+    if ( size.isNull() ) {
+        setContentSize( image.size() );
+    }
+    else {
+        setContentSize( size );
+    }
+}
+
+void LabelGraphicsItem::setIcon( const QIcon& icon, const QSize& size )
+{
+    clear();
+    d->m_icon = icon;
+    setContentSize( size );
+}
+
 void LabelGraphicsItem::clear()
 {
     d->m_text.clear();
+    d->m_image = QImage();
+    d->m_icon = QIcon();
     setSize( QSizeF( 0.0, 0.0 ) );
 }
 
@@ -62,9 +84,20 @@
     Q_UNUSED( layer )
 
     painter->save();
-    painter->setFont( d->font() );
-    painter->drawText( contentRect().toRect(),
-                       Qt::AlignVCenter | Qt::AlignLeft,
-                       d->m_text );
+
+    if ( !d->m_text.isNull() ) {
+        painter->setFont( d->font() );
+        painter->drawText( contentRect().toRect(),
+                           Qt::AlignVCenter | Qt::AlignLeft,
+                           d->m_text );
+    }
+    else if ( !d->m_image.isNull() ) {
+        painter->drawImage( contentRect(),
+                            d->m_image );
+    }
+    else if ( !d->m_icon.isNull() ) {
+        d->m_icon.paint( painter, contentRect().toRect(), Qt::AlignCenter );
+    }
+
     painter->restore();
 }
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/LabelGraphicsItem.h #1006501:1006502
@@ -15,6 +15,9 @@
 #include "FrameGraphicsItem.h"
 #include "marble_export.h"
 
+class QImage;
+class QIcon;
+
 namespace Marble
 {
 
@@ -31,6 +34,9 @@
     explicit LabelGraphicsItem( MarbleGraphicsItem *parent = 0 );
 
     void setText( const QString& text );
+    void setImage( const QImage& image, const QSize& size = QSize() );
+    void setIcon( const QIcon& icon, const QSize& size );
+
     void clear();
 
  protected:
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/LabelGraphicsItem_p.h #1006501:1006502
@@ -12,6 +12,8 @@
 #define LABELGRAPHICSITEMPRIVATE_H
 
 #include <QtCore/QString>
+#include <QtGui/QImage>
+#include <QtGui/QIcon>
 
 class QFont;
 
@@ -27,6 +29,8 @@
     QFont font() const;
 
     QString m_text;
+    QImage m_image;
+    QIcon m_icon;
 };
 
 } // namespace Marble


More information about the Marble-commits mailing list