summaryrefslogtreecommitdiffstats
path: root/khotkeys/shared/khlistview.cpp
blob: ae348af337ebbc36c0d45d07508b3596360fac83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/****************************************************************************

 KHotKeys
 
 Copyright (C) 1999-2002 Lubos Lunak <[email protected]>

 Distributed under the terms of the GNU General Public License version 2.
 
****************************************************************************/

#define _KHLISTVIEW_CPP_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "khlistview.h"

#include <kdebug.h>

namespace KHotKeys
{

KHListView::KHListView( TQWidget* parent_P, const char* name_P )
    : TDEListView( parent_P, name_P ), saved_current_item( NULL ),
        in_clear( false ), ignore( false ), force_select( false )
    {
    connect( this, TQT_SIGNAL( selectionChanged( TQListViewItem* )),
        TQT_SLOT( slot_selection_changed( TQListViewItem* )));
    connect( this, TQT_SIGNAL( currentChanged( TQListViewItem* )),
        TQT_SLOT( slot_current_changed( TQListViewItem* )));
    // CHECKME grrr
    connect( this, TQT_SIGNAL( selectionChanged()),
        TQT_SLOT( slot_selection_changed()));
    connect( &insert_select_timer, TQT_SIGNAL( timeout()),
        TQT_SLOT( slot_insert_select()));
    }

void KHListView::slot_selection_changed()
    {
    if( ignore )
        return;
    if( saved_current_item == NULL )
        slot_selection_changed( NULL );
    else if( !saved_current_item->isSelected()) // no way
        setSelected( saved_current_item, true );
    }
    
void KHListView::slot_selection_changed( TQListViewItem* item_P )
    {
    if( ignore )
        return;
    if( item_P == saved_current_item )
        return;
    saved_current_item = item_P;
    setCurrentItem( saved_current_item );
    emit current_changed( saved_current_item );
    }
    
void KHListView::slot_current_changed( TQListViewItem* item_P )
    {
    if( ignore )
        return;
    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 );
    }

void KHListView::clear()
    {
    in_clear = true;
    TDEListView::clear();
    in_clear = false;
    slot_selection_changed( NULL );
    }
    
void KHListView::insertItem( TQListViewItem* item_P )
    {
    bool set = false;
    if( !in_clear )
        set = childCount() == 0;
    TDEListView::insertItem( item_P );
    if( set && force_select )
        {
        bool block = signalsBlocked();
        blockSignals( true );
// SELI	tohle spis jen blokovat sebe?
        setCurrentItem( item_P );
        blockSignals( block );
        insert_select_timer.start( 0, true );
        }
    }

void KHListView::clearSelection()
    {
    TDEListView::clearSelection();
    slot_current_changed( currentItem());
    }

// items are often inserted using the TQListViewItem constructor,
// which means that a derived class are not yet fully created
void KHListView::slot_insert_select()
    {
    if( ignore )
        return;
    slot_current_changed( currentItem());
    }

void KHListView::contentsDropEvent( TQDropEvent* e )
    {
    bool save_ignore = ignore;
    ignore = true;
    TDEListView::contentsDropEvent( e );
    ignore = save_ignore;
    }

} // namespace KHotKeys

#include "khlistview.moc"