File indexing completed on 2025-01-05 03:59:17

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009-2010 Bastian Holst <bastianholst@gmx.de>
0004 //
0005 
0006 #ifndef MARBLE_SCREENGRAPHICSITEMPRIVATE_H
0007 #define MARBLE_SCREENGRAPHICSITEMPRIVATE_H
0008 
0009 #include "MarbleGraphicsItem_p.h"
0010 
0011 #include "BillboardGraphicsItem.h"
0012 #include "ScreenGraphicsItem.h"
0013 #include "ViewportParams.h"
0014 
0015 #include "digikam_debug.h"
0016 
0017 namespace Marble
0018 {
0019 
0020 class ScreenGraphicsItemPrivate : public MarbleGraphicsItemPrivate
0021 {
0022  public:
0023     ScreenGraphicsItemPrivate( ScreenGraphicsItem *screenGraphicsItem,
0024                                MarbleGraphicsItem *parent )
0025         : MarbleGraphicsItemPrivate( screenGraphicsItem, parent ),
0026           m_position(),
0027           m_viewportSize(),
0028           m_floatItemMoving( false ),
0029           m_flags( ScreenGraphicsItem::GraphicsItemFlags() )
0030     {
0031     }
0032 
0033     ~ScreenGraphicsItemPrivate() override
0034     {
0035     }
0036 
0037     QVector<QPointF> positions() const override
0038     {
0039         QVector<QPointF> list;
0040 
0041         list.append( positivePosition() );
0042         return list;
0043     }
0044 
0045     QPointF positivePosition() const
0046     {
0047         const QSizeF parentSize = m_parent ? m_parent->size() : m_viewportSize;
0048         if ( !parentSize.isValid() ) {
0049             qCDebug(DIGIKAM_MARBLE_LOG) << "Invalid parent size";
0050             return m_position;
0051         }
0052         QPointF position;
0053         qreal x = m_position.x();
0054         qreal y = m_position.y();
0055 
0056         position.setX( ( x >= 0 ) ? x : parentSize.width() + x - m_size.width() );
0057         position.setY( ( y >= 0 ) ? y : parentSize.height() + y - m_size.height() );
0058 
0059         return position;
0060     }
0061 
0062     QVector<QPointF> absolutePositions() const override
0063     {
0064         if( m_parent == nullptr ) {
0065             return positions();
0066         }
0067 
0068         QVector<QPointF> parentPositions;
0069 
0070         if( ScreenGraphicsItem *screenItem = dynamic_cast<ScreenGraphicsItem*>( m_parent ) ) {
0071             parentPositions = screenItem->absolutePositions();
0072         }
0073         else if ( BillboardGraphicsItem *geoLabelItem = dynamic_cast<BillboardGraphicsItem *>( m_parent ) ) {
0074             parentPositions = geoLabelItem->positions();
0075         }
0076 
0077         QPointF relativePosition = positivePosition();
0078 
0079         QVector<QPointF> absolutePositions;
0080         absolutePositions.reserve(parentPositions.size());
0081         for( const QPointF &point: parentPositions ) {
0082             absolutePositions.append( point + relativePosition );
0083         }
0084 
0085         return absolutePositions;
0086     }
0087 
0088     void setProjection(const ViewportParams *viewport) override
0089     {
0090         // If we have no parent
0091         if( m_parent == nullptr ) {
0092             // Saving the screen size needed for positions()
0093             m_viewportSize = viewport->size();
0094         }
0095     }
0096 
0097     bool isMovable() const
0098     {
0099         return ( m_flags & ScreenGraphicsItem::ItemIsMovable ) ? true : false;
0100     }
0101 
0102     QPointF             m_position;
0103     // The size of the parent, or if no parent exists the size of the viewport.
0104     QSizeF              m_viewportSize;
0105 
0106     QPoint              m_floatItemMoveStartPos;
0107     bool                m_floatItemMoving;
0108 
0109     ScreenGraphicsItem::GraphicsItemFlags m_flags;
0110 };
0111 
0112 }
0113 
0114 #endif