File indexing completed on 2024-05-05 03:50:39
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2009 Andrew Manson <g.real.ate@gmail.com> 0004 // SPDX-FileCopyrightText: 2013 Thibaut Gridel <tgridel@free.fr> 0005 // SPDX-FileCopyrightText: 2014 Calin Cruceru <crucerucalincristian@gmail.com> 0006 // 0007 0008 // Self 0009 #include "PlacemarkTextAnnotation.h" 0010 0011 // Qt 0012 #include <QApplication> 0013 #include <QPalette> 0014 #include <QDebug> 0015 0016 // Marble 0017 #include "AbstractProjection.h" 0018 #include "GeoDataPlacemark.h" 0019 #include "GeoDataStyle.h" 0020 #include "GeoDataIconStyle.h" 0021 #include "GeoDataLabelStyle.h" 0022 #include "GeoPainter.h" 0023 #include "ViewportParams.h" 0024 #include "MarbleDirs.h" 0025 #include "SceneGraphicsTypes.h" 0026 0027 0028 namespace Marble 0029 { 0030 0031 PlacemarkTextAnnotation::PlacemarkTextAnnotation( GeoDataPlacemark *placemark ) : 0032 SceneGraphicsItem( placemark ), 0033 m_movingPlacemark( false ), 0034 m_labelColor( QColor() ) 0035 { 0036 if ( placemark->style()->iconStyle().iconPath().isNull() ) { 0037 GeoDataStyle::Ptr newStyle(new GeoDataStyle( *placemark->style() )); 0038 newStyle->iconStyle().setIconPath(MarbleDirs::path(QStringLiteral("bitmaps/redflag_22.png"))); 0039 placemark->setStyle( newStyle ); 0040 } 0041 setPaintLayers(QStringList() << "PlacemarkTextAnnotation"); 0042 } 0043 0044 PlacemarkTextAnnotation::~PlacemarkTextAnnotation() 0045 { 0046 // nothing to do 0047 } 0048 0049 void PlacemarkTextAnnotation::paint(GeoPainter *painter, const ViewportParams *viewport, const QString &layer , int tileZoomLevel) 0050 { 0051 Q_UNUSED(layer); 0052 Q_UNUSED( painter ); 0053 Q_UNUSED(tileZoomLevel); 0054 m_viewport = viewport; 0055 0056 GeoDataStyle::Ptr newStyle(new GeoDataStyle(*placemark()->style())); 0057 GeoDataLabelStyle labelStyle = newStyle->labelStyle(); 0058 0059 if (labelStyle.color() != QApplication::palette().highlight().color()) 0060 m_labelColor = labelStyle.color(); 0061 0062 if (hasFocus()) { 0063 labelStyle.setColor(QApplication::palette().highlight().color()); 0064 } else { 0065 labelStyle.setColor(m_labelColor); 0066 } 0067 0068 newStyle->setLabelStyle(labelStyle); 0069 placemark()->setStyle(newStyle); 0070 0071 qreal x, y; 0072 viewport->currentProjection()->screenCoordinates( placemark()->coordinate(), viewport, x, y ); 0073 m_region = QRegion( x - 10 , y - 10 , 20 , 20 ); 0074 } 0075 0076 bool PlacemarkTextAnnotation::containsPoint( const QPoint &eventPos ) const 0077 { 0078 return m_region.contains( eventPos ); 0079 } 0080 0081 void PlacemarkTextAnnotation::dealWithItemChange( const SceneGraphicsItem *other ) 0082 { 0083 Q_UNUSED( other ); 0084 } 0085 0086 void PlacemarkTextAnnotation::move( const GeoDataCoordinates &source, const GeoDataCoordinates &destination ) 0087 { 0088 Q_UNUSED( source ); 0089 qreal lat = destination.latitude(); 0090 qreal lon = destination.longitude(); 0091 GeoDataCoordinates::normalizeLonLat( lon, lat ); 0092 placemark()->setCoordinate( lon, lat ); 0093 } 0094 0095 const char *PlacemarkTextAnnotation::graphicType() const 0096 { 0097 return SceneGraphicsTypes::SceneGraphicTextAnnotation; 0098 } 0099 0100 QColor PlacemarkTextAnnotation::labelColor() const 0101 { 0102 return m_labelColor; 0103 } 0104 0105 bool PlacemarkTextAnnotation::mousePressEvent( QMouseEvent *event ) 0106 { 0107 setRequest( SceneGraphicsItem::NoRequest ); 0108 0109 if ( state() == SceneGraphicsItem::Editing ) { 0110 if ( event->button() == Qt::LeftButton ) { 0111 m_movingPlacemark = true; 0112 } else if ( event->button() == Qt::RightButton ) { 0113 setRequest( SceneGraphicsItem::ShowPlacemarkRmbMenu ); 0114 } 0115 0116 return true; 0117 } 0118 0119 return false; 0120 } 0121 0122 bool PlacemarkTextAnnotation::mouseMoveEvent( QMouseEvent *event ) 0123 { 0124 setRequest( SceneGraphicsItem::NoRequest ); 0125 0126 qreal lon, lat; 0127 m_viewport->geoCoordinates( event->pos().x(), 0128 event->pos().y(), 0129 lon, lat, 0130 GeoDataCoordinates::Radian ); 0131 0132 if ( m_movingPlacemark ) { 0133 placemark()->setCoordinate( lon, lat ); 0134 return true; 0135 } else { 0136 setRequest( SceneGraphicsItem::ChangeCursorPlacemarkHover ); 0137 return true; 0138 } 0139 0140 return false; 0141 } 0142 0143 bool PlacemarkTextAnnotation::mouseReleaseEvent( QMouseEvent *event ) 0144 { 0145 Q_UNUSED( event ); 0146 setRequest( SceneGraphicsItem::NoRequest ); 0147 0148 m_movingPlacemark = false; 0149 return true; 0150 } 0151 0152 void PlacemarkTextAnnotation::dealWithStateChange( SceneGraphicsItem::ActionState previousState ) 0153 { 0154 Q_UNUSED( previousState ); 0155 } 0156 0157 }