00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
#include "config.h"
00019
00020
#include <qtimer.h>
00021
00022
#include <kglobalsettings.h>
00023
#include <kcursor.h>
00024
#include <kapplication.h>
00025
#include <kipc.h>
00026
#include <kdebug.h>
00027
00028
#include "klistbox.h"
00029
00030 KListBox::KListBox(
QWidget *parent,
const char *name, WFlags f )
00031 :
QListBox( parent,
name, f ), d(0)
00032 {
00033 connect(
this, SIGNAL( onViewport() ),
00034
this, SLOT( slotOnViewport() ) );
00035 connect(
this, SIGNAL( onItem(
QListBoxItem * ) ),
00036
this, SLOT( slotOnItem(
QListBoxItem * ) ) );
00037 slotSettingsChanged(KApplication::SETTINGS_MOUSE);
00038
if (kapp)
00039 {
00040 connect( kapp, SIGNAL( settingsChanged(
int) ), SLOT( slotSettingsChanged(
int) ) );
00041 kapp->addKipcEventMask( KIPC::SettingsChanged );
00042 }
00043
00044 m_pCurrentItem = 0L;
00045
00046 m_pAutoSelect =
new QTimer(
this );
00047 connect( m_pAutoSelect, SIGNAL( timeout() ),
00048
this, SLOT( slotAutoSelect() ) );
00049 }
00050
00051
void KListBox::slotOnItem(
QListBoxItem *item )
00052 {
00053
if ( item && m_bChangeCursorOverItem && m_bUseSingle )
00054 viewport()->setCursor(
KCursor().handCursor() );
00055
00056
if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
00057 m_pAutoSelect->
start( m_autoSelectDelay,
true );
00058 m_pCurrentItem = item;
00059 }
00060 }
00061
00062
void KListBox::slotOnViewport()
00063 {
00064
if ( m_bChangeCursorOverItem )
00065 viewport()->unsetCursor();
00066
00067 m_pAutoSelect->
stop();
00068 m_pCurrentItem = 0L;
00069 }
00070
00071
00072
void KListBox::slotSettingsChanged(
int category)
00073 {
00074
if (category != KApplication::SETTINGS_MOUSE)
00075
return;
00076 m_bUseSingle =
KGlobalSettings::singleClick();
00077
00078 disconnect(
this, SIGNAL(
mouseButtonClicked(
int,
QListBoxItem *,
00079
const QPoint & ) ),
00080
this, SLOT( slotMouseButtonClicked(
int,
QListBoxItem *,
00081
const QPoint & ) ) );
00082
00083
00084
00085
00086
00087
if( m_bUseSingle )
00088 {
00089 connect(
this, SIGNAL(
mouseButtonClicked(
int,
QListBoxItem *,
00090
const QPoint & ) ),
00091
this, SLOT( slotMouseButtonClicked(
int,
QListBoxItem *,
00092
const QPoint & ) ) );
00093 }
00094
else
00095 {
00096
00097
00098
00099
00100 }
00101
00102 m_bChangeCursorOverItem =
KGlobalSettings::changeCursorOverIcon();
00103 m_autoSelectDelay =
KGlobalSettings::autoSelectDelay();
00104
00105
if( !m_bUseSingle || !m_bChangeCursorOverItem )
00106 viewport()->unsetCursor();
00107 }
00108
00109 void KListBox::slotAutoSelect()
00110 {
00111
00112
if( index( m_pCurrentItem ) == -1 )
00113
return;
00114
00115
00116
if( !hasFocus() )
00117 setFocus();
00118
00119 ButtonState keybstate =
KApplication::keyboardMouseState();
00120
00121
QListBoxItem* previousItem = item(
currentItem() );
00122 setCurrentItem( m_pCurrentItem );
00123
00124
if( m_pCurrentItem ) {
00125
00126
if( (keybstate & ShiftButton) ) {
00127
bool block = signalsBlocked();
00128 blockSignals(
true );
00129
00130
00131
if( !(keybstate & ControlButton) )
00132
clearSelection();
00133
00134
bool select = !m_pCurrentItem->
isSelected();
00135
bool update = viewport()->isUpdatesEnabled();
00136 viewport()->setUpdatesEnabled(
false );
00137
00138
bool down = index( previousItem ) < index( m_pCurrentItem );
00139
QListBoxItem* it = down ? previousItem : m_pCurrentItem;
00140
for (;it ; it = it->
next() ) {
00141
if ( down && it == m_pCurrentItem ) {
00142 setSelected( m_pCurrentItem, select );
00143
break;
00144 }
00145
if ( !down && it == previousItem ) {
00146 setSelected( previousItem, select );
00147
break;
00148 }
00149 setSelected( it, select );
00150 }
00151
00152 blockSignals( block );
00153 viewport()->setUpdatesEnabled( update );
00154 triggerUpdate(
false );
00155
00156 emit
selectionChanged();
00157
00158
if(
selectionMode() == QListBox::Single )
00159 emit
selectionChanged( m_pCurrentItem );
00160 }
00161
else if( (keybstate & ControlButton) )
00162 setSelected( m_pCurrentItem, !m_pCurrentItem->
isSelected() );
00163
else {
00164
bool block = signalsBlocked();
00165 blockSignals(
true );
00166
00167
if( !m_pCurrentItem->
isSelected() )
00168
clearSelection();
00169
00170 blockSignals( block );
00171
00172 setSelected( m_pCurrentItem,
true );
00173 }
00174 }
00175
else
00176
kdDebug() <<
"Thatīs not supposed to happen!!!!" <<
endl;
00177 }
00178
00179
void KListBox::emitExecute(
QListBoxItem *item,
const QPoint &pos )
00180 {
00181 ButtonState keybstate =
KApplication::keyboardMouseState();
00182
00183 m_pAutoSelect->
stop();
00184
00185
00186
if( !( m_bUseSingle && ((keybstate & ShiftButton) || (keybstate & ControlButton)) ) ) {
00187 emit executed( item );
00188 emit executed( item, pos );
00189 }
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
void KListBox::keyPressEvent(
QKeyEvent *e)
00200 {
00201
if( e->
key() == Key_Escape )
00202 {
00203 e->
ignore();
00204 }
00205
else if( e->
key() == Key_F1 )
00206 {
00207 e->
ignore();
00208 }
00209
else
00210 {
00211 QListBox::keyPressEvent(e);
00212 }
00213 }
00214
00215
void KListBox::focusOutEvent(
QFocusEvent *fe )
00216 {
00217 m_pAutoSelect->
stop();
00218
00219 QListBox::focusOutEvent( fe );
00220 }
00221
00222
void KListBox::leaveEvent(
QEvent *e )
00223 {
00224 m_pAutoSelect->
stop();
00225
00226 QListBox::leaveEvent( e );
00227 }
00228
00229
void KListBox::contentsMousePressEvent(
QMouseEvent *e )
00230 {
00231
if( (
selectionMode() == Extended) && (e->
state() & ShiftButton) && !(e->
state() & ControlButton) ) {
00232
bool block = signalsBlocked();
00233 blockSignals(
true );
00234
00235
clearSelection();
00236
00237 blockSignals( block );
00238 }
00239
00240 QListBox::contentsMousePressEvent( e );
00241 }
00242
00243
void KListBox::contentsMouseDoubleClickEvent (
QMouseEvent * e )
00244 {
00245 QListBox::contentsMouseDoubleClickEvent( e );
00246
00247
QListBoxItem* item =
itemAt( e->
pos() );
00248
00249
if( item ) {
00250 emit
doubleClicked( item, e->
globalPos() );
00251
00252
if( (e->
button() == LeftButton) && !m_bUseSingle )
00253 emitExecute( item, e->
globalPos() );
00254 }
00255 }
00256
00257
void KListBox::slotMouseButtonClicked(
int btn,
QListBoxItem *item,
const QPoint &pos )
00258 {
00259
if( (btn == LeftButton) && item )
00260 emitExecute( item, pos );
00261 }
00262
00263
void KListBox::virtual_hook(
int,
void* )
00264 { }
00265
00266
#include "klistbox.moc"