22 #include <tdeglobalsettings.h>
24 #include <tdeapplication.h>
28 #include "tdelistbox.h"
30 TDEListBox::TDEListBox( TQWidget *parent,
const char *name, WFlags f )
31 : TQListBox( parent,
name, f ), d(0)
33 connect(
this, TQ_SIGNAL( onViewport() ),
34 this, TQ_SLOT( slotOnViewport() ) );
35 connect(
this, TQ_SIGNAL( onItem( TQListBoxItem * ) ),
36 this, TQ_SLOT( slotOnItem( TQListBoxItem * ) ) );
37 slotSettingsChanged(TDEApplication::SETTINGS_MOUSE);
40 connect( kapp, TQ_SIGNAL( settingsChanged(
int) ), TQ_SLOT( slotSettingsChanged(
int) ) );
41 kapp->addKipcEventMask( KIPC::SettingsChanged );
46 m_pAutoSelect =
new TQTimer(
this );
47 connect( m_pAutoSelect, TQ_SIGNAL( timeout() ),
48 this, TQ_SLOT( slotAutoSelect() ) );
51 void TDEListBox::slotOnItem( TQListBoxItem *item )
53 if ( item && m_bChangeCursorOverItem && m_bUseSingle )
54 viewport()->setCursor(
KCursor().handCursor() );
56 if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
57 m_pAutoSelect->start( m_autoSelectDelay,
true );
58 m_pCurrentItem = item;
62 void TDEListBox::slotOnViewport()
64 if ( m_bChangeCursorOverItem )
65 viewport()->unsetCursor();
67 m_pAutoSelect->stop();
72 void TDEListBox::slotSettingsChanged(
int category)
74 if (category != TDEApplication::SETTINGS_MOUSE)
78 disconnect(
this, TQ_SIGNAL( mouseButtonClicked(
int, TQListBoxItem *,
80 this, TQ_SLOT( slotMouseButtonClicked(
int, TQListBoxItem *,
81 const TQPoint & ) ) );
89 connect(
this, TQ_SIGNAL( mouseButtonClicked(
int, TQListBoxItem *,
91 this, TQ_SLOT( slotMouseButtonClicked(
int, TQListBoxItem *,
92 const TQPoint & ) ) );
105 if( !m_bUseSingle || !m_bChangeCursorOverItem )
106 viewport()->unsetCursor();
112 if( index( m_pCurrentItem ) == -1 )
121 TQListBoxItem* previousItem = item( currentItem() );
122 setCurrentItem( m_pCurrentItem );
124 if( m_pCurrentItem ) {
126 if( (keybstate & ShiftButton) ) {
127 bool block = signalsBlocked();
128 blockSignals(
true );
131 if( !(keybstate & ControlButton) )
134 bool select = !m_pCurrentItem->isSelected();
135 bool update = viewport()->isUpdatesEnabled();
136 viewport()->setUpdatesEnabled(
false );
138 bool down = index( previousItem ) < index( m_pCurrentItem );
139 TQListBoxItem* it = down ? previousItem : m_pCurrentItem;
140 for (;it ; it = it->next() ) {
141 if ( down && it == m_pCurrentItem ) {
142 setSelected( m_pCurrentItem, select );
145 if ( !down && it == previousItem ) {
146 setSelected( previousItem, select );
149 setSelected( it, select );
152 blockSignals( block );
153 viewport()->setUpdatesEnabled( update );
154 triggerUpdate(
false );
156 emit selectionChanged();
158 if( selectionMode() == TQListBox::Single )
159 emit selectionChanged( m_pCurrentItem );
161 else if( (keybstate & ControlButton) )
162 setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() );
164 bool block = signalsBlocked();
165 blockSignals(
true );
167 if( !m_pCurrentItem->isSelected() )
170 blockSignals( block );
172 setSelected( m_pCurrentItem,
true );
176 kdDebug() <<
"Thatīs not supposed to happen!!!!" <<
endl;
179 void TDEListBox::emitExecute( TQListBoxItem *item,
const TQPoint &pos )
183 m_pAutoSelect->stop();
186 if( !( m_bUseSingle && ((keybstate & ShiftButton) || (keybstate & ControlButton)) ) ) {
199 void TDEListBox::keyPressEvent(TQKeyEvent *e)
201 if( e->key() == Key_Escape )
205 else if( e->key() == Key_F1 )
211 TQListBox::keyPressEvent(e);
215 void TDEListBox::focusOutEvent( TQFocusEvent *fe )
217 m_pAutoSelect->stop();
219 TQListBox::focusOutEvent( fe );
222 void TDEListBox::leaveEvent( TQEvent *e )
224 m_pAutoSelect->stop();
226 TQListBox::leaveEvent( e );
229 void TDEListBox::contentsMousePressEvent( TQMouseEvent *e )
231 if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) {
232 bool block = signalsBlocked();
233 blockSignals(
true );
237 blockSignals( block );
240 TQListBox::contentsMousePressEvent( e );
243 void TDEListBox::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
245 TQListBox::contentsMouseDoubleClickEvent( e );
247 TQListBoxItem* item = itemAt( contentsToViewport( e->pos() ) );
252 if( (e->button() == TQt::LeftButton) && !m_bUseSingle )
253 emitExecute( item, e->globalPos() );
257 void TDEListBox::slotMouseButtonClicked(
int btn, TQListBoxItem *item,
const TQPoint &pos )
259 if( (btn == TQt::LeftButton) && item )
260 emitExecute( item, pos );
263 void TDEListBox::virtual_hook(
int,
void* )
266 #include "tdelistbox.moc"
A TQCursor wrapper allowing "themed" cursors and auto-hiding cursors.
static ButtonState keyboardMouseState()
static bool changeCursorOverIcon()
static int autoSelectDelay()
static bool singleClick()
void slotAutoSelect()
Auto selection happend.
void executed(TQListBoxItem *item)
Emitted whenever the user executes an listbox item.
void doubleClicked(TQListBoxItem *item, const TQPoint &pos)
This signal gets emitted whenever the user double clicks into the listbox.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
TQString name(StdAccel id)