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::convertToKeyword(QString
id)
const
150 retval.push_back(
id[0]);
151 for (
int i=1; i<
id.size(); ++i)
156 if (this->isBreakChar(
id, i))
158 retval.push_back(
"_");
160 retval.push_back(
id[i]);
162 return retval.toLower();
165 QString HelpEngine::findBestMatchingKeyword(QObject*
object)
169 QString
id = this->convertToKeyword(object->objectName());
170 #ifdef DEBUG_HELP_SYSTEM
173 .arg(object->metaObject()->className());
175 if (
id.contains(
"help_widget"))
178 QMap<QString, QUrl> links = this->
engine()->linksForIdentifier(
id);
184 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
void keywordActivated(QString)