Marble

ScreenOverlayGraphicsItem.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
4// SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
5//
6
7#include "ScreenOverlayGraphicsItem.h"
8
9#include "ViewportParams.h"
10#include "GeoDataScreenOverlay.h"
11#include "GeoPainter.h"
12
13namespace Marble {
14
15ScreenOverlayGraphicsItem::ScreenOverlayGraphicsItem( const GeoDataScreenOverlay *screenOverlay ) :
16 m_screenOverlay( screenOverlay )
17{
18 /** @todo: take the possible size values into account according to kml spec */
19 setSize( QSizeF( m_screenOverlay->size().x(), m_screenOverlay->size().y() ) );
20
21 if ( !m_screenOverlay->icon().isNull() ) {
22 m_pixmap = QPixmap::fromImage( m_screenOverlay->icon().scaled( size().toSize() ) );
23 }
24}
25
26const GeoDataScreenOverlay *ScreenOverlayGraphicsItem::screenOverlay() const
27{
28 return m_screenOverlay;
29}
30
31void ScreenOverlayGraphicsItem::setProjection( const ViewportParams *viewport )
32{
33 ScreenGraphicsItem::setProjection( viewport );
34 /** @todo: take overlayXY into account */
35 setPosition( QPointF( pixelValue( m_screenOverlay->screenXY().xunit(),
36 viewport->width(),
37 size().width(),
38 m_screenOverlay->screenXY().x() ),
39 viewport->height()-pixelValue( m_screenOverlay->screenXY().yunit(),
40 viewport->height(),
41 size().height(),
42 m_screenOverlay->screenXY().y() ) ) );
43}
44
45qreal ScreenOverlayGraphicsItem::pixelValue( GeoDataVec2::Unit unit, qreal screenSize, qreal imageSize, qreal value )
46{
47 switch (unit) {
48 case GeoDataVec2::Pixels:
49 return imageSize;
50 case GeoDataVec2::Fraction:
51 return value * screenSize;
52 case GeoDataVec2::InsetPixels:
53 return screenSize - imageSize - value;
54 }
55
56 Q_ASSERT( false );
57 return 0.0;
58}
59
60void ScreenOverlayGraphicsItem::paint( QPainter *painter )
61{
62 if ( m_pixmap.isNull() ) {
63 painter->setBrush( m_screenOverlay->color() );
64 painter->drawRect( QRectF( QPointF( 0.0, 0.0 ), size() ) );
65 } else {
66 painter->drawPixmap( QPointF( 0.0, 0.0 ), m_pixmap );
67 }
68}
69
70}
This file contains the headers for ViewportParams.
Binds a QML item to a specific geodetic location in screen coordinates.
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void drawRect(const QRect &rectangle)
void setBrush(Qt::BrushStyle style)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:54:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.