Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / khotkeys / shared / khlistbox.cpp
blob412b47fc9ca4d08705e639fb2270cddc06e8bb64
1 /****************************************************************************
3 KHotKeys
5 Copyright (C) 1999-2002 Lubos Lunak <l.lunak@kde.org>
7 Distributed under the terms of the GNU General Public License version 2.
9 ****************************************************************************/
11 #define _KHLISTBOX_CPP_
13 #include "khlistbox.h"
15 #include <kdebug.h>
17 namespace KHotKeys
20 KHListBox::KHListBox( QWidget* parent_P, const char* name_P )
21 : QListWidget( parent_P ), saved_current_item( NULL ),
22 in_clear( false ), force_select( false )
24 setObjectName( name_P );
26 insert_select_timer.setSingleShot( true );
28 connect( this, SIGNAL( selectionChanged( QListWidgetItem* )),
29 SLOT( slot_selection_changed( QListWidgetItem* )));
30 connect( this, SIGNAL( currentChanged( QListWidgetItem* )),
31 SLOT( slot_current_changed( QListWidgetItem* )));
32 // CHECKME grrr
33 connect( this, SIGNAL( selectionChanged()),
34 SLOT( slot_selection_changed()));
35 connect( &insert_select_timer, SIGNAL( timeout()),
36 SLOT( slot_insert_select()));
39 void KHListBox::slot_selection_changed()
41 if( saved_current_item == NULL )
42 slot_selection_changed( NULL );
43 else if( !saved_current_item->isSelected()) // no way
44 saved_current_item->setSelected( true );
47 void KHListBox::slot_selection_changed( QListWidgetItem* item_P )
49 if( item_P == saved_current_item )
50 return;
51 saved_current_item = item_P;
52 setCurrentItem( saved_current_item );
53 emit current_changed( saved_current_item );
56 void KHListBox::slot_current_changed( QListWidgetItem* item_P )
58 insert_select_timer.stop();
59 if( item_P == saved_current_item )
60 return;
61 saved_current_item = item_P;
62 saved_current_item->setSelected( true );
63 emit current_changed( saved_current_item );
66 // neni virtual :((
67 void KHListBox::clear()
69 in_clear = true;
70 QListWidget::clear();
71 in_clear = false;
72 slot_selection_changed( NULL );
76 // neni virtual :(( a vubec nefunguje
77 void KHListBox::insertItem( QListWidgetItem* item_P )
79 bool set = false;
80 if( !in_clear )
81 set = count() == 0;
82 QListWidget::addItem( item_P );
83 if( set && force_select )
85 bool block = signalsBlocked();
86 blockSignals( true );
87 setCurrentItem( item_P );
88 blockSignals( block );
89 insert_select_timer.start( 0 );
93 // items are often inserted using the QListBoxItem constructor,
94 // which means that a derived class are not yet fully created
95 void KHListBox::slot_insert_select()
97 slot_current_changed( item( currentRow()));
101 } // namespace KHotKeys
103 #include "khlistbox.moc"