1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2008 Torsten Rahn <tackat@kde.org>
4 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
5 //
6 
7 #ifndef MARBLE_ABSTRACTFLOATITEM_H
8 #define MARBLE_ABSTRACTFLOATITEM_H
9 
10 #include <QPointF>
11 #include <QSizeF>
12 
13 #include "RenderPlugin.h"
14 #include "FrameGraphicsItem.h"
15 #include "marble_export.h"
16 
17 class QContextMenuEvent;
18 class QHelpEvent;
19 class QMenu;
20 class QWidget;
21 class QFont;
22 class QPen;
23 
24 namespace Marble
25 {
26 
27 class AbstractFloatItemPrivate;
28 
29 /**
30  * @brief The abstract class for float item plugins
31  *
32  * Float Item is a variant of Marble render plugins
33  * It keeps floating on top of the map at a given screen position
34  *
35  * Good examples are Overview Map, License
36  *
37  */
38 
39 class MARBLE_EXPORT AbstractFloatItem : public RenderPlugin, public FrameGraphicsItem
40 {
41     Q_OBJECT
42 
43  public:
44     explicit AbstractFloatItem( const MarbleModel *marbleModel,
45                                 const QPointF &point = QPointF( 10.0, 10.0 ),
46                                 const QSizeF &size = QSizeF( 150.0, 50.0 ) );
47     ~AbstractFloatItem() override;
48 
49     QHash<QString,QVariant> settings() const override;
50     void setSettings(const QHash<QString, QVariant> &settings) override;
51 
52     RenderType renderType() const override;
53 
54     /**
55      * @brief current pen for rendering
56      * @return pen
57      */
58     QPen pen() const;
59 
60     /**
61      * @brief setting current pen for rendering
62      * @param pen
63      */
64     void setPen( const QPen &pen );
65 
66     /**
67      * @brief current font for rendering
68      * @return font
69      */
70     QFont font() const;
71 
72     /**
73      * @brief setting current font for rendering
74      * @param font
75      */
76     void setFont( const QFont &font );
77 
78     /**
79      * @brief Paints the float item on the map.
80      * @deprecated Do not override this method since it won't be called any longer.
81      *             Override one of FrameGraphicsItem's paint methods instead.
82      */
83     MARBLE_DEPRECATED bool render( GeoPainter *painter, ViewportParams *viewport,
84                  const QString& renderPos = QLatin1String("FLOAT_ITEM"),
85                  GeoSceneLayer * layer = nullptr ) override;
86 
87     QString renderPolicy() const override;
88 
89     /**
90      * @brief Returns the rendering position of this float item.
91      * @deprecated The return value of method is ignored. The float item's rendering position
92      *             will always be "FLOAT_ITEM".
93      */
94     MARBLE_DEPRECATED QStringList renderPosition() const override;
95 
96     /**
97      * @brief Set visibility of the float item
98      *
99      * Float items can be visible or invisible.
100      * It's possible to check visibility with @see visible
101      *
102      * @param visible visibility of the item
103      */
104     void setVisible( bool visible );
105 
106     /**
107      * @brief Check visibility of the float item
108      *
109      * Float items can be visible or invisible.
110      * It's possible to set visibility with @see setVisible
111      *
112      * @return visible or not
113      */
114     bool visible() const;
115 
116     /**
117      * @brief Check is position locked
118      *
119      * Float Item position can be locked. If it is,
120      * the item can't be moved with the cursor (in the UI)
121      *
122      * To set it use @see setPositionLocked
123      *
124      * @return position locked or not
125      */
126     bool positionLocked() const;
127 
128  public Q_SLOTS:
129     /**
130      * @brief Set is position locked
131      * @param lock is locked?
132      *
133      * Float Item position can be locked. If it is,
134      * item can't be moved with cursor (in UI)
135      *
136      * To check it use @see positionLocked
137      *
138      */
139     void setPositionLocked( bool lock );
140 
141     /**
142      * @brief Show the item
143      *
144      * If the item was hidden this function will show it
145      *
146      */
147     void show();
148 
149     /**
150      * @brief Hide the item
151      *
152      * If the item was shown this function will hide it
153      *
154      */
155     void hide();
156 
157  protected:
158     bool eventFilter(QObject *object, QEvent *e) override;
159     virtual void contextMenuEvent ( QWidget *w, QContextMenuEvent *e );
160     virtual void toolTipEvent( QHelpEvent *e );
161     QMenu* contextMenu();
162 
163  private:
164     Q_DISABLE_COPY( AbstractFloatItem )
165     AbstractFloatItemPrivate * const d;
166 };
167 
168 }
169 
170 #endif
171