[Marble-commits] KDE/kdeedu/marble/src
Bastian Holst
bastianholst at gmx.de
Wed Mar 31 20:24:07 CEST 2010
SVN commit 1109686 by bholst:
Marble GraphicsItem changes:
* Making FrameGraphicsItem more solid
* Removing the constructor which accepts information that can be nicely set after that from
** FrameGraphicsItem
** ScreenGraphicsItem
(again one step towards QGraphicsItem)
M +3 -1 lib/AbstractFloatItem.cpp
M +13 -21 lib/graphicsview/FrameGraphicsItem.cpp
M +2 -5 lib/graphicsview/FrameGraphicsItem.h
M +22 -2 lib/graphicsview/FrameGraphicsItem_p.h
M +0 -8 lib/graphicsview/ScreenGraphicsItem.cpp
M +0 -2 lib/graphicsview/ScreenGraphicsItem.h
M +5 -5 plugins/render/mapscale/MapScaleFloatItem.cpp
--- trunk/KDE/kdeedu/marble/src/lib/AbstractFloatItem.cpp #1109685:1109686
@@ -42,12 +42,14 @@
AbstractFloatItem::AbstractFloatItem( const QPointF &point, const QSizeF &size )
: RenderPlugin(),
- FrameGraphicsItem( point, size ),
+ FrameGraphicsItem(),
d( new AbstractFloatItemPrivate() )
{
setCacheMode( MarbleGraphicsItem::ItemCoordinateCache );
setFrame( RectFrame );
setPadding( 4.0 );
+ setContentSize( size );
+ setPosition( point );
}
AbstractFloatItem::~AbstractFloatItem()
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/FrameGraphicsItem.cpp #1109685:1109686
@@ -26,17 +26,10 @@
FrameGraphicsItem::FrameGraphicsItem( MarbleGraphicsItem *parent )
: ScreenGraphicsItem( parent ),
- d( new FrameGraphicsItemPrivate() )
+ d( new FrameGraphicsItemPrivate( this ) )
{
}
-FrameGraphicsItem::FrameGraphicsItem( const QPointF& position, const QSizeF& size,
- MarbleGraphicsItem *parent )
- : ScreenGraphicsItem( position, size, parent ),
- d( new FrameGraphicsItemPrivate() )
-{
-}
-
FrameGraphicsItem::~FrameGraphicsItem()
{
delete d;
@@ -61,6 +54,7 @@
void FrameGraphicsItem::setMargin( qreal margin )
{
d->m_margin = margin;
+ d->updateSize();
update();
}
@@ -72,6 +66,7 @@
void FrameGraphicsItem::setMarginTop( qreal marginTop )
{
d->m_marginTop = marginTop;
+ d->updateSize();
update();
}
@@ -83,6 +78,7 @@
void FrameGraphicsItem::setMarginBottom( qreal marginBottom )
{
d->m_marginBottom = marginBottom;
+ d->updateSize();
update();
}
@@ -94,6 +90,7 @@
void FrameGraphicsItem::setMarginLeft( qreal marginLeft )
{
d->m_marginLeft = marginLeft;
+ d->updateSize();
update();
}
@@ -105,6 +102,7 @@
void FrameGraphicsItem::setMarginRight( qreal marginRight )
{
d->m_marginRight = marginRight;
+ d->updateSize();
update();
}
@@ -116,6 +114,7 @@
void FrameGraphicsItem::setBorderWidth( qreal width )
{
d->m_borderWidth = width;
+ d->updateSize();
update();
}
@@ -135,6 +134,7 @@
else {
d->m_padding = width;
}
+ d->updateSize();
}
QBrush FrameGraphicsItem::borderBrush() const
@@ -181,8 +181,8 @@
QRectF contentRect = QRectF( position.x() + marginLeft + d->m_padding,
position.y() + marginTop + d->m_padding,
- size.width() - ( marginLeft + marginRight + 2.0 * d->m_padding ),
- size.height() - ( marginTop + marginBottom + 2.0 * d->m_padding ) );
+ d->m_contentSize.width(),
+ d->m_contentSize.height() );
return contentRect;
}
@@ -194,7 +194,7 @@
QSizeF FrameGraphicsItem::contentSize() const
{
- return contentRect().size();
+ return d->m_contentSize;
}
QRectF FrameGraphicsItem::paintedRect( const QPointF& position ) const
@@ -215,16 +215,8 @@
void FrameGraphicsItem::setContentSize( const QSizeF& size )
{
- qreal marginTop = ( d->m_marginTop == 0.0 ) ? d->m_margin : d->m_marginTop;
- qreal marginBottom = ( d->m_marginBottom == 0.0 ) ? d->m_margin : d->m_marginBottom;
- qreal marginLeft = ( d->m_marginLeft == 0.0 ) ? d->m_margin : d->m_marginLeft;
- qreal marginRight = ( d->m_marginRight == 0.0 ) ? d->m_margin : d->m_marginRight;
-
- QSizeF totalSize = size;
- totalSize += QSizeF( marginLeft + marginRight, marginTop + marginBottom );
- totalSize += QSizeF( d->m_padding * 2, d->m_padding * 2 );
-
- setSize( totalSize );
+ d->m_contentSize = size;
+ d->updateSize();
}
QPainterPath FrameGraphicsItem::backgroundShape() const
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/FrameGraphicsItem.h #1109685:1109686
@@ -32,8 +32,6 @@
};
explicit FrameGraphicsItem( MarbleGraphicsItem *parent = 0 );
- FrameGraphicsItem( const QPointF& position, const QSizeF& size,
- MarbleGraphicsItem *parent = 0 );
virtual ~FrameGraphicsItem();
@@ -160,9 +158,8 @@
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
- * afterwards.
+ * Sets the size of the content of the item.
+ * @p size is the size required for contents.
*/
void setContentSize( const QSizeF& size );
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/FrameGraphicsItem_p.h #1109685:1109686
@@ -25,8 +25,9 @@
class FrameGraphicsItemPrivate
{
public:
- FrameGraphicsItemPrivate()
+ FrameGraphicsItemPrivate( FrameGraphicsItem *parent )
: m_frame( FrameGraphicsItem::NoFrame ),
+ m_contentSize( 0.0, 0.0 ),
m_margin( 0.0 ),
m_marginTop( 0.0 ),
m_marginBottom( 0.0 ),
@@ -36,11 +37,28 @@
m_borderWidth( 1.0 ),
m_borderBrush( QBrush( Qt::black ) ),
m_borderStyle( Qt::SolidLine ),
- m_backgroundBrush( QBrush( QColor( 192, 192, 192, 192 ) ) )
+ m_backgroundBrush( QBrush( QColor( 192, 192, 192, 192 ) ) ),
+ m_parent( parent )
{
+ updateSize();
}
+ void updateSize()
+ {
+ qreal marginTop = ( m_marginTop == 0.0 ) ? m_margin : m_marginTop;
+ qreal marginBottom = ( m_marginBottom == 0.0 ) ? m_margin : m_marginBottom;
+ qreal marginLeft = ( m_marginLeft == 0.0 ) ? m_margin : m_marginLeft;
+ qreal marginRight = ( m_marginRight == 0.0 ) ? m_margin : m_marginRight;
+
+ QSizeF totalSize = m_contentSize;
+ totalSize += QSizeF( marginLeft + marginRight, marginTop + marginBottom );
+ totalSize += QSizeF( m_padding * 2, m_padding * 2 );
+
+ m_parent->setSize( totalSize );
+ }
+
FrameGraphicsItem::FrameType m_frame;
+ QSizeF m_contentSize;
// Margin
qreal m_margin;
@@ -56,6 +74,8 @@
QBrush m_borderBrush;
Qt::PenStyle m_borderStyle;
QBrush m_backgroundBrush;
+
+ FrameGraphicsItem * const m_parent;
};
} // namespace Marble
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/ScreenGraphicsItem.cpp #1109685:1109686
@@ -28,14 +28,6 @@
{
}
-ScreenGraphicsItem::ScreenGraphicsItem( const QPointF& position, const QSizeF& size,
- MarbleGraphicsItem *parent )
- : MarbleGraphicsItem( new ScreenGraphicsItemPrivate( this, parent ) )
-{
- setPosition( position );
- setSize( size );
-}
-
ScreenGraphicsItem::ScreenGraphicsItem( ScreenGraphicsItemPrivate *d_ptr )
: MarbleGraphicsItem( d_ptr )
{
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/ScreenGraphicsItem.h #1109685:1109686
@@ -36,8 +36,6 @@
Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
explicit ScreenGraphicsItem( MarbleGraphicsItem *parent = 0 );
- ScreenGraphicsItem( const QPointF& position, const QSizeF& size,
- MarbleGraphicsItem *parent = 0 );
virtual ~ScreenGraphicsItem();
--- trunk/KDE/kdeedu/marble/src/plugins/render/mapscale/MapScaleFloatItem.cpp #1109685:1109686
@@ -98,13 +98,13 @@
&& m_scaleInitDone ) )
{
int fontHeight = QFontMetrics( font() ).ascent();
- setSize( QSizeF( viewport->width() / 2,
- 2 * padding() + fontHeight + 3 + m_scaleBarHeight ) );
+ 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;
- m_scaleBarWidth = contentRect().width() - m_leftBarMargin - m_rightBarMargin;
+ m_scaleBarWidth = contentSize().width() - m_leftBarMargin - m_rightBarMargin;
m_viewportWidth = viewport->width();
m_radius = viewport->radius();
m_scaleInitDone = true;
@@ -129,7 +129,7 @@
qreal pixel2Length = dataFacade()->planetRadius() /
(qreal)(viewport->radius());
-
+
if ( viewport->currentProjection()->surfaceType() == AbstractProjection::Cylindrical )
{
qreal centerLatitude = viewport->viewLatLonAltBox().center().latitude();
@@ -138,7 +138,7 @@
// the pixel based radius propertyy.
pixel2Length *= M_PI / 2 * cos( centerLatitude );
}
-
+
m_scaleBarDistance = (qreal)(m_scaleBarWidth) * pixel2Length;
DistanceUnit distanceUnit;
More information about the Marble-commits
mailing list