Make use of the core engine, no need for gui stuff.

This commit is contained in:
kh1
2010-03-23 16:56:59 +01:00
parent 63f31dcb66
commit fa32d9a9d0
5 changed files with 44 additions and 53 deletions

View File

@@ -28,6 +28,7 @@
**************************************************************************/ **************************************************************************/
#include "centralwidget.h" #include "centralwidget.h"
#include "helpmanager.h"
#include "helpviewer.h" #include "helpviewer.h"
#include "topicchooser.h" #include "topicchooser.h"
@@ -78,12 +79,10 @@ CentralWidget::CentralWidget(QHelpEngine *engine, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, findBar(0) , findBar(0)
, tabWidget(0) , tabWidget(0)
, helpEngine(engine)
, printer(0) , printer(0)
{ {
lastTabPage = 0; lastTabPage = 0;
globalActionList.clear(); globalActionList.clear();
collectionFile = helpEngine->collectionFile();
tabWidget = new QTabWidget; tabWidget = new QTabWidget;
tabWidget->setDocumentMode(true); tabWidget->setDocumentMode(true);
@@ -126,11 +125,6 @@ CentralWidget::~CentralWidget()
delete printer; delete printer;
#endif #endif
QHelpEngineCore engine(collectionFile, 0);
if (!engine.setupData())
return;
QString zoomCount; QString zoomCount;
QString currentPages; QString currentPages;
for (int i = 0; i < tabWidget->count(); ++i) { for (int i = 0; i < tabWidget->count(); ++i) {
@@ -140,9 +134,11 @@ CentralWidget::~CentralWidget()
zoomCount += QString::number(viewer->zoom()) + QLatin1Char('|'); zoomCount += QString::number(viewer->zoom()) + QLatin1Char('|');
} }
} }
engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
engine.setCustomValue(QLatin1String("LastShownPages"), currentPages); QHelpEngineCore *engine = &HelpManager::helpEngineCore();
engine.setCustomValue(QLatin1String("LastShownPagesZoom"), zoomCount); engine->setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
engine->setCustomValue(QLatin1String("LastShownPages"), currentPages);
engine->setCustomValue(QLatin1String("LastShownPagesZoom"), zoomCount);
} }
CentralWidget *CentralWidget::instance() CentralWidget *CentralWidget::instance()
@@ -222,7 +218,7 @@ void CentralWidget::setSource(const QUrl &url)
qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage)); qobject_cast<HelpViewer*>(tabWidget->widget(lastTabPage));
if (!viewer && !lastViewer) { if (!viewer && !lastViewer) {
viewer = new HelpViewer(helpEngine, this, this); viewer = new HelpViewer(this, this);
viewer->installEventFilter(this); viewer->installEventFilter(this);
lastTabPage = tabWidget->addTab(viewer, QString()); lastTabPage = tabWidget->addTab(viewer, QString());
tabWidget->setCurrentIndex(lastTabPage); tabWidget->setCurrentIndex(lastTabPage);
@@ -241,19 +237,20 @@ void CentralWidget::setSource(const QUrl &url)
void CentralWidget::setLastShownPages() void CentralWidget::setLastShownPages()
{ {
QString value = helpEngine->customValue(QLatin1String("LastShownPages"), const QHelpEngineCore &engine = HelpManager::helpEngineCore();
QString value = engine.customValue(QLatin1String("LastShownPages"),
QString()).toString(); QString()).toString();
const QStringList lastShownPageList = value.split(QLatin1Char('|'), const QStringList lastShownPageList = value.split(QLatin1Char('|'),
QString::SkipEmptyParts); QString::SkipEmptyParts);
const int pageCount = lastShownPageList.count(); const int pageCount = lastShownPageList.count();
QString homePage = helpEngine->customValue(QLatin1String("DefaultHomePage"), QString homePage = engine.customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString(); 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 || option == 1 || pageCount <= 0) {
if (option == 0) { if (option == 0) {
homePage = helpEngine->customValue(QLatin1String("HomePage"), homePage = engine.customValue(QLatin1String("HomePage"),
homePage).toString(); homePage).toString();
} else if (option == 1) { } else if (option == 1) {
homePage = QLatin1String("about:blank"); homePage = QLatin1String("about:blank");
@@ -262,7 +259,7 @@ void CentralWidget::setLastShownPages()
return; return;
} }
value = helpEngine->customValue(QLatin1String("LastShownPagesZoom"), value = engine.customValue(QLatin1String("LastShownPagesZoom"),
QString()).toString(); QString()).toString();
QVector<QString> zoomVector = value.split(QLatin1Char('|'), QVector<QString> zoomVector = value.split(QLatin1Char('|'),
QString::SkipEmptyParts).toVector(); QString::SkipEmptyParts).toVector();
@@ -275,7 +272,7 @@ void CentralWidget::setLastShownPages()
for (; it != lastShownPageList.constEnd(); ++it, ++zIt) for (; it != lastShownPageList.constEnd(); ++it, ++zIt)
setSourceInNewTab((*it), (*zIt).toInt()); setSourceInNewTab((*it), (*zIt).toInt());
int tab = helpEngine->customValue(QLatin1String("LastTabPage"), 0).toInt(); int tab = engine.customValue(QLatin1String("LastTabPage"), 0).toInt();
tabWidget->setCurrentIndex(tab); tabWidget->setCurrentIndex(tab);
} }
@@ -430,7 +427,7 @@ void CentralWidget::setGlobalActions(const QList<QAction*> &actions)
void CentralWidget::setSourceInNewTab(const QUrl &url, int zoom) 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->installEventFilter(this);
viewer->setZoom(zoom); viewer->setZoom(zoom);
viewer->setSource(url); viewer->setSource(url);
@@ -450,7 +447,7 @@ void CentralWidget::setSourceInNewTab(const QUrl &url, int zoom)
HelpViewer *CentralWidget::newEmptyTab() HelpViewer *CentralWidget::newEmptyTab()
{ {
HelpViewer* viewer = new HelpViewer(helpEngine, this, this); HelpViewer* viewer = new HelpViewer(this, this);
viewer->installEventFilter(this); viewer->installEventFilter(this);
viewer->setFocus(Qt::OtherFocusReason); viewer->setFocus(Qt::OtherFocusReason);
#if defined(QT_NO_WEBKIT) #if defined(QT_NO_WEBKIT)

View File

@@ -134,12 +134,10 @@ private:
private: private:
int lastTabPage; int lastTabPage;
QString collectionFile;
QList<QAction*> globalActionList; QList<QAction*> globalActionList;
QWidget *findBar; QWidget *findBar;
QTabWidget* tabWidget; QTabWidget* tabWidget;
QHelpEngine *helpEngine;
QPrinter *printer; QPrinter *printer;
}; };

View File

@@ -536,7 +536,7 @@ void HelpPlugin::createRightPaneContextViewer()
rightPaneStyledBar->setLayout(hboxLayout); rightPaneStyledBar->setLayout(hboxLayout);
rightPaneLayout->addWidget(rightPaneStyledBar); rightPaneLayout->addWidget(rightPaneStyledBar);
m_helpViewerForSideBar = new HelpViewer(m_helpEngine, 0, rightPaneSideBar); m_helpViewerForSideBar = new HelpViewer(0, rightPaneSideBar);
rightPaneLayout->addWidget(m_helpViewerForSideBar); rightPaneLayout->addWidget(m_helpViewerForSideBar);
rightPaneLayout->addWidget(new Core::FindToolBarPlaceHolder(rightPaneSideBar)); rightPaneLayout->addWidget(new Core::FindToolBarPlaceHolder(rightPaneSideBar));
rightPaneSideBar->setFocusProxy(m_helpViewerForSideBar); rightPaneSideBar->setFocusProxy(m_helpViewerForSideBar);

View File

@@ -28,7 +28,9 @@
**************************************************************************/ **************************************************************************/
#include "helpviewer.h" #include "helpviewer.h"
#include "centralwidget.h" #include "centralwidget.h"
#include "helpmanager.h"
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QEvent> #include <QtCore/QEvent>
@@ -43,7 +45,7 @@
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtGui/QDesktopServices> #include <QtGui/QDesktopServices>
#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpEngineCore>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
@@ -104,19 +106,15 @@ qint64 HelpNetworkReply::readData(char *buffer, qint64 maxlen)
class HelpNetworkAccessManager : public QNetworkAccessManager class HelpNetworkAccessManager : public QNetworkAccessManager
{ {
public: public:
HelpNetworkAccessManager(QHelpEngine *engine, QObject *parent); HelpNetworkAccessManager(QObject *parent);
protected: protected:
virtual QNetworkReply *createRequest(Operation op, virtual QNetworkReply *createRequest(Operation op,
const QNetworkRequest &request, QIODevice *outgoingData = 0); const QNetworkRequest &request, QIODevice *outgoingData = 0);
private:
QHelpEngine *helpEngine;
}; };
HelpNetworkAccessManager::HelpNetworkAccessManager(QHelpEngine *engine, HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent)
QObject *parent) : QNetworkAccessManager(parent)
: QNetworkAccessManager(parent), helpEngine(engine)
{ {
} }
@@ -138,8 +136,9 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/,
mimeType = QLatin1String("text/html"); mimeType = QLatin1String("text/html");
} }
const QByteArray &data = helpEngine->findFile(url).isValid() const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore();
? helpEngine->fileData(url) : QByteArray("The page could not be found"); const QByteArray &data = engine.findFile(url).isValid()
? engine.fileData(url) : QByteArray("The page could not be found");
return new HelpNetworkReply(request, data, mimeType); return new HelpNetworkReply(request, data, mimeType);
} }
@@ -147,7 +146,7 @@ class HelpPage : public QWebPage
{ {
friend class HelpViewer; friend class HelpViewer;
public: public:
HelpPage(Help::Internal::CentralWidget *central, QHelpEngine *engine, QObject *parent); HelpPage(Help::Internal::CentralWidget *central, QObject *parent);
protected: protected:
virtual QWebPage *createWindow(QWebPage::WebWindowType); virtual QWebPage *createWindow(QWebPage::WebWindowType);
@@ -157,15 +156,13 @@ protected:
private: private:
Help::Internal::CentralWidget *centralWidget; Help::Internal::CentralWidget *centralWidget;
QHelpEngine *helpEngine;
Qt::MouseButtons m_pressedButtons; Qt::MouseButtons m_pressedButtons;
Qt::KeyboardModifiers m_keyboardModifiers; Qt::KeyboardModifiers m_keyboardModifiers;
}; };
HelpPage::HelpPage(Help::Internal::CentralWidget *central, QHelpEngine *engine, QObject *parent) HelpPage::HelpPage(Help::Internal::CentralWidget *central, QObject *parent)
: QWebPage(parent) : QWebPage(parent)
, centralWidget(central) , centralWidget(central)
, helpEngine(engine)
, m_pressedButtons(Qt::NoButton) , m_pressedButtons(Qt::NoButton)
, m_keyboardModifiers(Qt::NoModifier) , m_keyboardModifiers(Qt::NoModifier)
{ {
@@ -205,7 +202,7 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
QFile tmpFile(QDir::cleanPath(fileName)); QFile tmpFile(QDir::cleanPath(fileName));
if (tmpFile.open(QIODevice::ReadWrite)) { if (tmpFile.open(QIODevice::ReadWrite)) {
tmpFile.write(helpEngine->fileData(url)); tmpFile.write(Help::HelpManager::helpEngineCore().fileData(url));
tmpFile.close(); tmpFile.close();
} }
QDesktopServices::openUrl(QUrl(tmpFile.fileName())); QDesktopServices::openUrl(QUrl(tmpFile.fileName()));
@@ -229,14 +226,13 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
return false; return false;
} }
HelpViewer::HelpViewer(QHelpEngine *engine, Help::Internal::CentralWidget *central, QWidget *parent) HelpViewer::HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent)
: QWebView(parent) : QWebView(parent)
, helpEngine(engine)
, parentWidget(central) , parentWidget(central)
, multiTabsAllowed(true) , multiTabsAllowed(true)
, loadFinished(false) , loadFinished(false)
{ {
setPage(new HelpPage(central, helpEngine, this)); setPage(new HelpPage(central, this));
settings()->setAttribute(QWebSettings::PluginsEnabled, false); settings()->setAttribute(QWebSettings::PluginsEnabled, false);
settings()->setAttribute(QWebSettings::JavaEnabled, false); settings()->setAttribute(QWebSettings::JavaEnabled, false);
@@ -297,11 +293,12 @@ int HelpViewer::zoom() const
void HelpViewer::home() void HelpViewer::home()
{ {
QString homepage = helpEngine->customValue(QLatin1String("HomePage"), const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore();
QString homepage = engine.customValue(QLatin1String("HomePage"),
QLatin1String("")).toString(); QLatin1String("")).toString();
if (homepage.isEmpty()) { if (homepage.isEmpty()) {
homepage = helpEngine->customValue(QLatin1String("DefaultHomePage"), homepage = engine.customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString(); QLatin1String("about:blank")).toString();
} }
@@ -392,12 +389,11 @@ void HelpViewer::setLoadFinished(bool ok)
#else // !defined(QT_NO_WEBKIT) #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) : QTextBrowser(parent)
, zoomCount(0) , zoomCount(0)
, controlPressed(false) , controlPressed(false)
, lastAnchor(QString()) , lastAnchor(QString())
, helpEngine(engine)
, parentWidget(central) , parentWidget(central)
{ {
document()->setDocumentMargin(8); document()->setDocumentMargin(8);
@@ -410,7 +406,7 @@ void HelpViewer::setSource(const QUrl &url)
if (launchedWithExternalApp(url)) if (launchedWithExternalApp(url))
return; return;
QUrl u = helpEngine->findFile(url); QUrl u = Help::HelpManager::helpEngineCore().findFile(url);
if (u.isValid()) { if (u.isValid()) {
if (!homeUrl.isValid()) if (!homeUrl.isValid())
homeUrl = url; homeUrl = url;
@@ -472,7 +468,7 @@ bool HelpViewer::launchedWithExternalApp(const QUrl &url)
QFile tmpFile(QDir::cleanPath(fileName)); QFile tmpFile(QDir::cleanPath(fileName));
if (tmpFile.open(QIODevice::ReadWrite)) { if (tmpFile.open(QIODevice::ReadWrite)) {
tmpFile.write(helpEngine->fileData(url)); tmpFile.write(Help::HelpManager::helpEngineCore().fileData(url));
tmpFile.close(); tmpFile.close();
} }
launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName())); launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName()));
@@ -493,7 +489,7 @@ QVariant HelpViewer::loadResource(int type, const QUrl &name)
{ {
QByteArray ba; QByteArray ba;
if (type < 4) { if (type < 4) {
ba = helpEngine->fileData(name); ba = Help::HelpManager::helpEngineCore().fileData(name);
if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) { if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {
QImage image; QImage image;
image.loadFromData(ba, "svg"); image.loadFromData(ba, "svg");
@@ -578,6 +574,7 @@ void HelpViewer::mousePressEvent(QMouseEvent *e)
if (handleForwardBackwardMouseButtons(e)) if (handleForwardBackwardMouseButtons(e))
return; return;
#endif #endif
QTextBrowser::mousePressEvent(e);
} }
void HelpViewer::mouseReleaseEvent(QMouseEvent *e) void HelpViewer::mouseReleaseEvent(QMouseEvent *e)
@@ -610,11 +607,12 @@ void HelpViewer::keyPressEvent(QKeyEvent *e)
void HelpViewer::home() void HelpViewer::home()
{ {
QString homepage = helpEngine->customValue(QLatin1String("HomePage"), const QHelpEngineCore &engine = Help::HelpManager::helpEngineCore();
QString homepage = engine.customValue(QLatin1String("HomePage"),
QLatin1String("")).toString(); QLatin1String("")).toString();
if (homepage.isEmpty()) { if (homepage.isEmpty()) {
homepage = helpEngine->customValue(QLatin1String("DefaultHomePage"), homepage = engine.customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString(); QLatin1String("about:blank")).toString();
} }

View File

@@ -41,7 +41,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QHelpEngine;
class QPoint; class QPoint;
class QString; class QString;
@@ -64,7 +63,7 @@ class HelpViewer : public QWebView
Q_OBJECT Q_OBJECT
public: public:
HelpViewer(QHelpEngine *helpEngine, Help::Internal::CentralWidget *central, QWidget *parent); HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent);
void setSource(const QUrl &url); void setSource(const QUrl &url);
inline QUrl source() const inline QUrl source() const
@@ -132,7 +131,7 @@ class HelpViewer : public QTextBrowser
Q_OBJECT Q_OBJECT
public: public:
HelpViewer(QHelpEngine *helpEngine, Help::Internal::CentralWidget *central, QWidget *parent); HelpViewer(Help::Internal::CentralWidget *central, QWidget *parent);
void setSource(const QUrl &url); void setSource(const QUrl &url);
void zoomIn(int range = 1); void zoomIn(int range = 1);
@@ -171,7 +170,6 @@ private:
int zoomCount; int zoomCount;
bool controlPressed; bool controlPressed;
QString lastAnchor; QString lastAnchor;
QHelpEngine *helpEngine;
Help::Internal::CentralWidget* parentWidget; Help::Internal::CentralWidget* parentWidget;
QUrl homeUrl; QUrl homeUrl;
}; };