24 #include <QtCore/QTimer>
26 #include <QApplication>
28 class KListWidget::KListWidgetPrivate
38 void _k_slotItemEntered(QListWidgetItem*);
39 void _k_slotOnViewport();
40 void _k_slotSettingsChanged(
int);
41 void _k_slotAutoSelect();
42 void _k_slotEmitExecute(QListWidgetItem *item);
45 bool m_bUseSingle : 1;
46 bool m_bChangeCursorOverItem : 1;
48 QListWidgetItem* m_pCurrentItem;
49 QTimer* m_pAutoSelect;
50 int m_autoSelectDelay;
55 :
QListWidget(parent), d(new KListWidgetPrivate(this))
57 connect(
this, SIGNAL(viewportEntered()),
58 this, SLOT(_k_slotOnViewport()) );
59 connect(
this, SIGNAL(itemEntered(QListWidgetItem*)),
60 this, SLOT(_k_slotItemEntered(QListWidgetItem*)) );
64 d->m_pAutoSelect =
new QTimer(
this );
65 connect( d->m_pAutoSelect, SIGNAL(
timeout()),
66 this, SLOT(_k_slotAutoSelect()) );
74 void KListWidget::KListWidgetPrivate::_k_slotItemEntered( QListWidgetItem *item )
76 if ( item && m_bChangeCursorOverItem && m_bUseSingle )
77 q->viewport()->setCursor(
QCursor( Qt::OpenHandCursor ) );
79 if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
80 m_pAutoSelect->setSingleShot(
true );
81 m_pAutoSelect->start( m_autoSelectDelay );
82 m_pCurrentItem = item;
86 void KListWidget::KListWidgetPrivate::_k_slotOnViewport()
88 if ( m_bChangeCursorOverItem )
89 q->viewport()->unsetCursor();
91 m_pAutoSelect->stop();
96 void KListWidget::KListWidgetPrivate::_k_slotSettingsChanged(
int category)
102 q->disconnect(q, SIGNAL(itemClicked(QListWidgetItem*)));
103 q->disconnect(q, SIGNAL(itemDoubleClicked(QListWidgetItem*)));
107 q->connect(q, SIGNAL(itemClicked(QListWidgetItem*)),
108 SLOT(_k_slotEmitExecute(QListWidgetItem*)));
112 q->connect(q, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
113 SLOT(_k_slotEmitExecute(QListWidgetItem*)));
119 if( !m_bUseSingle || !m_bChangeCursorOverItem )
120 q->viewport()->unsetCursor();
123 void KListWidget::KListWidgetPrivate::_k_slotAutoSelect()
126 if( q->row( m_pCurrentItem ) == -1 )
133 Qt::KeyboardModifiers keybstate = QApplication::keyboardModifiers();
135 QListWidgetItem* previousItem = q->currentItem();
136 q->setCurrentItem( m_pCurrentItem );
138 if( m_pCurrentItem ) {
140 if( (keybstate & Qt::ShiftModifier) ) {
141 bool block = q->signalsBlocked();
142 q->blockSignals(
true );
145 if( !(keybstate & Qt::ControlModifier) )
148 bool select = !m_pCurrentItem->isSelected();
149 bool update = q->viewport()->updatesEnabled();
150 q->viewport()->setUpdatesEnabled(
false );
152 bool down = q->row( previousItem ) < q->row( m_pCurrentItem );
153 QListWidgetItem* it = down ? previousItem : m_pCurrentItem;
155 for (
int i = q->row(it) ; i < q->count() ; i++ ) {
156 if ( down && q->item(i) == m_pCurrentItem ) {
157 m_pCurrentItem->setSelected(select);
161 if ( !down && q->item(i) == previousItem ) {
162 previousItem->setSelected(select);
165 it->setSelected(select);
168 q->blockSignals( block );
169 q->viewport()->setUpdatesEnabled( update );
171 emit q->itemSelectionChanged();
173 if( q->selectionMode() == QAbstractItemView::SingleSelection )
174 q->emit itemSelectionChanged();
176 else if( (keybstate & Qt::ControlModifier) )
177 m_pCurrentItem->setSelected(!m_pCurrentItem->isSelected());
179 bool block = q->signalsBlocked();
180 q->blockSignals(
true );
182 if( !m_pCurrentItem->isSelected() )
185 q->blockSignals( block );
187 m_pCurrentItem->setSelected(
true);
191 kDebug() <<
"That's not supposed to happen!!!!";
194 void KListWidget::KListWidgetPrivate::_k_slotEmitExecute(QListWidgetItem *item)
196 Qt::KeyboardModifiers keybstate = QApplication::keyboardModifiers();
198 m_pAutoSelect->stop();
201 if( !( m_bUseSingle && ((keybstate & Qt::ShiftModifier) || (keybstate & Qt::ControlModifier)) ) ) {
202 emit q->executed( item );
203 if (!m_eventPos.isNull()) {
204 emit q->executed( item, m_eventPos );
218 if( e->key() == Qt::Key_Escape )
222 else if( e->key() == Qt::Key_F1 )
228 QListWidget::keyPressEvent(e);
234 d->m_pAutoSelect->stop();
236 QListWidget::focusOutEvent( fe );
241 d->m_pAutoSelect->stop();
243 QListWidget::leaveEvent( e );
248 if( (selectionMode() == QAbstractItemView::ExtendedSelection) && (e->modifiers() & Qt::ShiftModifier) && !(e->modifiers() & Qt::ControlModifier) ) {
249 bool block = signalsBlocked();
250 blockSignals(
true );
254 blockSignals( block );
257 QListWidget::mousePressEvent( e );
262 QPoint oldPos = d->m_eventPos;
263 d->m_eventPos = e->globalPos();
264 QListWidget::mouseDoubleClickEvent(e);
265 d->m_eventPos = oldPos;
270 QPoint oldPos = d->m_eventPos;
271 d->m_eventPos = e->globalPos();
272 QListWidget::mouseReleaseEvent(e);
273 d->m_eventPos = oldPos;
276 #include "klistwidget.moc"
static bool singleClick()
Returns whether KDE runs in single (default) or double click mode.
static KGlobalSettings * self()
Return the KGlobalSettings singleton.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static bool changeCursorOverIcon()
Checks whether the cursor changes over icons.
static int autoSelectDelay()
Returns the KDE setting for the auto-select option.