1 /****************************************************************************
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"
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
* )));
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
)
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
)
61 saved_current_item
= item_P
;
62 saved_current_item
->setSelected( true );
63 emit
current_changed( saved_current_item
);
67 void KHListBox::clear()
72 slot_selection_changed( NULL
);
76 // neni virtual :(( a vubec nefunguje
77 void KHListBox::insertItem( QListWidgetItem
* item_P
)
82 QListWidget::addItem( item_P
);
83 if( set
&& force_select
)
85 bool block
= signalsBlocked();
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"