58 #include "helpWidget.hh" 64 HelpWidget::HelpWidget(QWidget* parent,
const QString& _homeSite ,
const bool _loadHomeSite )
65 : QMainWindow(parent),
74 homeSite_ = _homeSite;
76 QString filename = QString( OpenFlipper::Options::configDirStr() );
77 filename += OpenFlipper::Options::dirSeparator();
78 filename +=
"Help.qhc";
80 QDir helpDir = QDir(OpenFlipper::Options::helpDirStr());
82 QString iconPath = QString(OpenFlipper::Options::iconDirStr())+QString(OpenFlipper::Options::dirSeparator());
85 backButton_->setIcon(QIcon(iconPath+
"arrow-left.png"));
86 forwardButton_->setIcon(QIcon(iconPath+
"arrow-right.png"));
87 homeButton_->setIcon(QIcon(iconPath+
"go-home.png"));
88 searchButton_->setIcon(QIcon(iconPath+
"edit-find.png"));
90 tabWidget_ =
new QTabWidget(
this);
99 QStringList registeredNamespaces =
helpEngine_->registeredDocumentations();
101 QStringList documentationFiles;
104 QStringList helpFiles = helpDir.entryList(QStringList(
"*.qch"),QDir::Files);
107 for (QStringList::iterator iter = helpFiles.begin(); iter != helpFiles.end(); ++iter)
108 *iter = helpDir.path()+ OpenFlipper::Options::dirSeparator() + *iter;
110 for (
int i = 0; i < registeredNamespaces.size() ; ++i)
112 QString registredFilename (
helpEngine_->documentationFileName(registeredNamespaces[i]));
115 if (helpFiles.indexOf(registredFilename) != -1)
116 documentationFiles.push_back( registredFilename );
118 helpEngine_->unregisterDocumentation(registeredNamespaces[i]);
121 for (
int i = 0 ; i < helpFiles.size() ; ++i ) {
122 const QString filename = helpFiles[i];
125 if (documentationFiles.contains(filename))
129 if ( !
helpEngine_->registerDocumentation( filename ) ) {
130 std::cerr <<
"Error when trying to register file " << filename.toStdString() << std::endl;
131 std::cerr << helpFiles[i].toStdString() <<
" :" <<
helpEngine_->error().toStdString() << std::endl;
136 searchEngine_ =
new QHelpSearchEngine(
helpEngine_,
this);
140 homeIndex_ = tabWidget_->addTab(textWindow_, tr(
"Home"));
142 gridLayout_->addWidget(
helpEngine_->contentWidget(), 1, 0);
143 gridLayout_->addWidget(tabWidget_, 1, 1);
145 gridLayout_->setColumnStretch(0, 1);
146 gridLayout_->setColumnStretch(1, 3);
149 searchWidget_ =
new QDockWidget(tr(
"Search results"),
this);
150 searchWidget_->setFeatures( QDockWidget::DockWidgetClosable );
152 searchWidget_->resize(this->size().width(), floor(
double(this->size().height() / 3)) );
154 searchWidget_->setWidget(searchEngine_->queryWidget());
157 searchWidget_->hide();
158 addDockWidget(Qt::BottomDockWidgetArea, searchWidget_);
162 connect(
helpEngine_->contentWidget(), SIGNAL(linkActivated(
const QUrl&)),
163 this, SLOT(linkActivated(
const QUrl&)));
166 connect(searchButton_, SIGNAL(clicked()),
this, SLOT(showSearchWidget()));
169 connect(searchEngine_->queryWidget(), SIGNAL(search()),
this, SLOT(startSearch()));
172 connect(searchEngine_, SIGNAL(searchingFinished(
int)),
this, SLOT(showResults(
int)));
175 connect(searchEngine_->resultWidget(), SIGNAL(requestShowLink(
const QUrl&)),
176 this, SLOT(showFoundSite(
const QUrl&)));
179 connect(backButton_, SIGNAL(clicked()),
this, SLOT(goBack()));
182 connect(forwardButton_, SIGNAL(clicked()),
this, SLOT(goForward()));
185 connect(homeButton_, SIGNAL(clicked()),
this, SLOT(goHome()));
188 connect(textWindow_, SIGNAL(sourceChanged(
const QUrl&)),
this, SLOT(update(
const QUrl&)));
191 connect(textWindow_, SIGNAL(historyChanged(
const QUrl&)),
this, SLOT(updateButtons()));
197 QStringList tmp =
helpEngine_->registeredDocumentations ();
199 #ifdef DEBUG_HELP_CONTENTS 200 for (
int i = 0 ; i < tmp.size(); ++i) {
201 std::cerr <<
"=========================================================================================" << std::endl;
202 std::cerr <<
"Registered namespace: " << tmp[i].toStdString() << std::endl;
203 std::cerr <<
"From file : " <<
helpEngine_->documentationFileName(tmp[i]).toStdString() << std::endl;
206 QList<QStringList> filterAttribs =
helpEngine_->filterAttributeSets (tmp[i]);
215 if ( !filterAttribs.empty() ) {
216 QList<QUrl> list =
helpEngine_->files ( tmp[i], filterAttribs[0]);
217 for (
int j = 0 ; j < list.size(); ++j) {
218 std::cerr << list[j].toString().toStdString() << std::endl;
221 std::cerr <<
"Error, empty filter! Unable to get list of included files." << std::endl;
231 textWindow_->open(QUrl(homeSite_));
235 void HelpWidget::activateLink(
const QUrl& _url)
241 void HelpWidget::linkActivated(
const QUrl& _url) {
243 textWindow_->open(_url);
244 tabWidget_->setCurrentIndex(homeIndex_);
247 void HelpWidget::startSearch() {
249 searchEngine_->search(searchEngine_->queryWidget()->query());
252 void HelpWidget::setHomeSite(
const QString& _homeSite) {
254 homeSite_ = _homeSite;
257 void HelpWidget::showFoundSite(
const QUrl& _url) {
259 textWindow_->open(_url);
260 tabWidget_->setCurrentIndex(homeIndex_);
263 void HelpWidget::update(
const QUrl& _url ) {
269 QUrl newUrl = textWindow_->resolveUrl(_url);
271 QModelIndex modelIndex =
helpEngine_->contentWidget()->indexOf(newUrl);
274 if (modelIndex.isValid())
275 helpEngine_->contentWidget()->setCurrentIndex( modelIndex );
278 void HelpWidget::goForward() {
280 textWindow_->forward();
282 tabWidget_->setCurrentIndex(homeIndex_);
287 void HelpWidget::goBack() {
289 textWindow_->backward();
291 tabWidget_->setCurrentIndex(homeIndex_);
296 void HelpWidget::goHome() {
298 textWindow_->open(homeSite_);
300 tabWidget_->setCurrentIndex(homeIndex_);
305 void HelpWidget::updateButtons() {
307 if(!textWindow_->isBackwardAvailable()) {
308 backButton_->setEnabled(
false);
310 backButton_->setEnabled(
true);
313 if(!textWindow_->isForwardAvailable()) {
314 forwardButton_->setEnabled(
false);
316 forwardButton_->setEnabled(
true);
320 void HelpWidget::showSearchWidget() {
322 searchWidget_->show();
325 void HelpWidget::showResults(
int ) {
327 searchWidget_->hide();
329 int resultsTabIndex_ = tabWidget_->addTab(searchEngine_->resultWidget(), tr(
"Results") );
330 tabWidget_->setCurrentIndex(resultsTabIndex_);
333 void HelpWidget::openFoundSite(QListWidgetItem* ) {
337 HelpWidget::~HelpWidget() {
339 delete searchWidget_;
QHelpEngine * helpEngine_
The help engine the widget is working on.
HelpBrowser(QHelpEngine *_helpEngine, QWidget *parent=0)
Constructor.