summaryrefslogtreecommitdiff
path: root/dldialog/src/DLD_QT/dld_listitem.cc
blob: 8a2ed6fae1ca27259e0b224c28fdae32a36ad688 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/******************************************************************************
**
** $Id: dld_listitem.cc,v 1.9 1999/09/13 13:24:07 harald Exp $
**
**	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.
**
******************************************************************************/
#include "dld_qtlib.h"
#include "dld_listitem.h"
#include <qpixmap.h>
#include <qpainter.h> 
#include <qwidget.h> 

#include <iostream.h>

DLD_QTListItem:: 
DLD_QTListItem (QWidget *, const string& name, DLD_QTDialog *pd):
   QListBoxText (), 
   DLD_QTObj (name, pd)
{
   QListBoxText::setText(dld_name.c_str());
#ifdef DEBUG
   DLDdbg << DLD_LIB_PREFIX "listitem ";
#endif
}

DLD_QTListItem::
~DLD_QTListItem ()
{
#ifdef DEBUG
   DLDdbg << DLD_LIB_PREFIX "listitem deleted\n";
#endif
}

void DLD_QTListItem::create () {
   if (imagestr.length() > 0 ) 
   {
      pm.load(imagestr.c_str());
      if(pm.isNull()) {
	 DLDerr << "image " << imagestr << _(" could not be loaded")
		<< endl << flush;
      }
   }
   DLD_Obj::create();

}

void DLD_QTListItem::paint( QPainter *p )
{  
   // store the old settings
   QPen oldpen(p->pen());
   QColor oldbg(p->backgroundColor ());
   QFont oldfont(p->font());
   if ( fontname.length() > 0 )
      p->setFont( QFont( fontname.c_str() , fontsize, false ));
   
   if (fg_color.length() > 0)
      p->setPen(QColor(fg_color.c_str()));

   if (bg_color.length() > 0)
      p->setBackgroundColor(QColor(bg_color.c_str()));

   if(!pm.isNull()) {
      p->drawPixmap( 0, 0, pm );
   }

   QFontMetrics fm = p->fontMetrics();
   int yPos;                       // vertical text position
   if ( pm.height() < fm.height() )
      yPos = fm.ascent() + fm.leading()/2;
   else
      yPos = pm.height()/2 - fm.height()/2 + fm.ascent();
   p->drawText( pm.width() + 5, yPos, text() );

   // restore the old settings
   p->setFont( oldfont );
   p->setPen(oldpen);
   p->setBackgroundColor(oldbg);
}

int DLD_QTListItem::height(const QListBox *lb ) const
{
   return QMAX( pm.height() + 1, lb->fontMetrics().lineSpacing() + 1 );
}

int DLD_QTListItem::width(const QListBox *lb ) const
{
   return pm.width() + lb->fontMetrics().width( text() ) + 6;
}