File indexing completed on 2024-05-05 03:49:49

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0004 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
0005 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0006 //
0007 
0008 #ifndef POPUPLAYER_H
0009 #define POPUPLAYER_H
0010 
0011 #include "LayerInterface.h"
0012 
0013 #include <QObject>
0014 #include <QUrl>
0015 
0016 class QSizeF;
0017 
0018 namespace Marble
0019 {
0020 
0021 class GeoDataCoordinates;
0022 class MarbleWidget;
0023 
0024 /**
0025  * @brief The PopupLayer class
0026  *
0027  * A popup dialog opening on top of the map. The content is shown in a QWebView,
0028  * acting like a minimalistic web browser.
0029  *
0030  */
0031 class MARBLE_EXPORT PopupLayer : public QObject, public LayerInterface
0032 {
0033     Q_OBJECT
0034 public:
0035     explicit PopupLayer( MarbleWidget *widget, QObject* parent = nullptr );
0036     ~PopupLayer() override;
0037 
0038     QStringList renderPosition() const override;
0039     bool render( GeoPainter *painter, ViewportParams *viewport,
0040                  const QString &, GeoSceneLayer * ) override;
0041     bool eventFilter( QObject *, QEvent * ) override;
0042     qreal zValue() const override;
0043 
0044     RenderState renderState() const override;
0045 
0046     QString runtimeTrace() const override { return QStringLiteral("PopupLayer"); }
0047 
0048     /**
0049      * @brief Is popup item visible
0050      *
0051      * If popup item visible, it will return `true`,
0052      * otherwise - `false`
0053      *
0054      * @return visibility of the item
0055      */
0056     bool visible() const;
0057 
0058     /**
0059      * @brief Set visibility of the item
0060      *
0061      * If @p visible is `true`, popup will be visible,
0062      * otherwise - popup won't be visible.
0063      *
0064      * @param visible visibility of the item
0065      */
0066     void setVisible( bool visible );
0067 
0068     /**
0069      * @brief Make the dialog pop up
0070      *
0071      * This has the same effect as setVisible( true ) and additionally
0072      * adjusts the viewport so that the dialog is fully visible.
0073      */
0074     void popup();
0075 
0076     /**
0077      * @brief Sets coordinates
0078      *
0079      * Use a geo position as the dialog base position. The dialog will be shown if
0080      * it is visible and if the map viewport includes the given coordinates.
0081      * This invalidates a screen position set with setPosition(), if any.
0082      *
0083      * Alignment of the dialog from the point of view of the coordinates. For example,
0084      * Qt::AlignRight | Qt::AlignVCenter shows the dialog to the right of the geo position,
0085      * vertically centered. An arrow points from the dialog to the geo position.
0086      *
0087      * @param coordinates geo coordinates
0088      * @param alignment alignment of popup when it visible
0089      */
0090     void setCoordinates( const GeoDataCoordinates &coordinates, Qt::Alignment alignment );
0091 
0092     /**
0093      * @brief Sets URL of the browser
0094      *
0095      * @see PopupItem::setUrl();
0096      *
0097      * @param url url for web browser
0098      */
0099     void setUrl( const QUrl &url );
0100 
0101     /**
0102      * @brief Sets size of popup item
0103      *
0104      * Sets the @p size of the dialog (including the arrow, if any).
0105      *
0106      * @param size popup size, arrows in count
0107      */
0108     void setSize( const QSizeF &size );
0109 
0110     /**
0111      * @brief Sets content of the browser
0112      *
0113      * @see PopupItem::setContent();
0114      *
0115      * @param html content (in html format)
0116      */
0117     void setContent( const QString &html, const QUrl & baseUrl = QUrl() );
0118 
0119     /**
0120      * @brief Sets background color of the header
0121      *
0122      * @see PopupItem::setBackgroundColor();
0123      *
0124      * @param color color to set
0125      */
0126     void setBackgroundColor( const QColor &color );
0127 
0128     /**
0129      * @brief Sets text color of the header
0130      *
0131      * @see PopupItem::setTextColor();
0132      *
0133      * @param color color to set
0134      */
0135     void setTextColor( const QColor &color );
0136 
0137 Q_SIGNALS:
0138     void repaintNeeded();
0139 
0140 private Q_SLOTS:
0141     void hidePopupItem();
0142 
0143 private:
0144     class Private;
0145     Private *const d;
0146 };
0147 
0148 }
0149 
0150 #endif