kexi
kexidropdownbutton.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexidropdownbutton.h"
00021
00022 #include <kpopupmenu.h>
00023 #include <kdebug.h>
00024
00025 #include <qstyle.h>
00026 #include <qapplication.h>
00027
00028 KexiDropDownButton::KexiDropDownButton(QWidget *parent)
00029 : QToolButton(parent, "KexiDBImageBox::Button")
00030 {
00031 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
00033
00034 int fixedWidth;
00035
00036 if (qstricmp(style().name(),"thinkeramik")==0)
00037 fixedWidth = 18;
00038 else
00039 fixedWidth = style().querySubControlMetrics( QStyle::CC_ComboBox,
00040 this, QStyle::SC_ComboBoxArrow ).width();
00041 setFixedWidth( fixedWidth );
00042 setPopupDelay(10);
00043 }
00044
00045 KexiDropDownButton::~KexiDropDownButton()
00046 {
00047 }
00048
00049 void KexiDropDownButton::drawButton( QPainter *p )
00050 {
00051 QToolButton::drawButton(p);
00052 QStyle::SFlags arrowFlags = QStyle::Style_Default;
00053 if (isDown() || state()==On)
00054 arrowFlags |= QStyle::Style_Down;
00055 if (isEnabled())
00056 arrowFlags |= QStyle::Style_Enabled;
00057 style().drawPrimitive(QStyle::PE_ArrowDown, p,
00058 QRect((width()-7)/2, height()-9, 7, 7), colorGroup(),
00059 arrowFlags, QStyleOption() );
00060 }
00061
00062 QSize KexiDropDownButton::sizeHint () const
00063 {
00064 return QSize( fontMetrics().maxWidth() + 2*2, fontMetrics().height()*2 + 2*2 );
00065 }
00066
00067 void KexiDropDownButton::keyPressEvent( QKeyEvent * e )
00068 {
00069 const int k = e->key();
00070 const bool dropDown = (e->state() == Qt::NoButton && (k==Qt::Key_Space || k==Qt::Key_Enter || k==Qt::Key_Return || k==Qt::Key_F2 || k==Qt::Key_F4))
00071 || (e->state() == Qt::AltButton && k==Qt::Key_Down);
00072 if (dropDown) {
00073 e->accept();
00074 animateClick();
00075 QMouseEvent me( QEvent::MouseButtonPress, QPoint(2,2), Qt::LeftButton, Qt::NoButton );
00076 QApplication::sendEvent( this, &me );
00077 return;
00078 }
00079 QToolButton::keyPressEvent(e);
00080 }
00081
00082 #include "kexidropdownbutton.moc"
|