From: Carsten Niehaus Date: Tue, 5 Jul 2005 20:01:25 +0000 (+0000) Subject: * The dialog can now be set to be folded or now in the ctor X-Git-Tag: v3.4.90~11 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=73fef4de902e6a14029b1e15b3a41ad06d1bf7fd;p=libqmvoc.git * The dialog can now be set to be folded or now in the ctor * Each glossary can now be have its own backgroundpicture svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=431990 --- diff --git a/kdeeduui/kdeeduglossary.cpp b/kdeeduui/kdeeduglossary.cpp index d17987c..3a1da51 100644 --- a/kdeeduui/kdeeduglossary.cpp +++ b/kdeeduui/kdeeduglossary.cpp @@ -81,11 +81,28 @@ Glossary* Glossary::readFromXML( const KURL& url ) QValueList itemList; itemList = glossary->readItems( doc ); glossary->setItemlist( itemList ); + glossary->fixImagePath(); } return glossary; } +void Glossary::fixImagePath() +{ + kdDebug() << "Glossary::fixImagePath()" << endl; + QValueList::iterator it = m_itemlist.begin(); + const QValueList::iterator itEnd = m_itemlist.end(); + QString path = m_picturepath; + QString firstpart = "desc().replace("[img]", firstpart ); + ( *it )->desc().replace("[/img]", "\" />" ); + } +} + QValueList Glossary::readItems( QDomDocument &itemDocument ) { QValueList list; @@ -110,9 +127,6 @@ QValueList Glossary::readItems( QDomDocument &itemDocument ) QDomElement refNode = ( const QDomElement& ) itemElement.namedItem( "references" ).toElement(); QString desc = descNode.toElement().text(); -//TODO fix the pictures-tag -//X desc.replace("[img]", m_picbasestring ); -//X desc.replace("[/img]", "\" />" ); desc.replace("[b]", "" ); desc.replace("[/b]", "" ); desc.replace("[i]", "" ); @@ -136,22 +150,14 @@ QValueList Glossary::readItems( QDomDocument &itemDocument ) -GlossaryDialog::GlossaryDialog( QWidget *parent, const char *name) +GlossaryDialog::GlossaryDialog( bool folded, QWidget *parent, const char *name) : KDialogBase( Plain, i18n( "Glossary" ), Close, Close, parent, name, false ) { - //XX TMP!!! - QString baseHtml = "foo.png"; -//X QString baseHtml = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); -//X baseHtml.append("kalzium/data/"); -//X baseHtml.append("bg.jpg"); - -//X m_picbasestring = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); -//X m_picbasestring.append("kalzium/data/knowledgepics/"); -//X m_picbasestring.prepend( ""); + //this string will be used for all items. If a backgroundpicutures should + //be used call Glossary::setBackgroundPicture(). + m_htmlbasestring = "" ; + + m_folded = folded; QVBoxLayout *vbox = new QVBoxLayout( plainPage(), 0, KDialog::spacingHint() ); vbox->activate(); @@ -185,23 +191,6 @@ GlossaryDialog::GlossaryDialog( QWidget *parent, const char *name) m_htmlpart = new KHTMLPart( vs, "html-part" ); -//X m_actionCollection = new KActionCollection(this); -//X KStdAction::quit(this, SLOT(slotClose()), m_actionCollection); -//X -//X QDomDocument doc( "foo" ); -//X QString filename = "knowledge.xml"; -//X -//X if ( loadLayout( doc, filename ) ) -//X m_itemList = readItems( doc ); -//X -//X QDomDocument doc2( "foo" ); -//X filename = "tools.xml"; -//X -//X if ( loadLayout( doc2, filename ) ) -//X m_toolList = readTools( doc2 ); -//X -//X populateTree(); -//X connect( m_htmlpart->browserExtension(), SIGNAL( openURLRequestDelayed( const KURL &, const KParts::URLArgs & ) ), this, SLOT( displayItem( const KURL &, const KParts::URLArgs & ) ) ); connect( m_glosstree, SIGNAL(clicked( QListViewItem * )), this, SLOT(slotClicked( QListViewItem * ))); connect( clear, SIGNAL(clicked()), m_search, SLOT(clear())); @@ -245,7 +234,6 @@ void GlossaryDialog::displayItem( const KURL& url, const KParts::URLArgs& ) void GlossaryDialog::updateTree() { - //XXX hack hack hack hack m_glosstree->clear(); QValueList::iterator itGl = m_glossaries.begin(); @@ -261,9 +249,8 @@ void GlossaryDialog::updateTree() main->setExpandable( true ); main->setSelectable( false ); //XXX TMP!!! - bool foldinsubtrees = true; + bool foldinsubtrees = m_folded; - ///FIXME The next line is crashing for some unkown reasons... for ( ; it != itEnd ; ++it ) { if ( foldinsubtrees ) @@ -314,8 +301,6 @@ void GlossaryDialog::slotClicked( QListViewItem *item ) if ( !item ) return; - QString html = m_htmlbasestring; - /** * The next lines are searching for the correct KnowledgeItem * in the m_itemList. When it is found the HTML will be @@ -325,6 +310,9 @@ void GlossaryDialog::slotClicked( QListViewItem *item ) const QValueList::iterator itGlEnd = m_glossaries.end(); bool found = false; GlossaryItem *i = 0; + + QString bg_picture; + while ( !found && itGl != itGlEnd ) { QValueList items = ( *itGl )->itemlist(); @@ -335,6 +323,7 @@ void GlossaryDialog::slotClicked( QListViewItem *item ) if ( ( *it )->name() == item->text( 0 ) ) { i = *it; + bg_picture = ( *itGl )->backgroundPicture(); found = true; } ++it; @@ -343,9 +332,20 @@ void GlossaryDialog::slotClicked( QListViewItem *item ) } if ( found && i ) { + QString html; + if ( !bg_picture.isEmpty() ) + { + html = ""); + }else + html = m_htmlbasestring; + html += i->toHtml() + ""; m_htmlpart->begin(); m_htmlpart->write( html ); + + kdDebug() << "the html " << html << endl; m_htmlpart->end(); return; } @@ -361,7 +361,6 @@ QString GlossaryItem::toHtml() const { QString code = "

" + m_name + "

" + m_desc; -// QString pic_path = locate("data", "kalzium/data/knowledgepics/"); if ( !m_ref.isEmpty() ) { QString refcode = parseReferences(); diff --git a/kdeeduui/kdeeduglossary.h b/kdeeduui/kdeeduglossary.h index 1dd43e8..0eaf632 100644 --- a/kdeeduui/kdeeduglossary.h +++ b/kdeeduui/kdeeduglossary.h @@ -94,6 +94,36 @@ class Glossary * error, this won't return 0 but an empty Glossary. */ static Glossary* readFromXML( const KURL& url ); + + /** + * Every glossaryitem can show pictures. [img src="foo.png] + * will look for the file foo.png in the path defined be + * @p path + */ + void setPicturePath( const QString& path ){ + m_picturepath = path; + } + + QString picturePath()const{ + return m_picturepath; + } + + /** + * defines which picture to use as the background + * of the htmlview. The dialog + * will use the file specifiec by the @p filename + */ + void setBackgroundPicture( const QString& filename ){ + m_backgroundpicture = filename; + } + + /** + * @return the picuture used as the background in + * this background + */ + QString backgroundPicture()const{ + return m_backgroundpicture; + } private: /** @@ -103,6 +133,19 @@ class Glossary */ virtual QValueList readItems( QDomDocument &itemDocument ); + QString m_backgroundpicture; + + /** + * replaces the [img]-pseudocode with valid html. The path where + * the pictures are stored will be used for pictures + */ + void fixImagePath(); + + /** + * the path in which pictures of the glossary will be searched + */ + QString m_picturepath; + /** * Load the layout from an XML file. * @@ -198,7 +241,7 @@ class GlossaryDialog : public KDialogBase Q_OBJECT public: - GlossaryDialog( QWidget *parent=0, const char *name=0); + GlossaryDialog( bool folded = true, QWidget *parent=0, const char *name=0); ~GlossaryDialog(); void keyPressEvent(QKeyEvent*); @@ -213,12 +256,16 @@ class GlossaryDialog : public KDialogBase private: QValueList m_glossaries; + /** + * if true the items will be displayed folded + */ + bool m_folded; + void updateTree(); KHTMLPart *m_htmlpart; - QString m_htmlbasestring; - QString m_picbasestring; KListView *m_glosstree; + QString m_htmlbasestring; KActionCollection* m_actionCollection;