00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "tkcombobox.h"
00020
00021 #include <qlistbox.h>
00022 #include <qpainter.h>
00023 #include <qstyle.h>
00024 #include <qdrawutil.h>
00025
00026 #include <kapplication.h>
00027
00028 TKComboBox::TKComboBox(QWidget* parent, const char* name)
00029 : QComboBox(false,parent,name)
00030 {
00031 }
00032
00033
00034 TKComboBox::TKComboBox( bool isEditable, QWidget* parent, const char* name )
00035 : QComboBox(isEditable,parent,name)
00036 {
00037 }
00038
00039 TKComboBox::~TKComboBox()
00040 {
00041 }
00042
00043 void TKComboBox::paintEvent(QPaintEvent*)
00044 {
00045 QRect r;
00046 if (editable()){
00047 #ifdef __GNUC__
00048 #warning "Left out for now, lacking a style expert (Werner)"
00049 #endif
00050
00051 r = QRect(4, 2, width()-height()-2, height()-4);
00052 } else {
00053 r = QRect(4, 2, width()-height()-2, height()-4);
00054 }
00055 int by = 2;
00056 int bx = r.x() + r.width();
00057 int bw = width() - bx - 2;
00058 int bh = height()-4;
00059
00060 QPainter p( this );
00061 const QColorGroup& g = colorGroup();
00062
00063 QRect fr(2,2,width()-4,height()-4);
00064
00065 if ( hasFocus()) {
00066 p.fillRect( fr, g.brush( QColorGroup::Highlight ) );
00067 } else {
00068 p.fillRect( fr, g.brush( QColorGroup::Base ) );
00069 }
00070
00071 QRect r1(1,1,width()-1,height()-1);
00072 qDrawShadePanel( &p, r1, g, true, 1 );
00073
00074 static const char* arrow_down[] = {
00075 "7 7 2 1",
00076 "X c Gray0",
00077 " c None",
00078 "XXXXXXX",
00079 "XXXXXXX",
00080 " ",
00081 "XXXXXXX",
00082 " XXXXX ",
00083 " XXX ",
00084 " X "};
00085
00086 QPixmap pixmap(arrow_down);
00087
00088
00089 style().drawControl( QStyle::CE_PushButton, &p, this, QRect( bx, by, bw, bh ), colorGroup() );
00090 style().drawItem( &p, QRect( bx, by, bw, bh), AlignCenter, colorGroup(), isEnabled(), &pixmap, QString::null );
00091
00092 if ( hasFocus()) {
00093 style().drawPrimitive( QStyle::PE_FocusRect, &p, fr, g );
00094 }
00095
00096 if (!editable()) {
00097 p.setClipRect(r);
00098 p.setPen( g.text() );
00099 p.setBackgroundColor( g.background() );
00100
00101 if ( listBox()->item(currentItem()) ) {
00102 QListBoxItem * item = listBox()->item(currentItem());
00103 const QPixmap *pix = item->pixmap();
00104 QString text = item->text();
00105 int x = r.x();
00106 if ( pix ) {
00107 p.drawPixmap( x, r.y() + ( r.height() - pix->height() ) / 2 +1, *pix );
00108 x += pix->width()+3;
00109 }
00110 if (!text.isEmpty())
00111 p.drawText( x, r.y(), r.width()-x, r.height(), AlignLeft|AlignVCenter|SingleLine, text );
00112 }
00113 }
00114 p.end();
00115 }
00116
00117 void TKComboBox::activate()
00118 {
00119 emit activated(currentItem());
00120 }
00121
00122 #include "tkcombobox.moc"