kexi
kexicomboboxdropdownbutton.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexicomboboxdropdownbutton.h"
00021
00022 #include <kpopupmenu.h>
00023 #include <kdebug.h>
00024 #include <kcombobox.h>
00025
00026 #include <qstyle.h>
00027 #include <qapplication.h>
00028
00029 KexiComboBoxDropDownButton::KexiComboBoxDropDownButton( QWidget *parent )
00030 : KPushButton(parent)
00031 {
00032 m_paintedCombo = new KComboBox(this);
00033 m_paintedCombo->hide();
00034 m_paintedCombo->setEditable(true);
00035
00036 setToggleButton(true);
00037 styleChange(style());
00038 m_paintedCombo->move(0,0);
00039 m_paintedCombo->setFixedSize(size());
00040 }
00041
00042 KexiComboBoxDropDownButton::~KexiComboBoxDropDownButton()
00043 {
00044 }
00045
00046 void KexiComboBoxDropDownButton::drawButton(QPainter *p)
00047 {
00048 int flags = QStyle::Style_Enabled | QStyle::Style_HasFocus;
00049 if (isDown())
00050 flags |= QStyle::Style_Down;
00051
00052 KPushButton::drawButton(p);
00053
00054 QRect r = rect();
00055 r.setHeight(r.height()+m_fixForHeight);
00056 if (m_drawComplexControl) {
00057 if (m_fixForHeight>0 && m_paintedCombo->size()!=size()) {
00058 m_paintedCombo->move(0,0);
00059 m_paintedCombo->setFixedSize(size()+QSize(0, m_fixForHeight));
00060 }
00061 style().drawComplexControl( QStyle::CC_ComboBox, p,
00062 m_fixForHeight>0 ? (const QWidget*)m_paintedCombo : this, r, colorGroup(),
00063 flags, (uint)(QStyle::SC_ComboBoxArrow), QStyle::SC_None );
00064 }
00065 else {
00066 r.setWidth(r.width()+2);
00067 style().drawPrimitive( QStyle::PE_ArrowDown, p, r, colorGroup(), flags);
00068 }
00069 }
00070
00071 void KexiComboBoxDropDownButton::styleChange( QStyle & oldStyle )
00072 {
00073
00074 if (qstricmp(style().name(),"thinkeramik")==0) {
00075 m_fixForHeight = 3;
00076 }
00077 else
00078 m_fixForHeight = 0;
00079
00080 m_drawComplexControl = style().inherits("KStyle")
00081 || qstricmp(style().name(),"platinum")==0;
00082 if (m_fixForHeight==0)
00083 setFixedWidth( style().querySubControlMetrics( QStyle::CC_ComboBox,
00084 (const QWidget*)m_paintedCombo, QStyle::SC_ComboBoxArrow ).width() +1 );
00085 KPushButton::styleChange(oldStyle);
00086 }
|