File indexing completed on 2025-01-05 03:59:03
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com> 0004 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org> 0005 // 0006 0007 #include "ScreenOverlayGraphicsItem.h" 0008 0009 #include "ViewportParams.h" 0010 #include "GeoDataScreenOverlay.h" 0011 #include "GeoPainter.h" 0012 0013 namespace Marble { 0014 0015 ScreenOverlayGraphicsItem::ScreenOverlayGraphicsItem( const GeoDataScreenOverlay *screenOverlay ) : 0016 m_screenOverlay( screenOverlay ) 0017 { 0018 /** @todo: take the possible size values into account according to kml spec */ 0019 setSize( QSizeF( m_screenOverlay->size().x(), m_screenOverlay->size().y() ) ); 0020 0021 if ( !m_screenOverlay->icon().isNull() ) { 0022 m_pixmap = QPixmap::fromImage( m_screenOverlay->icon().scaled( size().toSize() ) ); 0023 } 0024 } 0025 0026 const GeoDataScreenOverlay *ScreenOverlayGraphicsItem::screenOverlay() const 0027 { 0028 return m_screenOverlay; 0029 } 0030 0031 void ScreenOverlayGraphicsItem::setProjection( const ViewportParams *viewport ) 0032 { 0033 ScreenGraphicsItem::setProjection( viewport ); 0034 /** @todo: take overlayXY into account */ 0035 setPosition( QPointF( pixelValue( m_screenOverlay->screenXY().xunit(), 0036 viewport->width(), 0037 size().width(), 0038 m_screenOverlay->screenXY().x() ), 0039 viewport->height()-pixelValue( m_screenOverlay->screenXY().yunit(), 0040 viewport->height(), 0041 size().height(), 0042 m_screenOverlay->screenXY().y() ) ) ); 0043 } 0044 0045 qreal ScreenOverlayGraphicsItem::pixelValue( GeoDataVec2::Unit unit, qreal screenSize, qreal imageSize, qreal value ) 0046 { 0047 switch (unit) { 0048 case GeoDataVec2::Pixels: 0049 return imageSize; 0050 case GeoDataVec2::Fraction: 0051 return value * screenSize; 0052 case GeoDataVec2::InsetPixels: 0053 return screenSize - imageSize - value; 0054 } 0055 0056 Q_ASSERT( false ); 0057 return 0.0; 0058 } 0059 0060 void ScreenOverlayGraphicsItem::paint( QPainter *painter ) 0061 { 0062 if ( m_pixmap.isNull() ) { 0063 painter->setBrush( m_screenOverlay->color() ); 0064 painter->drawRect( QRectF( QPointF( 0.0, 0.0 ), size() ) ); 0065 } else { 0066 painter->drawPixmap( QPointF( 0.0, 0.0 ), m_pixmap ); 0067 } 0068 } 0069 0070 }