kpushbutton.cpp Source File (kdeui Library)

| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kpushbutton.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
    00003
    00004     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 <kglobalsettings.h>
    00021 #include <qdragobject.h>
    00022 #include <kconfig.h>
    00023 #include <kglobal.h>
    00024 #include <kipc.h>
    00025 #include <kapplication.h>
    00026
    00027 #include "kpushbutton.h"
    00028
    00029 class KPushButton::KPushButtonPrivate
    00030 {
    00031 public:
    00032     KGuiItem item;
    00033 };
    00034
    00035 bool KPushButton::s_useIcons = false;
    00036
    00037 KPushButton::KPushButton( QWidget *parent, const char *name )
    00038     : QPushButton( parent, name ),
    00039       m_dragEnabled( false )
    00040 {
    00041     init( KGuiItem( "" ) );
    00042 }
    00043
    00044 KPushButton::KPushButton( const QString &text, QWidget *parent,
    00045                                   const char *name)
    00046     : QPushButton( parent, name ),
    00047       m_dragEnabled( false )
    00048 {
    00049     init( KGuiItem( text ) );
    00050 }
    00051
    00052 KPushButton::KPushButton( const QIconSet &icon, const QString &text,
    00053                                   QWidget *parent, const char *name )
    00054     : QPushButton( text, parent, name ),
    00055       m_dragEnabled( false )
    00056 {
    00057     init( KGuiItem( text, icon ) );
    00058 }
    00059
    00060 KPushButton::KPushButton( const KGuiItem &item, QWidget *parent,
    00061                           const char *name )
    00062     : QPushButton( parent, name ),
    00063       m_dragEnabled( false )
    00064 {
    00065     init( item );
    00066 }
    00067
    00068 KPushButton::~KPushButton()
    00069 {
    00070     if( d )
    00071     {
    00072         delete d;
    00073         d = 0L;
    00074     }
    00075 }
    00076
    00077 void KPushButton::init( const KGuiItem &item )
    00078 {
    00079     d = new KPushButtonPrivate;
    00080     d->item = item;
    00081     setText( item.text() );
    00082
    00083     static bool initialized = false;
    00084     if ( !initialized ) {
    00085         readSettings();
    00086         initialized = true;
    00087     }
    00088
    00089     if ( needIcons() )
    00090         setIconSet( d->item.iconSet() );
    00091
    00092     setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
    00093
    00094     if (kapp)
    00095     {
    00096        connect( kapp, SIGNAL( settingsChanged(int) ),
    00097                SLOT( slotSettingsChanged(int) ) );
    00098        kapp->addKipcEventMask( KIPC::SettingsChanged );
    00099     }
    00100 }
    00101
    00102 bool KPushButton::needIcons()
    00103 {
    00104     return s_useIcons && d->item.hasIconSet();
    00105 }
    00106
    00107 void KPushButton::readSettings()
    00108 {
    00109     KConfigGroup cg ( KGlobal::config(), "KDE" );
    00110     s_useIcons = cg.readBoolEntry( "ShowIconsOnPushButtons", false );
    00111 }
    00112
    00113 void KPushButton::setGuiItem( const KGuiItem& item )
    00114 {
    00115     d->item = item;
    00116     setText( item.text() );
    00117     if ( needIcons() )
    00118         setIconSet( d->item.iconSet() );
    00119 }
    00120
    00121 void KPushButton::slotSettingsChanged( int /* category */ )
    00122 {
    00123     readSettings();
    00124     if ( needIcons() )
    00125         setIconSet( d->item.iconSet() );
    00126     else
    00127         setIconSet( QIconSet() );
    00128 }
    00129
    00130 void KPushButton::setDragEnabled( bool enable )
    00131 {
    00132     m_dragEnabled = enable;
    00133 }
    00134
    00135 void KPushButton::mousePressEvent( QMouseEvent *e )
    00136 {
    00137     if ( m_dragEnabled )
    00138         startPos = e->pos();
    00139     QPushButton::mousePressEvent( e );
    00140 }
    00141
    00142 void KPushButton::mouseMoveEvent( QMouseEvent *e )
    00143 {
    00144     if ( !m_dragEnabled ) {
    00145         QPushButton::mouseMoveEvent( e );
    00146         return;
    00147     }
    00148
    00149     if ( (e->state() & LeftButton) &&
    00150          (e->pos() - startPos).manhattanLength() >
    00151          KGlobalSettings::dndEventDelay() ) {
    00152
    00153         startDrag();
    00154         setDown( false );
    00155     }
    00156 }
    00157
    00158 QDragObject * KPushButton::dragObject()
    00159 {
    00160     return 0L;
    00161 }
    00162
    00163 void KPushButton::startDrag()
    00164 {
    00165     QDragObject *d = dragObject();
    00166     if ( d )
    00167         d->dragCopy();
    00168 }
    00169
    00170 void KPushButton::virtual_hook( int, void* )
    00171 { /*BASE::virtual_hook( id, data );*/ }
    00172
    00173 #include "kpushbutton.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:35 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001