kpushbutton.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 )
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 { }
00172
00173 #include "kpushbutton.moc"
This file is part of the documentation for kdelibs Version 3.1.5.