35 #include <QHelpEngine> 40 #include <QApplication> 54 QDir().mkpath(
profile()->getPath());
55 QString helpFile =
profile()->getPath() +
"/cx_user_doc.qhc";
56 helpEngine =
new QHelpEngine(helpFile, NULL);
58 this->setupDataWithWarning();
60 this->setupDataWithWarning();
62 connect(qApp, SIGNAL(focusObjectChanged(QObject*)),
this, SLOT(focusObjectChanged(QObject*)));
63 connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
this, SLOT(focusChanged(QWidget*, QWidget*)));
65 QTimer::singleShot(100,
this, SLOT(setInitialPage()));
73 void HelpEngine::setupDocFile()
76 if(!QFile(docFile).exists())
77 reportWarning(QString(
"HelpEngine: Cannot find docFile: %1").arg(docFile));
78 helpEngine->unregisterDocumentation(helpEngine->namespaceName(docFile));
79 if(!helpEngine->registerDocumentation(docFile))
80 reportWarning(QString(
"HelpEngine: Documentation registration failed: %1").arg(helpEngine->error()));
83 void HelpEngine::setupDataWithWarning()
85 bool success = helpEngine->setupData();
88 CX_LOG_WARNING() << QString(
"Help engine setup failed with error [%1]").arg(helpEngine->error());
91 void HelpEngine::setInitialPage()
96 void HelpEngine::focusChanged(QWidget * old, QWidget * now)
102 void HelpEngine::focusObjectChanged(QObject* newFocus)
106 #ifdef DEBUG_HELP_SYSTEM 107 CX_LOG_CHANNEL_INFO(
"HELP_DB") << QString(
"**Focus on [%1]: %2").arg(newFocus->objectName()).arg(dynamic_cast<QWidget*>(newFocus)->windowTitle());
109 QString keyword = this->findBestMatchingKeyword(newFocus);
110 if (!keyword.isEmpty())
112 #ifdef DEBUG_HELP_SYSTEM 119 bool HelpEngine::isBreakChar(QChar c)
const 121 return c.isDigit() || c.isUpper();
124 bool HelpEngine::isBreakChar(QString text,
int index)
const 126 if (!this->isBreakChar(text[index]))
131 prev = this->isBreakChar(text[index-1]);
134 if (index+1<text.size())
135 next = this->isBreakChar(text[index+1]);
143 QString HelpEngine::findBestMatchingKeyword(QObject*
object)
147 QString
id =
object->objectName();
148 #ifdef DEBUG_HELP_SYSTEM 151 .arg(object->metaObject()->className());
156 QMap<QString, QUrl> links = this->
engine()->linksForIdentifier(
id);
162 object =
object->parent();
#define CX_LOG_CHANNEL_INFO(channel)
cxResource_EXPORT ProfilePtr profile()
void reportWarning(QString msg)
#define CX_LOG_CHANNEL_DEBUG(channel)
bool contains(std::string const &s, std::string const &infix)
static QString getDocPath()
return path to folder containing documentation files
Namespace for all CustusX production code.
void keywordActivated(QString)