kexicomboboxdropdownbutton.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexicomboboxdropdownbutton.h"
21
22#include <tdepopupmenu.h>
23#include <kdebug.h>
24#include <kcombobox.h>
25
26#include <tqstyle.h>
27#include <tqapplication.h>
28
29KexiComboBoxDropDownButton::KexiComboBoxDropDownButton( TQWidget *parent )
30 : KPushButton(parent)
31{
32 m_paintedCombo = new KComboBox(this);
33 m_paintedCombo->hide();
34 m_paintedCombo->setEditable(true);
35
36 setToggleButton(true);
37 styleChange(style());
38 m_paintedCombo->move(0,0);
39 m_paintedCombo->setFixedSize(size());
40}
41
42KexiComboBoxDropDownButton::~KexiComboBoxDropDownButton()
43{
44}
45
47{
48 int flags = TQStyle::Style_Enabled | TQStyle::Style_HasFocus;
49 if (isDown())
50 flags |= TQStyle::Style_Down;
51
52 KPushButton::drawButton(p);
53
54 TQRect r = rect();
55 r.setHeight(r.height()+m_fixForHeight);
56 if (m_drawComplexControl) {
57 if (m_fixForHeight>0 && m_paintedCombo->size()!=size()) {
58 m_paintedCombo->move(0,0);
59 m_paintedCombo->setFixedSize(size()+TQSize(0, m_fixForHeight)); //last chance to fix size
60 }
61 style().drawComplexControl( TQStyle::CC_ComboBox, p,
62 m_fixForHeight>0 ? (const TQWidget*)m_paintedCombo : this, r, colorGroup(),
63 flags, (uint)(TQStyle::SC_ComboBoxArrow), TQStyle::SC_None );
64 }
65 else {
66 r.setWidth(r.width()+2);
67 style().drawPrimitive( TQStyle::PE_ArrowDown, p, r, colorGroup(), flags);
68 }
69}
70
72{
73 //<hack>
74 if (tqstricmp(style().name(),"thinkeramik")==0) {
75 m_fixForHeight = 3;
76 }
77 else
78 m_fixForHeight = 0;
79 //</hack>
80 m_drawComplexControl =
81 (style().inherits("TDEStyle") && tqstricmp(style().name(),"qtcurve")!=0)
82 || tqstricmp(style().name(),"platinum")==0;
83 if (m_fixForHeight==0)
84 setFixedWidth( style().querySubControlMetrics( TQStyle::CC_ComboBox,
85 (const TQWidget*)m_paintedCombo, TQStyle::SC_ComboBoxArrow ).width() +1 );
86 KPushButton::styleChange(oldStyle);
87}
virtual void styleChange(TQStyle &oldStyle)
KComboBox * m_paintedCombo
fake combo used only to pass it as 'this' for TQStyle (because styles use <static_cast>)
virtual void drawButton(TQPainter *p)