From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- khotkeys/shared/khlistbox.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 khotkeys/shared/khlistbox.cpp (limited to 'khotkeys/shared/khlistbox.cpp') diff --git a/khotkeys/shared/khlistbox.cpp b/khotkeys/shared/khlistbox.cpp new file mode 100644 index 000000000..694fb658b --- /dev/null +++ b/khotkeys/shared/khlistbox.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** + + KHotKeys + + Copyright (C) 1999-2002 Lubos Lunak + + Distributed under the terms of the GNU General Public License version 2. + +****************************************************************************/ + +#define _KHLISTBOX_CPP_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "khlistbox.h" + +#include + +namespace KHotKeys +{ + +KHListBox::KHListBox( QWidget* parent_P, const char* name_P ) + : QListBox( parent_P, name_P ), saved_current_item( NULL ), + in_clear( false ), force_select( false ) + { + connect( this, SIGNAL( selectionChanged( QListBoxItem* )), + SLOT( slot_selection_changed( QListBoxItem* ))); + connect( this, SIGNAL( currentChanged( QListBoxItem* )), + SLOT( slot_current_changed( QListBoxItem* ))); + // CHECKME grrr + connect( this, SIGNAL( selectionChanged()), + SLOT( slot_selection_changed())); + connect( &insert_select_timer, SIGNAL( timeout()), + SLOT( slot_insert_select())); + } + +void KHListBox::slot_selection_changed() + { + if( saved_current_item == NULL ) + slot_selection_changed( NULL ); + else if( !saved_current_item->isSelected()) // no way + setSelected( saved_current_item, true ); + } + +void KHListBox::slot_selection_changed( QListBoxItem* item_P ) + { + if( item_P == saved_current_item ) + return; + saved_current_item = item_P; + setCurrentItem( saved_current_item ); + emit current_changed( saved_current_item ); + } + +void KHListBox::slot_current_changed( QListBoxItem* item_P ) + { + insert_select_timer.stop(); + if( item_P == saved_current_item ) + return; + saved_current_item = item_P; + setSelected( saved_current_item, true ); + emit current_changed( saved_current_item ); + } + +// neni virtual :(( +void KHListBox::clear() + { + in_clear = true; + QListBox::clear(); + in_clear = false; + slot_selection_changed( NULL ); + } + + +// neni virtual :(( a vubec nefunguje +void KHListBox::insertItem( QListBoxItem* item_P ) + { + bool set = false; + if( !in_clear ) + set = count() == 0; + QListBox::insertItem( item_P ); + if( set && force_select ) + { + bool block = signalsBlocked(); + blockSignals( true ); + setCurrentItem( item_P ); + blockSignals( block ); + insert_select_timer.start( 0, true ); + } + } + +// items are often inserted using the QListBoxItem constructor, +// which means that a derived class are not yet fully created +void KHListBox::slot_insert_select() + { + slot_current_changed( item( currentItem())); + } + + +} // namespace KHotKeys + +#include "khlistbox.moc" -- cgit v1.2.1