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 "GeoDataScreenOverlay.h"
10#include "GeoPainter.h"
11#include "ViewportParams.h"
12
13namespace Marble
14{
15
16ScreenOverlayGraphicsItem::ScreenOverlayGraphicsItem(const GeoDataScreenOverlay *screenOverlay)
17 : m_screenOverlay(screenOverlay)
18{
19 /** @todo: take the possible size values into account according to kml spec */
20 setSize(QSizeF(m_screenOverlay->size().x(), m_screenOverlay->size().y()));
21
22 if (!m_screenOverlay->icon().isNull()) {
23 m_pixmap = QPixmap::fromImage(m_screenOverlay->icon().scaled(size().toSize()));
24 }
25}
26
27const GeoDataScreenOverlay *ScreenOverlayGraphicsItem::screenOverlay() const
28{
29 return m_screenOverlay;
30}
31
32void ScreenOverlayGraphicsItem::setProjection(const ViewportParams *viewport)
33{
34 ScreenGraphicsItem::setProjection(viewport);
35 /** @todo: take overlayXY into account */
36 setPosition(
37 QPointF(pixelValue(m_screenOverlay->screenXY().xunit(), viewport->width(), size().width(), m_screenOverlay->screenXY().x()),
38 viewport->height() - pixelValue(m_screenOverlay->screenXY().yunit(), viewport->height(), size().height(), m_screenOverlay->screenXY().y())));
39}
40
41qreal ScreenOverlayGraphicsItem::pixelValue(GeoDataVec2::Unit unit, qreal screenSize, qreal imageSize, qreal value)
42{
43 switch (unit) {
44 case GeoDataVec2::Pixels:
45 return imageSize;
46 case GeoDataVec2::Fraction:
47 return value * screenSize;
48 case GeoDataVec2::InsetPixels:
49 return screenSize - imageSize - value;
50 }
51
52 Q_ASSERT(false);
53 return 0.0;
54}
55
56void ScreenOverlayGraphicsItem::paint(QPainter *painter)
57{
58 if (m_pixmap.isNull()) {
59 painter->setBrush(m_screenOverlay->color());
60 painter->drawRect(QRectF(QPointF(0.0, 0.0), size()));
61 } else {
62 painter->drawPixmap(QPointF(0.0, 0.0), m_pixmap);
63 }
64}
65
66}
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 Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.