kpushbutton.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kpushbutton.h"
00021
00022 #include <qdragobject.h>
00023 #include <qwhatsthis.h>
00024 #include <qtooltip.h>
00025
00026 #include "config.h"
00027
00028 #include <kglobalsettings.h>
00029 #include <kconfig.h>
00030 #include <kglobal.h>
00031 #include <kipc.h>
00032 #include <kapplication.h>
00033
00034 class KPushButton::KPushButtonPrivate
00035 {
00036 public:
00037 KGuiItem item;
00038 KStdGuiItem::StdItem itemType;
00039 };
00040
00041 bool KPushButton::s_useIcons = false;
00042
00043 KPushButton::KPushButton( QWidget *parent, const char *name )
00044 : QPushButton( parent, name ),
00045 m_dragEnabled( false )
00046 {
00047 init( KGuiItem( "" ) );
00048 }
00049
00050 KPushButton::KPushButton( const QString &text, QWidget *parent,
00051 const char *name)
00052 : QPushButton( parent, name ),
00053 m_dragEnabled( false )
00054 {
00055 init( KGuiItem( text ) );
00056 }
00057
00058 KPushButton::KPushButton( const QIconSet &icon, const QString &text,
00059 QWidget *parent, const char *name )
00060 : QPushButton( text, parent, name ),
00061 m_dragEnabled( false )
00062 {
00063 init( KGuiItem( text, icon ) );
00064 }
00065
00066 KPushButton::KPushButton( const KGuiItem &item, QWidget *parent,
00067 const char *name )
00068 : QPushButton( parent, name ),
00069 m_dragEnabled( false )
00070 {
00071 init( item );
00072 }
00073
00074 KPushButton::~KPushButton()
00075 {
00076 if( d )
00077 {
00078 delete d;
00079 d = 0L;
00080 }
00081 }
00082
00083 void KPushButton::init( const KGuiItem &item )
00084 {
00085 d = new KPushButtonPrivate;
00086 d->item = item;
00087 d->itemType = (KStdGuiItem::StdItem) 0;
00088
00089
00090
00091 QPushButton::setText( d->item.text() );
00092
00093 static bool initialized = false;
00094 if ( !initialized ) {
00095 readSettings();
00096 initialized = true;
00097 }
00098
00099 setIconSet( d->item.iconSet() );
00100
00101 setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
00102
00103 QToolTip::add( this, item.toolTip() );
00104
00105 QWhatsThis::add( this, item.whatsThis() );
00106
00107 if (kapp)
00108 {
00109 connect( kapp, SIGNAL( settingsChanged(int) ),
00110 SLOT( slotSettingsChanged(int) ) );
00111 kapp->addKipcEventMask( KIPC::SettingsChanged );
00112 }
00113 }
00114
00115 void KPushButton::readSettings()
00116 {
00117 s_useIcons = KGlobalSettings::showIconsOnPushButtons();
00118 }
00119
00120 void KPushButton::setGuiItem( const KGuiItem& item )
00121 {
00122 d->item = item;
00123
00124
00125
00126 QPushButton::setText( d->item.text() );
00127 setIconSet( d->item.iconSet() );
00128 QToolTip::add( this, d->item.toolTip() );
00129 QWhatsThis::add( this, d->item.whatsThis() );
00130 }
00131
00132 void KPushButton::setGuiItem( KStdGuiItem::StdItem item )
00133 {
00134 setGuiItem( KStdGuiItem::guiItem(item) );
00135 d->itemType = item;
00136 }
00137
00138 KStdGuiItem::StdItem KPushButton::guiItem() const
00139 {
00140 return d->itemType;
00141 }
00142
00143 void KPushButton::setText( const QString &text )
00144 {
00145 QPushButton::setText(text);
00146
00147
00148
00149 if (text.isEmpty() != d->item.text().isEmpty())
00150 setIconSet(d->item.iconSet());
00151
00152 d->item.setText(text);
00153 }
00154
00155 void KPushButton::setIconSet( const QIconSet &iconSet )
00156 {
00157 d->item.setIconSet(iconSet);
00158
00159 if ( s_useIcons || text().isEmpty() )
00160 QPushButton::setIconSet( iconSet );
00161 else
00162 QPushButton::setIconSet( QIconSet() );
00163 }
00164
00165 void KPushButton::slotSettingsChanged( int )
00166 {
00167 readSettings();
00168 setIconSet( d->item.iconSet() );
00169 }
00170
00171 void KPushButton::setDragEnabled( bool enable )
00172 {
00173 m_dragEnabled = enable;
00174 }
00175
00176 void KPushButton::mousePressEvent( QMouseEvent *e )
00177 {
00178 if ( m_dragEnabled )
00179 startPos = e->pos();
00180 QPushButton::mousePressEvent( e );
00181 }
00182
00183 void KPushButton::mouseMoveEvent( QMouseEvent *e )
00184 {
00185 if ( !m_dragEnabled )
00186 {
00187 QPushButton::mouseMoveEvent( e );
00188 return;
00189 }
00190
00191 if ( (e->state() & LeftButton) &&
00192 (e->pos() - startPos).manhattanLength() >
00193 KGlobalSettings::dndEventDelay() )
00194 {
00195 startDrag();
00196 setDown( false );
00197 }
00198 }
00199
00200 QDragObject * KPushButton::dragObject()
00201 {
00202 return 0L;
00203 }
00204
00205 void KPushButton::startDrag()
00206 {
00207 QDragObject *d = dragObject();
00208 if ( d )
00209 d->dragCopy();
00210 }
00211
00212 void KPushButton::virtual_hook( int, void* )
00213 { }
00214
00215 #include "kpushbutton.moc"
This file is part of the documentation for kdeui Library Version 3.4.2.