forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/4.0'
This commit is contained in:
@@ -63,6 +63,13 @@ FORMS += docsettingspage.ui \
|
||||
generalsettingspage.ui \
|
||||
remotehelpfilter.ui
|
||||
|
||||
!isEmpty(QT.webenginewidgets.name):minQtVersion(5, 6, 0) {
|
||||
QT += webenginewidgets
|
||||
HEADERS += webenginehelpviewer.h
|
||||
SOURCES += webenginehelpviewer.cpp
|
||||
DEFINES += QTC_WEBENGINE_HELPVIEWER
|
||||
}
|
||||
|
||||
osx {
|
||||
DEFINES += QTC_MAC_NATIVE_HELPVIEWER
|
||||
QT += macextras
|
||||
|
||||
@@ -47,6 +47,9 @@
|
||||
#ifdef QTC_MAC_NATIVE_HELPVIEWER
|
||||
#include "macwebkithelpviewer.h"
|
||||
#endif
|
||||
#ifdef QTC_WEBENGINE_HELPVIEWER
|
||||
#include "webenginehelpviewer.h"
|
||||
#endif
|
||||
|
||||
#include <bookmarkmanager.h>
|
||||
#include <contentwindow.h>
|
||||
@@ -69,6 +72,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <coreplugin/find/findplugin.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/styledbar.h>
|
||||
@@ -362,48 +366,43 @@ HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
|
||||
{
|
||||
// check for backends
|
||||
typedef std::function<HelpViewer *()> ViewerFactory;
|
||||
QHash<QString, ViewerFactory> factories; // id -> factory
|
||||
#ifdef QTC_MAC_NATIVE_HELPVIEWER
|
||||
factories.insert(QLatin1String("native"), []() { return new MacWebKitHelpViewer(); });
|
||||
#endif
|
||||
typedef QPair<QByteArray, ViewerFactory> ViewerFactoryItem; // id -> factory
|
||||
QVector<ViewerFactoryItem> factories;
|
||||
#ifndef QT_NO_WEBKIT
|
||||
factories.insert(QLatin1String("qtwebkit"), []() { return new QtWebKitHelpViewer(); });
|
||||
factories.append(qMakePair(QByteArray("qtwebkit"), []() { return new QtWebKitHelpViewer(); }));
|
||||
#endif
|
||||
factories.insert(QLatin1String("textbrowser"), []() { return new TextBrowserHelpViewer(); });
|
||||
#ifdef QTC_WEBENGINE_HELPVIEWER
|
||||
factories.append(qMakePair(QByteArray("qtwebengine"), []() { return new WebEngineHelpViewer(); }));
|
||||
#endif
|
||||
factories.append(qMakePair(QByteArray("textbrowser"), []() { return new TextBrowserHelpViewer(); }));
|
||||
|
||||
ViewerFactory factory;
|
||||
// TODO: Visual Studio < 2013 has a bug in std::function's operator bool, which in this case
|
||||
// leads to succeeding boolean checks on factory which should not succeed.
|
||||
// So we may not check against "if (!factory)"
|
||||
bool factoryFound = false;
|
||||
|
||||
// check requested backend
|
||||
const QString backend = QLatin1String(qgetenv("QTC_HELPVIEWER_BACKEND"));
|
||||
if (!backend.isEmpty()) {
|
||||
if (!factories.contains(backend)) {
|
||||
qWarning("Help viewer backend \"%s\" not found, using default.", qPrintable(backend));
|
||||
} else {
|
||||
factory = factories.value(backend);
|
||||
factoryFound = true;
|
||||
}
|
||||
}
|
||||
#ifdef QTC_MAC_NATIVE_HELPVIEWER
|
||||
// default setting
|
||||
#ifdef QTC_MAC_NATIVE_HELPVIEWER_DEFAULT
|
||||
if (!factoryFound && factories.contains(QLatin1String("native"))) {
|
||||
factory = factories.value(QLatin1String("native"));
|
||||
factoryFound = true;
|
||||
}
|
||||
factories.prepend(qMakePair(QByteArray("native"), []() { return new MacWebKitHelpViewer(); }));
|
||||
#else
|
||||
factories.append(qMakePair(QByteArray("native"), []() { return new MacWebKitHelpViewer(); }));
|
||||
#endif
|
||||
if (!factoryFound && factories.contains(QLatin1String("qtwebkit"))) {
|
||||
factory = factories.value(QLatin1String("qtwebkit"));
|
||||
factoryFound = true;
|
||||
#endif
|
||||
|
||||
HelpViewer *viewer = nullptr;
|
||||
|
||||
// check requested backend
|
||||
const QByteArray backend = qgetenv("QTC_HELPVIEWER_BACKEND");
|
||||
if (!backend.isEmpty()) {
|
||||
const int pos = Utils::indexOf(factories, [backend](const ViewerFactoryItem &item) {
|
||||
return backend == item.first;
|
||||
});
|
||||
if (pos == -1) {
|
||||
qWarning("Help viewer backend \"%s\" not found, using default.", backend.constData());
|
||||
} else {
|
||||
viewer = factories.at(pos).second();
|
||||
}
|
||||
}
|
||||
if (!factoryFound && factories.contains(QLatin1String("textbrowser"))) {
|
||||
factory = factories.value(QLatin1String("textbrowser"));
|
||||
factoryFound = true;
|
||||
}
|
||||
QTC_ASSERT(factoryFound, return 0);
|
||||
HelpViewer *viewer = factory();
|
||||
|
||||
if (!viewer)
|
||||
viewer = factories.first().second();
|
||||
QTC_ASSERT(viewer, return nullptr);
|
||||
|
||||
// initialize font
|
||||
viewer->setViewerFont(LocalHelpManager::fallbackFont());
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <app/app_version.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QMutexLocker>
|
||||
@@ -56,7 +57,10 @@ QString LocalHelpManager::m_currentFilter = QString();
|
||||
int LocalHelpManager::m_currentFilterIndex = -1;
|
||||
|
||||
static const char kHelpHomePageKey[] = "Help/HomePage";
|
||||
static const char kFontKey[] = "Help/Font";
|
||||
static const char kFontFamilyKey[] = "Help/FallbackFontFamily";
|
||||
static const char kFontStyleKey[] = "Help/FallbackFontStyle";
|
||||
static const char kFontWeightKey[] = "Help/FallbackFontWeight";
|
||||
static const char kFontSizeKey[] = "Help/FallbackFontSize";
|
||||
static const char kStartOptionKey[] = "Help/StartOption";
|
||||
static const char kContextHelpOptionKey[] = "Help/ContextHelpOption";
|
||||
static const char kReturnOnCloseKey[] = "Help/ReturnOnClose";
|
||||
@@ -64,6 +68,29 @@ static const char kLastShownPagesKey[] = "Help/LastShownPages";
|
||||
static const char kLastShownPagesZoomKey[] = "Help/LastShownPagesZoom";
|
||||
static const char kLastSelectedTabKey[] = "Help/LastSelectedTab";
|
||||
|
||||
static const QFont::Style kDefaultFallbackFontStyle = QFont::StyleNormal;
|
||||
static const int kDefaultFallbackFontWeight = QFont::Normal;
|
||||
static const int kDefaultFallbackFontSize = 14;
|
||||
|
||||
static QString defaultFallbackFontFamily()
|
||||
{
|
||||
if (Utils::HostOsInfo::isMacHost())
|
||||
return QLatin1String("Helvetica");
|
||||
if (Utils::HostOsInfo::isAnyUnixHost())
|
||||
return QLatin1String("sans-serif");
|
||||
return QLatin1String("Arial");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void setOrRemoveSetting(const char *key, const T &value, const T &defaultValue)
|
||||
{
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
if (value == defaultValue)
|
||||
settings->remove(QLatin1String(key));
|
||||
else
|
||||
settings->setValue(QLatin1String(key), value);
|
||||
}
|
||||
|
||||
// TODO remove some time after Qt Creator 3.5
|
||||
static QVariant getSettingWithFallback(const QString &settingsKey,
|
||||
const QString &fallbackSettingsKey,
|
||||
@@ -123,14 +150,22 @@ void LocalHelpManager::setHomePage(const QString &page)
|
||||
|
||||
QFont LocalHelpManager::fallbackFont()
|
||||
{
|
||||
const QVariant value = getSettingWithFallback(QLatin1String(kFontKey),
|
||||
QLatin1String("font"), QVariant());
|
||||
return value.value<QFont>();
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
const QString family = settings->value(QLatin1String(kFontFamilyKey), defaultFallbackFontFamily()).toString();
|
||||
const QFont::Style style = QFont::Style(settings->value(QLatin1String(kFontStyleKey), kDefaultFallbackFontStyle).toInt());
|
||||
const int weight = settings->value(QLatin1String(kFontWeightKey), kDefaultFallbackFontWeight).toInt();
|
||||
const int size = settings->value(QLatin1String(kFontSizeKey), kDefaultFallbackFontSize).toInt();
|
||||
QFont font(family, size, weight);
|
||||
font.setStyle(style);
|
||||
return font;
|
||||
}
|
||||
|
||||
void LocalHelpManager::setFallbackFont(const QFont &font)
|
||||
{
|
||||
Core::ICore::settings()->setValue(QLatin1String(kFontKey), font);
|
||||
setOrRemoveSetting(kFontFamilyKey, font.family(), defaultFallbackFontFamily());
|
||||
setOrRemoveSetting(kFontStyleKey, font.style(), kDefaultFallbackFontStyle);
|
||||
setOrRemoveSetting(kFontWeightKey, font.weight(), kDefaultFallbackFontWeight);
|
||||
setOrRemoveSetting(kFontSizeKey, font.pointSize(), kDefaultFallbackFontSize);
|
||||
emit m_instance->fallbackFontChanged(font);
|
||||
}
|
||||
|
||||
|
||||
312
src/plugins/help/webenginehelpviewer.cpp
Normal file
312
src/plugins/help/webenginehelpviewer.cpp
Normal file
@@ -0,0 +1,312 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "webenginehelpviewer.h"
|
||||
|
||||
#include "localhelpmanager.h"
|
||||
#include "openpagesmanager.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QCoreApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWebEngineHistory>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QWebEngineSettings>
|
||||
#include <QWebEngineUrlRequestJob>
|
||||
|
||||
using namespace Help;
|
||||
using namespace Help::Internal;
|
||||
|
||||
HelpUrlSchemeHandler::HelpUrlSchemeHandler(QObject *parent) :
|
||||
QWebEngineUrlSchemeHandler(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void HelpUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
|
||||
{
|
||||
const QUrl url = job->requestUrl();
|
||||
if (!HelpViewer::isLocalUrl(url)) {
|
||||
job->fail(QWebEngineUrlRequestJob::RequestDenied);
|
||||
return;
|
||||
}
|
||||
LocalHelpManager::HelpData data = LocalHelpManager::helpData(url);
|
||||
|
||||
auto buffer = new QBuffer(job);
|
||||
buffer->setData(data.data);
|
||||
job->reply(data.mimeType.toUtf8(), buffer);
|
||||
}
|
||||
|
||||
static HelpUrlSchemeHandler *helpUrlSchemeHandler()
|
||||
{
|
||||
static HelpUrlSchemeHandler *schemeHandler = nullptr;
|
||||
if (!schemeHandler)
|
||||
schemeHandler = new HelpUrlSchemeHandler(LocalHelpManager::instance());
|
||||
return schemeHandler;
|
||||
}
|
||||
|
||||
WebEngineHelpViewer::WebEngineHelpViewer(QWidget *parent) :
|
||||
HelpViewer(parent),
|
||||
m_widget(new WebView(this))
|
||||
{
|
||||
m_widget->setPage(new HelpPage(this));
|
||||
auto layout = new QVBoxLayout;
|
||||
setLayout(layout);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(m_widget, 10);
|
||||
|
||||
QPalette p = palette();
|
||||
p.setColor(QPalette::Base, Qt::white);
|
||||
p.setColor(QPalette::Text, Qt::black);
|
||||
setPalette(p);
|
||||
|
||||
connect(m_widget, &QWebEngineView::urlChanged, this, &WebEngineHelpViewer::sourceChanged);
|
||||
connect(m_widget, &QWebEngineView::loadStarted, this, &WebEngineHelpViewer::slotLoadStarted);
|
||||
connect(m_widget, &QWebEngineView::loadFinished, this, &WebEngineHelpViewer::slotLoadFinished);
|
||||
connect(m_widget, &QWebEngineView::titleChanged, this, &WebEngineHelpViewer::titleChanged);
|
||||
connect(m_widget->page(), &QWebEnginePage::linkHovered, this, &WebEngineHelpViewer::setToolTip);
|
||||
connect(m_widget->pageAction(QWebEnginePage::Back), &QAction::changed, this, [this]() {
|
||||
emit backwardAvailable(isBackwardAvailable());
|
||||
});
|
||||
connect(m_widget->pageAction(QWebEnginePage::Forward), &QAction::changed, this, [this]() {
|
||||
emit forwardAvailable(isForwardAvailable());
|
||||
});
|
||||
|
||||
QAction* action = m_widget->pageAction(QWebEnginePage::OpenLinkInNewTab);
|
||||
action->setText(QCoreApplication::translate("HelpViewer",
|
||||
"Open Link as New Page"));
|
||||
|
||||
QWebEnginePage *viewPage = m_widget->page();
|
||||
QTC_ASSERT(viewPage, return);
|
||||
QWebEngineProfile *viewProfile = viewPage->profile();
|
||||
QTC_ASSERT(viewProfile, return);
|
||||
if (!viewProfile->urlSchemeHandler("qthelp"))
|
||||
viewProfile->installUrlSchemeHandler("qthelp", helpUrlSchemeHandler());
|
||||
}
|
||||
|
||||
QFont WebEngineHelpViewer::viewerFont() const
|
||||
{
|
||||
QWebEngineSettings *webSettings = m_widget->settings();
|
||||
return QFont(webSettings->fontFamily(QWebEngineSettings::StandardFont),
|
||||
webSettings->fontSize(QWebEngineSettings::DefaultFontSize));
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::setViewerFont(const QFont &font)
|
||||
{
|
||||
QWebEngineSettings *webSettings = m_widget->settings();
|
||||
webSettings->setFontFamily(QWebEngineSettings::StandardFont, font.family());
|
||||
webSettings->setFontSize(QWebEngineSettings::DefaultFontSize, font.pointSize());
|
||||
}
|
||||
|
||||
qreal WebEngineHelpViewer::scale() const
|
||||
{
|
||||
return m_widget->zoomFactor();
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::setScale(qreal scale)
|
||||
{
|
||||
m_widget->setZoomFactor(scale);
|
||||
}
|
||||
|
||||
QString WebEngineHelpViewer::title() const
|
||||
{
|
||||
return m_widget->title();
|
||||
}
|
||||
|
||||
QUrl WebEngineHelpViewer::source() const
|
||||
{
|
||||
return m_widget->url();
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::setSource(const QUrl &url)
|
||||
{
|
||||
m_widget->setUrl(url);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::setHtml(const QString &html)
|
||||
{
|
||||
m_widget->setHtml(html);
|
||||
}
|
||||
|
||||
QString WebEngineHelpViewer::selectedText() const
|
||||
{
|
||||
return m_widget->selectedText();
|
||||
}
|
||||
|
||||
bool WebEngineHelpViewer::isForwardAvailable() const
|
||||
{
|
||||
// m_view->history()->canGoForward()
|
||||
return m_widget->pageAction(QWebEnginePage::Forward)->isEnabled();
|
||||
}
|
||||
|
||||
bool WebEngineHelpViewer::isBackwardAvailable() const
|
||||
{
|
||||
return m_widget->pageAction(QWebEnginePage::Back)->isEnabled();
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::addBackHistoryItems(QMenu *backMenu)
|
||||
{
|
||||
if (QWebEngineHistory *history = m_widget->history()) {
|
||||
QList<QWebEngineHistoryItem> items = history->backItems(history->count());
|
||||
for (int i = items.count() - 1; i >= 0; --i) {
|
||||
QWebEngineHistoryItem item = items.at(i);
|
||||
auto action = new QAction(backMenu);
|
||||
action->setText(item.title());
|
||||
connect(action, &QAction::triggered, this, [this,item]() {
|
||||
if (QWebEngineHistory *history = m_widget->history())
|
||||
history->goToItem(item);
|
||||
});
|
||||
backMenu->addAction(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::addForwardHistoryItems(QMenu *forwardMenu)
|
||||
{
|
||||
if (QWebEngineHistory *history = m_widget->history()) {
|
||||
QList<QWebEngineHistoryItem> items = history->forwardItems(history->count());
|
||||
for (int i = 0; i < items.count(); ++i) {
|
||||
QWebEngineHistoryItem item = items.at(i);
|
||||
auto action = new QAction(forwardMenu);
|
||||
action->setText(item.title());
|
||||
connect(action, &QAction::triggered, this, [this,item]() {
|
||||
if (QWebEngineHistory *history = m_widget->history())
|
||||
history->goToItem(item);
|
||||
});
|
||||
forwardMenu->addAction(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::setOpenInNewPageActionVisible(bool visible)
|
||||
{
|
||||
m_widget->setOpenInNewPageActionVisible(visible);
|
||||
}
|
||||
|
||||
bool WebEngineHelpViewer::findText(const QString &text, Core::FindFlags flags, bool incremental,
|
||||
bool fromSearch, bool *wrapped)
|
||||
{
|
||||
Q_UNUSED(incremental)
|
||||
Q_UNUSED(fromSearch)
|
||||
if (wrapped)
|
||||
*wrapped = false; // missing feature in QWebEngine
|
||||
QWebEnginePage::FindFlags webEngineFlags = 0;
|
||||
if (flags & Core::FindBackward)
|
||||
webEngineFlags |= QWebEnginePage::FindBackward;
|
||||
if (flags & Core::FindCaseSensitively)
|
||||
webEngineFlags |= QWebEnginePage::FindCaseSensitively;
|
||||
// QWebEngineView's findText is asynchronous, and the variant taking a callback runs the
|
||||
// callback on the main thread, so blocking here becomes ugly too
|
||||
// So we just claim that the search succeeded
|
||||
m_widget->findText(text, webEngineFlags);
|
||||
return true;
|
||||
}
|
||||
|
||||
HelpPage *WebEngineHelpViewer::page() const
|
||||
{
|
||||
return static_cast<HelpPage *>(m_widget->page());
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::scaleUp()
|
||||
{
|
||||
m_widget->setZoomFactor(m_widget->zoomFactor() + 0.1);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::scaleDown()
|
||||
{
|
||||
m_widget->setZoomFactor(qMax(qreal(0.1), m_widget->zoomFactor() - qreal(0.1)));
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::resetScale()
|
||||
{
|
||||
m_widget->setZoomFactor(1.0);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::copy()
|
||||
{
|
||||
m_widget->triggerPageAction(QWebEnginePage::Copy);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::stop()
|
||||
{
|
||||
m_widget->triggerPageAction(QWebEnginePage::Stop);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::forward()
|
||||
{
|
||||
m_widget->triggerPageAction(QWebEnginePage::Forward);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::backward()
|
||||
{
|
||||
m_widget->triggerPageAction(QWebEnginePage::Back);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::print(QPrinter *printer)
|
||||
{
|
||||
Q_UNUSED(printer)
|
||||
}
|
||||
|
||||
HelpPage::HelpPage(QObject *parent)
|
||||
: QWebEnginePage(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWebEnginePage *HelpPage::createWindow(QWebEnginePage::WebWindowType)
|
||||
{
|
||||
auto viewer = static_cast<WebEngineHelpViewer *>(OpenPagesManager::instance().createPage());
|
||||
return viewer->page();
|
||||
}
|
||||
|
||||
WebView::WebView(QWidget *parent)
|
||||
: QWebEngineView(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void WebView::setOpenInNewPageActionVisible(bool visible)
|
||||
{
|
||||
m_openInNewPageActionVisible = visible;
|
||||
}
|
||||
|
||||
void WebView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu *menu = page()->createStandardContextMenu();
|
||||
if (m_openInNewPageActionVisible) {
|
||||
// insert Open In New Tab if OpenLinkInThisWindow is also there
|
||||
const QList<QAction*> actions = menu->actions();
|
||||
auto it = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::OpenLinkInThisWindow));
|
||||
if (it != actions.cend()) {
|
||||
// insert after
|
||||
++it;
|
||||
QAction *before = (it == actions.cend() ? 0 : *it);
|
||||
menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewTab));
|
||||
}
|
||||
}
|
||||
|
||||
connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
|
||||
menu->popup(event->globalPos());
|
||||
}
|
||||
103
src/plugins/help/webenginehelpviewer.h
Normal file
103
src/plugins/help/webenginehelpviewer.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "helpviewer.h"
|
||||
|
||||
#include <QWebEngineUrlSchemeHandler>
|
||||
#include <QWebEngineView>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
class HelpUrlSchemeHandler : public QWebEngineUrlSchemeHandler
|
||||
{
|
||||
public:
|
||||
explicit HelpUrlSchemeHandler(QObject *parent = 0);
|
||||
void requestStarted(QWebEngineUrlRequestJob *job) override;
|
||||
};
|
||||
|
||||
class HelpPage : public QWebEnginePage
|
||||
{
|
||||
public:
|
||||
explicit HelpPage(QObject *parent = 0);
|
||||
QWebEnginePage *createWindow(QWebEnginePage::WebWindowType) override;
|
||||
};
|
||||
|
||||
class WebView : public QWebEngineView
|
||||
{
|
||||
public:
|
||||
explicit WebView(QWidget *parent = 0);
|
||||
|
||||
void setOpenInNewPageActionVisible(bool visible);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
|
||||
private:
|
||||
bool m_openInNewPageActionVisible = true;
|
||||
};
|
||||
|
||||
class WebEngineHelpViewer : public HelpViewer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WebEngineHelpViewer(QWidget *parent = 0);
|
||||
|
||||
QFont viewerFont() const override;
|
||||
void setViewerFont(const QFont &font) override;
|
||||
qreal scale() const override;
|
||||
void setScale(qreal scale) override;
|
||||
QString title() const override;
|
||||
QUrl source() const override;
|
||||
void setSource(const QUrl &url) override;
|
||||
void setHtml(const QString &html) override;
|
||||
QString selectedText() const override;
|
||||
bool isForwardAvailable() const override;
|
||||
bool isBackwardAvailable() const override;
|
||||
void addBackHistoryItems(QMenu *backMenu) override;
|
||||
void addForwardHistoryItems(QMenu *forwardMenu) override;
|
||||
void setOpenInNewPageActionVisible(bool visible) override;
|
||||
bool findText(const QString &text, Core::FindFlags flags, bool incremental, bool fromSearch, bool *wrapped) override;
|
||||
|
||||
HelpPage *page() const;
|
||||
|
||||
public slots:
|
||||
void scaleUp() override;
|
||||
void scaleDown() override;
|
||||
void resetScale() override;
|
||||
void copy() override;
|
||||
void stop() override;
|
||||
void forward() override;
|
||||
void backward() override;
|
||||
void print(QPrinter *printer) override;
|
||||
|
||||
private:
|
||||
WebView *m_widget;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Help
|
||||
Reference in New Issue
Block a user