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