File indexing completed on 2024-05-05 03:50:40

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 #ifndef SCENEGRAPHICSITEM_H
0009 #define SCENEGRAPHICSITEM_H
0010 
0011 #include <QMouseEvent>
0012 
0013 #include "GeoGraphicsItem.h"
0014 
0015 
0016 namespace Marble
0017 {
0018 
0019 class GeoDataPlacemark;
0020 class GeoDataCoordinates;
0021 
0022 /**
0023  * @brief This is the base class for all scene graphics included within the
0024  * annotate plugin. It is not instantiated by itself but it is always used
0025  * as a part of a derived object.
0026  */
0027 class SceneGraphicsItem : public GeoGraphicsItem
0028 {
0029 public:
0030     explicit SceneGraphicsItem( GeoDataPlacemark *placemark );
0031     ~SceneGraphicsItem() override;
0032 
0033     enum ActionState {
0034         // General action states
0035         Editing,
0036 
0037         // Polygon specific
0038         DrawingPolygon,
0039         AddingPolygonHole,
0040 
0041         // Polygon/Placemark specific
0042         MergingNodes,
0043         AddingNodes,
0044 
0045         // Polyline specific
0046         DrawingPolyline
0047     };
0048 
0049     /**
0050      * @brief Some events may lead to particular requests to the widget, so it is the
0051      * AnnotatePlugin which has to test whether there is any request from this polygon.
0052      */
0053     enum MarbleWidgetRequest {
0054         NoRequest,
0055 
0056         // Polygon specific
0057         OuterInnerMergingWarning,
0058         InnerInnerMergingWarning,
0059         InvalidShapeWarning,
0060         ShowPolygonRmbMenu,
0061         ShowNodeRmbMenu,
0062         StartPolygonAnimation,
0063         RemovePolygonRequest,
0064         ChangeCursorPolygonNodeHover,
0065         ChangeCursorPolygonBodyHover,
0066 
0067         // Placemark specific
0068         ShowPlacemarkRmbMenu,
0069         ChangeCursorPlacemarkHover,
0070 
0071         // Polyline specific
0072         RemovePolylineRequest,
0073         ShowPolylineRmbMenu,
0074         StartPolylineAnimation,
0075         ChangeCursorPolylineNodeHover,
0076         ChangeCursorPolylineLineHover,
0077 
0078         // GroundOverlay specific
0079         ChangeCursorOverlayVerticalHover,
0080         ChangeCursorOverlayHorizontalHover,
0081         ChangeCursorOverlayBDiagHover,
0082         ChangeCursorOverlayFDiagHover,
0083         ChangeCursorOverlayBodyHover,
0084         ChangeCursorOverlayRotateHover
0085     };
0086 
0087     /**
0088      * @copydoc
0089      */
0090     const GeoDataLatLonAltBox &latLonAltBox() const override;
0091 
0092     /**
0093      * @brief Pure virtual method which is implemented by concrete scene graphic items
0094      * and returns true if the item contains the @p eventPos.
0095      */
0096     virtual bool containsPoint( const QPoint &eventPos ) const = 0;
0097 
0098     /**
0099      * @brief Pure virtual method which is implemented by concrete scene graphic items
0100      * and deals with changes that occur when this item is no longer the item we interact
0101      * with (by means of mouse events - so far).
0102      */
0103     virtual void dealWithItemChange( const SceneGraphicsItem *other ) = 0;
0104 
0105     /**
0106      * @brief Pure virtual method which is implemented by concrete scene graphic items
0107      * and deals with moving it from the @param source coordinates to the @param
0108      * destination coordinates.
0109      * FIXME: Maybe move this to the model classes since the classes derived from this
0110      * abstract class should only deal with painting and event handling.
0111      */
0112     virtual void move( const GeoDataCoordinates &source, const GeoDataCoordinates &destination ) = 0;
0113 
0114     /**
0115      * @brief Returns the current state.
0116      */
0117     ActionState state() const;
0118 
0119     /**
0120      * @brief Sets the ActionState of this item. This also calls dealWithStateChange() with
0121      * a parameter: the previous state.
0122      */
0123     void setState( ActionState state );
0124 
0125     /**
0126      * @brief Returns whether this item has the focus or not.
0127      */
0128     bool hasFocus() const;
0129 
0130     /**
0131      * @brief Sets the focus of this item according to the @p enabled.
0132      *
0133      * @param enabled whether the item is to be focused
0134      */
0135     void setFocus( bool enabled );
0136 
0137     /**
0138      * @brief Returns the widget request.
0139      */
0140     MarbleWidgetRequest request() const;
0141 
0142     /**
0143      * @brief SceneGraphicItem class, when called from one of its derived classes'
0144      * constructors, takes as a parameter a pointer to the placemark of the graphic
0145      * element.
0146      * @return The pointer to the placemark mentioned above.
0147      */
0148     const GeoDataPlacemark *placemark() const;
0149 
0150     GeoDataPlacemark *placemark();
0151 
0152     /**
0153      * @brief This function is used to call the event distributer and makes use of
0154      * the re-implemented virtual functions which handle the mouse events.
0155      */
0156     bool sceneEvent( QEvent *event );
0157 
0158     /**
0159      * @brief It is used for downcasting a SceneGraphicItem. It returns a const char
0160      * which is the name of the element's class and is defined within the
0161      * SceneGraphicsTypes namespace.
0162      */
0163     virtual const char *graphicType() const = 0;
0164 
0165 protected:
0166     /**
0167      * @brief Pure virtual functions which handle the mouse events, all of which are
0168      * re-implemented in every SceneGraphicItem derived classes.
0169      */
0170     virtual bool mousePressEvent( QMouseEvent *event ) = 0;
0171     virtual bool mouseMoveEvent( QMouseEvent *event ) = 0;
0172     virtual bool mouseReleaseEvent( QMouseEvent *event ) = 0;
0173 
0174     virtual void dealWithStateChange( SceneGraphicsItem::ActionState previousState ) = 0;
0175 
0176     /**
0177      * @brief Sets the widget request.
0178      */
0179     void setRequest( MarbleWidgetRequest request );
0180 
0181 private:
0182     ActionState         m_state;
0183     bool                m_hasFocus;
0184     MarbleWidgetRequest m_request;
0185     GeoDataPlacemark   *m_placemark;
0186 };
0187 
0188 }
0189 
0190 #endif // SCENEGRAPHICSITEM_H