43 #include "helpWidget.hh" 49 HelpWidget::HelpWidget(QWidget* parent,
const QString& _homeSite ,
const bool _loadHomeSite )
50 : QMainWindow(parent),
59 homeSite_ = _homeSite;
61 QString filename = QString( OpenFlipper::Options::configDirStr() );
62 filename += OpenFlipper::Options::dirSeparator();
63 filename +=
"Help.qhc";
65 QDir helpDir = QDir(OpenFlipper::Options::helpDirStr());
67 QString iconPath = QString(OpenFlipper::Options::iconDirStr())+QString(OpenFlipper::Options::dirSeparator());
70 backButton_->setIcon(QIcon(iconPath+
"arrow-left.png"));
71 forwardButton_->setIcon(QIcon(iconPath+
"arrow-right.png"));
72 homeButton_->setIcon(QIcon(iconPath+
"go-home.png"));
73 searchButton_->setIcon(QIcon(iconPath+
"edit-find.png"));
75 tabWidget_ =
new QTabWidget(
this);
84 QStringList registeredNamespaces =
helpEngine_->registeredDocumentations();
86 QStringList documentationFiles;
89 QStringList helpFiles = helpDir.entryList(QStringList(
"*.qch"),QDir::Files);
92 for (QStringList::iterator iter = helpFiles.begin(); iter != helpFiles.end(); ++iter)
93 *iter = helpDir.path()+ OpenFlipper::Options::dirSeparator() + *iter;
95 for (
int i = 0; i < registeredNamespaces.size() ; ++i)
97 QString registredFilename (
helpEngine_->documentationFileName(registeredNamespaces[i]));
100 if (helpFiles.indexOf(registredFilename) != -1)
101 documentationFiles.push_back( registredFilename );
103 helpEngine_->unregisterDocumentation(registeredNamespaces[i]);
106 for (
int i = 0 ; i < helpFiles.size() ; ++i ) {
107 const QString filename = helpFiles[i];
110 if (documentationFiles.contains(filename))
114 if ( !
helpEngine_->registerDocumentation( filename ) ) {
115 std::cerr <<
"Error when trying to register file " << filename.toStdString() << std::endl;
116 std::cerr << helpFiles[i].toStdString() <<
" :" <<
helpEngine_->error().toStdString() << std::endl;
121 searchEngine_ =
new QHelpSearchEngine(
helpEngine_,
this);
125 homeIndex_ = tabWidget_->addTab(textWindow_, tr(
"Home"));
127 gridLayout_->addWidget(
helpEngine_->contentWidget(), 1, 0);
128 gridLayout_->addWidget(tabWidget_, 1, 1);
130 gridLayout_->setColumnStretch(0, 1);
131 gridLayout_->setColumnStretch(1, 3);
134 searchWidget_ =
new QDockWidget(tr(
"Search results"),
this);
135 searchWidget_->setFeatures( QDockWidget::DockWidgetClosable );
137 searchWidget_->resize(this->size().width(), floor(
double(this->size().height() / 3)) );
139 searchWidget_->setWidget(searchEngine_->queryWidget());
142 searchWidget_->hide();
143 addDockWidget(Qt::BottomDockWidgetArea, searchWidget_);
147 connect(
helpEngine_->contentWidget(), SIGNAL(linkActivated(
const QUrl&)),
148 this, SLOT(linkActivated(
const QUrl&)));
151 connect(searchButton_, SIGNAL(clicked()),
this, SLOT(showSearchWidget()));
154 connect(searchEngine_->queryWidget(), SIGNAL(search()),
this, SLOT(startSearch()));
157 connect(searchEngine_, SIGNAL(searchingFinished(
int)),
this, SLOT(showResults(
int)));
160 connect(searchEngine_->resultWidget(), SIGNAL(requestShowLink(
const QUrl&)),
161 this, SLOT(showFoundSite(
const QUrl&)));
164 connect(backButton_, SIGNAL(clicked()),
this, SLOT(goBack()));
167 connect(forwardButton_, SIGNAL(clicked()),
this, SLOT(goForward()));
170 connect(homeButton_, SIGNAL(clicked()),
this, SLOT(goHome()));
173 connect(textWindow_, SIGNAL(sourceChanged(
const QUrl&)),
this, SLOT(update(
const QUrl&)));
176 connect(textWindow_, SIGNAL(historyChanged(
const QUrl&)),
this, SLOT(updateButtons()));
182 QStringList tmp =
helpEngine_->registeredDocumentations ();
184 #ifdef DEBUG_HELP_CONTENTS 185 for (
int i = 0 ; i < tmp.size(); ++i) {
186 std::cerr <<
"=========================================================================================" << std::endl;
187 std::cerr <<
"Registered namespace: " << tmp[i].toStdString() << std::endl;
188 std::cerr <<
"From file : " <<
helpEngine_->documentationFileName(tmp[i]).toStdString() << std::endl;
191 QList<QStringList> filterAttribs =
helpEngine_->filterAttributeSets (tmp[i]);
200 if ( !filterAttribs.empty() ) {
201 QList<QUrl> list =
helpEngine_->files ( tmp[i], filterAttribs[0]);
202 for (
int j = 0 ; j < list.size(); ++j) {
203 std::cerr << list[j].toString().toStdString() << std::endl;
206 std::cerr <<
"Error, empty filter! Unable to get list of included files." << std::endl;
216 textWindow_->open(QUrl(homeSite_));
220 void HelpWidget::activateLink(
const QUrl& _url)
226 void HelpWidget::linkActivated(
const QUrl& _url) {
228 textWindow_->open(_url);
229 tabWidget_->setCurrentIndex(homeIndex_);
232 void HelpWidget::startSearch() {
234 searchEngine_->search(searchEngine_->queryWidget()->query());
237 void HelpWidget::setHomeSite(
const QString& _homeSite) {
239 homeSite_ = _homeSite;
242 void HelpWidget::showFoundSite(
const QUrl& _url) {
244 textWindow_->open(_url);
245 tabWidget_->setCurrentIndex(homeIndex_);
248 void HelpWidget::update(
const QUrl& _url ) {
254 QUrl newUrl = textWindow_->resolveUrl(_url);
256 QModelIndex modelIndex =
helpEngine_->contentWidget()->indexOf(newUrl);
259 if (modelIndex.isValid())
260 helpEngine_->contentWidget()->setCurrentIndex( modelIndex );
263 void HelpWidget::goForward() {
265 textWindow_->forward();
267 tabWidget_->setCurrentIndex(homeIndex_);
272 void HelpWidget::goBack() {
274 textWindow_->backward();
276 tabWidget_->setCurrentIndex(homeIndex_);
281 void HelpWidget::goHome() {
283 textWindow_->open(homeSite_);
285 tabWidget_->setCurrentIndex(homeIndex_);
290 void HelpWidget::updateButtons() {
292 if(!textWindow_->isBackwardAvailable()) {
293 backButton_->setEnabled(
false);
295 backButton_->setEnabled(
true);
298 if(!textWindow_->isForwardAvailable()) {
299 forwardButton_->setEnabled(
false);
301 forwardButton_->setEnabled(
true);
305 void HelpWidget::showSearchWidget() {
307 searchWidget_->show();
310 void HelpWidget::showResults(
int ) {
312 searchWidget_->hide();
314 int resultsTabIndex_ = tabWidget_->addTab(searchEngine_->resultWidget(), tr(
"Results") );
315 tabWidget_->setCurrentIndex(resultsTabIndex_);
318 void HelpWidget::openFoundSite(QListWidgetItem* ) {
322 HelpWidget::~HelpWidget() {
324 delete searchWidget_;
HelpBrowser(QHelpEngine *_helpEngine, QWidget *parent=0)
Constructor.
QHelpEngine * helpEngine_
The help engine the widget is working on.