1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef EMBEDDEDWEBVIEW_H
23 #define EMBEDDEDWEBVIEW_H
26 #include <QWebPluginFactory>
33 /** @short An embeddable QWebView with some safety checks and modified resizing
35 This class configures the QWebView in such a way that it will prevent certain
36 dangerous (or unexpected, in the context of a MUA) features from being invoked.
38 Another function is to configure the QWebView in such a way that it resizes
39 itself to show all required contents.
41 Note that you still have to provide a proper eventFilter in the parent widget
42 (and register it for use).
47 class EmbeddedWebView
: public QWebView
51 enum class ColorScheme
{
52 /** @short System's color scheme, but let the content override this */
54 /** @short System's color scheme adjusted towards a compromise for reasonable contrats on funny backgrounds */
56 /** @short Use boring black-text-on-white-background */
60 EmbeddedWebView(QWidget
*parent
, QNetworkAccessManager
*networkManager
, QSettings
*profileSettings
);
61 QSize
sizeHint() const;
62 QWidget
*scrollParent() const;
63 void setStaticWidth(int staticWidth
);
64 int staticWidth() const;
65 static std::map
<ColorScheme
, QString
> supportedColorSchemes();
67 void changeColorScheme(const ColorScheme colorScheme
);
69 void changeEvent(QEvent
*e
);
70 bool eventFilter(QObject
*o
, QEvent
*e
);
71 void mouseMoveEvent(QMouseEvent
*e
);
72 void mouseReleaseEvent(QMouseEvent
*e
);
73 void showEvent(QShowEvent
*se
);
74 void addCustomStylesheet(const QString
&css
);
77 void findScrollParent();
78 void loadColorScheme();
79 void setColorScheme(const ColorScheme colorScheme
);
82 void slotLinkClicked(const QUrl
&url
);
83 void handlePageLoadFinished();
85 QWidget
*m_scrollParent
;
86 int m_scrollParentPadding
;
87 int m_resizeInProgress
;
88 QTimer
*m_autoScrollTimer
;
89 QTimer
*m_sizeContrainTimer
;
90 int m_autoScrollPixels
;
93 QSettings
*m_settings
;
95 ColorScheme m_colorScheme
;
98 class ErrorCheckingPage
: public QWebPage
102 explicit ErrorCheckingPage(QObject
*parent
);
104 virtual bool extension(Extension extension
, const ExtensionOption
*option
, ExtensionReturn
*output
);
105 virtual bool supportsExtension(Extension extension
) const;
110 Q_DECLARE_METATYPE(Gui::EmbeddedWebView::ColorScheme
)
112 #endif // EMBEDDEDWEBVIEW_H