6#include "MarbleGraphicsItem.h"
8#include "MarbleGraphicsItem_p.h"
11#include "MarbleDebug.h"
22MarbleGraphicsItem::MarbleGraphicsItem(MarbleGraphicsItemPrivate *dd)
27MarbleGraphicsItem::~MarbleGraphicsItem()
34 Q_D(MarbleGraphicsItem);
36 if (!d->m_visibility) {
40 if (d->m_repaintNeeded) {
41 d->updateChildPositions();
43 d->m_repaintNeeded =
false;
46 setProjection(viewport);
48 if (d->positions().size() == 0) {
54 if (ItemCoordinateCache == cacheMode() || DeviceCoordinateCache == cacheMode()) {
59 if (d->m_pixmap.size() != neededPixmapSize || d->m_pixmap.devicePixelRatio() != scale) {
60 if (size().
isValid() && !size().isNull()) {
61 d->m_pixmap =
QPixmap(neededPixmapSize);
62 d->m_pixmap.setDevicePixelRatio(scale);
64 mDebug() <<
"Warning: Invalid pixmap size suggested: " << d->m_size;
68 QPainter pixmapPainter(&d->m_pixmap);
72 pixmapPainter.translate(0.5, 0.5);
73 paint(&pixmapPainter);
76 for (MarbleGraphicsItem *item : std::as_const(d->m_children)) {
77 item->paintEvent(&pixmapPainter, viewport);
81 for (
const QPointF &position : d->positions()) {
85 for (
const QPointF &position : d->positions()) {
92 for (MarbleGraphicsItem *item : std::as_const(d->m_children)) {
93 item->paintEvent(painter, viewport);
103bool MarbleGraphicsItem::contains(
const QPointF &point)
const
105 Q_D(
const MarbleGraphicsItem);
106 for (
const QRectF &rect : d->boundingRects()) {
107 if (rect.contains(point))
113QList<QRectF> MarbleGraphicsItemPrivate::boundingRects()
const
120 for (
const QPointF &point : positions) {
121 QRectF rect(point, m_size);
133QSizeF MarbleGraphicsItem::size()
const
135 Q_D(
const MarbleGraphicsItem);
139AbstractMarbleGraphicsLayout *MarbleGraphicsItem::layout()
const
141 Q_D(
const MarbleGraphicsItem);
145void MarbleGraphicsItem::setLayout(AbstractMarbleGraphicsLayout *layout)
147 Q_D(MarbleGraphicsItem);
150 d->m_layout = layout;
154MarbleGraphicsItem::CacheMode MarbleGraphicsItem::cacheMode()
const
156 Q_D(
const MarbleGraphicsItem);
157 return d->m_cacheMode;
160void MarbleGraphicsItem::setCacheMode(CacheMode mode)
162 Q_D(MarbleGraphicsItem);
163 d->m_cacheMode = mode;
164 if (d->m_cacheMode == NoCache) {
165 d->m_repaintNeeded =
true;
169void MarbleGraphicsItem::update()
171 Q_D(MarbleGraphicsItem);
172 d->m_repaintNeeded =
true;
176 d->m_parent->update();
180bool MarbleGraphicsItem::visible()
const
182 Q_D(
const MarbleGraphicsItem);
183 return d->m_visibility;
186void MarbleGraphicsItem::setVisible(
bool visible)
188 Q_D(MarbleGraphicsItem);
189 d->m_visibility = visible;
192void MarbleGraphicsItem::hide()
197void MarbleGraphicsItem::show()
202void MarbleGraphicsItem::setSize(
const QSizeF &size)
204 Q_D(MarbleGraphicsItem);
205 if (d->m_size != size) {
211QSizeF MarbleGraphicsItem::contentSize()
const
216void MarbleGraphicsItem::setContentSize(
const QSizeF &size)
221QRectF MarbleGraphicsItem::contentRect()
const
226void MarbleGraphicsItem::paint(
QPainter *painter)
231bool MarbleGraphicsItem::eventFilter(
QObject *
object,
QEvent *e)
238 Q_D(
const MarbleGraphicsItem);
241 if (!d->m_children.isEmpty()) {
244 for (
const QPointF &absolutePosition : absolutePositions) {
245 QPoint shiftedPos =
event->pos() - absolutePosition.toPoint();
247 if (
QRect(
QPoint(0, 0), size().toSize()).contains(shiftedPos)) {
248 for (MarbleGraphicsItem *child : d->m_children) {
249 const QList<QRectF> childRects = child->d_func()->boundingRects();
251 for (
const QRectF &childRect : childRects) {
252 if (childRect.toRect().contains(shiftedPos)) {
253 if (child->eventFilter(
object, e)) {
266void MarbleGraphicsItem::setProjection(
const ViewportParams *viewport)
268 Q_D(MarbleGraphicsItem);
269 d->setProjection(viewport);
This file contains the headers for ViewportParams.
A public class that controls what is visible in the viewport of a Marble map.
bool isValid(QStringView ifopt)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
Binds a QML item to a specific geodetic location in screen coordinates.
void append(QList< T > &&value)
qsizetype count() const const
void reserve(qsizetype size)
qreal devicePixelRatio() const const
QPaintDevice * device() const const
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void translate(const QPoint &offset)
QSize toSize() const const