ResultListItem.cpp

Go to the documentation of this file.
00001 #include "ResultListItem.h"
00002 
00003 ResultListItem::ResultListItem( QListView* parent, Term* term, const QString& firstLanguage, const QString& testLanguage, const QString& vocabTitle, const QString& location, bool isAltShown = true )
00004     : QListViewItem( parent ), term( term ), firstLanguage( firstLanguage ), testLanguage( testLanguage ), 
00005         vocabTitle( vocabTitle ), location( location ), altShown( isAltShown ) {
00006     updateUi();
00007 }
00008 
00009 ResultListItem::~ResultListItem() {
00010 }
00011 
00012 void ResultListItem::setup() {
00013     int rowHeight = QFontMetrics( listView()->font() ).height();
00014     QFontMetrics firstLangFontMetrics( font( 0 ) );
00015     if( firstLangFontMetrics.height() > rowHeight )
00016         rowHeight = firstLangFontMetrics.height();
00017     QFontMetrics testLangFontMetrics( font( 1 ) );
00018     if( testLangFontMetrics.height() > rowHeight )
00019         rowHeight = testLangFontMetrics.height();
00020     setHeight( rowHeight );
00021 }
00022 
00023 void ResultListItem::updateUi() {
00024     if( term ) {
00025         if( term->isTranslationExists( firstLanguage ) ) {
00026             const Translation& firstLangTranslation = term->getTranslation( firstLanguage );
00027             setText( 0, firstLangTranslation.getWord() );
00028         }
00029         else
00030             setText( 0, QObject::tr( "Undefined" ) );
00031 
00032         if( term->isTranslationExists( testLanguage ) ) {
00033             const Translation& testLangTranslation = term->getTranslation( testLanguage );
00034             QString testLangStr = testLangTranslation.getWord(); 
00035             if( altShown && testLangTranslation.getAlt().length() > 0 )
00036                 testLangStr += " [" + testLangTranslation.getAlt() + "]";
00037             setText( 1, testLangStr );
00038         }
00039         else
00040             setText( 1, QObject::tr( "Undefined" ) );
00041 
00042         setText( 2, vocabTitle );
00043         setText( 3, location );
00044     }
00045 }
00046 
00047 Term* ResultListItem::getTerm() {
00048     return( term );
00049 }
00050 
00051 void ResultListItem::setFont( int column, const QFont& font ) {
00052     fonts[ column ] = font;
00053 }
00054 
00055 QFont ResultListItem::font( int column ) const {
00056     if( fonts.contains( column ) )
00057         return( fonts[ column ] );
00058     else
00059         return( listView()->font() );
00060 }
00061 
00062 void ResultListItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align ) {
00063     if( !p )
00064         return;
00065 
00066     QFont oldFont = p->font();
00067     p->setFont( font( column ) );
00068 
00069     QColorGroup colorGroup( cg );
00070     switch( column ) {
00071         case 0 : 
00072             if( term && !term->isTranslationExists( firstLanguage ) )
00073                 colorGroup.setColor( QColorGroup::Text, listView()->palette().color( QPalette::Disabled, QColorGroup::Text ) );
00074             break;
00075 
00076         case 1 :
00077             if( term && !term->isTranslationExists( testLanguage ) )
00078                 colorGroup.setColor( QColorGroup::Text, listView()->palette().color( QPalette::Disabled, QColorGroup::Text ) );
00079             break;
00080     }
00081 
00082     QListViewItem::paintCell( p, colorGroup, column, width, align );
00083 
00084     p->setFont( oldFont );
00085 }

Generated on Sun Mar 1 17:30:47 2009 for toMOTko by  doxygen 1.5.6