helpWidget.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 83 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-02-27 17:31:45 +0100 (Fr, 27. Feb 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 /*
00045  * helpWidget.cc
00046  *
00047  *  Created on: Apr 7, 2009
00048  *      Author: kremer
00049  */
00050 
00051 #include "helpWidget.hh"
00052 
00053 #include <OpenFlipper/common/GlobalOptions.hh>
00054 
00055 #include <iostream>
00056 
00057 #include <QTextStream>
00058 
00059 HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
00060         : QMainWindow(parent),
00061         searchWidget_(0),
00062         tabWidget_(0),
00063         textWindow_(0),
00064         helpEngine_(0),
00065         searchEngine_(0) {
00066 
00067         setupUi(this);
00068 
00069         homeSite_ = _homeSite;
00070 
00071         QString filename = QString(OpenFlipper::Options::helpDirStr());
00072         filename += OpenFlipper::Options::dirSeparator();
00073         filename += "Help.qhc";
00074 
00075         QString iconPath = QString(OpenFlipper::Options::iconDirStr());
00076 #ifdef WIN32
00077         iconPath += "\\";
00078 #else
00079         iconPath += "/";
00080 #endif
00081 
00082         // Set Buttons
00083         backButton_->setIcon(QIcon(iconPath+"arrow-left.png"));
00084         forwardButton_->setIcon(QIcon(iconPath+"arrow-right.png"));
00085         homeButton_->setIcon(QIcon(iconPath+"go-home.png"));
00086         searchButton_->setIcon(QIcon(iconPath+"edit-find.png"));
00087 
00088         tabWidget_ = new QTabWidget(this);
00089 
00090         helpEngine_ = new QHelpEngine(filename, this);
00091 
00092         helpEngine_->setupData();
00093 
00094         searchEngine_ = new QHelpSearchEngine(helpEngine_, this);
00095 
00096     textWindow_ = new HelpBrowser(helpEngine_, this);
00097 
00098     homeIndex_ = tabWidget_->addTab(textWindow_, tr("Home"));
00099 
00100     gridLayout_->addWidget(helpEngine_->contentWidget(), 1, 0);
00101     gridLayout_->addWidget(tabWidget_, 1, 1);
00102 
00103     gridLayout_->setColumnStretch(0, 1);
00104     gridLayout_->setColumnStretch(1, 3);
00105 
00106     // Search popup at bottom of window
00107     searchWidget_ = new QDockWidget(tr("Search results"), this);
00108         searchWidget_->setFeatures( QDockWidget::DockWidgetClosable );
00109 
00110         searchWidget_->resize(this->size().width(), floor( double(this->size().height() / 3)) );
00111 
00112         searchWidget_->setWidget(searchEngine_->queryWidget());
00113         //searchWidget_->setWidget(results_);
00114 
00115         searchWidget_->hide();
00116         addDockWidget(Qt::BottomDockWidgetArea, searchWidget_);
00117 
00118 
00119     // Entry in tree view has been clicked
00120     connect(helpEngine_->contentWidget(), SIGNAL(linkActivated(const QUrl&)),
00121             this, SLOT(linkActivated(const QUrl&)));
00122 
00123 
00124     // Search button
00125     connect(searchButton_, SIGNAL(clicked()), this, SLOT(showSearchWidget()));
00126 
00127     // Search button
00128     connect(searchEngine_->queryWidget(), SIGNAL(search()), this, SLOT(startSearch()));
00129 
00130     // Show results if search is finished
00131     connect(searchEngine_, SIGNAL(searchingFinished(int)), this, SLOT(showResults(int)));
00132 
00133     // Show results if search is finished
00134     connect(searchEngine_->resultWidget(), SIGNAL(requestShowLink(const QUrl&)),
00135                 this, SLOT(showFoundSite(const QUrl&)));
00136 
00137     // Back button
00138     connect(backButton_, SIGNAL(clicked()), this, SLOT(goBack()));
00139 
00140     // Forward button
00141     connect(forwardButton_, SIGNAL(clicked()), this, SLOT(goForward()));
00142 
00143     // Forward button
00144     connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));
00145 
00146     // Source has been reloaded
00147     connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&)));
00148 
00149     // Register documentation
00150     helpEngine_->registerDocumentation(filename);
00151 
00152     // Load main page
00153     textWindow_->open(QUrl(homeSite_));
00154 }
00155 
00156 void HelpWidget::linkActivated(const QUrl& _url) {
00157 
00158         textWindow_->open(_url);
00159         tabWidget_->setCurrentIndex(homeIndex_);
00160 }
00161 
00162 void HelpWidget::startSearch() {
00163 
00164         searchEngine_->search(searchEngine_->queryWidget()->query());
00165 }
00166 
00167 void HelpWidget::setHomeSite(const QString& _homeSite) {
00168 
00169         homeSite_ = _homeSite;
00170 }
00171 
00172 void HelpWidget::showFoundSite(const QUrl& _url) {
00173 
00174         textWindow_->open(_url);
00175         tabWidget_->setCurrentIndex(homeIndex_);
00176 }
00177 
00178 void HelpWidget::update(const QUrl& /* url */) {
00179 
00180         updateButtons();
00181 }
00182 
00183 void HelpWidget::goForward() {
00184 
00185         textWindow_->forward();
00186 
00187         tabWidget_->setCurrentIndex(homeIndex_);
00188 
00189         updateButtons();
00190 }
00191 
00192 void HelpWidget::goBack() {
00193 
00194         textWindow_->backward();
00195 
00196         tabWidget_->setCurrentIndex(homeIndex_);
00197 
00198         updateButtons();
00199 }
00200 
00201 void HelpWidget::goHome() {
00202 
00203         textWindow_->open(homeSite_);
00204 
00205         tabWidget_->setCurrentIndex(homeIndex_);
00206 
00207         updateButtons();
00208 }
00209 
00210 void HelpWidget::updateButtons() {
00211 
00212         if(!textWindow_->isBackwardAvailable()) {
00213                 backButton_->setEnabled(false);
00214         } else {
00215                 backButton_->setEnabled(true);
00216         }
00217 
00218         if(!textWindow_->isForwardAvailable()) {
00219                 forwardButton_->setEnabled(false);
00220         } else {
00221                 forwardButton_->setEnabled(true);
00222         }
00223 }
00224 
00225 void HelpWidget::showSearchWidget() {
00226 
00227         searchWidget_->show();
00228 }
00229 
00230 void HelpWidget::showResults(int /*_hits*/) {
00231 
00232         searchWidget_->hide();
00233 
00234         int resultsTabIndex_ = tabWidget_->addTab(searchEngine_->resultWidget(), tr("Results") );
00235         tabWidget_->setCurrentIndex(resultsTabIndex_);
00236 }
00237 
00238 void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
00239 
00240 }
00241 
00242 HelpWidget::~HelpWidget() {
00243 
00244         delete searchWidget_;
00245         delete textWindow_;
00246 }

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .