From: Pino Toscano Date: Mon, 12 Sep 2005 16:25:26 +0000 (+0000) Subject: Some small code improvements X-Git-Tag: v3.80.2~314 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=7d00940642335553af88eb1d72a0182a35f803ef;p=libqmvoc.git Some small code improvements svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=459986 --- diff --git a/kdeeduui/kdeeduglossary.cpp b/kdeeduui/kdeeduglossary.cpp index 40a3c46..fed9a03 100644 --- a/kdeeduui/kdeeduglossary.cpp +++ b/kdeeduui/kdeeduglossary.cpp @@ -164,7 +164,7 @@ QList Glossary::readItems( QDomDocument &itemDocument ) QString desc = descNode.toElement().text().utf8(); if ( !picName.isEmpty() ) - desc.prepend("[img]"+picName +"[/img]" ); + desc.prepend("[img]"+picName +"[/img][brclear][br]" ); item->setName( i18n( nameNode.toElement( ).text().utf8() ) ); @@ -177,6 +177,7 @@ QList Glossary::readItems( QDomDocument &itemDocument ) desc = desc.replace("[sup]", "" ); desc = desc.replace("[/sup]", "" ); desc = desc.replace("[br]", "
" ); + desc = desc.replace("[brclear]", "
" ); item->setDesc( desc ); refNodeList = refNode.elementsByTagName( "refitem" ); @@ -184,7 +185,6 @@ QList Glossary::readItems( QDomDocument &itemDocument ) { reflist << i18n( refNodeList.item( it ).toElement().text().utf8() ); } - reflist.sort(); item->setRef( reflist ); list.append( item ); @@ -193,14 +193,12 @@ QList Glossary::readItems( QDomDocument &itemDocument ) return list; } - - GlossaryDialog::GlossaryDialog( bool folded, QWidget *parent, const char *name) : KDialogBase( Plain, i18n( "Glossary" ), Close, NoDefault, parent, name, false ) { //this string will be used for all items. If a backgroundpicture should //be used call Glossary::setBackgroundPicture(). - m_htmlbasestring = "" ; + m_htmlbasestring = "" ; m_folded = folded; @@ -236,11 +234,11 @@ GlossaryDialog::GlossaryDialog( bool folded, QWidget *parent, const char *name) m_search->setListView( m_glosstree ); m_htmlpart = new KHTMLPart( vs, "html-part" ); - + connect( m_htmlpart->browserExtension(), SIGNAL( openURLRequestDelayed( const KURL &, const KParts::URLArgs & ) ), this, SLOT( displayItem( const KURL &, const KParts::URLArgs & ) ) ); connect( m_glosstree, SIGNAL(clicked( Q3ListViewItem * )), this, SLOT(slotClicked( Q3ListViewItem * ))); connect( clear, SIGNAL(clicked()), m_search, SLOT(clear())); - + resize( 600, 400 ); } @@ -294,12 +292,10 @@ void GlossaryDialog::updateTree() Q3ListViewItem *main = new Q3ListViewItem( m_glosstree, ( *itGl )->name() ); main->setExpandable( true ); main->setSelectable( false ); - //XXX TMP!!! - bool foldinsubtrees = m_folded; for ( ; it != itEnd ; ++it ) { - if ( foldinsubtrees ) + if ( m_folded ) { QChar thisletter = ( *it )->name().upper()[0]; Q3ListViewItem *thisletteritem = findTreeWithLetter( thisletter, main ); @@ -379,46 +375,44 @@ void GlossaryDialog::slotClicked( Q3ListViewItem *item ) QString html; if ( !bg_picture.isEmpty() ) { - html = ""); - }else - html = m_htmlbasestring; - + html = " background=\"" + bg_picture + "\""; + } + + html = m_htmlbasestring.arg( html ); html += i->toHtml() + ""; + m_htmlpart->begin(); m_htmlpart->write( html ); - m_htmlpart->end(); return; } } +void GlossaryItem::setRef( const QStringList& s ) +{ + m_ref = s; + m_ref.sort(); +} + QString GlossaryItem::toHtml() const { - QString code = "

" + m_name + "

" + m_desc; + QString code = "

" + m_name + "

" + m_desc + parseReferences(); - if ( !m_ref.isEmpty() ) - { - QString refcode = parseReferences(); - code += refcode; - } return code; } QString GlossaryItem::parseReferences() const { - QString htmlcode = "

" + i18n( "References" ) + "

"; + if ( m_ref.isEmpty() ) + return QString(); + + QString htmlcode = "

" + i18n( "References" ) + "

    "; - bool first = true; for ( int i = 0; i < m_ref.size(); i++ ) { - if ( !first ) - htmlcode += "
    "; - else - first = false; - htmlcode += QString( "%2" ).arg( m_ref[i], m_ref[i] ); + htmlcode += QString( "
  • %2
  • " ).arg( m_ref[i], m_ref[i] ); } + htmlcode += "
"; return htmlcode; } diff --git a/kdeeduui/kdeeduglossary.h b/kdeeduui/kdeeduglossary.h index 80606fa..3dc8a3c 100644 --- a/kdeeduui/kdeeduglossary.h +++ b/kdeeduui/kdeeduglossary.h @@ -190,9 +190,13 @@ class GlossaryItem m_desc = s; } - void setRef( const QStringList& s){ - m_ref = s; - } + /** + * Set the references for the current GlossaryItem to + * @p s. + * There's no need to sort the list before, as they + * will be sorted automatically + */ + void setRef( const QStringList& s); void setPictures( const QString& s ){ m_pic = QStringList(s);