summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2010-02-11 10:37:38 (GMT)
committerkh1 <qt-info@nokia.com>2010-02-12 15:53:37 (GMT)
commitffeeac8031d3ac561a8bfb424323ae2c81f82b28 (patch)
tree9ec43c4e1f3825b79a5f45cd5415d625e1b373fe
parent5f17496ac4a7179f91b3160e7083808200b91716 (diff)
downloadQt-ffeeac8031d3ac561a8bfb424323ae2c81f82b28.zip
Qt-ffeeac8031d3ac561a8bfb424323ae2c81f82b28.tar.gz
Qt-ffeeac8031d3ac561a8bfb424323ae2c81f82b28.tar.bz2
Move the QWebView based help viewer into it's own source files.
-rw-r--r--tools/assistant/tools/assistant/aboutdialog.cpp1
-rw-r--r--tools/assistant/tools/assistant/assistant.pro2
-rw-r--r--tools/assistant/tools/assistant/centralwidget.cpp2
-rw-r--r--tools/assistant/tools/assistant/contentwindow.cpp1
-rw-r--r--tools/assistant/tools/assistant/helpviewer.cpp386
-rw-r--r--tools/assistant/tools/assistant/helpviewer.h83
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.cpp397
-rw-r--r--tools/assistant/tools/assistant/helpviewer_qwv.h121
-rw-r--r--tools/assistant/tools/assistant/indexwindow.cpp1
9 files changed, 560 insertions, 434 deletions
diff --git a/tools/assistant/tools/assistant/aboutdialog.cpp b/tools/assistant/tools/assistant/aboutdialog.cpp
index 26d488d..c4f5fd2 100644
--- a/tools/assistant/tools/assistant/aboutdialog.cpp
+++ b/tools/assistant/tools/assistant/aboutdialog.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
#include "helpviewer.h"
+#include "helpviewer_qwv.h"
#include "tracer.h"
#include <QtCore/QBuffer>
diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro
index edaf076..2ae03d4 100644
--- a/tools/assistant/tools/assistant/assistant.pro
+++ b/tools/assistant/tools/assistant/assistant.pro
@@ -28,6 +28,7 @@ HEADERS += aboutdialog.h \
findwidget.h \
filternamedialog.h \
helpenginewrapper.h \
+ helpviewer_qwv.h \
helpviewer.h \
indexwindow.h \
installdialog.h \
@@ -54,6 +55,7 @@ SOURCES += aboutdialog.cpp \
findwidget.cpp \
filternamedialog.cpp \
helpenginewrapper.cpp \
+ helpviewer_qwv.cpp \
helpviewer.cpp \
indexwindow.cpp \
installdialog.cpp \
diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp
index 03af06c..41b0df4 100644
--- a/tools/assistant/tools/assistant/centralwidget.cpp
+++ b/tools/assistant/tools/assistant/centralwidget.cpp
@@ -44,6 +44,7 @@
#include "findwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "helpviewer_qwv.h"
#include "searchwidget.h"
#include "mainwindow.h"
#include "../shared/collectionconfiguration.h"
@@ -57,6 +58,7 @@
#include <QtGui/QPrinter>
#include <QtGui/QTabBar>
#include <QtGui/QTabWidget>
+#include <QtGui/QTextBrowser>
#include <QtGui/QToolButton>
#include <QtGui/QPageSetupDialog>
#include <QtGui/QPrintDialog>
diff --git a/tools/assistant/tools/assistant/contentwindow.cpp b/tools/assistant/tools/assistant/contentwindow.cpp
index 976ed7a..bfb88c7 100644
--- a/tools/assistant/tools/assistant/contentwindow.cpp
+++ b/tools/assistant/tools/assistant/contentwindow.cpp
@@ -44,6 +44,7 @@
#include "centralwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "helpviewer_qwv.h"
#include <QtGui/QLayout>
#include <QtGui/QFocusEvent>
diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp
index 8e4d3ed..0f198ac 100644
--- a/tools/assistant/tools/assistant/helpviewer.cpp
+++ b/tools/assistant/tools/assistant/helpviewer.cpp
@@ -38,361 +38,54 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "tracer.h"
-
#include "helpviewer.h"
+#include "helpviewer_qwv.h"
+
#include "centralwidget.h"
#include "helpenginewrapper.h"
+#include "tracer.h"
#include <QtCore/QDir>
-#include <QtCore/QEvent>
-#include <QtCore/QVariant>
-#include <QtCore/QByteArray>
#include <QtCore/QStringBuilder>
-#include <QtCore/QTemporaryFile>
-#include <QtCore/QTimer>
+#include <QtGui/QContextMenuEvent>
#include <QtGui/QMenu>
-#include <QtGui/QKeyEvent>
#include <QtGui/QClipboard>
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#include <QtGui/QDesktopServices>
-#include <QNetworkAccessManager>
-#include <QNetworkReply>
-#include <QNetworkRequest>
-
QT_BEGIN_NAMESPACE
-namespace {
- const QString PageNotFoundMessage =
- QCoreApplication::translate("HelpViewer",
- "<title>Error 404...</title><div align=\"center\"><br><br>"
- "<h1>The page could not be found</h1><br><h3>'%1'</h3></div>");
-}
-
-#if !defined(QT_NO_WEBKIT)
-
-class HelpNetworkReply : public QNetworkReply
-{
-public:
- HelpNetworkReply(const QNetworkRequest &request, const QByteArray &fileData,
- const QString &mimeType);
-
- virtual void abort();
-
- virtual qint64 bytesAvailable() const
- { return data.length() + QNetworkReply::bytesAvailable(); }
-
-protected:
- virtual qint64 readData(char *data, qint64 maxlen);
-
-private:
- QByteArray data;
- qint64 origLen;
-};
-
-HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request,
- const QByteArray &fileData, const QString& mimeType)
- : data(fileData), origLen(fileData.length())
-{
- TRACE_OBJ
- setRequest(request);
- setOpenMode(QIODevice::ReadOnly);
-
- setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
- setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen));
- QTimer::singleShot(0, this, SIGNAL(metaDataChanged()));
- QTimer::singleShot(0, this, SIGNAL(readyRead()));
-}
-
-void HelpNetworkReply::abort()
-{
- TRACE_OBJ
- // nothing to do
-}
-
-qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen)
-{
- TRACE_OBJ
- qint64 len = qMin(qint64(data.length()), maxlen);
- if (len) {
- qMemCopy(buffer, data.constData(), len);
- data.remove(0, len);
- }
- if (!data.length())
- QTimer::singleShot(0, this, SIGNAL(finished()));
- return len;
-}
-
-class HelpNetworkAccessManager : public QNetworkAccessManager
-{
-public:
- HelpNetworkAccessManager(QObject *parent);
-
-protected:
- virtual QNetworkReply *createRequest(Operation op,
- const QNetworkRequest &request, QIODevice *outgoingData = 0);
-};
-
-HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent)
- : QNetworkAccessManager(parent)
-{
- TRACE_OBJ
-}
-
-QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
- const QNetworkRequest &request, QIODevice* /*outgoingData*/)
-{
- TRACE_OBJ
- const QUrl& url = request.url();
- QString mimeType = url.toString();
- if (mimeType.endsWith(QLatin1String(".svg"))
- || mimeType.endsWith(QLatin1String(".svgz"))) {
- mimeType = QLatin1String("image/svg+xml");
- } else if (mimeType.endsWith(QLatin1String(".css"))) {
- mimeType = QLatin1String("text/css");
- } else if (mimeType.endsWith(QLatin1String(".js"))) {
- mimeType = QLatin1String("text/javascript");
- } else if (mimeType.endsWith(QLatin1String(".txt"))) {
- mimeType = QLatin1String("text/plain");
- } else {
- mimeType = QLatin1String("text/html");
- }
-
- HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
- const QByteArray &data = helpEngine.findFile(url).isValid()
- ? helpEngine.fileData(url)
- : PageNotFoundMessage.arg(url.toString()).toUtf8();
- return new HelpNetworkReply(request, data, mimeType);
-}
-
-class HelpPage : public QWebPage
-{
-public:
- HelpPage(CentralWidget *central, QObject *parent);
-
-protected:
- virtual QWebPage *createWindow(QWebPage::WebWindowType);
- virtual void triggerAction(WebAction action, bool checked = false);
-
- virtual bool acceptNavigationRequest(QWebFrame *frame,
- const QNetworkRequest &request, NavigationType type);
-
-private:
- CentralWidget *centralWidget;
- bool closeNewTabIfNeeded;
-
- friend class HelpViewer;
- Qt::MouseButtons m_pressedButtons;
- Qt::KeyboardModifiers m_keyboardModifiers;
-};
-
-HelpPage::HelpPage(CentralWidget *central, QObject *parent)
- : QWebPage(parent)
- , centralWidget(central)
- , closeNewTabIfNeeded(false)
- , m_pressedButtons(Qt::NoButton)
- , m_keyboardModifiers(Qt::NoModifier)
-{
- TRACE_OBJ
-}
-
-QWebPage *HelpPage::createWindow(QWebPage::WebWindowType)
-{
- TRACE_OBJ
- HelpPage* newPage = static_cast<HelpPage*>(centralWidget->newEmptyTab()->page());
- if (newPage)
- newPage->closeNewTabIfNeeded = closeNewTabIfNeeded;
- closeNewTabIfNeeded = false;
- return newPage;
-}
-
-void HelpPage::triggerAction(WebAction action, bool checked)
-{
- TRACE_OBJ
- switch (action) {
- case OpenLinkInNewWindow:
- closeNewTabIfNeeded = true;
- default: // fall through
- QWebPage::triggerAction(action, checked);
- break;
- }
-}
-
-bool HelpPage::acceptNavigationRequest(QWebFrame *,
- const QNetworkRequest &request, QWebPage::NavigationType type)
-{
- TRACE_OBJ
- const QUrl &url = request.url();
- const bool closeNewTab = closeNewTabIfNeeded;
- closeNewTabIfNeeded = false;
-
- if (HelpViewer::isLocalUrl(url)) {
- const QString& path = url.path();
- if (!HelpViewer::canOpenPage(path)) {
- QTemporaryFile tmpTmpFile;
- if (!tmpTmpFile.open())
- return false;
- const QString extension = QFileInfo(path).completeSuffix();
- QFile actualTmpFile(tmpTmpFile.fileName() % QLatin1String(".")
- % extension);
- if (actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
- actualTmpFile.write(HelpEngineWrapper::instance().fileData(url));
- actualTmpFile.close();
- QDesktopServices::openUrl(QUrl(actualTmpFile.fileName()));
- }
-
- if (closeNewTab)
- QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab");
- return false;
- }
-
- if (type == QWebPage::NavigationTypeLinkClicked
- && (m_keyboardModifiers & Qt::ControlModifier
- || m_pressedButtons == Qt::MidButton)) {
- HelpViewer* viewer = centralWidget->newEmptyTab();
- if (viewer)
- CentralWidget::instance()->setSource(url);
- m_pressedButtons = Qt::NoButton;
- m_keyboardModifiers = Qt::NoModifier;
- return false;
- }
- return true;
- }
-
- QDesktopServices::openUrl(url);
- return false;
-}
-
-HelpViewer::HelpViewer(CentralWidget *parent)
- : QWebView(parent)
- , parentWidget(parent)
- , loadFinished(false)
- , helpEngine(HelpEngineWrapper::instance())
-{
- TRACE_OBJ
- setAcceptDrops(false);
-
- setPage(new HelpPage(parent, this));
-
- page()->setNetworkAccessManager(new HelpNetworkAccessManager(this));
-
- QAction* action = pageAction(QWebPage::OpenLinkInNewWindow);
- action->setText(tr("Open Link in New Tab"));
- if (!parent)
- action->setVisible(false);
-
- pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false);
- pageAction(QWebPage::DownloadImageToDisk)->setVisible(false);
- pageAction(QWebPage::OpenImageInNewWindow)->setVisible(false);
-
- connect(pageAction(QWebPage::Copy), SIGNAL(changed()), this,
- SLOT(actionChanged()));
- connect(pageAction(QWebPage::Back), SIGNAL(changed()), this,
- SLOT(actionChanged()));
- connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this,
- SLOT(actionChanged()));
- connect(page(), SIGNAL(linkHovered(QString,QString,QString)), this,
- SIGNAL(highlighted(QString)));
- connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl)));
- connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool)));
-}
-
-void HelpViewer::setSource(const QUrl &url)
-{
- TRACE_OBJ
- loadFinished = false;
- if (url.toString() == QLatin1String("help")) {
- load(QUrl(QLatin1String("qthelp://com.trolltech.com."
- "assistantinternal-1.0.0/assistant/assistant.html")));
- } else {
- load(url);
- }
-}
-
-void HelpViewer::resetZoom()
-{
- TRACE_OBJ
- setTextSizeMultiplier(1.0);
-}
-
-void HelpViewer::zoomIn(qreal range)
-{
- TRACE_OBJ
- setTextSizeMultiplier(textSizeMultiplier() + range / 10.0);
-}
-
-void HelpViewer::zoomOut(qreal range)
-{
- TRACE_OBJ
- setTextSizeMultiplier(qMax(0.0, textSizeMultiplier() - range / 10.0));
-}
-
-void HelpViewer::wheelEvent(QWheelEvent *e)
-{
- TRACE_OBJ
- if (e->modifiers() & Qt::ControlModifier) {
- const int delta = e->delta();
- if (delta > 0)
- zoomIn(delta / 120);
- else if (delta < 0)
- zoomOut(-delta / 120);
- e->accept();
- return;
- }
- QWebView::wheelEvent(e);
-}
-
-void HelpViewer::mouseReleaseEvent(QMouseEvent *e)
+bool HelpViewer::canOpenPage(const QString &url)
{
TRACE_OBJ
- if (e->button() == Qt::XButton1) {
- triggerPageAction(QWebPage::Back);
- return;
- }
-
- if (e->button() == Qt::XButton2) {
- triggerPageAction(QWebPage::Forward);
- return;
- }
-
- QWebView::mouseReleaseEvent(e);
+ return url.endsWith(QLatin1String(".html"), Qt::CaseInsensitive)
+ || url.endsWith(QLatin1String(".htm"), Qt::CaseInsensitive)
+ || url == QLatin1String("blank");
}
-void HelpViewer::actionChanged()
+bool HelpViewer::isLocalUrl(const QUrl &url)
{
TRACE_OBJ
- QAction *a = qobject_cast<QAction *>(sender());
- if (a == pageAction(QWebPage::Copy))
- emit copyAvailable(a->isEnabled());
- else if (a == pageAction(QWebPage::Back))
- emit backwardAvailable(a->isEnabled());
- else if (a == pageAction(QWebPage::Forward))
- emit forwardAvailable(a->isEnabled());
+ const QString scheme = url.scheme();
+ return scheme.isEmpty()
+ || scheme == QLatin1String("file")
+ || scheme == QLatin1String("qrc")
+ || scheme == QLatin1String("data")
+ || scheme == QLatin1String("qthelp")
+ || scheme == QLatin1String("about");
}
-void HelpViewer::mousePressEvent(QMouseEvent *event)
-{
- TRACE_OBJ
- HelpPage *currentPage = static_cast<HelpPage*>(page());
- if (currentPage) {
- currentPage->m_pressedButtons = event->buttons();
- currentPage->m_keyboardModifiers = event->modifiers();
- }
- QWebView::mousePressEvent(event);
-}
+#if defined(QT_NO_WEBKIT)
-void HelpViewer::setLoadFinished(bool ok)
-{
- TRACE_OBJ
- loadFinished = ok;
- emit sourceChanged(url());
+namespace {
+const QString PageNotFoundMessage =
+ QCoreApplication::translate("HelpViewer", "<title>Error 404...</title><div "
+ "align=\"center\"><br><br><h1>The page could not be found</h1><br><h3>'%1'"
+ "</h3></div>");
}
-#else // !defined(QT_NO_WEBKIT)
-
HelpViewer::HelpViewer(CentralWidget *parent)
: QTextBrowser(parent)
, zoomCount(0)
@@ -603,6 +296,12 @@ void HelpViewer::keyPressEvent(QKeyEvent *e)
QTextBrowser::keyPressEvent(e);
}
+void HelpViewer::home()
+{
+ TRACE_OBJ
+ setSource(helpEngine.homePage());
+}
+
void HelpViewer::wheelEvent(QWheelEvent *e)
{
TRACE_OBJ
@@ -615,33 +314,6 @@ void HelpViewer::wheelEvent(QWheelEvent *e)
}
}
-#endif // !defined(QT_NO_WEBKIT)
-
-void HelpViewer::home()
-{
- TRACE_OBJ
- setSource(helpEngine.homePage());
-}
-
-bool HelpViewer::canOpenPage(const QString &url)
-{
- TRACE_OBJ
- return url.endsWith(QLatin1String(".html"), Qt::CaseInsensitive)
- || url.endsWith(QLatin1String(".htm"), Qt::CaseInsensitive)
- || url == QLatin1String("blank");
-}
-
-bool HelpViewer::isLocalUrl(const QUrl &url)
-{
- TRACE_OBJ
- const QString scheme = url.scheme();
- return scheme.isEmpty()
- || scheme == QLatin1String("file")
- || scheme == QLatin1String("qrc")
- || scheme == QLatin1String("data")
- || scheme == QLatin1String("qthelp")
- || scheme == QLatin1String("about");
-}
-
+#endif
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h
index 4dd8064..da992fa 100644
--- a/tools/assistant/tools/assistant/helpviewer.h
+++ b/tools/assistant/tools/assistant/helpviewer.h
@@ -44,89 +44,18 @@
#include <QtCore/QUrl>
#include <QtCore/QVariant>
-#include <QtGui/QTextBrowser>
-#include <QtGui/QAction>
-#if !defined(QT_NO_WEBKIT)
-#include <QWebView>
-#endif
+#if defined(QT_NO_WEBKIT)
+
+#include <QtGui/QTextBrowser>
QT_BEGIN_NAMESPACE
class CentralWidget;
class HelpEngineWrapper;
-
-class QPoint;
-class QString;
+class QContextMenuEvent;
class QKeyEvent;
class QMouseEvent;
-class QContextMenuEvent;
-
-#if !defined(QT_NO_WEBKIT)
-
-class HelpViewer : public QWebView
-{
- Q_OBJECT
-
-public:
- HelpViewer(CentralWidget *parent);
- void setSource(const QUrl &url);
-
- inline QUrl source() const
- { return url(); }
-
- inline QString documentTitle() const
- { return title(); }
-
- inline bool hasSelection() const
- { return !selectedText().isEmpty(); } // ### this is suboptimal
-
- void resetZoom();
- void zoomIn(qreal range = 1);
- void zoomOut(qreal range = 1);
-
- inline void copy()
- { return triggerPageAction(QWebPage::Copy); }
-
- inline bool isForwardAvailable() const
- { return pageAction(QWebPage::Forward)->isEnabled(); }
- inline bool isBackwardAvailable() const
- { return pageAction(QWebPage::Back)->isEnabled(); }
- inline bool hasLoadFinished() const
- { return loadFinished; }
- inline qreal zoom() const
- { return textSizeMultiplier(); }
-
- static bool canOpenPage(const QString &url);
- static bool isLocalUrl(const QUrl &url);
-
-public Q_SLOTS:
- void home();
- void backward() { back(); }
-
-Q_SIGNALS:
- void copyAvailable(bool enabled);
- void forwardAvailable(bool enabled);
- void backwardAvailable(bool enabled);
- void highlighted(const QString &);
- void sourceChanged(const QUrl &);
-
-protected:
- virtual void wheelEvent(QWheelEvent *);
- void mouseReleaseEvent(QMouseEvent *e);
- void mousePressEvent(QMouseEvent *event);
-
-private Q_SLOTS:
- void actionChanged();
- void setLoadFinished(bool ok);
-
-private:
- CentralWidget* parentWidget;
- bool loadFinished;
- HelpEngineWrapper &helpEngine;
-};
-
-#else
class HelpViewer : public QTextBrowser
{
@@ -156,7 +85,7 @@ protected:
void wheelEvent(QWheelEvent *e);
private:
- QVariant loadResource(int type, const QUrl &name);
+ QVariant loadResource(int type, const QUrl &name);
void openLinkInNewTab(const QString &link);
bool hasAnchorAt(const QPoint& pos);
void contextMenuEvent(QContextMenuEvent *e);
@@ -178,4 +107,4 @@ private:
QT_END_NAMESPACE
-#endif
+#endif // HELPVIEWER_H
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.cpp b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
new file mode 100644
index 0000000..cd6c89b
--- /dev/null
+++ b/tools/assistant/tools/assistant/helpviewer_qwv.cpp
@@ -0,0 +1,397 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Assistant of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "helpviewer.h"
+#include "helpviewer_qwv.h"
+
+#include "centralwidget.h"
+#include "helpenginewrapper.h"
+#include "tracer.h"
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QFileInfo>
+#include <QtCore/QString>
+#include <QtCore/QStringBuilder>
+#include <QtCore/QTemporaryFile>
+#include <QtCore/QTimer>
+
+#include <QtGui/QDesktopServices>
+#include <QtGui/QWheelEvent>
+
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QtNetwork/QNetworkRequest>
+
+QT_BEGIN_NAMESPACE
+
+#if !defined(QT_NO_WEBKIT)
+
+namespace {
+const QString PageNotFoundMessage =
+ QCoreApplication::translate("HelpViewer", "<title>Error 404...</title><div "
+ "align=\"center\"><br><br><h1>The page could not be found</h1><br><h3>'%1'"
+ "</h3></div>");
+}
+
+class HelpNetworkReply : public QNetworkReply
+{
+public:
+ HelpNetworkReply(const QNetworkRequest &request, const QByteArray &fileData,
+ const QString &mimeType);
+
+ virtual void abort();
+
+ virtual qint64 bytesAvailable() const
+ { return data.length() + QNetworkReply::bytesAvailable(); }
+
+protected:
+ virtual qint64 readData(char *data, qint64 maxlen);
+
+private:
+ QByteArray data;
+ qint64 origLen;
+};
+
+HelpNetworkReply::HelpNetworkReply(const QNetworkRequest &request,
+ const QByteArray &fileData, const QString& mimeType)
+ : data(fileData), origLen(fileData.length())
+{
+ TRACE_OBJ
+ setRequest(request);
+ setOpenMode(QIODevice::ReadOnly);
+
+ setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
+ setHeader(QNetworkRequest::ContentLengthHeader, QByteArray::number(origLen));
+ QTimer::singleShot(0, this, SIGNAL(metaDataChanged()));
+ QTimer::singleShot(0, this, SIGNAL(readyRead()));
+}
+
+void HelpNetworkReply::abort()
+{
+ TRACE_OBJ
+}
+
+qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen)
+{
+ TRACE_OBJ
+ qint64 len = qMin(qint64(data.length()), maxlen);
+ if (len) {
+ qMemCopy(buffer, data.constData(), len);
+ data.remove(0, len);
+ }
+ if (!data.length())
+ QTimer::singleShot(0, this, SIGNAL(finished()));
+ return len;
+}
+
+class HelpNetworkAccessManager : public QNetworkAccessManager
+{
+public:
+ HelpNetworkAccessManager(QObject *parent);
+
+protected:
+ virtual QNetworkReply *createRequest(Operation op,
+ const QNetworkRequest &request, QIODevice *outgoingData = 0);
+};
+
+HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent)
+ : QNetworkAccessManager(parent)
+{
+ TRACE_OBJ
+}
+
+QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
+ const QNetworkRequest &request, QIODevice* /*outgoingData*/)
+{
+ TRACE_OBJ
+ const QUrl& url = request.url();
+ QString mimeType = url.toString();
+ if (mimeType.endsWith(QLatin1String(".svg"))
+ || mimeType.endsWith(QLatin1String(".svgz"))) {
+ mimeType = QLatin1String("image/svg+xml");
+ } else if (mimeType.endsWith(QLatin1String(".css"))) {
+ mimeType = QLatin1String("text/css");
+ } else if (mimeType.endsWith(QLatin1String(".js"))) {
+ mimeType = QLatin1String("text/javascript");
+ } else if (mimeType.endsWith(QLatin1String(".txt"))) {
+ mimeType = QLatin1String("text/plain");
+ } else {
+ mimeType = QLatin1String("text/html");
+ }
+
+ HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
+ const QByteArray &data = helpEngine.findFile(url).isValid()
+ ? helpEngine.fileData(url)
+ : PageNotFoundMessage.arg(url.toString()).toUtf8();
+ return new HelpNetworkReply(request, data, mimeType);
+}
+
+class HelpPage : public QWebPage
+{
+public:
+ HelpPage(CentralWidget *central, QObject *parent);
+
+protected:
+ virtual QWebPage *createWindow(QWebPage::WebWindowType);
+ virtual void triggerAction(WebAction action, bool checked = false);
+
+ virtual bool acceptNavigationRequest(QWebFrame *frame,
+ const QNetworkRequest &request, NavigationType type);
+
+private:
+ CentralWidget *centralWidget;
+ bool closeNewTabIfNeeded;
+
+ friend class HelpViewer;
+ Qt::MouseButtons m_pressedButtons;
+ Qt::KeyboardModifiers m_keyboardModifiers;
+};
+
+HelpPage::HelpPage(CentralWidget *central, QObject *parent)
+ : QWebPage(parent)
+ , centralWidget(central)
+ , closeNewTabIfNeeded(false)
+ , m_pressedButtons(Qt::NoButton)
+ , m_keyboardModifiers(Qt::NoModifier)
+{
+ TRACE_OBJ
+}
+
+QWebPage *HelpPage::createWindow(QWebPage::WebWindowType)
+{
+ TRACE_OBJ
+ HelpPage* newPage = static_cast<HelpPage*>(centralWidget->newEmptyTab()->page());
+ if (newPage)
+ newPage->closeNewTabIfNeeded = closeNewTabIfNeeded;
+ closeNewTabIfNeeded = false;
+ return newPage;
+}
+
+void HelpPage::triggerAction(WebAction action, bool checked)
+{
+ TRACE_OBJ
+ switch (action) {
+ case OpenLinkInNewWindow:
+ closeNewTabIfNeeded = true;
+ default: // fall through
+ QWebPage::triggerAction(action, checked);
+ break;
+ }
+}
+
+bool HelpPage::acceptNavigationRequest(QWebFrame *,
+ const QNetworkRequest &request, QWebPage::NavigationType type)
+{
+ TRACE_OBJ
+ const QUrl &url = request.url();
+ const bool closeNewTab = closeNewTabIfNeeded;
+ closeNewTabIfNeeded = false;
+
+ if (HelpViewer::isLocalUrl(url)) {
+ const QString& path = url.path();
+ if (!HelpViewer::canOpenPage(path)) {
+ QTemporaryFile tmpTmpFile;
+ if (!tmpTmpFile.open())
+ return false;
+ const QString &extension = QFileInfo(path).completeSuffix();
+ QFile actualTmpFile(tmpTmpFile.fileName() % QLatin1String(".")
+ % extension);
+ if (actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
+ actualTmpFile.write(HelpEngineWrapper::instance().fileData(url));
+ actualTmpFile.close();
+ QDesktopServices::openUrl(QUrl(actualTmpFile.fileName()));
+ }
+
+ if (closeNewTab)
+ QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab");
+ return false;
+ }
+
+ if (type == QWebPage::NavigationTypeLinkClicked
+ && (m_keyboardModifiers & Qt::ControlModifier
+ || m_pressedButtons == Qt::MidButton)) {
+ HelpViewer* viewer = centralWidget->newEmptyTab();
+ if (viewer)
+ CentralWidget::instance()->setSource(url);
+ m_pressedButtons = Qt::NoButton;
+ m_keyboardModifiers = Qt::NoModifier;
+ return false;
+ }
+ return true;
+ }
+
+ QDesktopServices::openUrl(url);
+ return false;
+}
+
+HelpViewer::HelpViewer(CentralWidget *parent)
+ : QWebView(parent)
+ , parentWidget(parent)
+ , loadFinished(false)
+ , helpEngine(HelpEngineWrapper::instance())
+{
+ TRACE_OBJ
+ setAcceptDrops(false);
+
+ setPage(new HelpPage(parent, this));
+
+ page()->setNetworkAccessManager(new HelpNetworkAccessManager(this));
+
+ QAction* action = pageAction(QWebPage::OpenLinkInNewWindow);
+ action->setText(tr("Open Link in New Tab"));
+ if (!parent)
+ action->setVisible(false);
+
+ pageAction(QWebPage::DownloadLinkToDisk)->setVisible(false);
+ pageAction(QWebPage::DownloadImageToDisk)->setVisible(false);
+ pageAction(QWebPage::OpenImageInNewWindow)->setVisible(false);
+
+ connect(pageAction(QWebPage::Copy), SIGNAL(changed()), this,
+ SLOT(actionChanged()));
+ connect(pageAction(QWebPage::Back), SIGNAL(changed()), this,
+ SLOT(actionChanged()));
+ connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this,
+ SLOT(actionChanged()));
+ connect(page(), SIGNAL(linkHovered(QString,QString,QString)), this,
+ SIGNAL(highlighted(QString)));
+ connect(this, SIGNAL(urlChanged(QUrl)), this, SIGNAL(sourceChanged(QUrl)));
+ connect(this, SIGNAL(loadFinished(bool)), this, SLOT(setLoadFinished(bool)));
+}
+
+void HelpViewer::setSource(const QUrl &url)
+{
+ TRACE_OBJ
+ loadFinished = false;
+ if (url.toString() == QLatin1String("help")) {
+ load(QUrl(QLatin1String("qthelp://com.trolltech.com."
+ "assistantinternal-1.0.0/assistant/assistant.html")));
+ } else {
+ load(url);
+ }
+}
+
+void HelpViewer::resetZoom()
+{
+ TRACE_OBJ
+ setTextSizeMultiplier(1.0);
+}
+
+void HelpViewer::zoomIn(qreal range)
+{
+ TRACE_OBJ
+ setTextSizeMultiplier(textSizeMultiplier() + range / 10.0);
+}
+
+void HelpViewer::zoomOut(qreal range)
+{
+ TRACE_OBJ
+ setTextSizeMultiplier(qMax(0.0, textSizeMultiplier() - range / 10.0));
+}
+
+void HelpViewer::home()
+{
+ TRACE_OBJ
+ setSource(helpEngine.homePage());
+}
+
+void HelpViewer::wheelEvent(QWheelEvent *e)
+{
+ TRACE_OBJ
+ if (e->modifiers() & Qt::ControlModifier) {
+ const int delta = e->delta();
+ if (delta > 0)
+ zoomIn(delta / 120);
+ else if (delta < 0)
+ zoomOut(-delta / 120);
+ e->accept();
+ return;
+ }
+ QWebView::wheelEvent(e);
+}
+
+void HelpViewer::mouseReleaseEvent(QMouseEvent *e)
+{
+ TRACE_OBJ
+ if (e->button() == Qt::XButton1) {
+ triggerPageAction(QWebPage::Back);
+ return;
+ }
+
+ if (e->button() == Qt::XButton2) {
+ triggerPageAction(QWebPage::Forward);
+ return;
+ }
+
+ QWebView::mouseReleaseEvent(e);
+}
+
+void HelpViewer::actionChanged()
+{
+ TRACE_OBJ
+ QAction *a = qobject_cast<QAction *>(sender());
+ if (a == pageAction(QWebPage::Copy))
+ emit copyAvailable(a->isEnabled());
+ else if (a == pageAction(QWebPage::Back))
+ emit backwardAvailable(a->isEnabled());
+ else if (a == pageAction(QWebPage::Forward))
+ emit forwardAvailable(a->isEnabled());
+}
+
+void HelpViewer::mousePressEvent(QMouseEvent *event)
+{
+ TRACE_OBJ
+ HelpPage *currentPage = static_cast<HelpPage*>(page());
+ if (currentPage) {
+ currentPage->m_pressedButtons = event->buttons();
+ currentPage->m_keyboardModifiers = event->modifiers();
+ }
+ QWebView::mousePressEvent(event);
+}
+
+void HelpViewer::setLoadFinished(bool ok)
+{
+ TRACE_OBJ
+ loadFinished = ok;
+ emit sourceChanged(url());
+}
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/helpviewer_qwv.h b/tools/assistant/tools/assistant/helpviewer_qwv.h
new file mode 100644
index 0000000..a78bd57
--- /dev/null
+++ b/tools/assistant/tools/assistant/helpviewer_qwv.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Assistant of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef HELPVIEWERQWV_H
+#define HELPVIEWERQWV_H
+
+#if !defined(QT_NO_WEBKIT)
+
+#include <QtGui/QAction>
+#include <QtWebKit/QWebView>
+
+QT_BEGIN_NAMESPACE
+
+class CentralWidget;
+class HelpEngineWrapper;
+class QMouseEvent;
+
+class HelpViewer : public QWebView
+{
+ Q_OBJECT
+
+public:
+ HelpViewer(CentralWidget *parent);
+ void setSource(const QUrl &url);
+
+ inline QUrl source() const
+ { return url(); }
+
+ inline QString documentTitle() const
+ { return title(); }
+
+ inline bool hasSelection() const
+ { return !selectedText().isEmpty(); } // ### this is suboptimal
+
+ void resetZoom();
+ void zoomIn(qreal range = 1);
+ void zoomOut(qreal range = 1);
+
+ inline void copy()
+ { return triggerPageAction(QWebPage::Copy); }
+
+ inline bool isForwardAvailable() const
+ { return pageAction(QWebPage::Forward)->isEnabled(); }
+ inline bool isBackwardAvailable() const
+ { return pageAction(QWebPage::Back)->isEnabled(); }
+ inline bool hasLoadFinished() const
+ { return loadFinished; }
+ inline qreal zoom() const
+ { return textSizeMultiplier(); }
+
+ static bool canOpenPage(const QString &url);
+ static bool isLocalUrl(const QUrl &url);
+
+public Q_SLOTS:
+ void home();
+ void backward() { back(); }
+
+Q_SIGNALS:
+ void copyAvailable(bool enabled);
+ void forwardAvailable(bool enabled);
+ void backwardAvailable(bool enabled);
+ void highlighted(const QString &);
+ void sourceChanged(const QUrl &);
+
+protected:
+ virtual void wheelEvent(QWheelEvent *);
+ void mouseReleaseEvent(QMouseEvent *e);
+ void mousePressEvent(QMouseEvent *event);
+
+private Q_SLOTS:
+ void actionChanged();
+ void setLoadFinished(bool ok);
+
+private:
+ CentralWidget* parentWidget;
+ bool loadFinished;
+ HelpEngineWrapper &helpEngine;
+};
+
+#endif
+
+QT_END_NAMESPACE
+
+#endif // HELPVIEWERQWV_H
diff --git a/tools/assistant/tools/assistant/indexwindow.cpp b/tools/assistant/tools/assistant/indexwindow.cpp
index 82242e5..1879db7 100644
--- a/tools/assistant/tools/assistant/indexwindow.cpp
+++ b/tools/assistant/tools/assistant/indexwindow.cpp
@@ -44,6 +44,7 @@
#include "centralwidget.h"
#include "helpenginewrapper.h"
#include "helpviewer.h"
+#include "helpviewer_qwv.h"
#include "topicchooser.h"
#include <QtGui/QLayout>