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

Bastian Holst bastianholst at gmx.de
Wed Aug 5 19:04:31 CEST 2009


SVN commit 1007371 by bholst:

Two changes to Marble GraphicsView:
* FrameItem now supports RoundedRectFrame.
* GridLayout now supports spacing between items.
* LabelItem has no spacing anymore.


 M  +20 -8     lib/graphicsview/FrameGraphicsItem.cpp  
 M  +2 -1      lib/graphicsview/FrameGraphicsItem.h  
 M  +0 -4      lib/graphicsview/LabelGraphicsItem.cpp  
 M  +29 -11    lib/graphicsview/MarbleGraphicsGridLayout.cpp  
 M  +10 -0     lib/graphicsview/MarbleGraphicsGridLayout.h  
 M  +2 -8      plugins/render/navigation/NavigationFloatItem.cpp  
 M  +0 -2      plugins/render/navigation/NavigationFloatItem.h  
 M  +2 -1      plugins/render/weather/WeatherItem.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/FrameGraphicsItem.cpp #1007370:1007371
@@ -21,6 +21,9 @@
 
 using namespace Marble;
 
+const int RECT_FRAME_MIN_PADDING = 1;
+const int ROUNDED_RECT_FRAME_MIN_PADDING = 2;
+
 FrameGraphicsItem::FrameGraphicsItem( MarbleGraphicsItem *parent )
         : ScreenGraphicsItem( parent ),
           d( new FrameGraphicsItemPrivate() )
@@ -46,9 +49,7 @@
 
 void FrameGraphicsItem::setFrame( FrameType type ) {
     d->m_frame = type;
-    if ( type == RectFrame && padding() < 2 ) {
-        setPadding( 2 );
-    }
+    setPadding( padding() );
 }
 
 qreal FrameGraphicsItem::margin() const
@@ -124,7 +125,15 @@
 
 void FrameGraphicsItem::setPadding( qreal width )
 {
-    d->m_padding = width;
+    if ( d->m_frame == RectFrame && width < RECT_FRAME_MIN_PADDING ) {
+        d->m_padding = RECT_FRAME_MIN_PADDING;
+    }
+    else if ( d->m_frame == RoundedRectFrame && width < ROUNDED_RECT_FRAME_MIN_PADDING ) {
+        d->m_padding = ROUNDED_RECT_FRAME_MIN_PADDING;
+    }
+    else {
+        d->m_padding = width;
+    }
 }
 
 QBrush FrameGraphicsItem::borderBrush() const
@@ -217,15 +226,18 @@
 
 QPainterPath FrameGraphicsItem::backgroundShape() const
 {
+    QPainterPath path;
     if ( d->m_frame == RectFrame ) {
         QRectF renderedRect = paintedRect( QPointF( 0.0, 0.0 ) );
-        QPainterPath path;
         path.addRect( QRectF( 0.0, 0.0, renderedRect.size().width(), renderedRect.size().height() ) );
-        return path;
     }
-    else {
-        return QPainterPath();
+    else if ( d->m_frame == RoundedRectFrame ) {
+        QSizeF paintedSize = paintedRect().size();
+        path.addRoundedRect( QRectF( 0.0, 0.0, paintedSize.width() - 1, paintedSize.height() - 1 ),
+                             6, 6 );
     }
+
+    return path;
 }
 
 void FrameGraphicsItem::paintBackground( GeoPainter *painter )
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/FrameGraphicsItem.h #1007370:1007371
@@ -27,7 +27,8 @@
  public:
     enum FrameType {
         NoFrame,
-        RectFrame
+        RectFrame,
+        RoundedRectFrame
     };
 
     explicit FrameGraphicsItem( MarbleGraphicsItem *parent = 0 );
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/LabelGraphicsItem.cpp #1007370:1007371
@@ -39,10 +39,6 @@
     : FrameGraphicsItem( parent ),
       d( new LabelGraphicsItemPrivate() )
 {
-    setMarginLeft( 2 );
-    setMarginRight( 2 );
-    setMarginTop( 1 );
-    setMarginBottom( 1 );
 }
 
 void LabelGraphicsItem::setText( const QString& text )
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsGridLayout.cpp #1007370:1007371
@@ -29,6 +29,7 @@
     MarbleGraphicsGridLayoutPrivate( int rows, int columns )
             : m_rows( rows ),
               m_columns( columns ),
+              m_spacing( 0 ),
               m_alignment( Qt::AlignLeft | Qt::AlignTop )
     {
         m_items = new ScreenGraphicsItem **[rows];
@@ -51,6 +52,7 @@
     ScreenGraphicsItem ***m_items;
     int m_rows;
     int m_columns;
+    int m_spacing;
     Qt::Alignment m_alignment;
     QHash<ScreenGraphicsItem*, Qt::Alignment> m_itemAlignment;
 };
@@ -107,18 +109,24 @@
         }
     }
 
-    double *startX = new double[d->m_columns+1];
-    double *startY = new double[d->m_rows+1];
+    double *startX = new double[d->m_columns];
+    double *endX = new double[d->m_columns];
+    double *startY = new double[d->m_rows];
+    double *endY = new double[d->m_rows];
     QRectF contentRect = parent->contentRect();
 
-    startX[0] = contentRect.left();
-    for ( int i = 1; i <= d->m_columns; i++ ) {
-        startX[i] = startX[i-1] + maxWidth[i-1];
+    double nextStartX = contentRect.left();
+    for ( int i = 0; i < d->m_columns; i++ ) {
+        startX[i] = nextStartX;
+        endX[i] = nextStartX + maxWidth[i];
+        nextStartX = endX[i] + d->m_spacing;
     }
 
-    startY[0] = contentRect.top();
-    for ( int i = 1; i <= d->m_rows; i++ ) {
-        startY[i] = startY[i-1] + maxHeight[i-1];
+    double nextStartY = contentRect.top();
+    for ( int i = 0; i < d->m_rows; i++ ) {
+        startY[i] = nextStartY;
+        endY[i] = nextStartY + maxHeight[i];
+        nextStartY = endY[i] + d->m_spacing;
     }
 
     // Setting the positions
@@ -133,7 +141,7 @@
             Qt::Alignment align = alignment( d->m_items[row][column] );
 
             if ( align & Qt::AlignRight ) {
-                xPos = startX[column+1] - d->m_items[row][column]->size().width();
+                xPos = endX[column] - d->m_items[row][column]->size().width();
             }
             else if ( align & Qt::AlignHCenter ) {
                 xPos = startX[column]
@@ -144,7 +152,7 @@
             }
 
             if ( align & Qt::AlignBottom ) {
-                yPos = startY[row+1] - d->m_items[row][column]->size().height();
+                yPos = endY[row] - d->m_items[row][column]->size().height();
             }
             else if ( align & Qt::AlignVCenter ) {
                 yPos = startY[row]
@@ -158,7 +166,7 @@
         }
     }
 
-    parent->setContentSize( QSizeF( startX[d->m_columns], startY[d->m_rows] ) );
+    parent->setContentSize( QSizeF( endX[d->m_columns - 1], endY[d->m_rows - 1] ) );
 }
 
 Qt::Alignment MarbleGraphicsGridLayout::alignment() const
@@ -181,4 +189,14 @@
     d->m_itemAlignment.insert( item, align );
 }
 
+int MarbleGraphicsGridLayout::spacing() const
+{
+    return d->m_spacing;
+}
+
+void MarbleGraphicsGridLayout::setSpacing( int spacing )
+{
+    d->m_spacing = spacing;
+}
+
 } // namespace Marble
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsGridLayout.h #1007370:1007371
@@ -46,6 +46,16 @@
 
     void setAlignment( ScreenGraphicsItem *item, Qt::Alignment );
 
+    /**
+     * Returns the spacing between the items inside the layout.
+     */
+    int spacing() const;
+
+    /**
+     * Set the spacing between the items inside the layout. By default the spacing is 0.
+     */
+    void setSpacing( int spacing );
+
  private:
     MarbleGraphicsGridLayoutPrivate * const d;
 };
--- trunk/KDE/kdeedu/marble/src/plugins/render/navigation/NavigationFloatItem.cpp #1007370:1007371
@@ -31,6 +31,8 @@
     setEnabled( true );
     // Plugin is not visible by default
     setVisible( false );
+
+    setFrame( FrameGraphicsItem::RoundedRectFrame );
 }
 
 NavigationFloatItem::~NavigationFloatItem()
@@ -89,14 +91,6 @@
     return m_navigationParent != 0;
 }
 
-QPainterPath NavigationFloatItem::backgroundShape() const
-{
-    QPainterPath path;
-    QSizeF paintedSize = paintedRect().size();
-    path.addRoundedRect( QRectF( 0.0, 0.0, paintedSize.width() - 1, paintedSize.height() - 1 ), 6, 6 );
-    return path;
-}
-
 void NavigationFloatItem::changeViewport( ViewportParams *viewport )
 {
     if ( viewport->radius() != m_oldViewportRadius ) {
--- trunk/KDE/kdeedu/marble/src/plugins/render/navigation/NavigationFloatItem.h #1007370:1007371
@@ -54,8 +54,6 @@
 
     bool isInitialized () const;
 
-    virtual QPainterPath backgroundShape() const;
-
     void changeViewport( ViewportParams *viewport );
 
     void paintContent( GeoPainter *painter, ViewportParams *viewport,
--- trunk/KDE/kdeedu/marble/src/plugins/render/weather/WeatherItem.cpp #1007370:1007371
@@ -62,8 +62,9 @@
 
         MarbleGraphicsGridLayout *gridLayout = new MarbleGraphicsGridLayout( 2, 2 );
         gridLayout->setAlignment( Qt::AlignCenter );
+        gridLayout->setSpacing( 4 );
         m_frameItem->setLayout( gridLayout );
-        m_frameItem->setFrame( FrameGraphicsItem::RectFrame );
+        m_frameItem->setFrame( FrameGraphicsItem::RoundedRectFrame );
 
         gridLayout->addItem( m_conditionLabel, 0, 0 );
         gridLayout->addItem( m_temperatureLabel, 0, 1 );


More information about the Marble-commits mailing list