# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kpushbutton.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
    00003
    00004     This library 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 library 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 library; see the file COPYING.LIB.  If not, write to
    00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    00018 */
    00019
    00020 #include "kpushbutton.h"
    00021
    00022 #include <qdragobject.h>
    00023 #include <qwhatsthis.h>
    00024
    00025 #include "config.h"
    00026
    00027 #include <kglobalsettings.h>
    00028 #include <kconfig.h>
    00029 #include <kglobal.h>
    00030 #include <kipc.h>
    00031 #include <kapplication.h>
    00032
    00033 class KPushButton::KPushButtonPrivate
    00034 {
    00035 public:
    00036     KGuiItem item;
    00037     KStdGuiItem::StdItem itemType;
    00038 };
    00039
    00040 bool KPushButton::s_useIcons = false;
    00041
    00042 KPushButton::KPushButton( QWidget *parent, const char *name )
    00043     : QPushButton( parent, name ),
    00044       m_dragEnabled( false )
    00045 {
    00046     init( KGuiItem( "" ) );
    00047 }
    00048
    00049 KPushButton::KPushButton( const QString &text, QWidget *parent,
    00050                           const char *name)
    00051     : QPushButton( parent, name ),
    00052       m_dragEnabled( false )
    00053 {
    00054     init( KGuiItem( text ) );
    00055 }
    00056
    00057 KPushButton::KPushButton( const QIconSet &icon, const QString &text,
    00058                           QWidget *parent, const char *name )
    00059     : QPushButton( text, parent, name ),
    00060       m_dragEnabled( false )
    00061 {
    00062     init( KGuiItem( text, icon ) );
    00063 }
    00064
    00065 KPushButton::KPushButton( const KGuiItem &item, QWidget *parent,
    00066                           const char *name )
    00067     : QPushButton( parent, name ),
    00068       m_dragEnabled( false )
    00069 {
    00070     init( item );
    00071 }
    00072
    00073 KPushButton::~KPushButton()
    00074 {
    00075     if( d )
    00076     {
    00077         delete d;
    00078         d = 0L;
    00079     }
    00080 }
    00081
    00082 void KPushButton::init( const KGuiItem &item )
    00083 {
    00084     d = new KPushButtonPrivate;
    00085     d->item = item;
    00086     d->itemType = (KStdGuiItem::StdItem) 0;
    00087
    00088     // call QPushButton's implementation since we don't need to
    00089     // set the GUI items text or check the state of the icon set
    00090     QPushButton::setText( d->item.text() );
    00091
    00092     static bool initialized = false;
    00093     if ( !initialized ) {
    00094         readSettings();
    00095         initialized = true;
    00096     }
    00097
    00098     setIconSet( d->item.iconSet() );
    00099
    00100     setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
    00101
    00102     QWhatsThis::add( this, item.whatsThis() );
    00103
    00104     if (kapp)
    00105     {
    00106        connect( kapp, SIGNAL( settingsChanged(int) ),
    00107                SLOT( slotSettingsChanged(int) ) );
    00108        kapp->addKipcEventMask( KIPC::SettingsChanged );
    00109     }
    00110 }
    00111
    00112 void KPushButton::readSettings()
    00113 {
    00114     s_useIcons = KGlobalSettings::showIconsOnPushButtons();
    00115 }
    00116
    00117 void KPushButton::setGuiItem( const KGuiItem& item )
    00118 {
    00119     d->item = item;
    00120
    00121     // call QPushButton's implementation since we don't need to
    00122     // set the GUI items text or check the state of the icon set
    00123     QPushButton::setText( d->item.text() );
    00124     setIconSet( d->item.iconSet() );
    00125 }
    00126
    00127 void KPushButton::setGuiItem( KStdGuiItem::StdItem item )
    00128 {
    00129     setGuiItem( KStdGuiItem::guiItem(item) );
    00130     d->itemType = item;
    00131 }
    00132
    00133 KStdGuiItem::StdItem KPushButton::guiItem() const
    00134 {
    00135     return d->itemType;
    00136 }
    00137
    00138 void KPushButton::setText( const QString &text )
    00139 {
    00140     QPushButton::setText(text);
    00141
    00142     // we need to re-evaluate the icon set when the text
    00143     // is removed, or when it is supplied
    00144     if (text.isEmpty() != d->item.text().isEmpty())
    00145         setIconSet(d->item.iconSet());
    00146
    00147     d->item.setText(text);
    00148 }
    00149
    00150 void KPushButton::setIconSet( const QIconSet &iconSet )
    00151 {
    00152     d->item.setIconSet(iconSet);
    00153
    00154     if ( s_useIcons || text().isEmpty() )
    00155         QPushButton::setIconSet( iconSet );
    00156     else
    00157         QPushButton::setIconSet( QIconSet() );
    00158 }
    00159
    00160 void KPushButton::slotSettingsChanged( int /* category */ )
    00161 {
    00162     readSettings();
    00163     setIconSet( d->item.iconSet() );
    00164 }
    00165
    00166 void KPushButton::setDragEnabled( bool enable )
    00167 {
    00168     m_dragEnabled = enable;
    00169 }
    00170
    00171 void KPushButton::mousePressEvent( QMouseEvent *e )
    00172 {
    00173     if ( m_dragEnabled )
    00174     startPos = e->pos();
    00175     QPushButton::mousePressEvent( e );
    00176 }
    00177
    00178 void KPushButton::mouseMoveEvent( QMouseEvent *e )
    00179 {
    00180     if ( !m_dragEnabled )
    00181     {
    00182         QPushButton::mouseMoveEvent( e );
    00183         return;
    00184     }
    00185
    00186     if ( (e->state() & LeftButton) &&
    00187          (e->pos() - startPos).manhattanLength() >
    00188          KGlobalSettings::dndEventDelay() )
    00189     {
    00190         startDrag();
    00191         setDown( false );
    00192     }
    00193 }
    00194
    00195 QDragObject * KPushButton::dragObject()
    00196 {
    00197     return 0L;
    00198 }
    00199
    00200 void KPushButton::startDrag()
    00201 {
    00202     QDragObject *d = dragObject();
    00203     if ( d )
    00204     d->dragCopy();
    00205 }
    00206
    00207 void KPushButton::virtual_hook( int, void* )
    00208 { /*BASE::virtual_hook( id, data );*/ }
    00209
    00210 #include "kpushbutton.moc"

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:22 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003