Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 2006 → Rev 2007

/trunk/Scribus/scribus/helpbrowser.h
37,6 → 37,9
class QToolButton;
class QPopupMenu;
class QSplitter;
class QLabel;
class QLineEdit;
class QPushButton;
 
class HelpBrowser : public QWidget
{
51,6 → 54,8
QHBoxLayout* helpBrowserLayout;
QHBoxLayout* tabLayout;
QHBoxLayout* buttonLayout;
QVBoxLayout* searchingMainLayout;
QHBoxLayout* searchingButtonLayout;
QToolButton* homeButton;
QToolButton* backButton;
QToolButton* forwButton;
57,10 → 62,15
 
QTabWidget* tabWidget;
QWidget* tabContents;
QWidget* tabSearching;
QListView* listView;
QTextBrowser* textBrowser;
QSplitter* splitter;
QString language;
// searching
QLineEdit* searchingEdit;
QPushButton* searchingButton;
QListView* searchingView;
 
QPopupMenu* histMenu;
struct histd {
69,14 → 79,43
};
QMap<int, histd> mHistory;
 
/*! Text to be finded in document */
QString findText;
/*! \brief Search in doc files in spec. dir.
It uses directory-recursion. I hope that the documentation will have
only 2-3 level dir structure so it doesn't matter.
\author Petr Vanek <petr@yarpen.cz> */
void searchingInDirectory(QString);
 
protected slots:
virtual void languageChange();
 
/*! Load doc file when user select filename in content view. */
void itemSelected( QListViewItem *);
 
/*! Load doc file when user select filename in search view.
Then it performs some doc-finding and highlighting.
\author Petr Vanek <petr@yarpen.cz> */
void itemSearchSelected( QListViewItem *);
void sourceChanged(const QString& url);
void histChosen(int i);
void jumpToHelpSection(QString jumpToSection, QString jumpToFile="");
void loadHelp(QString filename);
void loadMenu();
 
/*! \brief Performs searching in documentation.
It walks through installed documentation and searching in all text files
\author Petr Vanek <petr@yarpen.cz> */
void searchingButton_clicked();
 
/*! \brief Find text in one document.
Classical ctrl+f searching.
\author Petr Vanek <petr@yarpen.cz> */
void find();
 
/*! \brief Find next occurences of the text in one document.
\author Petr Vanek <petr@yarpen.cz> */
void findNext();
};
 
#endif // HELPBROWSER_H
/trunk/Scribus/scribus/helpbrowser.cpp
41,6 → 41,10
#include <qdir.h>
#include <qsplitter.h>
#include <qmime.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qaccel.h>
#include <qinputdialog.h>
 
#ifdef _MSC_VER
#if (_MSC_VER >= 1200)
53,7 → 57,7
extern QPixmap loadIcon(QString nam);
 
 
HelpBrowser::HelpBrowser( QWidget* parent, QString caption, QString guiLanguage, QString jumpToSection, QString jumpToFile)
HelpBrowser::HelpBrowser( QWidget* parent, QString /*caption*/, QString guiLanguage, QString jumpToSection, QString jumpToFile)
: QWidget( parent, "Help", WType_TopLevel | WDestructiveClose )
{
QString fileName;
60,7 → 64,7
mHistory.clear();
struct histd his;
language = guiLanguage=="" ? "en" : guiLanguage.left(2);
helpBrowsermainLayout = new QVBoxLayout( this);
helpBrowsermainLayout = new QVBoxLayout( this);
buttonLayout = new QHBoxLayout;
buttonLayout->setSpacing( 6 );
buttonLayout->setMargin( 2 );
87,7 → 91,7
buttonLayout->addItem( spacer );
helpBrowsermainLayout->addLayout( buttonLayout );
 
helpBrowserLayout = new QHBoxLayout;
helpBrowserLayout = new QHBoxLayout;
splitter = new QSplitter(this, "splitter");
splitter->setChildrenCollapsible( false );
helpBrowserLayout->addWidget( splitter );
97,7 → 101,7
splitter->setResizeMode(tabWidget, QSplitter::Stretch );
tabWidget->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Expanding, false) );
tabContents = new QWidget( tabWidget, "tabContents" );
tabLayout = new QHBoxLayout( tabContents, 11, 6, "tabLayout");
tabLayout = new QHBoxLayout( tabContents, 11, 6, "tabLayout");
 
listView = new QListView( tabContents, "listView" );
listView->addColumn( tr( "Contents" ) );
111,10 → 115,33
listView->setDefaultRenameAction(QListView::Reject);
listView->clear();
tabLayout->addWidget( listView );
tabWidget->insertTab( tabContents, QString("Contents") );
 
tabWidget->insertTab( tabContents, tr("&Contents") );
//helpBrowserLayout->addWidget( tabWidget );
 
// searching
tabSearching = new QWidget(tabWidget, "tabSearching");
searchingMainLayout = new QVBoxLayout(tabSearching, 11, 6, "searchingMainLayout");
searchingButtonLayout = new QHBoxLayout;
searchingEdit = new QLineEdit(tabSearching, "searchingEdit");
searchingButton = new QPushButton(tabSearching, "searchingButton");
searchingButton->setText(tr("&Search"));
searchingButtonLayout->addWidget(searchingEdit);
searchingButtonLayout->addWidget(searchingButton);
searchingMainLayout->addLayout(searchingButtonLayout);
searchingView = new QListView(tabSearching, "searchingView");
searchingView->addColumn( tr( "Contents" ) );
searchingView->addColumn( tr( "Link" ) , 0 );
searchingView->setColumnWidthMode( 0, QListView::Maximum );
searchingView->setColumnWidthMode( 1, QListView::Manual );
searchingView->setSorting(-1,-1);
searchingView->setRootIsDecorated( true );
searchingView->setSelectionMode(QListView::Single);
searchingView->setDefaultRenameAction(QListView::Reject);
searchingView->clear();
searchingMainLayout->addWidget(searchingView);
tabWidget->insertTab(tabSearching, tr("S&earch"));
 
textBrowser = new QTextBrowser( splitter, "textBrowser" );
splitter->setResizeMode(textBrowser, QSplitter::Stretch);
//textBrowser = new QTextBrowser( this, "textBrowser" );
122,7 → 149,6
textBrowser->setFrameShape( QTextBrowser::StyledPanel );
QMimeSourceFactory *textBrowserMSF=textBrowser->mimeSourceFactory();
textBrowserMSF->setExtensionType("html", "text/html;charset=UTF-8");
//helpBrowserLayout->addWidget( textBrowser );
helpBrowsermainLayout->addLayout( helpBrowserLayout );
 
131,13 → 157,21
clearWState( WState_Polished );
loadMenu();
listView->header()->hide();
searchingView->header()->hide();
jumpToHelpSection(jumpToSection, jumpToFile );
 
QAccel *a = new QAccel( this, "a");
a->connectItem(a->insertItem(QAccel::stringToKey(tr("Ctrl+F"))), this, SLOT(find()));
a->connectItem(a->insertItem(QAccel::stringToKey(tr("F3"))), this, SLOT(findNext()));
 
connect( homeButton, SIGNAL( clicked() ), textBrowser, SLOT( home() ) );
connect( forwButton, SIGNAL( clicked() ), textBrowser, SLOT( forward() ) );
connect( backButton, SIGNAL( clicked() ), textBrowser, SLOT( backward() ) );
connect( histMenu, SIGNAL(activated(int)), this, SLOT(histChosen(int)));
connect( listView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSelected( QListViewItem *)));
// searching
connect(searchingView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSearchSelected(QListViewItem *)));
connect(searchingButton, SIGNAL(clicked()), this, SLOT(searchingButton_clicked()));
}
 
HelpBrowser::~HelpBrowser()
151,7 → 185,7
listView->header()->setLabel( 0, tr( "Contents" ) );
listView->clear();
 
tabWidget->changeTab( tabContents, tr( "Contents" ) );
tabWidget->changeTab( tabContents, tr( "&Contents" ) );
}
 
 
193,11 → 227,11
QString toLoad;
bool noDocs=false;
 
if (jumpToFile=="")
if (jumpToFile=="")
{
QString pfad = DOCDIR;
toLoad = pfad + language + "/"; //clean this later to handle 5 char locales
if (jumpToSection=="")
if (jumpToSection=="")
{
if (listView->firstChild())
{
207,11 → 241,11
else
noDocs=true;
}
else if (jumpToSection=="scripter")
else if (jumpToSection=="scripter")
{
toLoad+="scripter1.html";
QListViewItemIterator it(listView);
while (it.current())
while (it.current())
{
if (it.current()->text(1)=="scripter1.html")
listView->setSelected( it.current(), true );
241,7 → 275,7
{
if (fi.exists())
toLoad=filename;
else
else
{
QString pfad = DOCDIR;
toLoad = pfad + "en/index.html";
254,9 → 288,9
}
}
}
else
else
Avail=false;
if (Avail)
if (Avail)
{
textBrowser->setSource(toLoad);
his.Title = textBrowser->documentTitle();
290,7 → 324,7
QFile file( toLoad );
if ( !file.open( IO_ReadOnly ) )
return;
if ( !doc.setContent( &file ) )
if ( !doc.setContent( &file ) )
{
file.close();
return;
303,23 → 337,23
QListViewItem *tutorialsMenuItem;
bool haveTutorials=false;
 
while( !n.isNull() )
while( !n.isNull() )
{
QDomElement e = n.toElement(); // try to convert the node to an element.
if( !e.isNull() )
if( !e.isNull() )
{
if (e.hasAttribute( "text" ) && e.hasAttribute( "file" ))
if (e.hasAttribute( "text" ) && e.hasAttribute( "file" ))
{
QDomAttr textAttr = e.attributeNode( "text" );
QDomAttr fileAttr = e.attributeNode( "file" );
if (qlvi2==NULL)
qlvi=new QListViewItem(listView, textAttr.value(), fileAttr.value());
else
else
qlvi=new QListViewItem(listView, qlvi2, textAttr.value(), fileAttr.value());
if (qlvi!=NULL && e.hasAttribute( "section" ))
{
QDomAttr sectionAttr = e.attributeNode( "section" );
if (sectionAttr.value()=="tutorials" && !haveTutorials)
if (sectionAttr.value()=="tutorials" && !haveTutorials)
{
haveTutorials=true;
tutorialsMenuItem=qlvi;
331,21 → 365,21
}
 
QDomNodeList nl=n.childNodes();
for(uint i=0 ; i<= nl.count() ; i++)
for(uint i=0 ; i<= nl.count() ; i++)
{
QDomNode child=nl.item(i);
if (child.isElement())
if (child.isElement())
{
QDomElement ec = child.toElement();
if (!ec.isNull())
QDomElement ec = child.toElement();
if (!ec.isNull())
{
if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" ))
if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" ))
{
QDomAttr textAttr = ec.attributeNode( "text" );
QDomAttr fileAttr = ec.attributeNode( "file" );
if (qlvi4==NULL)
qlvi3=new QListViewItem(qlvi, textAttr.value(), fileAttr.value());
else
else
qlvi3=new QListViewItem(qlvi, qlvi4, textAttr.value(), fileAttr.value());
if (qlvi3!=NULL && ec.hasAttribute( "section" ))
{
361,21 → 395,21
}
//3rd level
QDomNodeList nl2=child.childNodes();
for(uint i=0 ; i<= nl2.count() ; i++)
for(uint i=0 ; i<= nl2.count() ; i++)
{
QDomNode childchild=nl2.item(i);
if (childchild.isElement())
if (childchild.isElement())
{
QDomElement ecc = childchild.toElement();
if (!ecc.isNull())
QDomElement ecc = childchild.toElement();
if (!ecc.isNull())
{
if (ecc.hasAttribute( "text" ) && ecc.hasAttribute( "file" ))
if (ecc.hasAttribute( "text" ) && ecc.hasAttribute( "file" ))
{
QDomAttr textAttr = ecc.attributeNode( "text" );
QDomAttr fileAttr = ecc.attributeNode( "file" );
if (qlvi6==NULL)
qlvi5=new QListViewItem(qlvi3, textAttr.value(), fileAttr.value());
else
else
qlvi5=new QListViewItem(qlvi3, qlvi6, textAttr.value(), fileAttr.value());
if (qlvi5!=NULL && ecc.hasAttribute( "section" ))
{
399,15 → 433,15
n = n.nextSibling();
}
//scan for installed tutorials
if (haveTutorials)
if (haveTutorials)
{
QString path = DOCDIR;
path += language + "/tutorials/";
QDir dir(path, "*", QDir::Name, QDir::Dirs | QDir::NoSymLinks);
 
if (dir.exists() && (dir.count() != 0))
if (dir.exists() && (dir.count() != 0))
{
for (uint i = 0; i < dir.count(); ++i)
for (uint i = 0; i < dir.count(); ++i)
{
if (dir[i]!="." && dir[i]!="..")
{
419,7 → 453,7
QFile fileTutorialMenu( file.filePath() );
if ( !fileTutorialMenu.open( IO_ReadOnly ) )
break;
if ( !docTutorial.setContent( &fileTutorialMenu ) )
if ( !docTutorial.setContent( &fileTutorialMenu ) )
{
fileTutorialMenu.close();
break;
430,12 → 464,12
QDomNode nTutorial = docElemTutorial.firstChild();
QListViewItem *tutorialQLVI=NULL;
 
while( !nTutorial.isNull() )
while( !nTutorial.isNull() )
{
QDomElement eTutorial = nTutorial.toElement(); // try to convert the node to an element.
if( !eTutorial.isNull() )
if( !eTutorial.isNull() )
{
if (tutorialsMenuItem!=NULL && eTutorial.hasAttribute( "text" ) && eTutorial.hasAttribute( "file" ))
if (tutorialsMenuItem!=NULL && eTutorial.hasAttribute( "text" ) && eTutorial.hasAttribute( "file" ))
{
QDomAttr textAttr = eTutorial.attributeNode( "text" );
QDomAttr fileAttr = eTutorial.attributeNode( "file" );
457,7 → 491,7
QDomAttr fileAttr = ec.attributeNode( "file" );
if (tutorialSubMenuItemLast==NULL)
tutorialSubMenuItem=new QListViewItem(tutorialQLVI, textAttr.value(), tutorialdir + fileAttr.value());
else
else
tutorialSubMenuItem=new QListViewItem(tutorialQLVI, tutorialSubMenuItemLast, textAttr.value(), tutorialdir + fileAttr.value());
if (tutorialSubMenuItem!=NULL)
tutorialSubMenuItemLast=tutorialSubMenuItem;
487,3 → 521,74
loadHelp(pfad + language + "/" + item->text(1));
}
}
 
void HelpBrowser::itemSearchSelected(QListViewItem *item)
{
if (item && item->text(1) != QString::null)
{
loadHelp(item->text(1));
findText = searchingEdit->text();
findNext();
}
}
 
void HelpBrowser::searchingInDirectory(QString aDir)
{
QDir dir(aDir + "/");
QStringList lst = dir.entryList("*.html");
for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
{
QString fname(aDir + (*it));
QFile f(fname);
if (f.open(IO_ReadOnly))
{
QTextStream stream(&f);
QString str = stream.read().lower();
int cnt = str.contains(searchingEdit->text().lower());
if (cnt > 0)
{
// the remove() hack is here for itemSelected() handling
QString fullname = fname;
QString title;
QListViewItem *refItem = listView->findItem(fname.remove(QString(DOCDIR)+"en/"), 1);
refItem ? title = refItem->text(0) : title = tr("unknown");
QListViewItem *item = new QListViewItem(searchingView, QString("%1x %2").arg(cnt).arg(title), fullname);
searchingView->insertItem(item);
}
f.close();
}
}
// get dirs - ugly recursion
QStringList dst = dir.entryList("*", QDir::Dirs);
for (QStringList::Iterator it = dst.begin(); it != dst.end(); ++it)
if ((*it)!="." && (*it)!="..")
searchingInDirectory(aDir + QString((*it)) + "/");
}
 
void HelpBrowser::searchingButton_clicked()
{
searchingView->clear();
// root files
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
searchingInDirectory(QString(DOCDIR) + "en/");
QApplication::restoreOverrideCursor();
}
 
void HelpBrowser::find()
{
findText = QInputDialog::getText(tr("Find"), tr("Search Term:"), QLineEdit::Normal, findText, 0, this);
if (findText == QString::null)
return;
findNext();
}
 
void HelpBrowser::findNext()
{
if (findText == QString::null)
{
find();
return;
}
// find it. finally
textBrowser->find(findText, false, false, true, 0, 0);
}