lib Library API Documentation

tkcombobox.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000 theKompany.com
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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     //r = QRect( style().comboButtonRect( 0, 0, width(), height() ) );
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"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 11 11:47:46 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003