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

Bastian Holst bastianholst at gmx.de
Mon Aug 3 16:36:05 CEST 2009


SVN commit 1006350 by bholst:

MarbleGraphicsItem layout preview.


 AM            AbstractMarbleGraphicsLayout.cpp   [License: LGPL]
 AM            AbstractMarbleGraphicsLayout.h   [License: LGPL]
 M  +4 -0      CMakeLists.txt  
 M  +8 -0      FrameGraphicsItem.cpp  
 M  +6 -1      FrameGraphicsItem.h  
 AM            MarbleGraphicsGridLayout.cpp   [License: LGPL]
 AM            MarbleGraphicsGridLayout.h   [License: LGPL]
 M  +41 -3     MarbleGraphicsItem.cpp  
 M  +39 -12    MarbleGraphicsItem.h  
 M  +11 -2     MarbleGraphicsItem_p.h  


** trunk/KDE/kdeedu/marble/src/lib/graphicsview/AbstractMarbleGraphicsLayout.cpp #property svn:eol-style
   + native
** trunk/KDE/kdeedu/marble/src/lib/graphicsview/AbstractMarbleGraphicsLayout.h #property svn:eol-style
   + native
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/CMakeLists.txt #1006349:1006350
@@ -10,6 +10,8 @@
         graphicsview/ScreenGraphicsItem.h
         graphicsview/FrameGraphicsItem.h
         graphicsview/LabelGraphicsItem.h
+        graphicsview/AbstractMarbleGraphicsLayout.h
+        graphicsview/MarbleGraphicsGridLayout.h
    )
 
 SET( graphicsview_SRCS
@@ -18,4 +20,6 @@
         graphicsview/ScreenGraphicsItem.cpp
         graphicsview/FrameGraphicsItem.cpp
         graphicsview/LabelGraphicsItem.cpp
+        graphicsview/AbstractMarbleGraphicsLayout.h
+        graphicsview/MarbleGraphicsGridLayout.h
    )
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/FrameGraphicsItem.cpp #1006349:1006350
@@ -165,6 +165,14 @@
     return contentRect;
 }
 
+QRectF FrameGraphicsItem::contentRect() const {
+    return contentRect( QPointF( 0.0, 0.0 ) );
+}
+
+QSizeF FrameGraphicsItem::contentSize() const {
+    return contentRect().size();
+}
+
 QRectF FrameGraphicsItem::paintedRect( const QPointF& position ) const
 {
     qreal marginTop = ( d->m_marginTop == 0.0 ) ? d->m_margin : d->m_marginTop;
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/FrameGraphicsItem.h #1006349:1006350
@@ -15,6 +15,8 @@
 #include "marble_export.h"
 #include "ScreenGraphicsItem.h"
 
+class QBrush;
+
 namespace Marble
 {
 
@@ -135,9 +137,12 @@
      */
     void setBackground( const QBrush &background );
 
-    QRectF contentRect( const QPointF& position = QPointF( 0.0, 0.0 ) ) const;
+    QRectF contentRect( const QPointF& position ) const;
     QRectF paintedRect( const QPointF& position = QPointF( 0.0, 0.0 ) ) const;
 
+    QRectF contentRect() const;
+    QSizeF contentSize() const;
+
     /**
      * Sets the size of the item. The given size is the size required for contents.
      * This function does not guarantee a correct content size if you set margin or padding
** trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsGridLayout.cpp #property svn:eol-style
   + native
** trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsGridLayout.h #property svn:eol-style
   + native
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsItem.cpp #1006349:1006350
@@ -12,7 +12,7 @@
 
 #include "MarbleGraphicsItem_p.h"
 
-//Marble
+// Marble
 #include "GeoPainter.h"
 #include "ViewportParams.h"
 
@@ -87,6 +87,7 @@
             // The cache image will get a 0.5 pixel bounding to save antialiasing effects.
             pixmapPainter.translate( 0.5, 0.5 );
             paint( &pixmapPainter, viewport, renderPos, layer );
+
             // Paint children
             if ( p()->m_children ) {
                 foreach ( MarbleGraphicsItem *item, *p()->m_children ) {
@@ -111,6 +112,7 @@
 
             painter->translate( position );
             paint( painter, viewport, renderPos, layer );
+
             // Paint children
             if ( p()->m_children ) {
                 foreach ( MarbleGraphicsItem *item, *p()->m_children ) {
@@ -148,6 +150,19 @@
     return p()->m_size;
 }
 
+AbstractMarbleGraphicsLayout *MarbleGraphicsItem::layout() const
+{
+    return p()->m_layout;
+}
+
+void MarbleGraphicsItem::setLayout( AbstractMarbleGraphicsLayout *layout )
+{
+    // Deleting the old layout
+    delete p()->m_layout;
+    p()->m_layout = layout;
+    update();
+}
+
 MarbleGraphicsItem::CacheMode MarbleGraphicsItem::cacheMode() const
 {
     return p()->m_cacheMode;
@@ -165,6 +180,12 @@
 void MarbleGraphicsItem::update()
 {
     p()->m_removeCachedPixmap = true;
+
+    // Adjust positions
+    if ( p()->m_layout ) {
+        p()->m_layout->updatePositions( this );
+    }
+
     // Update the parent.
     if ( p()->m_parent ) {
         p()->m_parent->update();
@@ -197,11 +218,28 @@
     update();
 }
 
-QString MarbleGraphicsItem::toolTip() const {
+QSizeF MarbleGraphicsItem::contentSize() const
+{
+    return size();
+}
+
+void MarbleGraphicsItem::setContentSize( const QSizeF& size )
+{
+    setSize( size );
+}
+
+QRectF MarbleGraphicsItem::contentRect() const
+{
+    return QRectF( QPointF( 0, 0 ), contentSize() );
+}
+
+QString MarbleGraphicsItem::toolTip() const
+{
     return p()->m_toolTip;
 }
 
-void MarbleGraphicsItem::setToolTip( const QString& toolTip ) {
+void MarbleGraphicsItem::setToolTip( const QString& toolTip )
+{
     p()->m_toolTip = toolTip;
 }
 
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsItem.h #1006349:1006350
@@ -16,17 +16,17 @@
 #include <QtCore/QPointF>
 #include <QtCore/QList>
 #include <QtCore/QSizeF>
+#include <QtCore/QRectF>
+#include <QtCore/QString>
 
-class QBrush;
 class QEvent;
 class QPainterPath;
 class QObject;
-class QRectF;
-class QString;
 
 namespace Marble
 {
     
+class AbstractMarbleGraphicsLayout;
 class GeoPainter;
 class GeoSceneLayer;
 class ViewportParams;
@@ -64,11 +64,17 @@
      * Returns the rect of one represenation of the object that is at the given position.
      */
     QRectF containsRect( const QPointF& point ) const;
-    
+
     /**
-     * Returns the size of the item
+     * Returns the layout of the MarbleGraphicsItem.
      */
-    QSizeF size() const;
+    AbstractMarbleGraphicsLayout *layout() const;
+
+    /**
+     * Set the layout of the graphics item. The layout will now handle positions of added child
+     * items. The MarbleGraphicsItem takes ownership of the layout.
+     */
+    void setLayout( AbstractMarbleGraphicsLayout *layout );
     
     /**
      * Returns the cache mode of the item
@@ -116,7 +122,33 @@
      * Set the tool tip for this GraphicItem.
      */
     void setToolTip( const QString& toolTip );
-    
+
+    /**
+     * Returns the size of the item
+     */
+    QSizeF size() const;
+
+    /**
+     * Set the size of the item
+     */
+    void setSize( const QSizeF& size );
+
+    /**
+     * Returns the size of the content of the MarbleGraphicsItem.
+     * This is identical to size() for default MarbleGraphicsItems.
+     */
+    virtual QSizeF contentSize() const;
+
+    /**
+     * Set the size of the content of the item.
+     */
+    virtual void setContentSize( const QSizeF& size );
+
+    /**
+     * Returns the rect of the content in item coordinates.
+     */
+    virtual QRectF contentRect() const;
+
  protected:
     explicit MarbleGraphicsItem( MarbleGraphicsItemPrivate *d_ptr );
 
@@ -129,11 +161,6 @@
      
     virtual bool eventFilter( QObject *object, QEvent *e );
     
-    /**
-     * Set the size of the item
-     */
-    void setSize( const QSizeF& size );
-    
     MarbleGraphicsItemPrivate * const d;
     
  private:
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsItem_p.h #1006349:1006350
@@ -13,7 +13,9 @@
 
 // Marble
 #include "AbstractProjection.h"
+#include "AbstractMarbleGraphicsLayout.h"
 #include "GeoPainter.h"
+#include "MarbleGraphicsItem.h"
 
 // Qt
 #include<QtCore/QList>
@@ -35,10 +37,11 @@
           m_visibility( true ),
           m_parent( parent ),
           m_children( 0 ),
+          m_layout( 0 ),
           m_marbleGraphicsItem( marbleGraphicsItem )
     {
         if ( m_parent ) {
-            m_parent->p()->addChild( m_marbleGraphicsItem );
+//            m_parent->p()>addChild( m_marbleGraphicsItem );
         }
     }
 
@@ -52,8 +55,11 @@
 
         // Remove from parent
         if ( m_parent ) {
-            m_parent->p()->removeChild( m_marbleGraphicsItem );
+//            m_parent->p()->removeChild( m_marbleGraphicsItem );
         }
+
+        // Delete Layout
+        delete m_layout;
     }
 
     void addChild( MarbleGraphicsItem *child )
@@ -125,6 +131,9 @@
     MarbleGraphicsItem *m_parent;
     // The set of children. WARNING: This is not initialized by default.
     QSet<MarbleGraphicsItem *> *m_children;
+
+    // The layout handling the positions of the children
+    AbstractMarbleGraphicsLayout *m_layout;
     
     QString m_toolTip;
 


More information about the Marble-commits mailing list