forked from qt-creator/qt-creator
Make use of the core engine, no need for gui stuff.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "helpmanager.h"
|
||||
#include "helpviewer.h"
|
||||
#include "topicchooser.h"
|
||||
|
||||
@@ -78,12 +79,10 @@ CentralWidget::CentralWidget(QHelpEngine *engine, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, findBar(0)
|
||||
, tabWidget(0)
|
||||
, helpEngine(engine)
|
||||
, printer(0)
|
||||
{
|
||||
lastTabPage = 0;
|
||||
globalActionList.clear();
|
||||
collectionFile = helpEngine->collectionFile();
|
||||
|
||||
tabWidget = new QTabWidget;
|
||||
tabWidget->setDocumentMode(true);
|
||||
@@ -126,11 +125,6 @@ CentralWidget::~CentralWidget()
|
||||
delete printer;
|
||||
#endif
|
||||
|
||||
|
||||
QHelpEngineCore engine(collectionFile, 0);
|
||||
if (!engine.setupData())
|
||||
return;
|
||||
|
||||
QString zoomCount;
|
||||
QString currentPages;
|
||||
for (int i = 0; i < tabWidget->count(); ++i) {
|
||||
@@ -140,9 +134,11 @@ CentralWidget::~CentralWidget()
|
||||
zoomCount += QString::number(viewer->zoom()) + QLatin1Char('|');
|
||||
}
|
||||
}
|
||||
engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
|
||||
engine.setCustomValue(QLatin1String("LastShownPages"), currentPages);
|
||||
engine.setCustomValue(QLatin1String("LastShownPagesZoom"), zoomCount);
|
||||
|
||||
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
|
||||
engine->setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
|
||||
engine->setCustomValue(QLatin1String("LastShownPages"), currentPages);
|
||||
engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomCount);
|
||||
}
|
||||
|
||||
CentralWidget *CentralWidget::instance()
|
||||
@@ -222,7 +218,7 @@ void CentralWidget::setSource(const QUrl &url)
|
||||
qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage));
|
||||
|
||||
if (!viewer && !lastViewer) {
|
||||
viewer = new HelpViewer(helpEngine, this, this);
|
||||
viewer = new HelpViewer(this, this);
|
||||
viewer->installEventFilter(this);
|
||||
lastTabPage = tabWidget->addTab(viewer, QString());
|
||||
tabWidget->setCurrentIndex(lastTabPage);
|
||||
@@ -241,19 +237,20 @@ void CentralWidget::setSource(const QUrl &url)
|
||||
|
||||
void CentralWidget::setLastShownPages()
|
||||
{
|
||||
QString value = helpEngine->customValue(QLatin1String("LastShownPages"),
|
||||
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
|
||||
QString value = engine.customValue(QLatin1String("LastShownPages"),
|
||||
QString()).toString();
|
||||
const QStringList lastShownPageList = value.split(QLatin1Char('|'),
|
||||
QString::SkipEmptyParts);
|
||||
const int pageCount = lastShownPageList.count();
|
||||
|
||||
QString homePage = helpEngine->customValue(QLatin1String("DefaultHomePage"),
|
||||
QString homePage = engine.customValue(QLatin1String("DefaultHomePage"),
|
||||
QLatin1String("about:blank")).toString();
|
||||
|
||||
int option = helpEngine->customValue(QLatin1String("StartOption"), 2).toInt();
|
||||
int option = engine.customValue(QLatin1String("StartOption"), 2).toInt();
|
||||
if (option == 0 || option == 1 || pageCount <= 0) {
|
||||
if (option == 0) {
|
||||
homePage = helpEngine->customValue(QLatin1String("HomePage"),
|
||||
homePage = engine.customValue(QLatin1String("HomePage"),
|
||||
homePage).toString();
|
||||
} else if (option == 1) {
|
||||
homePage = QLatin1String("about:blank");
|
||||
@@ -262,7 +259,7 @@ void CentralWidget::setLastShownPages()
|
||||
return;
|
||||
}
|
||||
|
||||
value = helpEngine->customValue(QLatin1String("LastShownPagesZoom"),
|
||||
value = engine.customValue(QLatin1String("LastShownPagesZoom"),
|
||||
QString()).toString();
|
||||
QVector<QString> zoomVector = value.split(QLatin1Char('|'),
|
||||
QString::SkipEmptyParts).toVector();
|
||||
@@ -275,7 +272,7 @@ void CentralWidget::setLastShownPages()
|
||||
for (; it != lastShownPageList.constEnd(); ++it, ++zIt)
|
||||
setSourceInNewTab((*it), (*zIt).toInt());
|
||||
|
||||
int tab = helpEngine->customValue(QLatin1String("LastTabPage"), 0).toInt();
|
||||
int tab = engine.customValue(QLatin1String("LastTabPage"), 0).toInt();
|
||||
tabWidget->setCurrentIndex(tab);
|
||||
}
|
||||
|
||||
@@ -430,7 +427,7 @@ void CentralWidget::setGlobalActions(const QList<QAction*> &actions)
|
||||
|
||||
void CentralWidget::setSourceInNewTab(const QUrl &url, int zoom)
|
||||
{
|
||||
HelpViewer* viewer = new HelpViewer(helpEngine, this, this);
|
||||
HelpViewer* viewer = new HelpViewer(this, this);
|
||||
viewer->installEventFilter(this);
|
||||
viewer->setZoom(zoom);
|
||||
viewer->setSource(url);
|
||||
@@ -450,7 +447,7 @@ void CentralWidget::setSourceInNewTab(const QUrl &url, int zoom)
|
||||
|
||||
HelpViewer *CentralWidget::newEmptyTab()
|
||||
{
|
||||
HelpViewer* viewer = new HelpViewer(helpEngine, this, this);
|
||||
HelpViewer* viewer = new HelpViewer(this, this);
|
||||
viewer->installEventFilter(this);
|
||||
viewer->setFocus(Qt::OtherFocusReason);
|
||||
#if defined(QT_NO_WEBKIT)
|
||||
|
||||
@@ -134,12 +134,10 @@ private:
|
||||
|
||||
private:
|
||||
int lastTabPage;
|
||||
QString collectionFile;
|
||||
QList<QAction*> globalActionList;
|
||||
|
||||
QWidget *findBar;
|
||||
QTabWidget* tabWidget;
|
||||
QHelpEngine *helpEngine;
|
||||
QPrinter *printer;
|
||||
};
|
||||
|
||||
|
||||
@@ -536,7 +536,7 @@ void HelpPlugin::createRightPaneContextViewer()
|
||||
rightPaneStyledBar->setLayout(hboxLayout);
|
||||
rightPaneLayout->addWidget(rightPaneStyledBar);
|
||||
|
||||
m_helpViewerForSideBar = new HelpViewer(m_helpEngine, 0, rightPaneSideBar);
|
||||
m_helpViewerForSideBar = new HelpViewer(0, rightPaneSideBar);
|
||||
rightPaneLayout->addWidget(m_helpViewerForSideBar);
|
||||
rightPaneLayout->addWidget(new Core::FindToolBarPlaceHolder(rightPaneSideBar));
|
||||
rightPaneSideBar->setFocusProxy(m_helpViewerForSideBar);
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "helpviewer.h"
|
||||
|
||||
#include "centralwidget.h"
|
||||
#include "helpmanager.h"
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QEvent>
|
||||
@@ -43,7 +45,7 @@
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QDesktopServices>
|
||||
|
||||
#include <QtHelp/QHelpEngine>
|
||||
#include <QtHelp/QHelpEngineCore>
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
@@ -104,19 +106,15 @@ qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen)
|
||||
class HelpNetworkAccessManager : public QNetworkAccessManager
|
||||
{
|
||||
public:
|
||||
HelpNetworkAccessManager(QHelpEngine *engine, QObject *parent);
|
||||
HelpNetworkAccessManager(QObject *parent);
|
||||
|
||||
protected:
|
||||
virtual QNetworkReply *createRequest(Operation op,
|
||||
const QNetworkRequest &request, QIODevice *outgoingData = 0);
|
||||
|
||||
private:
|
||||
QHelpEngine *helpEngine;
|
||||
};
|
||||
|
||||
HelpNetworkAccessManager::HelpNetworkAccessManager(QHelpEngine *engine,
|
||||
QObject *parent)
|
||||
: QNetworkAccessManager(parent), helpEngine(engine)
|
||||
HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent)
|
||||
: QNetworkAccessManager(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -138,8 +136,9 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
|
||||
mimeType = QLatin1String("text/html");
|
||||
}
|
||||
|
||||
const QByteArray &data = helpEngine->findFile(url).isValid()
|
||||
? helpEngine->fileData(url) : QByteArray("The page could not be found");
|
||||
const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore();
|
||||
const QByteArray &data = engine.findFile(url).isValid()
|
||||
? engine.fileData(url) : QByteArray("The page could not be found");
|
||||
return new HelpNetworkReply(request, data, mimeType);
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ class HelpPage : public QWebPage
|
||||
{
|
||||
friend class HelpViewer;
|
||||
public:
|
||||
HelpPage(Help::Internal::CentralWidget *central, QHelpEngine *engine, QObject *parent);
|
||||
HelpPage(Help::Internal::CentralWidget *central, QObject *parent);
|
||||
|
||||
protected:
|
||||
virtual QWebPage *createWindow(QWebPage::WebWindowType);
|
||||
@@ -157,15 +156,13 @@ protected:
|
||||
|
||||
private:
|
||||
Help::Internal::CentralWidget *centralWidget;
|
||||
QHelpEngine *helpEngine;
|
||||
Qt::MouseButtons m_pressedButtons;
|
||||
Qt::KeyboardModifiers m_keyboardModifiers;
|
||||
};
|
||||
|
||||
HelpPage::HelpPage(Help::Internal::CentralWidget *central, QHelpEngine *engine, QObject *parent)
|
||||
HelpPage::HelpPage(Help::Internal::CentralWidget *central, QObject *parent)
|
||||
: QWebPage(parent)
|
||||
, centralWidget(central)
|
||||
, helpEngine(engine)
|
||||
, m_pressedButtons(Qt::NoButton)
|
||||
, m_keyboardModifiers(Qt::NoModifier)
|
||||
{
|
||||
@@ -205,7 +202,7 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
|
||||
|
||||
QFile tmpFile(QDir::cleanPath(fileName));
|
||||
if (tmpFile.open(QIODevice::ReadWrite)) {
|
||||
tmpFile.write(helpEngine->fileData(url));
|
||||
tmpFile.write(Help::HelpManager::helpEngineCore().fileData(url));
|
||||
tmpFile.close();
|
||||
}
|
||||
QDesktopServices::openUrl(QUrl(tmpFile.fileName()));
|
||||
@@ -229,14 +226,13 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
|
||||
return false;
|
||||
}
|
||||
|
||||
HelpViewer::HelpViewer(QHelpEngine *engine, Help::Internal::CentralWidget *central, QWidget *parent)
|
||||
HelpViewer::HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent)
|
||||
: QWebView(parent)
|
||||
, helpEngine(engine)
|
||||
, parentWidget(central)
|
||||
, multiTabsAllowed(true)
|
||||
, loadFinished(false)
|
||||
{
|
||||
setPage(new HelpPage(central, helpEngine, this));
|
||||
setPage(new HelpPage(central, this));
|
||||
settings()->setAttribute(QWebSettings::PluginsEnabled, false);
|
||||
settings()->setAttribute(QWebSettings::JavaEnabled, false);
|
||||
|
||||
@@ -297,11 +293,12 @@ int HelpViewer::zoom() const
|
||||
|
||||
void HelpViewer::home()
|
||||
{
|
||||
QString homepage = helpEngine->customValue(QLatin1String("HomePage"),
|
||||
const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore();
|
||||
QString homepage = engine.customValue(QLatin1String("HomePage"),
|
||||
QLatin1String("")).toString();
|
||||
|
||||
if (homepage.isEmpty()) {
|
||||
homepage = helpEngine->customValue(QLatin1String("DefaultHomePage"),
|
||||
homepage = engine.customValue(QLatin1String("DefaultHomePage"),
|
||||
QLatin1String("about:blank")).toString();
|
||||
}
|
||||
|
||||
@@ -392,12 +389,11 @@ void HelpViewer::setLoadFinished(bool ok)
|
||||
|
||||
#else // !defined(QT_NO_WEBKIT)
|
||||
|
||||
HelpViewer::HelpViewer(QHelpEngine *engine, Help::Internal::CentralWidget *central, QWidget *parent)
|
||||
HelpViewer::HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent)
|
||||
: QTextBrowser(parent)
|
||||
, zoomCount(0)
|
||||
, controlPressed(false)
|
||||
, lastAnchor(QString())
|
||||
, helpEngine(engine)
|
||||
, parentWidget(central)
|
||||
{
|
||||
document()->setDocumentMargin(8);
|
||||
@@ -410,7 +406,7 @@ void HelpViewer::setSource(const QUrl &url)
|
||||
if (launchedWithExternalApp(url))
|
||||
return;
|
||||
|
||||
QUrl u = helpEngine->findFile(url);
|
||||
QUrl u = Help::HelpManager::helpEngineCore().findFile(url);
|
||||
if (u.isValid()) {
|
||||
if (!homeUrl.isValid())
|
||||
homeUrl = url;
|
||||
@@ -472,7 +468,7 @@ bool HelpViewer::launchedWithExternalApp(const QUrl &url)
|
||||
|
||||
QFile tmpFile(QDir::cleanPath(fileName));
|
||||
if (tmpFile.open(QIODevice::ReadWrite)) {
|
||||
tmpFile.write(helpEngine->fileData(url));
|
||||
tmpFile.write(Help::HelpManager::helpEngineCore().fileData(url));
|
||||
tmpFile.close();
|
||||
}
|
||||
launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName()));
|
||||
@@ -493,7 +489,7 @@ QVariant HelpViewer::loadResource(int type, const QUrl &name)
|
||||
{
|
||||
QByteArray ba;
|
||||
if (type < 4) {
|
||||
ba = helpEngine->fileData(name);
|
||||
ba = Help::HelpManager::helpEngineCore().fileData(name);
|
||||
if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {
|
||||
QImage image;
|
||||
image.loadFromData(ba, "svg");
|
||||
@@ -578,6 +574,7 @@ void HelpViewer::mousePressEvent(QMouseEvent *e)
|
||||
if (handleForwardBackwardMouseButtons(e))
|
||||
return;
|
||||
#endif
|
||||
QTextBrowser::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void HelpViewer::mouseReleaseEvent(QMouseEvent *e)
|
||||
@@ -610,11 +607,12 @@ void HelpViewer::keyPressEvent(QKeyEvent *e)
|
||||
|
||||
void HelpViewer::home()
|
||||
{
|
||||
QString homepage = helpEngine->customValue(QLatin1String("HomePage"),
|
||||
const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore();
|
||||
QString homepage = engine.customValue(QLatin1String("HomePage"),
|
||||
QLatin1String("")).toString();
|
||||
|
||||
if (homepage.isEmpty()) {
|
||||
homepage = helpEngine->customValue(QLatin1String("DefaultHomePage"),
|
||||
homepage = engine.customValue(QLatin1String("DefaultHomePage"),
|
||||
QLatin1String("about:blank")).toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QHelpEngine;
|
||||
|
||||
class QPoint;
|
||||
class QString;
|
||||
@@ -64,7 +63,7 @@ class HelpViewer : public QWebView
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HelpViewer(QHelpEngine *helpEngine, Help::Internal::CentralWidget *central, QWidget *parent);
|
||||
HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent);
|
||||
void setSource(const QUrl &url);
|
||||
|
||||
inline QUrl source() const
|
||||
@@ -132,7 +131,7 @@ class HelpViewer : public QTextBrowser
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HelpViewer(QHelpEngine *helpEngine, Help::Internal::CentralWidget *central, QWidget *parent);
|
||||
HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent);
|
||||
void setSource(const QUrl &url);
|
||||
|
||||
void zoomIn(int range = 1);
|
||||
@@ -171,7 +170,6 @@ private:
|
||||
int zoomCount;
|
||||
bool controlPressed;
|
||||
QString lastAnchor;
|
||||
QHelpEngine *helpEngine;
|
||||
Help::Internal::CentralWidget* parentWidget;
|
||||
QUrl homeUrl;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user