QValueList<GlossaryItem*> itemList;
itemList = glossary->readItems( doc );
glossary->setItemlist( itemList );
+ glossary->fixImagePath();
}
return glossary;
}
+void Glossary::fixImagePath()
+{
+ kdDebug() << "Glossary::fixImagePath()" << endl;
+ QValueList<GlossaryItem*>::iterator it = m_itemlist.begin();
+ const QValueList<GlossaryItem*>::iterator itEnd = m_itemlist.end();
+ QString path = m_picturepath;
+ QString firstpart = "<img src=\"";
+ firstpart += path;
+
+ for ( ; it != itEnd ; ++it )
+ {
+ ( *it )->desc().replace("[img]", firstpart );
+ ( *it )->desc().replace("[/img]", "\" />" );
+ }
+}
+
QValueList<GlossaryItem*> Glossary::readItems( QDomDocument &itemDocument )
{
QValueList<GlossaryItem*> list;
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]", "<b>" );
desc.replace("[/b]", "</b>" );
desc.replace("[i]", "<i>" );
-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( "<img src=\"" );
-
- m_htmlbasestring = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><body background=\"" ;
- m_htmlbasestring.append( baseHtml );
- m_htmlbasestring.append("\">");
+ //this string will be used for all items. If a backgroundpicutures should
+ //be used call Glossary::setBackgroundPicture().
+ m_htmlbasestring = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><body>" ;
+
+ m_folded = folded;
QVBoxLayout *vbox = new QVBoxLayout( plainPage(), 0, KDialog::spacingHint() );
vbox->activate();
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()));
void GlossaryDialog::updateTree()
{
- //XXX hack hack hack hack
m_glosstree->clear();
QValueList<Glossary*>::iterator itGl = m_glossaries.begin();
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 )
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
const QValueList<Glossary*>::iterator itGlEnd = m_glossaries.end();
bool found = false;
GlossaryItem *i = 0;
+
+ QString bg_picture;
+
while ( !found && itGl != itGlEnd )
{
QValueList<GlossaryItem*> items = ( *itGl )->itemlist();
if ( ( *it )->name() == item->text( 0 ) )
{
i = *it;
+ bg_picture = ( *itGl )->backgroundPicture();
found = true;
}
++it;
}
if ( found && i )
{
+ QString html;
+ if ( !bg_picture.isEmpty() )
+ {
+ html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><body background=\"" ;
+ html.append( bg_picture );
+ html.append("\">");
+ }else
+ html = m_htmlbasestring;
+
html += i->toHtml() + "</body></html>";
m_htmlpart->begin();
m_htmlpart->write( html );
+
+ kdDebug() << "the html " << html << endl;
m_htmlpart->end();
return;
}
{
QString code = "<h1>" + m_name + "</h1>" + m_desc;
-// QString pic_path = locate("data", "kalzium/data/knowledgepics/");
if ( !m_ref.isEmpty() )
{
QString refcode = parseReferences();
* 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:
/**
*/
virtual QValueList<GlossaryItem*> 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.
*
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*);
private:
QValueList<Glossary*> 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;