File indexing completed on 2024-04-14 03:47:40

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2008 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0005 //
0006 
0007 #ifndef MARBLE_ABSTRACTFLOATITEM_H
0008 #define MARBLE_ABSTRACTFLOATITEM_H
0009 
0010 #include <QPointF>
0011 #include <QSizeF>
0012 
0013 #include "RenderPlugin.h"
0014 #include "FrameGraphicsItem.h"
0015 #include "marble_export.h"
0016 
0017 class QContextMenuEvent;
0018 class QHelpEvent;
0019 class QMenu;
0020 class QWidget;
0021 class QFont;
0022 class QPen;
0023 
0024 namespace Marble
0025 {
0026 
0027 class AbstractFloatItemPrivate;
0028 
0029 /**
0030  * @brief The abstract class for float item plugins
0031  *
0032  * Float Item is a variant of Marble render plugins
0033  * It keeps floating on top of the map at a given screen position
0034  *
0035  * Good examples are Overview Map, License
0036  *
0037  */
0038 
0039 class MARBLE_EXPORT AbstractFloatItem : public RenderPlugin, public FrameGraphicsItem
0040 {
0041     Q_OBJECT
0042 
0043  public:
0044     explicit AbstractFloatItem( const MarbleModel *marbleModel,
0045                                 const QPointF &point = QPointF( 10.0, 10.0 ),
0046                                 const QSizeF &size = QSizeF( 150.0, 50.0 ) );
0047     ~AbstractFloatItem() override;
0048 
0049     QHash<QString,QVariant> settings() const override;
0050     void setSettings(const QHash<QString, QVariant> &settings) override;
0051 
0052     RenderType renderType() const override;
0053 
0054     /**
0055      * @brief current pen for rendering
0056      * @return pen
0057      */
0058     QPen pen() const;
0059 
0060     /**
0061      * @brief setting current pen for rendering
0062      * @param pen
0063      */
0064     void setPen( const QPen &pen );
0065 
0066     /**
0067      * @brief current font for rendering
0068      * @return font
0069      */
0070     QFont font() const;
0071 
0072     /**
0073      * @brief setting current font for rendering
0074      * @param font
0075      */
0076     void setFont( const QFont &font );
0077 
0078     /**
0079      * @brief Paints the float item on the map.
0080      * @deprecated Do not override this method since it won't be called any longer.
0081      *             Override one of FrameGraphicsItem's paint methods instead.
0082      */
0083     MARBLE_DEPRECATED bool render( GeoPainter *painter, ViewportParams *viewport,
0084                  const QString& renderPos = QLatin1String("FLOAT_ITEM"),
0085                  GeoSceneLayer * layer = nullptr ) override;
0086 
0087     QString renderPolicy() const override;
0088 
0089     /**
0090      * @brief Returns the rendering position of this float item.
0091      * @deprecated The return value of method is ignored. The float item's rendering position
0092      *             will always be "FLOAT_ITEM".
0093      */
0094     MARBLE_DEPRECATED QStringList renderPosition() const override;
0095 
0096     /**
0097      * @brief Set visibility of the float item
0098      *
0099      * Float items can be visible or invisible.
0100      * It's possible to check visibility with @see visible
0101      *
0102      * @param visible visibility of the item
0103      */
0104     void setVisible( bool visible );
0105 
0106     /**
0107      * @brief Check visibility of the float item
0108      *
0109      * Float items can be visible or invisible.
0110      * It's possible to set visibility with @see setVisible
0111      *
0112      * @return visible or not
0113      */
0114     bool visible() const;
0115 
0116     /**
0117      * @brief Check is position locked
0118      *
0119      * Float Item position can be locked. If it is,
0120      * the item can't be moved with the cursor (in the UI)
0121      *
0122      * To set it use @see setPositionLocked
0123      *
0124      * @return position locked or not
0125      */
0126     bool positionLocked() const;
0127 
0128  public Q_SLOTS:
0129     /**
0130      * @brief Set is position locked
0131      * @param lock is locked?
0132      *
0133      * Float Item position can be locked. If it is,
0134      * item can't be moved with cursor (in UI)
0135      *
0136      * To check it use @see positionLocked
0137      *
0138      */
0139     void setPositionLocked( bool lock );
0140 
0141     /**
0142      * @brief Show the item
0143      *
0144      * If the item was hidden this function will show it
0145      *
0146      */
0147     void show();
0148 
0149     /**
0150      * @brief Hide the item
0151      *
0152      * If the item was shown this function will hide it
0153      *
0154      */
0155     void hide();
0156 
0157  protected:
0158     bool eventFilter(QObject *object, QEvent *e) override;
0159     virtual void contextMenuEvent ( QWidget *w, QContextMenuEvent *e );
0160     virtual void toolTipEvent( QHelpEvent *e );
0161     QMenu* contextMenu();
0162 
0163  private:
0164     Q_DISABLE_COPY( AbstractFloatItem )
0165     AbstractFloatItemPrivate * const d;
0166 };
0167 
0168 }
0169 
0170 #endif