From 998f21e02a725cd553d7c278819f67cd81295af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Mon, 24 Jun 2013 02:08:15 +0200 Subject: Initial import --- src/documentlistviewitem.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/documentlistviewitem.cpp (limited to 'src/documentlistviewitem.cpp') diff --git a/src/documentlistviewitem.cpp b/src/documentlistviewitem.cpp new file mode 100644 index 0000000..7a71873 --- /dev/null +++ b/src/documentlistviewitem.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** +* Copyright (C) 2004-2009 by Thomas Fischer * +* fischer@unix-ag.uni-kl.de * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include +#include +#include + +#include + +#include "documentlistviewitem.h" +#include "entry.h" +#include "comment.h" +#include +#include "macro.h" + +namespace KBibTeX +{ + DocumentListViewItem::DocumentListViewItem( BibTeX::File *file, BibTeX::Element *element, DocumentListView *parent ) : KListViewItem( parent, parent->lastItem() ), m_element( element ), m_bibtexFile( file ), m_parent( parent ), m_unreadStatus( FALSE ) + { + setTexts(); + } + + DocumentListViewItem::DocumentListViewItem( BibTeX::File *file, BibTeX::Element *element, DocumentListView *parent, QListViewItem *after ) : KListViewItem( parent, after ), m_element( element ), m_bibtexFile( file ), m_parent( parent ) + { + setTexts(); + } + + DocumentListViewItem::~DocumentListViewItem() + { + // nothing + } + + BibTeX::Element* DocumentListViewItem::element() + { + return m_element; + } + + void DocumentListViewItem::updateItem() + { + setTexts(); + } + + void DocumentListViewItem::setUnreadStatus( bool unread ) + { + m_unreadStatus = unread; + } + + void DocumentListViewItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ) + { + if ( !p ) + return ; + + // make unread items bold + if ( m_unreadStatus ) + { + QFont f = p->font(); + f.setBold( TRUE ); + p->setFont( f ); + } + + KListViewItem::paintCell( p, cg, column, width, align ); + } + + + void DocumentListViewItem::setTexts() + { + BibTeX::Entry * entry = dynamic_cast( m_element ); + + if ( entry ) + { + entry = new BibTeX::Entry( entry ); + m_bibtexFile->completeReferencedFields( entry ); + + if ( entry->entryType() != BibTeX::Entry::etUnknown ) + setText( 0, BibTeX::Entry::entryTypeToString( entry->entryType() ) ); + else + setText( 0, entry->entryTypeString() ); + setText( 1, entry->id() ); + + for ( int i = 2; i < m_parent->columns(); i++ ) + { + BibTeX::EntryField::FieldType fieldType = ( BibTeX::EntryField::FieldType )( i - 2 + ( int ) BibTeX::EntryField::ftAbstract ); + BibTeX::EntryField *field = entry->getField( fieldType ); + BibTeX::Value *value = NULL; + if ( field != NULL && (( value = field->value() ) != NULL ) ) + setText( i, value->text().replace( '{', "" ).replace( '}', "" ).replace( '~', "" ) ); + else + setText( i, "" ); + } + + delete entry; + } + else + { + BibTeX::Comment *comment = dynamic_cast( m_element ); + if ( comment ) + { + setText( 0, i18n( "Comment" ) ); + QString text = comment->text(); + text.replace( '\n', ' ' ); + setText(( int ) BibTeX::EntryField::ftTitle - ( int ) BibTeX::EntryField::ftAbstract + 2, text ); + } + else + { + BibTeX::Macro * macro = dynamic_cast( m_element ); + if ( macro ) + { + setText( 0, i18n( "Macro" ) ); + setText( 1, macro->key() ); + BibTeX::Value *value = macro->value(); + int i = ( int ) BibTeX::EntryField::ftTitle - ( int ) BibTeX::EntryField::ftAbstract + 2; + if ( value ) + setText( i, macro->value() ->text() ); + else + setText( i, "" ); + } + else + { + BibTeX::Preamble *preamble = dynamic_cast( m_element ); + if ( preamble ) + { + setText( 0, i18n( "Preamble" ) ); + BibTeX::Value *value = preamble->value(); + int i = ( int ) BibTeX::EntryField::ftTitle - ( int ) BibTeX::EntryField::ftAbstract + 2; + if ( value ) + setText( i, preamble->value() ->text() ); + else + setText( i, "" ); + } + + } + } + } + } +} -- cgit v1.2.1