kexi

kexidropdownbutton.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 "kexidropdownbutton.h"
21
22#include <tdepopupmenu.h>
23#include <kdebug.h>
24
25#include <tqstyle.h>
26#include <tqapplication.h>
27
29 : TQToolButton(parent, "KexiDBImageBox::Button")
30{
31 setSizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Expanding);
33// setFixedWidth(TQMAX(18, tqApp->globalStrut().width()));
34 int fixedWidth;
35 //hack
36 if (tqstricmp(style().name(),"thinkeramik")==0)
37 fixedWidth = 18; //typical width as in "windows" style
38 else
39 fixedWidth = style().querySubControlMetrics( TQStyle::CC_ComboBox,
40 this, TQStyle::SC_ComboBoxArrow ).width();
41 setFixedWidth( fixedWidth );
42 setPopupDelay(10/*ms*/);
43}
44
45KexiDropDownButton::~KexiDropDownButton()
46{
47}
48
49void KexiDropDownButton::drawButton( TQPainter *p )
50{
51 TQToolButton::drawButton(p);
52 TQStyle::SFlags arrowFlags = TQStyle::Style_Default;
53 if (isDown() || state()==On)
54 arrowFlags |= TQStyle::Style_Down;
55 if (isEnabled())
56 arrowFlags |= TQStyle::Style_Enabled;
57 style().drawPrimitive(TQStyle::PE_ArrowDown, p,
58 TQRect((width()-7)/2, height()-9, 7, 7), colorGroup(),
59 arrowFlags, TQStyleOption() );
60}
61
62TQSize KexiDropDownButton::sizeHint () const
63{
64 return TQSize( fontMetrics().maxWidth() + 2*2, fontMetrics().height()*2 + 2*2 );
65}
66
67void KexiDropDownButton::keyPressEvent( TQKeyEvent * e )
68{
69 const int k = e->key();
70 const bool dropDown = (e->state() == TQt::NoButton && (k==TQt::Key_Space || k==TQt::Key_Enter || k==TQt::Key_Return || k==TQt::Key_F2 || k==TQt::Key_F4))
71 || (e->state() == TQt::AltButton && k==TQt::Key_Down);
72 if (dropDown) {
73 e->accept();
74 animateClick();
75 TQMouseEvent me( TQEvent::MouseButtonPress, TQPoint(2,2), TQt::LeftButton, TQt::NoButton );
76 TQApplication::sendEvent( this, &me );
77 return;
78 }
79 TQToolButton::keyPressEvent(e);
80}
81
82#include "kexidropdownbutton.moc"
KexiDropDownButton(TQWidget *parent)