From: Pino Toscano Date: Tue, 5 Jul 2005 09:43:11 +0000 (+0000) Subject: Trying to active the Glossary dialog, but atm it crashes ;( X-Git-Tag: v3.4.90~15 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=28d4e0daf76e8687185281a8b79a0e296aa83adc;p=libqmvoc.git Trying to active the Glossary dialog, but atm it crashes ;( svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=431801 --- diff --git a/kdeeduui/kdeeduglossary.cpp b/kdeeduui/kdeeduglossary.cpp index da8fde9..0b3c2b1 100644 --- a/kdeeduui/kdeeduglossary.cpp +++ b/kdeeduui/kdeeduglossary.cpp @@ -103,12 +103,15 @@ QValueList Glossary::readItems( QDomDocument &itemDocument ) desc.replace("[i]", "" ); desc.replace("[/i]", "" ); - item->setName( i18n( nameNode.toElement( ).text().utf8() ) ); - item->setDesc( i18n( desc.utf8() ) ); +// item->setName( i18n( nameNode.toElement( ).text().utf8() ) ); +// item->setDesc( i18n( desc.utf8() ) ); + item->setName( nameNode.toElement().text() ); + item->setDesc( desc ); refNodeList = refNode.elementsByTagName( "refitem" ); for ( uint it = 0; it < refNodeList.count(); it++ ) { - reflist << i18n( refNodeList.item( it ).toElement().text().utf8() ); +// reflist << i18n( refNodeList.item( it ).toElement().text().utf8() ); + reflist << refNodeList.item( it ).toElement().text(); } reflist.sort(); item->setRef( reflist ); @@ -124,19 +127,18 @@ QValueList Glossary::readItems( QDomDocument &itemDocument ) GlossaryDialog::GlossaryDialog( QWidget *parent, const char *name) : KDialogBase( Plain, i18n( "Glossary" ), Close, Close, parent, name, false ) { -//X QString baseHtml = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); -//X baseHtml.append("kalzium/data/"); -//X baseHtml.append("bg.jpg"); -//X -//X m_picbasestring = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); -//X m_picbasestring.append("kalzium/data/knowledgepics/"); -//X m_picbasestring.prepend( ""); -//X + QString baseHtml = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); + baseHtml.append("kalzium/data/"); + baseHtml.append("bg.jpg"); + + m_picbasestring = KGlobal::dirs()->findResourceDir("data", "kalzium/data/" ); + m_picbasestring.append("kalzium/data/knowledgepics/"); + m_picbasestring.prepend( ""); + QVBoxLayout *vbox = new QVBoxLayout( plainPage(), 0, KDialog::spacingHint() ); vbox->activate(); @@ -227,25 +229,34 @@ void GlossaryDialog::displayItem( const KURL& url, const KParts::URLArgs& ) slotClicked( found ); } -void GlossaryDialog::populateTree() +void GlossaryDialog::addGlossary( Glossary* newgloss ) { - QValueList::iterator it = m_glossary.itemlist().begin(); - const QValueList::iterator itEnd = m_glossary.itemlist().end(); + m_glossaries.append( newgloss ); + + QValueList::iterator it = newgloss->itemlist().begin(); + const QValueList::iterator itEnd = newgloss->itemlist().end(); - QListViewItem *main = new QListViewItem( m_glosstree, m_glossary.name() ); + QListViewItem *main = new QListViewItem( m_glosstree, newgloss->name() ); main->setExpandable( true ); main->setSelectable( false ); + //XXX TMP!!! + bool foldinsubtrees = true; for ( ; it != itEnd ; ++it ) { - QChar thisletter = ( *it )->name().upper()[0]; - QListViewItem *thisletteritem = findTreeWithLetter( thisletter, main ); - if ( !thisletteritem ) + if ( foldinsubtrees ) { - thisletteritem = new QListViewItem( main, thisletter ); - thisletteritem->setExpandable( true ); - thisletteritem->setSelectable( false ); + 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() ); } - new QListViewItem( thisletteritem, ( *it )->name() ); + else + new QListViewItem( main, ( *it )->name() ); } main->sort(); } @@ -274,18 +285,24 @@ void GlossaryDialog::slotClicked( QListViewItem *item ) * in the m_itemList. When it is found the HTML will be * generated */ - QValueList::iterator it = m_glossary.itemlist().begin(); - const QValueList::iterator itEnd = m_glossary.itemlist().end(); + QValueList::iterator itGl = m_glossaries.begin(); + const QValueList::iterator itGlEnd = m_glossaries.end(); bool found = false; GlossaryItem *i = 0; - while ( !found && it != itEnd ) + while ( !found && itGl != itGlEnd ) { - if ( ( *it )->name() == item->text( 0 ) ) + QValueList::iterator it = ( *itGl )->itemlist().begin(); + const QValueList::iterator itEnd = ( *itGl )->itemlist().end(); + while ( !found && it != itEnd ) { - i = *it; - found = true; + if ( ( *it )->name() == item->text( 0 ) ) + { + i = *it; + found = true; + } + ++it; } - ++it; + ++itGl; } if ( found && i ) { @@ -305,35 +322,31 @@ void GlossaryDialog::slotClose() QString GlossaryItem::toHtml() const { - //XXX TMP!!! - QString code; -//X QString code = "

" + m_name + "

" + m_desc; -//X -//X // QString pic_path = locate("data", "kalzium/data/knowledgepics/"); -//X if ( !m_ref.isEmpty() ) -//X { -//X QString refcode = parseReferences(); -//X code += refcode; -//X } + QString code = "

" + m_name + "

" + m_desc; + +// QString pic_path = locate("data", "kalzium/data/knowledgepics/"); + if ( !m_ref.isEmpty() ) + { + QString refcode = parseReferences(); + code += refcode; + } return code; } QString GlossaryItem::parseReferences() const { - //XXX TMP!!! - QString htmlcode; -//X QString htmlcode = "

" + i18n( "References" ) + "

"; -//X -//X bool first = true; -//X for ( uint i = 0; i < m_ref.size(); i++ ) -//X { -//X if ( !first ) -//X htmlcode += "
"; -//X else -//X first = false; -//X htmlcode += QString( "%2" ).arg( m_ref[i], m_ref[i] ); -//X } -//X + QString htmlcode = "

" + i18n( "References" ) + "

"; + + bool first = true; + for ( uint i = 0; i < m_ref.size(); i++ ) + { + if ( !first ) + htmlcode += "
"; + else + first = false; + htmlcode += QString( "%2" ).arg( m_ref[i], m_ref[i] ); + } + return htmlcode; } diff --git a/kdeeduui/kdeeduglossary.h b/kdeeduui/kdeeduglossary.h index 96694f5..85d2b5e 100644 --- a/kdeeduui/kdeeduglossary.h +++ b/kdeeduui/kdeeduglossary.h @@ -194,14 +194,13 @@ class GlossaryDialog : public KDialogBase void keyPressEvent(QKeyEvent*); /** - * sets the glossary + * add a new glossary */ - void setGlossary( const Glossary& glossary ){ - m_glossary = glossary; - } + void addGlossary( Glossary* newgloss ); + private: - Glossary m_glossary; + QValueList m_glossaries; KHTMLPart *m_htmlpart; QString m_htmlbasestring; @@ -210,7 +209,6 @@ class GlossaryDialog : public KDialogBase KActionCollection* m_actionCollection; - void populateTree(); QListViewItem* findTreeWithLetter( const QChar&, QListViewItem* ); KListViewSearchLine *m_search;