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();
61 helpEngine->registerDocumentation(docFile);
63 this->setupDataWithWarning();
65 connect(qApp, SIGNAL(focusObjectChanged(QObject*)),
this, SLOT(focusObjectChanged(QObject*)));
66 connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
this, SLOT(focusChanged(QWidget*, QWidget*)));
68 QTimer::singleShot(100,
this, SLOT(setInitialPage()));
76 void HelpEngine::setupDataWithWarning()
78 bool success = helpEngine->setupData();
81 CX_LOG_WARNING() << QString(
"Help engine setup failed with error [%1]").arg(helpEngine->error());
84 void HelpEngine::setInitialPage()
89 void HelpEngine::focusChanged(QWidget * old, QWidget * now)
95 void HelpEngine::focusObjectChanged(QObject* newFocus)
99 #ifdef DEBUG_HELP_SYSTEM
100 CX_LOG_CHANNEL_INFO(
"HELP_DB") << QString(
"**Focus on [%1]: %2").arg(newFocus->objectName()).arg(dynamic_cast<QWidget*>(newFocus)->windowTitle());
102 QString keyword = this->findBestMatchingKeyword(newFocus);
103 if (!keyword.isEmpty())
105 #ifdef DEBUG_HELP_SYSTEM
112 bool HelpEngine::isBreakChar(QChar c)
const
114 return c.isDigit() || c.isUpper();
117 bool HelpEngine::isBreakChar(QString text,
int index)
const
119 if (!this->isBreakChar(text[index]))
124 prev = this->isBreakChar(text[index-1]);
127 if (index+1<text.size())
128 next = this->isBreakChar(text[index+1]);
136 QString HelpEngine::convertToKeyword(QString
id)
const
143 retval.push_back(
id[0]);
144 for (
int i=1; i<
id.size(); ++i)
149 if (this->isBreakChar(
id, i))
151 retval.push_back(
"_");
153 retval.push_back(
id[i]);
155 return retval.toLower();
158 QString HelpEngine::findBestMatchingKeyword(QObject*
object)
162 QString
id = this->convertToKeyword(object->objectName());
163 #ifdef DEBUG_HELP_SYSTEM
166 .arg(object->metaObject()->className());
168 if (
id.contains(
"help_widget"))
171 QMap<QString, QUrl> links = this->
engine()->linksForIdentifier(
id);
177 object =
object->parent();
#define CX_LOG_CHANNEL_INFO(channel)
cxResource_EXPORT ProfilePtr profile()
#define CX_LOG_CHANNEL_DEBUG(channel)
static QString getDocPath()
return path to folder containing documentation files
void keywordActivated(QString)