lib

tkcombobox.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000 theKompany.com
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20#include "tkcombobox.h"
21
22#include <tqlistbox.h>
23#include <tqpainter.h>
24#include <tqstyle.h>
25#include <tqdrawutil.h>
26
27#include <tdeapplication.h>
28
29TKComboBox::TKComboBox(TQWidget* parent, const char* name)
30: TQComboBox(false,parent,name)
31{
32}
33
34
35TKComboBox::TKComboBox( bool isEditable, TQWidget* parent, const char* name )
36: TQComboBox(isEditable,parent,name)
37{
38}
39
40TKComboBox::~TKComboBox()
41{
42}
43
44void TKComboBox::paintEvent(TQPaintEvent*)
45{
46 TQRect r;
47 if (editable()){
48#ifdef __GNUC__
49#warning "Left out for now, lacking a style expert (Werner)"
50#endif
51 //r = TQRect( style().comboButtonRect( 0, 0, width(), height() ) );
52 r = TQRect(4, 2, width()-height()-2, height()-4);
53 } else {
54 r = TQRect(4, 2, width()-height()-2, height()-4);
55 }
56 int by = 2;
57 int bx = r.x() + r.width();
58 int bw = width() - bx - 2;
59 int bh = height()-4;
60
61 TQPainter p( this );
62 const TQColorGroup& g = colorGroup();
63
64 TQRect fr(2,2,width()-4,height()-4);
65
66 if ( hasFocus()) {
67 p.fillRect( fr, g.brush( TQColorGroup::Highlight ) );
68 } else {
69 p.fillRect( fr, g.brush( TQColorGroup::Base ) );
70 }
71
72 TQRect r1(1,1,width()-1,height()-1);
73 qDrawShadePanel( &p, r1, g, true, 1 );
74
75 static const char* arrow_down[] = {
76 "7 7 2 1",
77 "X c Gray0",
78 " c None",
79 "XXXXXXX",
80 "XXXXXXX",
81 " ",
82 "XXXXXXX",
83 " XXXXX ",
84 " XXX ",
85 " X "};
86
87 TQPixmap pixmap(arrow_down);
88
89
90 style().drawControl( TQStyle::CE_PushButton, &p, this, TQRect( bx, by, bw, bh ), colorGroup() );
91 style().drawItem( &p, TQRect( bx, by, bw, bh), AlignCenter, colorGroup(), isEnabled(), &pixmap, TQString() );
92
93 if ( hasFocus()) {
94 style().drawPrimitive( TQStyle::PE_FocusRect, &p, fr, g );
95 }
96
97 if (!editable()) {
98 p.setClipRect(r);
99 p.setPen( g.text() );
100 p.setBackgroundColor( g.background() );
101
102 if ( listBox()->item(currentItem()) ) {
103 TQListBoxItem * item = listBox()->item(currentItem());
104 const TQPixmap *pix = item->pixmap();
105 TQString text = item->text();
106 int x = r.x();
107 if ( pix ) {
108 p.drawPixmap( x, r.y() + ( r.height() - pix->height() ) / 2 +1, *pix );
109 x += pix->width()+3;
110 }
111 if (!text.isEmpty())
112 p.drawText( x, r.y(), r.width()-x, r.height(), AlignLeft|AlignVCenter|SingleLine, text );
113 }
114 }
115 p.end();
116}
117
118void TKComboBox::activate()
119{
120 emit activated(currentItem());
121}
122
123#include "tkcombobox.moc"
const char * name(StdAction id)