kexi

kexicomboboxdropdownbutton.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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)); //last chance to fix size
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     //<hack>
00074     if (qstricmp(style().name(),"thinkeramik")==0) {
00075         m_fixForHeight = 3;
00076     }
00077     else
00078         m_fixForHeight = 0;
00079     //</hack>
00080     m_drawComplexControl =
00081         (style().inherits("KStyle") && qstricmp(style().name(),"qtcurve")!=0)
00082         || qstricmp(style().name(),"platinum")==0;
00083     if (m_fixForHeight==0)
00084         setFixedWidth( style().querySubControlMetrics( QStyle::CC_ComboBox, 
00085             (const QWidget*)m_paintedCombo, QStyle::SC_ComboBoxArrow ).width() +1 );
00086     KPushButton::styleChange(oldStyle);
00087 }
KDE Home | KDE Accessibility Home | Description of Access Keys