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
00025 #include "config.h"
00026 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00027 #include <kipc.h>
00028 #endif
00029
00030 #include <kapplication.h>
00031
00032 #include "kpushbutton.h"
00033
00034 class KPushButton::KPushButtonPrivate
00035 {
00036 public:
00037 KGuiItem item;
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
00087
00088
00089 QPushButton::setText( d->item.text() );
00090
00091 static bool initialized = false;
00092 if ( !initialized ) {
00093 readSettings();
00094 initialized = true;
00095 }
00096
00097 setIconSet( d->item.iconSet() );
00098
00099 setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
00100
00101 if (kapp)
00102 {
00103 connect( kapp, SIGNAL( settingsChanged(int) ),
00104 SLOT( slotSettingsChanged(int) ) );
00105 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00106 kapp->addKipcEventMask( KIPC::SettingsChanged );
00107 #endif
00108 }
00109 }
00110
00111 void KPushButton::readSettings()
00112 {
00113 s_useIcons = KGlobalSettings::showIconsOnPushButtons();
00114 }
00115
00116 void KPushButton::setGuiItem( const KGuiItem& item )
00117 {
00118 d->item = item;
00119
00120
00121
00122 QPushButton::setText( d->item.text() );
00123 setIconSet( d->item.iconSet() );
00124 }
00125
00126 void KPushButton::setText( const QString &text )
00127 {
00128 QPushButton::setText(text);
00129
00130
00131
00132 if (text.isEmpty() != d->item.text().isEmpty())
00133 setIconSet(d->item.iconSet());
00134
00135 d->item.setText(text);
00136 }
00137
00138 void KPushButton::setIconSet( const QIconSet &iconSet )
00139 {
00140 d->item.setIconSet(iconSet);
00141
00142 if ( s_useIcons || text().isEmpty() )
00143 QPushButton::setIconSet( iconSet );
00144 else
00145 QPushButton::setIconSet( QIconSet() );
00146 }
00147
00148 void KPushButton::slotSettingsChanged( int )
00149 {
00150 readSettings();
00151 setIconSet( d->item.iconSet() );
00152 }
00153
00154 void KPushButton::setDragEnabled( bool enable )
00155 {
00156 m_dragEnabled = enable;
00157 }
00158
00159 void KPushButton::mousePressEvent( QMouseEvent *e )
00160 {
00161 if ( m_dragEnabled )
00162 startPos = e->pos();
00163 QPushButton::mousePressEvent( e );
00164 }
00165
00166 void KPushButton::mouseMoveEvent( QMouseEvent *e )
00167 {
00168 if ( !m_dragEnabled )
00169 {
00170 QPushButton::mouseMoveEvent( e );
00171 return;
00172 }
00173
00174 if ( (e->state() & LeftButton) &&
00175 (e->pos() - startPos).manhattanLength() >
00176 KGlobalSettings::dndEventDelay() )
00177 {
00178 startDrag();
00179 setDown( false );
00180 }
00181 }
00182
00183 QDragObject * KPushButton::dragObject()
00184 {
00185 return 0L;
00186 }
00187
00188 void KPushButton::startDrag()
00189 {
00190 QDragObject *d = dragObject();
00191 if ( d )
00192 d->dragCopy();
00193 }
00194
00195 void KPushButton::virtual_hook( int, void* )
00196 { }
00197
00198 #include "kpushbutton.moc"
This file is part of the documentation for kdeui Library Version 3.3.2.