#include "help_window.h"
#include <QtGui/QGridLayout>
#include <QtGui/QPushButton>
#include <QtHelp/QHelpEngineCore>
HelpBrowser::HelpBrowser(QWidget *parent) : QTextBrowser(parent)
{
QString collectionFile = QLatin1String("/tmp/test/simpletextviewer.qhc");
QString documentationFile = QLatin1String("/tmp/test/simpletextviewer.qch");
// QString collectionFile = QLatin1String(":/help/simpletextviewer.qhc");
// QString documentationFile = QLatin1String(":/help/simpletextviewer.qch");
helpEngine = new QHelpEngineCore(collectionFile);
helpEngine->setupData();
helpEngine->unregisterDocumentation(helpEngine->namespaceName(documentationFile));
helpEngine->registerDocumentation(documentationFile);
setSource(QString(QLatin1String("qthelp://com.trolltech.examples.simpletextviewer/doc/index.html")));
}
QVariant HelpBrowser::loadResource(int type, const QUrl &name)
{
QByteArray ba;
if (type < 4) {
ba = helpEngine->fileData(name);
if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {
QImage image;
image.loadFromData(ba, "svg");
if (!image.isNull())
return image;
}
}
return ba;
}
HelpWindow::HelpWindow(QWidget *parent)
:QWidget(parent)
{
m_ppbBackward = new QPushButton(QLatin1String("<<"), this);
m_ppbForward = new QPushButton(QLatin1String(">>"), this);
m_ppbHome = new QPushButton(tr("Home"), this);
m_ptxbHelp = new HelpBrowser(this);
QGridLayout *grid = new QGridLayout(this);
grid->addWidget(m_ppbBackward, 0,0);
grid->addWidget(m_ppbHome, 0,1);
grid->addWidget(m_ppbForward, 0,2);
grid->addWidget(m_ptxbHelp, 1,0, 1,3);
connect(m_ppbBackward, SIGNAL(clicked()), m_ptxbHelp, SLOT(backward()));
connect(m_ppbForward, SIGNAL(clicked()), m_ptxbHelp, SLOT(forward()));
connect(m_ppbHome, SIGNAL(clicked()), m_ptxbHelp, SLOT(home()));
connect(m_ptxbHelp, SIGNAL(backwardAvailable(bool)), m_ppbBackward, SLOT(setEnabled(bool)));
connect(m_ptxbHelp, SIGNAL(forwardAvailable(bool)), m_ppbForward, SLOT(setEnabled(bool)));
setWindowTitle(tr("Help Window"));
}