File indexing completed on 2024-06-23 05:20:49
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 #ifndef EMBEDDEDWEBVIEW_H 0023 #define EMBEDDEDWEBVIEW_H 0024 0025 #include <QSettings> 0026 #include <QWebPluginFactory> 0027 #include <QWebView> 0028 0029 namespace Gui 0030 { 0031 0032 0033 /** @short An embeddable QWebView with some safety checks and modified resizing 0034 0035 This class configures the QWebView in such a way that it will prevent certain 0036 dangerous (or unexpected, in the context of a MUA) features from being invoked. 0037 0038 Another function is to configure the QWebView in such a way that it resizes 0039 itself to show all required contents. 0040 0041 Note that you still have to provide a proper eventFilter in the parent widget 0042 (and register it for use). 0043 0044 @see Gui::MessageView 0045 0046 */ 0047 class EmbeddedWebView: public QWebView 0048 { 0049 Q_OBJECT 0050 public: 0051 enum class ColorScheme { 0052 /** @short System's color scheme, but let the content override this */ 0053 System, 0054 /** @short System's color scheme adjusted towards a compromise for reasonable contrats on funny backgrounds */ 0055 AdjustedSystem, 0056 /** @short Use boring black-text-on-white-background */ 0057 BlackOnWhite, 0058 }; 0059 0060 EmbeddedWebView(QWidget *parent, QNetworkAccessManager *networkManager, QSettings *profileSettings); 0061 QSize sizeHint() const; 0062 QWidget *scrollParent() const; 0063 void setStaticWidth(int staticWidth); 0064 int staticWidth() const; 0065 static std::map<ColorScheme, QString> supportedColorSchemes(); 0066 public slots: 0067 void changeColorScheme(const ColorScheme colorScheme); 0068 protected: 0069 void changeEvent(QEvent *e); 0070 bool eventFilter(QObject *o, QEvent *e); 0071 void mouseMoveEvent(QMouseEvent *e); 0072 void mouseReleaseEvent(QMouseEvent *e); 0073 void showEvent(QShowEvent *se); 0074 void addCustomStylesheet(const QString &css); 0075 void constrainSize(); 0076 private: 0077 void findScrollParent(); 0078 void loadColorScheme(); 0079 void setColorScheme(const ColorScheme colorScheme); 0080 private slots: 0081 void autoScroll(); 0082 void slotLinkClicked(const QUrl &url); 0083 void handlePageLoadFinished(); 0084 private: 0085 QWidget *m_scrollParent; 0086 int m_scrollParentPadding; 0087 int m_resizeInProgress; 0088 QTimer *m_autoScrollTimer; 0089 QTimer *m_sizeContrainTimer; 0090 int m_autoScrollPixels; 0091 int m_staticWidth; 0092 QString m_customCss; 0093 QSettings *m_settings; 0094 protected: 0095 ColorScheme m_colorScheme; 0096 }; 0097 0098 class ErrorCheckingPage: public QWebPage 0099 { 0100 Q_OBJECT 0101 public: 0102 explicit ErrorCheckingPage(QObject *parent); 0103 0104 virtual bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output); 0105 virtual bool supportsExtension(Extension extension) const; 0106 }; 0107 0108 } 0109 0110 Q_DECLARE_METATYPE(Gui::EmbeddedWebView::ColorScheme) 0111 0112 #endif // EMBEDDEDWEBVIEW_H