1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/* vi: set sw=4 ts=4:
*
* Copyright (C) 2001 - 2012 Christian Hohnstaedt.
*
* All rights reserved.
*/
#include "Help.h"
#include "lib/func.h"
#include <QDebug>
#include <QDialog>
#include <QHelpEngine>
#include <QDialogButtonBox>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
#include <QHelpLink>
#endif
Help::Help() : QWidget(NULL)
{
setupUi(this);
setWindowTitle(XCA_TITLE);
textbox->setSearchPaths(QStringList(getDocDir()));
textbox->setOpenExternalLinks(true);
textbox->clearHistory();
if (!getDocDir().isEmpty())
helpengine = new QHelpEngineCore(getDocDir() + "/xca.qhc");
}
Help::~Help()
{
delete helpengine;
}
void Help::display(const QUrl &url)
{
textbox->setSource(QUrl(url.fileName()));
textbox->scrollToAnchor(url.fragment());
show();
raise();
}
void Help::content()
{
display(QUrl("qthelp://org.sphinx.xca/doc/index.html"));
}
QList<QUrl> Help::url_by_ctx(const QString &ctx) const
{
if (!helpengine)
return QList<QUrl>();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
QList<QUrl> l;
foreach(QHelpLink hl,
helpengine->documentsForIdentifier(QString("%1.%1").arg(ctx)))
{
l << hl.url;
}
return l;
#else
return helpengine->linksForIdentifier(QString("%1.%1").arg(ctx)).values();
#endif
}
void Help::contexthelp(const QString &context)
{
QList<QUrl> helpctx = url_by_ctx(context);
if (helpctx.count())
display(helpctx.at(0));
}
void Help::contexthelp()
{
QObject *o = sender();
if (!o)
return;
QString ctx = o->property("help_ctx").toString();
if (ctx.isEmpty())
return;
contexthelp(ctx);
}
void Help::register_ctxhelp_button(QDialog *dlg, const QString &help_ctx) const
{
QDialogButtonBox *buttonBox =
dlg->findChild<QDialogButtonBox*>("buttonBox");
if (!buttonBox || help_ctx.isEmpty())
return;
dlg->setWindowModality(Qt::WindowModal);
buttonBox->addButton(QDialogButtonBox::Help);
buttonBox->setProperty("help_ctx", QVariant(help_ctx));
connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(contexthelp()));
if (url_by_ctx(help_ctx).count() == 0) {
qWarning() << "Unknown help context: " << help_ctx;
buttonBox->button(QDialogButtonBox::Help)->setEnabled(false);
}
}
void Help::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi(this);
}
|