14 #include <QHelpEngine> 19 #include <QApplication> 33 QDir().mkpath(
profile()->getPath());
34 QString helpFile =
profile()->getPath() +
"/cx_user_doc.qhc";
35 helpEngine =
new QHelpEngine(helpFile, NULL);
37 this->setupDataWithWarning();
39 this->setupDataWithWarning();
41 connect(qApp, SIGNAL(focusObjectChanged(QObject*)),
this, SLOT(focusObjectChanged(QObject*)));
42 connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
this, SLOT(focusChanged(QWidget*, QWidget*)));
44 QTimer::singleShot(100,
this, SLOT(setInitialPage()));
52 void HelpEngine::setupDocFile()
55 if(!QFile(docFile).exists())
56 reportWarning(QString(
"HelpEngine: Cannot find docFile: %1").arg(docFile));
57 helpEngine->unregisterDocumentation(helpEngine->namespaceName(docFile));
58 if(!helpEngine->registerDocumentation(docFile))
59 reportWarning(QString(
"HelpEngine: Documentation registration failed: %1").arg(helpEngine->error()));
62 void HelpEngine::setupDataWithWarning()
64 bool success = helpEngine->setupData();
67 CX_LOG_WARNING() << QString(
"Help engine setup failed with error [%1]").arg(helpEngine->error());
70 void HelpEngine::setInitialPage()
75 void HelpEngine::focusChanged(QWidget * old, QWidget * now)
81 void HelpEngine::focusObjectChanged(QObject* newFocus)
85 #ifdef DEBUG_HELP_SYSTEM 86 CX_LOG_CHANNEL_INFO(
"HELP_DB") << QString(
"**Focus on [%1]: %2").arg(newFocus->objectName()).arg(dynamic_cast<QWidget*>(newFocus)->windowTitle());
88 QString keyword = this->findBestMatchingKeyword(newFocus);
89 if (!keyword.isEmpty())
91 #ifdef DEBUG_HELP_SYSTEM 98 bool HelpEngine::isBreakChar(QChar c)
const 100 return c.isDigit() || c.isUpper();
103 bool HelpEngine::isBreakChar(QString text,
int index)
const 105 if (!this->isBreakChar(text[index]))
110 prev = this->isBreakChar(text[index-1]);
113 if (index+1<text.size())
114 next = this->isBreakChar(text[index+1]);
122 QString HelpEngine::findBestMatchingKeyword(QObject*
object)
126 QString
id =
object->objectName();
127 #ifdef DEBUG_HELP_SYSTEM 130 .arg(object->metaObject()->className());
132 if (
id.contains(
"help_widget"))
135 QMap<QString, QUrl> links = this->
engine()->linksForIdentifier(
id);
141 object =
object->parent();
#define CX_LOG_CHANNEL_INFO(channel)
cxResource_EXPORT ProfilePtr profile()
void reportWarning(QString msg)
#define CX_LOG_CHANNEL_DEBUG(channel)
static QString getDocPath()
return path to folder containing documentation files
Namespace for all CustusX production code.
void keywordActivated(QString)