Commit 9969216c authored by Dirk Wilden's avatar Dirk Wilden
Browse files

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3633 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 576349d6
...@@ -3,46 +3,188 @@ ...@@ -3,46 +3,188 @@
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <QtWebKit>
#include <iostream>
HelpWidget::HelpWidget(QWidget *parent, bool _user) HelpWidget::HelpWidget(QWidget *parent, bool _user)
: QMainWindow(parent) : QMainWindow(parent)
{ {
setupUi(this); setupUi(this);
QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
//create toolbar
QAction* action = toolBar->addAction(QIcon(iconPath + "arrow-left.png"), "Back");
connect(action, SIGNAL(triggered()), webView, SLOT(back()));
action = toolBar->addAction(QIcon(iconPath + "arrow-right.png"), "Forward");
connect(action, SIGNAL(triggered()), webView, SLOT(forward()));
action = toolBar->addAction(QIcon(iconPath + "go-home.png"), "Home");
connect(action, SIGNAL(triggered()), this, SLOT(goHome()));
QIcon icon; QIcon icon;
icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"window-close.png"); icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"window-close.png");
actionClose->setIcon(icon); actionClose->setIcon(icon);
QString baseDir = OpenFlipper::Options::applicationDirStr() + baseDir_ = OpenFlipper::Options::applicationDirStr() +
OpenFlipper::Options::dirSeparator() + "Docs"; OpenFlipper::Options::dirSeparator() + "Docs";
QString startFile;
if ( _user ) { if ( _user ) {
baseDir += OpenFlipper::Options::dirSeparator() + "User" + baseDir_ += OpenFlipper::Options::dirSeparator() + "User" +
OpenFlipper::Options::dirSeparator(); OpenFlipper::Options::dirSeparator();
startFile = baseDir + "OpenFlipperUserDoc.html"; startFile_ = baseDir_ + "OpenFlipperUserDoc.html";
} else { } else {
baseDir += OpenFlipper::Options::dirSeparator() + "Developer" + baseDir_ += OpenFlipper::Options::dirSeparator() + "Developer" +
OpenFlipper::Options::dirSeparator(); OpenFlipper::Options::dirSeparator();
startFile = baseDir + "OpenFlipperDeveloperDoc.html"; startFile_ = baseDir_ + "OpenFlipperDeveloperDoc.html";
} }
textBrowser->setSource( QUrl(startFile) ); connect(webView, SIGNAL( loadFinished(bool) ), this, SLOT( loadFinished(bool) ));
textBrowser->find( "REPLACEWITHPLUGINLINKS", QTextDocument::FindCaseSensitively ); webView->load( QUrl(startFile_) );
QTextCursor textCursor = textBrowser->textCursor();
webView->history()->clear();
QDir docDir = QDir(baseDir);
QStringList plugins = docDir.entryList ( QDir::AllDirs | QDir::NoDotAndDotDot);
for ( int i = 0 ; i < plugins.size(); ++i )
if ( plugins[i].contains("Plugin-") )
textCursor.insertHtml( "<a href=\"" + plugins[i] + OpenFlipper::Options::dirSeparator()
+ "index.html\">" + plugins[i] + "</a><br>" );
connect( actionClose , SIGNAL(triggered() ) , this, SLOT(hide()) ); connect( actionClose , SIGNAL(triggered() ) , this, SLOT(hide()) );
connect( closeButton , SIGNAL(clicked() ) , this, SLOT(hide()) ); connect( closeButton , SIGNAL(clicked() ) , this, SLOT(hide()) );
generateTree();
tree->setHeaderHidden( true );
connect( tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(treeClicked(QTreeWidgetItem*,int)) );
}
void HelpWidget::loadFinished(bool ok)
{
if (ok)
tabWidget->setTabText(tabWidget->currentIndex(), webView->page()->mainFrame()->title());
// 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()
{
webView->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();
}
webView->load( QUrl(path + item->text(1) + OpenFlipper::Options::dirSeparator() + "index.html") );
}
\ No newline at end of file
...@@ -7,5 +7,19 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget ...@@ -7,5 +7,19 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget
public: public:
HelpWidget(QWidget *parent = 0, bool _user = true); HelpWidget(QWidget *parent = 0, bool _user = true);
private:
QString baseDir_;
QString startFile_;
void generateTree();
QString getTitle(QString htmlFile);
private slots:
void loadFinished( bool ok );
void goHome();
void treeClicked(QTreeWidgetItem* item, int column );
}; };
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>895</width> <width>1008</width>
<height>969</height> <height>813</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
...@@ -16,14 +16,62 @@ ...@@ -16,14 +16,62 @@
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>0</x> <x>0</x>
<y>25</y> <y>35</y>
<width>895</width> <width>1008</width>
<height>919</height> <height>757</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout" > <layout class="QVBoxLayout" name="verticalLayout_2" >
<item> <item>
<widget class="QTextBrowser" name="textBrowser" /> <layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QTreeWidget" name="tree" >
<property name="minimumSize" >
<size>
<width>160</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget" >
<property name="currentIndex" >
<number>0</number>
</property>
<widget class="QWidget" name="tab" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>818</width>
<height>677</height>
</rect>
</property>
<attribute name="title" >
<string>Tab 1</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QWebView" name="webView" >
<property name="sizePolicy" >
<sizepolicy vsizetype="MinimumExpanding" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="url" >
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout" > <layout class="QHBoxLayout" name="horizontalLayout" >
...@@ -56,8 +104,8 @@ ...@@ -56,8 +104,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>895</width> <width>1008</width>
<height>25</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile" > <widget class="QMenu" name="menuFile" >
...@@ -72,18 +120,44 @@ ...@@ -72,18 +120,44 @@
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>0</x> <x>0</x>
<y>944</y> <y>792</y>
<width>895</width> <width>1008</width>
<height>25</height> <height>21</height>
</rect> </rect>
</property> </property>
</widget> </widget>
<widget class="QToolBar" name="toolBar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>21</y>
<width>1008</width>
<height>14</height>
</rect>
</property>
<property name="windowTitle" >
<string>toolBar</string>
</property>
<attribute name="toolBarArea" >
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak" >
<bool>false</bool>
</attribute>
</widget>
<action name="actionClose" > <action name="actionClose" >
<property name="text" > <property name="text" >
<string>Close</string> <string>Close</string>
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment