File indexing completed on 2024-03-24 03:52:38
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2012 Torsten Rahn <tackat@kde.org> 0004 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com> 0005 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com> 0006 // 0007 0008 #ifndef POPUPITEM_H 0009 #define POPUPITEM_H 0010 0011 #include <QObject> 0012 #include <QUrl> 0013 0014 #include "BillboardGraphicsItem.h" 0015 0016 #ifdef MARBLE_NO_WEBKITWIDGETS 0017 #include "ui_NullWebPopupWidget.h" 0018 #else 0019 #include "ui_WebPopupWidget.h" 0020 #endif 0021 0022 class QPainter; 0023 0024 namespace Marble 0025 { 0026 0027 /** 0028 * @brief The PopupItem Class 0029 * 0030 * This class represents graphics item for information bubble. 0031 * Mostly used by @see MapInfoDialog. 0032 * 0033 * It has nice API for QWebEngineView and methods for styling it. 0034 * 0035 */ 0036 class PopupItem : public QObject, public BillboardGraphicsItem 0037 { 0038 Q_OBJECT 0039 public: 0040 explicit PopupItem( QObject* parent = nullptr ); 0041 ~PopupItem() override; 0042 0043 /** 0044 * @brief Print button visibility indicator 0045 * 0046 * There is a button in the header of item with print icon. 0047 * It used to print the content of QWebEngineView inside. 0048 * This method indicates visibility of this button. 0049 * 0050 * @see setPrintButtonVisible(); 0051 * 0052 * @return visibility of the print button 0053 */ 0054 bool isPrintButtonVisible() const; 0055 0056 /** 0057 * @brief Sets visibility of the print button 0058 * 0059 * There is a button in the header of item with print icon. 0060 * It used to print the content of QWebEngineView inside 0061 * 0062 * This method sets visibility of this button. 0063 * 0064 * If @p display is `true`, button will be displayed, 0065 * otherwise - button won't be displayed 0066 * 0067 * @param display visibility of the print button 0068 */ 0069 void setPrintButtonVisible(bool display); 0070 0071 /** 0072 * @brief Set URL for web window 0073 * 0074 * There is a small web browser inside. 0075 * It can show open websites. 0076 * 0077 * This method sets @p url for its window. 0078 * 0079 * @param url new url for web window 0080 */ 0081 void setUrl( const QUrl &url ); 0082 0083 /** 0084 * @brief Set content of the popup 0085 * 0086 * There is a small web browser inside. It can show custom HTML. 0087 * This method sets custom @p html for its window 0088 * 0089 * @param html custom html for popup 0090 * @param baseUrl base URL for popup 0091 */ 0092 void setContent( const QString &html, const QUrl & baseUrl = QUrl() ); 0093 0094 /** 0095 * @brief Sets text color of the header 0096 * 0097 * Frame of the web browser is called bubble. Bubble has 0098 * a header - part of the bubble at the top. Usually 0099 * it contains the name of the page which can be set via 0100 * TITLE html tag in HTML document loaded. 0101 * This method sets text @p color of the header. 0102 * 0103 * @param color text color of the header 0104 */ 0105 void setTextColor( const QColor &color ); 0106 0107 /** 0108 * @brief Sets background color of the bubble 0109 * 0110 * Frame of the web browser is called bubble. This method 0111 * sets background @p color of this bubble. 0112 * 0113 * @param color background color of the bubble 0114 */ 0115 void setBackgroundColor( const QColor &color ); 0116 0117 bool eventFilter( QObject *, QEvent *e ) override; 0118 0119 void clearHistory(); 0120 0121 private Q_SLOTS: 0122 /** 0123 * @brief Marks cache as dirty and tells the world its need for repainting. 0124 */ 0125 void requestUpdate(); 0126 0127 /** 0128 * @brief Print content of the web browser 0129 * 0130 * Popup Item has built-in mini-browser. This function 0131 * executes print dialog for printing its content. 0132 * 0133 */ 0134 void printContent() const; 0135 0136 /** 0137 * @brief Updates Back Button (web surfing history) 0138 * 0139 * When you are browsing the site you may need to visit 0140 * the page, you have visited before (Go Back). 0141 * 0142 * For this action Popup Item has a button Go Back placed 0143 * in the left of the header. 0144 * 0145 * @note it's visible only if web surfing history is not clear or 0146 * you are not on its first page. 0147 * 0148 * @see goBack(); 0149 * 0150 */ 0151 void updateBackButton(); 0152 0153 /** 0154 * @brief Go Back (web surfing history) 0155 * 0156 * This method moves you one step backwards in 0157 * web surfing history. 0158 * 0159 */ 0160 void goBack(); 0161 0162 /** 0163 * @brief Opens clicked URL in external browser. 0164 * @param url URL to be opened in external browser 0165 */ 0166 void openUrl(const QUrl &url); 0167 0168 protected: 0169 void paint( QPainter *painter ) override; 0170 0171 Q_SIGNALS: 0172 void repaintNeeded(); 0173 void hide(); 0174 0175 private: 0176 QPixmap pixmap( const QString &imageid ) const; 0177 static void colorize( QImage &img, const QColor &col ); 0178 QWidget* transform( QPoint &point ) const; 0179 0180 QWidget *m_widget; 0181 Ui::WebPopupWidget m_ui; 0182 QString m_content; 0183 QColor m_textColor; 0184 QColor m_backColor; 0185 bool m_needMouseRelease; 0186 QUrl m_baseUrl; 0187 }; 0188 0189 } 0190 0191 #endif