From a972aa299066f9b51d93be592184d434e6a25b02 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 5 Jul 2005 11:23:17 +0000 Subject: [PATCH] More work on the glossary. Now it behaves almost quite kalzium glossary, only a background is missing. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=431836 --- kdeeduui/kdeeduglossary.cpp | 146 +++++++++++++++++++++--------------- kdeeduui/kdeeduglossary.h | 15 ++-- 2 files changed, 93 insertions(+), 68 deletions(-) diff --git a/kdeeduui/kdeeduglossary.cpp b/kdeeduui/kdeeduglossary.cpp index 7939f8c..8b6a967 100644 --- a/kdeeduui/kdeeduglossary.cpp +++ b/kdeeduui/kdeeduglossary.cpp @@ -29,6 +29,15 @@ #include #include +Glossary::Glossary() +{ + m_name = i18n( "Glossary" ); +} + +Glossary::~Glossary() +{ +} + bool Glossary::loadLayout( QDomDocument &Document, const KURL& url ) { QFile layoutFile( url.path() ); @@ -54,6 +63,11 @@ bool Glossary::loadLayout( QDomDocument &Document, const KURL& url ) return true; } +bool Glossary::isEmpty() const +{ + return m_itemlist.count() == 0; +} + Glossary* Glossary::readFromXML( const KURL& url ) { @@ -127,13 +141,15 @@ QValueList Glossary::readItems( QDomDocument &itemDocument ) GlossaryDialog::GlossaryDialog( QWidget *parent, const char *name) : KDialogBase( Plain, i18n( "Glossary" ), Close, Close, parent, name, false ) { - QString baseHtml = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); - baseHtml.append("kalzium/data/"); - baseHtml.append("bg.jpg"); + //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"); - m_picbasestring = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); - m_picbasestring.append("kalzium/data/knowledgepics/"); - m_picbasestring.prepend( "findResourceDir("data", "kalzium/data/" ); +//X m_picbasestring.append("kalzium/data/knowledgepics/"); +//X m_picbasestring.prepend( "clear(); + QValueList::iterator itGl = m_glossaries.begin(); const QValueList::iterator itGlEnd = m_glossaries.end(); for ( ; itGl != itGlEnd ; ++itGl ) { - QValueList::iterator it = ( *itGl )->itemlist().begin(); - const QValueList::iterator itEnd = ( *itGl )->itemlist().end(); + QValueList items = ( *itGl )->itemlist(); + QValueList::iterator it = items.begin(); + const QValueList::iterator itEnd = items.end(); QListViewItem *main = new QListViewItem( m_glosstree, ( *itGl )->name() ); main->setExpandable( true ); @@ -246,30 +266,31 @@ void GlossaryDialog::updateTree() bool foldinsubtrees = true; ///FIXME The next line is crashing for some unkown reasons... -//X for ( ; it != itEnd ; ++it ) -//X { -//X if ( foldinsubtrees ) -//X { -//X QChar thisletter = ( *it )->name().upper()[0]; - //X QListViewItem *thisletteritem = findTreeWithLetter( thisletter, main ); - //X if ( !thisletteritem ) - //X { - //X thisletteritem = new QListViewItem( main, thisletter ); - //X thisletteritem->setExpandable( true ); - //X thisletteritem->setSelectable( false ); - //X } - //X new QListViewItem( thisletteritem, ( *it )->name() ); -//X } - //X else - //X new QListViewItem( main, ( *it )->name() ); -//X } -//X main->sort(); + for ( ; it != itEnd ; ++it ) + { + if ( foldinsubtrees ) + { + QChar thisletter = ( *it )->name().upper()[0]; + QListViewItem *thisletteritem = findTreeWithLetter( thisletter, main ); + if ( !thisletteritem ) + { + thisletteritem = new QListViewItem( main, thisletter ); + thisletteritem->setExpandable( true ); + thisletteritem->setSelectable( false ); + } + new QListViewItem( thisletteritem, ( *it )->name() ); + } + else + new QListViewItem( main, ( *it )->name() ); + } + main->sort(); } } void GlossaryDialog::addGlossary( Glossary* newgloss ) { if ( !newgloss ) return; + if ( newgloss->isEmpty() ) return; m_glossaries.append( newgloss ); kdDebug() << "Count of the new glossary: " << newgloss->itemlist().count() << endl; @@ -294,41 +315,42 @@ void GlossaryDialog::slotClicked( QListViewItem *item ) { if ( !item ) return; -//X -//X QString html = m_htmlbasestring; -//X -//X /** -//X * The next lines are searching for the correct KnowledgeItem -//X * in the m_itemList. When it is found the HTML will be -//X * generated -//X */ -//X QValueList::iterator itGl = m_glossaries.begin(); -//X const QValueList::iterator itGlEnd = m_glossaries.end(); -//X bool found = false; -//X GlossaryItem *i = 0; -//X while ( !found && itGl != itGlEnd ) -//X { -//X QValueList::iterator it = ( *itGl )->itemlist().begin(); -//X const QValueList::iterator itEnd = ( *itGl )->itemlist().end(); -//X while ( !found && it != itEnd ) -//X { -//X if ( ( *it )->name() == item->text( 0 ) ) -//X { -//X i = *it; -//X found = true; -//X } -//X ++it; -//X } -//X ++itGl; -//X } -//X if ( found && i ) -//X { -//X html += i->toHtml() + ""; -//X m_htmlpart->begin(); -//X m_htmlpart->write( html ); -//X m_htmlpart->end(); -//X return; -//X } + + 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 + * generated + */ + QValueList::iterator itGl = m_glossaries.begin(); + const QValueList::iterator itGlEnd = m_glossaries.end(); + bool found = false; + GlossaryItem *i = 0; + while ( !found && itGl != itGlEnd ) + { + QValueList items = ( *itGl )->itemlist(); + QValueList::iterator it = items.begin(); + const QValueList::iterator itEnd = items.end(); + while ( !found && it != itEnd ) + { + if ( ( *it )->name() == item->text( 0 ) ) + { + i = *it; + found = true; + } + ++it; + } + ++itGl; + } + if ( found && i ) + { + html += i->toHtml() + ""; + m_htmlpart->begin(); + m_htmlpart->write( html ); + m_htmlpart->end(); + return; + } } void GlossaryDialog::slotClose() diff --git a/kdeeduui/kdeeduglossary.h b/kdeeduui/kdeeduglossary.h index 837556d..e364ee3 100644 --- a/kdeeduui/kdeeduglossary.h +++ b/kdeeduui/kdeeduglossary.h @@ -37,8 +37,8 @@ class GlossaryItem; class Glossary { public: - Glossary(){}; - ~Glossary(){}; + Glossary(); + ~Glossary(); /** * add the item @p item to the glossary @@ -58,6 +58,11 @@ class Glossary m_itemlist.clear(); } + /** + * does this glossary have items? + */ + bool isEmpty() const; + /** * Every glossary can have a name. It will be * set to @p name @@ -70,8 +75,7 @@ class Glossary * @returns the name of the glossary */ QString name()const{ - return "GlossaryName"; -//X return m_name; + return m_name; } /** @@ -151,8 +155,7 @@ class GlossaryItem } QString name() const { - return "moin moin"; -//X return m_name; + return m_name; } QString desc() const { -- 2.47.3