Commit 98b9cb16 authored by Mike Kremer's avatar Mike Kremer

Reverted removal of former help browser

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5569 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f7ebd05c
......@@ -76,7 +76,7 @@
#include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh>
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
#include <OpenFlipper/widgets/helpAssistant/helpAssistant.hh>
#include <OpenFlipper/widgets/helpBrowser/helpWidget.hh>
#include <OpenFlipper/Core/PluginInfo.hh>
......@@ -671,10 +671,10 @@ public:
private:
/// Pointer to the help Browser
HelpAssistant* helpBrowserDeveloper_;
HelpWidget* helpBrowserDeveloper_;
/// Pointer to the help Browser
HelpAssistant* helpBrowserUser_;
HelpWidget* helpBrowserUser_;
/** @} */
......
......@@ -51,54 +51,43 @@
void CoreWidget::showHelpBrowserUser( ) {
if ( OpenFlipper::Options::nogui() )
return;
if ( OpenFlipper::Options::nogui() )
return;
if ( helpBrowserUser_ == 0 ) {
helpBrowserUser_ = new HelpAssistant();
}
if ( helpBrowserUser_ == 0 ) {
helpBrowserUser_ = new HelpWidget( this ,true);
}
helpBrowserUser_->startAssistant("user.qch");
//show the widget centered
QPoint center;
center.setX( x() + width() / 2 );
center.setY( y() + height() / 2 );
//show the widget centered
// QPoint center;
// center.setX( x() + width() / 2 );
// center.setY( y() + height() / 2 );
//
// helpBrowserUser_->setGeometry(center.x() - helpBrowserUser_->width() / 2,
// center.y() - helpBrowserUser_->height()/ 2, helpBrowserUser_->width(), helpBrowserUser_->height());
//
// helpBrowserUser_->show();
helpBrowserUser_->setGeometry(center.x() - helpBrowserUser_->width() / 2,
center.y() - helpBrowserUser_->height()/ 2, helpBrowserUser_->width(), helpBrowserUser_->height());
helpBrowserUser_->show();
}
void CoreWidget::showHelpBrowserDeveloper( ) {
if ( OpenFlipper::Options::nogui() )
return;
if ( OpenFlipper::Options::nogui() )
return;
if ( helpBrowserUser_ == 0 ) {
helpBrowserUser_ = new HelpAssistant();
}
if ( helpBrowserDeveloper_ == 0 ) {
helpBrowserDeveloper_ = new HelpWidget( this ,false);
}
helpBrowserUser_->startAssistant("developer.qch");
//show the widget centered
QPoint center;
center.setX( x() + width() / 2 );
center.setY( y() + height() / 2 );
// if ( OpenFlipper::Options::nogui() )
// return;
//
// if ( helpBrowserDeveloper_ == 0 ) {
// helpBrowserDeveloper_ = new HelpWidget( this ,false);
// }
//
// //show the widget centered
// QPoint center;
// center.setX( x() + width() / 2 );
// center.setY( y() + height() / 2 );
//
// helpBrowserDeveloper_->setGeometry(center.x() - helpBrowserDeveloper_->width() / 2,
// center.y() - helpBrowserDeveloper_->height()/ 2, helpBrowserDeveloper_->width(), helpBrowserDeveloper_->height());
//
// helpBrowserDeveloper_->show();
helpBrowserDeveloper_->setGeometry(center.x() - helpBrowserDeveloper_->width() / 2,
center.y() - helpBrowserDeveloper_->height()/ 2, helpBrowserDeveloper_->width(), helpBrowserDeveloper_->height());
helpBrowserDeveloper_->show();
}
......
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: $
// $Author: $
// $Date: $
//
//=============================================================================
#include "helpAssistant.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
#include <QMessageBox>
#include <QProcess>
#include <QLibraryInfo>
#include <QString>
#include <iostream>
HelpAssistant::HelpAssistant() : filename_(0), proc_(0) {
}
HelpAssistant::~HelpAssistant() {
if (proc_ && proc_->state() == QProcess::Running) {
proc_->terminate();
proc_->waitForFinished(3000);
}
delete proc_;
}
bool HelpAssistant::startAssistant(const std::string& _filename) {
filename_ = new QString(_filename.c_str());
if (!proc_)
proc_ = new QProcess();
if (proc_->state() != QProcess::Running) {
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
#if !defined(Q_OS_MAC)
app += QLatin1String("assistant");
#else
app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
#endif
QStringList args;
args << QLatin1String("-file")
<< OpenFlipper::Options::applicationDirStr()
+ QLatin1String("/Help/") + *filename_
<< QLatin1String("-server");
std::cerr << app.toStdString() << " " << args[0].toStdString() << " " << args[1].toStdString() << std::endl;
proc_->start(app, args);
if (!proc_->waitForStarted()) {
QMessageBox::critical(0, QObject::tr("OpenFlipper Help"),
QObject::tr("Unable to launch Qt Assistant (%1)").arg(app));
return false;
}
// Load page index.html:
QByteArray ba("SetSource ");
ba.append("qthelp://com.trolltech.qmake/doc/index.html");
proc_->write(ba + '\0');
}
return true;
}
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: $
// $Author: $
// $Date: $
//
//=============================================================================
#ifndef HELPASSISTANT_HH_
#define HELPASSISTANT_HH_
class QProcess;
class QString;
#include <string>
class HelpAssistant {
public:
/// Constructor
HelpAssistant();
/// Desctructor
virtual ~HelpAssistant();
/// Start and show help browser
bool startAssistant(const std::string& _filename);
private:
QString* filename_;
QProcess* proc_;
};
#endif /* HELPASSISTANT_HH_ */
#== SYSTEM PART -- DON'T TOUCH ==============================================
include $(ACGMAKE)/Config
#==============================================================================
SUBDIRS = $(call find-subdirs)
PACKAGES := qt4 glut opengl x11 math ACG2 openmesh2
PROJ_LIBS =
MODULES := uic4compat moc4 cxx
#== SYSTEM PART -- DON'T TOUCH ==============================================
include $(ACGMAKE)/Rules
#==============================================================================
#include "findEdit.hh"
#include <QKeyEvent>
findEdit::findEdit(QWidget* parent) : QLineEdit(parent)
{
connect(this, SIGNAL(textEdited(const QString&)), this, SLOT(slotTextEdited(const QString&)) );
}
void findEdit::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
emit find();
else if (event->key() == Qt::Key_F3)
emit find();
else if (event->key() == Qt::Key_Escape)
emit close();
else
QLineEdit::keyPressEvent(event);
}
void findEdit::slotTextEdited(const QString&)
{
emit textEdited();
}
#ifndef FINDEDIT_HH
#define FINDEDIT_HH
#include <QLineEdit>
class findEdit : public QLineEdit
{
Q_OBJECT
signals:
void find();
void close();
void textEdited();
public:
findEdit(QWidget *parent = 0);
protected:
void keyPressEvent( QKeyEvent* event );
private slots:
void slotTextEdited(const QString& /*text*/);
};
#endif //FINDEDIT_HH
#include "helpWidget.hh"
#include <QtGui>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <iostream>
HelpWidget::HelpWidget(QWidget *parent, bool _user)
: QMainWindow(parent)
{
setupUi(this);
QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
//create toolbar
back_ = toolBar->addAction(QIcon(iconPath + "arrow-left.png"), "Back");
forward_ = toolBar->addAction(QIcon(iconPath + "arrow-right.png"), "Forward");
QAction* action = toolBar->addAction(QIcon(iconPath + "go-home.png"), "Home");
connect(action, SIGNAL(triggered()), this, SLOT(goHome()));
toolBar->addSeparator();
action = toolBar->addAction(QIcon(iconPath + "edit-find.png"), "Find text");
connect(action, SIGNAL(triggered()), this, SLOT(showFind()));
//finding
initFindFrame();
//splitter position
QList<int> wsizes( splitter->sizes() );
wsizes[0] = 30;
wsizes[1] = 70;
splitter->setSizes(wsizes);
//tab buttons
QPushButton* closeTabButton = new QPushButton();
QPushButton* addTabButton = new QPushButton();
closeTabButton->setIcon(QIcon(iconPath+"tab-close.png"));
addTabButton->setIcon(QIcon(iconPath+"tab-new.png"));
addTabButton->setMaximumSize(26,26);
tabs->setCornerWidget(closeTabButton, Qt::TopRightCorner);
tabs->setCornerWidget(addTabButton, Qt::TopLeftCorner);
connect( closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()) );
connect( addTabButton, SIGNAL(clicked()), this, SLOT(duplicateCurrentTab()) );
QIcon icon;
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"window-close.png");
actionClose->setIcon(icon);
baseDir_ = OpenFlipper::Options::applicationDirStr() +
OpenFlipper::Options::dirSeparator() + "Docs";
if ( _user ) {
baseDir_ += OpenFlipper::Options::dirSeparator() + "User" +
OpenFlipper::Options::dirSeparator();
startFile_ = baseDir_ + "OpenFlipperUserDoc.html";
} else {
baseDir_ += OpenFlipper::Options::dirSeparator() + "Developer" +
OpenFlipper::Options::dirSeparator();
startFile_ = baseDir_ + "OpenFlipperDeveloperDoc.html";
}
currentView_ = new webView();
tabs->removeTab(0);
newTab(currentView_);
setConnections();
currentView_->load( QUrl(startFile_) );
connect( actionClose , SIGNAL(triggered() ) , this, SLOT(hide()) );
generateTree();
tree->setHeaderHidden( true );
tabs->setContextMenuPolicy( Qt::CustomContextMenu );
tree->setContextMenuPolicy( Qt::CustomContextMenu );
contextMenu_ = new QMenu();
connect( tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(treeClicked(QTreeWidgetItem*,int)) );
connect( tree, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(showContextMenu(const QPoint &)));
connect( tabs, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(showContextMenu(const QPoint &)));
connect( tabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) );
}
///update the signals/slots which are only active on the visible webView
void HelpWidget::setConnections()
{
back_->disconnect();
connect(back_, SIGNAL(triggered()), currentView_, SLOT(back()));
forward_->disconnect();
connect(forward_, SIGNAL(triggered()), currentView_, SLOT(forward()));
}
void HelpWidget::loadFinished(bool)
{
// std::cerr << "history " << webView->history()->items().count() << std::endl;
//
// if ( webView->url().path() != QUrl(startFile_).path() || !ok )
// return;
//
// QDir docDir = QDir(baseDir_);
// QStringList plugins = docDir.entryList ( QDir::AllDirs | QDir::NoDotAndDotDot);
//
// QString pluginHtml;
//
// for ( int i = 0 ; i < plugins.size(); ++i )
// if ( plugins[i].contains("Plugin-") )
// pluginHtml.append( "<a href=\"" + plugins[i] + OpenFlipper::Options::dirSeparator()
// + "index.html\">" + plugins[i] + "</a><br>" );
//
// QString source = webView->page()->currentFrame()->toHtml();
//
// source = source.replace("REPLACEWITHPLUGINLINKS",pluginHtml);
//
// webView->page()->currentFrame()->setHtml(source, QUrl(baseDir_));
}
/// go to home dir
void HelpWidget::goHome()
{
currentView_->load( QUrl(startFile_) );
}
///generate the documentation tree
void HelpWidget::generateTree(){
QDir docDir = QDir(baseDir_);
QStringList dirs = docDir.entryList(QDir::Readable | QDir::AllDirs | QDir::NoDotAndDotDot);
QStringList names = dirs;
QList< QTreeWidgetItem* > parents;
//prepend current path to dirs
for ( int j = 0 ; j < dirs.size(); ++j ){
dirs[j] = baseDir_ + dirs[j] ;
parents.append(0);
}
while ( dirs.size() > 0) {
QString indexHTML(dirs.first() + OpenFlipper::Options::dirSeparator() + "index.html");
QTreeWidgetItem* currentItem = 0;
if ( QFile(indexHTML).exists() ){
QString title = getTitle(indexHTML);
if (title == "")
std::cerr << "HelpWidget: Warning index.html without title found!" << std::endl;
else{
currentItem = new QTreeWidgetItem(QString(title + "," + names.first()).split(","));
if (parents.first() == 0)
tree->addTopLevelItem( currentItem );
else
parents.first()->addChild( currentItem );
}
}
QDir currentDir = QDir( dirs.first() );
QStringList newDirs = currentDir.entryList(QDir::Readable | QDir::AllDirs | QDir::NoDotAndDotDot);
names.removeFirst();
names << newDirs;
//prepend current path to dirs
for ( int j = 0 ; j < newDirs.size(); ++j ){
newDirs[j] = dirs.first() + OpenFlipper::Options::dirSeparator() + newDirs[j] ;
if (currentItem == 0)
parents.append( parents.first() );
else
parents.append( currentItem );
}
parents.removeFirst();
dirs.removeFirst();
dirs << newDirs;
}
}
///read the title from an html file
QString HelpWidget::getTitle(QString htmlFile){
QFile data( htmlFile );
if (data.open(QFile::ReadOnly)) {
QTextStream stream(&data);
QString source = stream.readAll();
int s = source.indexOf("<title>", Qt::CaseInsensitive);
int e = source.indexOf("</title>", Qt::CaseInsensitive);
if (s == -1 || e == -1)
return QString("");
return source.mid(s + 7, e-(s+7));
}
return QString("");
}
/// the user clicked on an item in the treeWidget
void HelpWidget::treeClicked(QTreeWidgetItem* item, int /*column*/ ){
QTreeWidgetItem* parent = item->parent();
QString path = baseDir_;
while(parent != 0){
path += parent->text(1) + OpenFlipper::Options::dirSeparator();
parent = parent->parent();
}
currentView_->load( QUrl(path + item->text(1) + OpenFlipper::Options::dirSeparator() + "index.html") );
}
///the url changed
void HelpWidget::urlChanged(const QUrl& /*url*/){
back_->setEnabled( currentView_->history()->canGoBack() );
forward_->setEnabled( currentView_->history()->canGoForward() );
}
/// add a new Tab to the Tabs
void HelpWidget::newTab(QWebView* _webView){
webView* view = dynamic_cast< webView* > (_webView);
connect(view, SIGNAL(titleChanged(const QString&)), this, SLOT(titleChanged(const QString&)));
connect(view, SIGNAL(windowCreated(QWebView*)), this, SLOT(newTab(QWebView*)) );
connect(view, SIGNAL( loadFinished(bool) ), this, SLOT( loadFinished(bool) ));
connect(view, SIGNAL( find() ), this, SLOT( showFind() ));
connect(view, SIGNAL( findNext() ), this, SLOT( findNext1() ));
connect(view, SIGNAL(urlChanged(const QUrl &)), this, SLOT(urlChanged(const QUrl &)) );
tabs->addTab(view, "");
}
/// the title of one of the tabs changed
void HelpWidget::titleChanged(const QString & title)
{
for(int i=0; i < tabs->count(); i++)
if (tabs->widget(i) == sender())
tabs->setTabText(i, title);
}
/// current tab changed
void HelpWidget::tabChanged(int _index)
{
currentView_ = dynamic_cast< webView* > (tabs->widget(_index));
setConnections();
back_->setEnabled( currentView_->history()->canGoBack() );
forward_->setEnabled( currentView_->history()->canGoForward() );
}
/// close the current tab
void HelpWidget::closeCurrentTab()
{
if (tabs->count() > 1)
tabs->removeTab( tabs->currentIndex() );
}
/// add a duplicate of the current Tab to the TabWidget
void HelpWidget::duplicateCurrentTab()
{
webView* newView = new webView();
newView->load( currentView_->url() );
newTab(newView);
tabs->setCurrentIndex(tabs->count()-1);
}
//----------------------------------------------------------------------------
// Finding
//----------------------------------------------------------------------------
///initialize the widgets corresponding to finding
void HelpWidget::initFindFrame()
{
findText_ = new findEdit();
//set icons
QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
findClose->setIcon( QIcon(iconPath + "application-exit.png") );
findPrev->setIcon( QIcon(iconPath + "arrow-left.png") );
findNext->setIcon( QIcon(iconPath + "arrow-right.png") );
//connect signals
connect(findText_, SIGNAL(find()), this, SLOT(findNext1()));
connect(findText_, SIGNAL(textEdited()), this, SLOT(findNext1()));
connect(findText_, SIGNAL(close()), findFrame, SLOT(hide()));
connect(findClose, SIGNAL(clicked()), findFrame, SLOT(hide()));
connect(findNext, SIGNAL(clicked()), this, SLOT(findNext1()));
connect(findPrev, SIGNAL(clicked()), this, SLOT(findPrev1()));
//set layout
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget( findClose );
layout->addWidget( findText_ );
layout->addWidget( findPrev );
layout->addWidget( findNext );
layout->addWidget( findSensitive );
layout->addStretch();
findFrame->setLayout(layout);
findFrame->hide();
}
///show the find frame under the current page
void HelpWidget::showFind(){
findFrame->setVisible( true );
findText_->selectAll();
findText_->setFocus(Qt::OtherFocusReason);
}
/// find the next element in the text that fits the search term
void HelpWidget::findNext1()
{
if (findText_->text() == ""){
//TODO do something that clears the selection
}
if ( findSensitive->isChecked() )
currentView_->findText( findText_->text() , QWebPage::FindCaseSensitively | QWebPage::FindWrapsAroundDocument);
else