• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDE3Support

  • kde3support
  • kdeui
k3listbox.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "k3listbox.h"
20
21#include <kglobalsettings.h>
22#include <kdebug.h>
23
24#include <QTimer>
25#include <QCursor>
26#include <QKeyEvent>
27#include <QApplication>
28
29K3ListBox::K3ListBox( QWidget *parent, const char *name, Qt::WindowFlags f )
30 : Q3ListBox( parent, name, f ), d(0)
31{
32 connect( this, SIGNAL(onViewport()),
33 this, SLOT(slotOnViewport()) );
34 connect( this, SIGNAL(onItem(Q3ListBoxItem*)),
35 this, SLOT(slotOnItem(Q3ListBoxItem*)) );
36 slotSettingsChanged(KGlobalSettings::SETTINGS_MOUSE);
37 connect( KGlobalSettings::self(), SIGNAL(settingsChanged(int)), SLOT(slotSettingsChanged(int)) );
38
39 m_pCurrentItem = 0L;
40
41 m_pAutoSelect = new QTimer( this );
42 connect( m_pAutoSelect, SIGNAL(timeout()),
43 this, SLOT(slotAutoSelect()) );
44}
45
46void K3ListBox::slotOnItem( Q3ListBoxItem *item )
47{
48 if ( item && m_bChangeCursorOverItem && m_bUseSingle )
49 viewport()->setCursor(Qt::PointingHandCursor);
50
51 if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
52 m_pAutoSelect->setSingleShot( true );
53 m_pAutoSelect->start( m_autoSelectDelay );
54 m_pCurrentItem = item;
55 }
56}
57
58void K3ListBox::slotOnViewport()
59{
60 if ( m_bChangeCursorOverItem )
61 viewport()->unsetCursor();
62
63 m_pAutoSelect->stop();
64 m_pCurrentItem = 0L;
65}
66
67
68void K3ListBox::slotSettingsChanged(int category)
69{
70 if (category != KGlobalSettings::SETTINGS_MOUSE)
71 return;
72 m_bUseSingle = KGlobalSettings::singleClick();
73
74 disconnect( this, SIGNAL( mouseButtonClicked( int, Q3ListBoxItem *,
75 const QPoint & ) ),
76 this, SLOT( slotMouseButtonClicked( int, Q3ListBoxItem *,
77 const QPoint & ) ) );
78// disconnect( this, SIGNAL( doubleClicked( QListBoxItem *,
79// const QPoint & ) ),
80// this, SLOT( slotExecute( QListBoxItem *,
81// const QPoint & ) ) );
82
83 if( m_bUseSingle )
84 {
85 connect( this, SIGNAL( mouseButtonClicked( int, Q3ListBoxItem *,
86 const QPoint & ) ),
87 this, SLOT( slotMouseButtonClicked( int, Q3ListBoxItem *,
88 const QPoint & ) ) );
89 }
90 else
91 {
92// connect( this, SIGNAL( doubleClicked( QListBoxItem *,
93// const QPoint & ) ),
94// this, SLOT( slotExecute( QListBoxItem *,
95// const QPoint & ) ) );
96 }
97
98 m_bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon();
99 m_autoSelectDelay = KGlobalSettings::autoSelectDelay();
100
101 if( !m_bUseSingle || !m_bChangeCursorOverItem )
102 viewport()->unsetCursor();
103}
104
105void K3ListBox::slotAutoSelect()
106{
107 // check that the item still exists
108 if( index( m_pCurrentItem ) == -1 )
109 return;
110
111 //Give this widget the keyboard focus.
112 if( !hasFocus() )
113 setFocus();
114
115 Qt::KeyboardModifiers keybstate = QApplication::keyboardModifiers();
116
117 Q3ListBoxItem* previousItem = item( currentItem() );
118 setCurrentItem( m_pCurrentItem );
119
120 if( m_pCurrentItem ) {
121 //Shift pressed?
122 if( (keybstate & Qt::ShiftModifier) ) {
123 bool block = signalsBlocked();
124 blockSignals( true );
125
126 //No Ctrl? Then clear before!
127 if( !(keybstate & Qt::ControlModifier) )
128 clearSelection();
129
130 bool select = !m_pCurrentItem->isSelected();
131 bool update = viewport()->updatesEnabled();
132 viewport()->setUpdatesEnabled( false );
133
134 bool down = index( previousItem ) < index( m_pCurrentItem );
135 Q3ListBoxItem* it = down ? previousItem : m_pCurrentItem;
136 for (;it ; it = it->next() ) {
137 if ( down && it == m_pCurrentItem ) {
138 setSelected( m_pCurrentItem, select );
139 break;
140 }
141 if ( !down && it == previousItem ) {
142 setSelected( previousItem, select );
143 break;
144 }
145 setSelected( it, select );
146 }
147
148 blockSignals( block );
149 viewport()->setUpdatesEnabled( update );
150 triggerUpdate( false );
151
152 emit selectionChanged();
153
154 if( selectionMode() == Q3ListBox::Single )
155 emit selectionChanged( m_pCurrentItem );
156 }
157 else if( (keybstate & Qt::ControlModifier) )
158 setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() );
159 else {
160 bool block = signalsBlocked();
161 blockSignals( true );
162
163 if( !m_pCurrentItem->isSelected() )
164 clearSelection();
165
166 blockSignals( block );
167
168 setSelected( m_pCurrentItem, true );
169 }
170 }
171 else
172 kDebug() << "That's not supposed to happen!!!!";
173}
174
175void K3ListBox::emitExecute( Q3ListBoxItem *item, const QPoint &pos )
176{
177 Qt::KeyboardModifiers keybstate = QApplication::keyboardModifiers();
178
179 m_pAutoSelect->stop();
180
181 //Don't emit executed if in SC mode and Shift or Ctrl are pressed
182 if( !( m_bUseSingle && ((keybstate & Qt::ShiftModifier) || (keybstate & Qt::ControlModifier)) ) ) {
183 emit executed( item );
184 emit executed( item, pos );
185 }
186}
187
188//
189// 2000-16-01 Espen Sand
190// This widget is used in dialogs. It should ignore
191// F1 (and combinations) and Escape since these are used
192// to start help or close the dialog. This functionality
193// should be done in QListView but it is not (at least now)
194//
195void K3ListBox::keyPressEvent(QKeyEvent *e)
196{
197 if( e->key() == Qt::Key_Escape )
198 {
199 e->ignore();
200 }
201 else if( e->key() == Qt::Key_F1 )
202 {
203 e->ignore();
204 }
205 else
206 {
207 Q3ListBox::keyPressEvent(e);
208 }
209}
210
211void K3ListBox::focusOutEvent( QFocusEvent *fe )
212{
213 m_pAutoSelect->stop();
214
215 Q3ListBox::focusOutEvent( fe );
216}
217
218void K3ListBox::leaveEvent( QEvent *e )
219{
220 m_pAutoSelect->stop();
221
222 Q3ListBox::leaveEvent( e );
223}
224
225void K3ListBox::contentsMousePressEvent( QMouseEvent *e )
226{
227 if( (selectionMode() == Extended) && (e->modifiers() & Qt::ShiftModifier) && !(e->modifiers() & Qt::ControlModifier) ) {
228 bool block = signalsBlocked();
229 blockSignals( true );
230
231 clearSelection();
232
233 blockSignals( block );
234 }
235
236 Q3ListBox::contentsMousePressEvent( e );
237}
238
239void K3ListBox::contentsMouseDoubleClickEvent ( QMouseEvent * e )
240{
241 Q3ListBox::contentsMouseDoubleClickEvent( e );
242
243 Q3ListBoxItem* item = itemAt( contentsToViewport( e->pos() ) );
244
245 if( item ) {
246 emit doubleClicked( item, e->globalPos() );
247
248 if( (e->button() == Qt::LeftButton) && !m_bUseSingle )
249 emitExecute( item, e->globalPos() );
250 }
251}
252
253void K3ListBox::slotMouseButtonClicked( int btn, Q3ListBoxItem *item, const QPoint &pos )
254{
255 if( (btn == Qt::LeftButton) && item )
256 emitExecute( item, pos );
257}
258
259#include "k3listbox.moc"
K3ListBox::slotSettingsChanged
void slotSettingsChanged(int)
Definition: k3listbox.cpp:68
K3ListBox::leaveEvent
virtual void leaveEvent(QEvent *e)
Definition: k3listbox.cpp:218
K3ListBox::contentsMouseDoubleClickEvent
virtual void contentsMouseDoubleClickEvent(QMouseEvent *e)
Definition: k3listbox.cpp:239
K3ListBox::contentsMousePressEvent
virtual void contentsMousePressEvent(QMouseEvent *e)
Definition: k3listbox.cpp:225
K3ListBox::K3ListBox
K3ListBox(QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0)
Definition: k3listbox.cpp:29
K3ListBox::executed
void executed(Q3ListBoxItem *item)
Emitted whenever the user executes an listbox item.
K3ListBox::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Definition: k3listbox.cpp:195
K3ListBox::slotOnViewport
void slotOnViewport()
Definition: k3listbox.cpp:58
K3ListBox::m_bUseSingle
bool m_bUseSingle
Definition: k3listbox.h:109
K3ListBox::emitExecute
void emitExecute(Q3ListBoxItem *item, const QPoint &pos)
Definition: k3listbox.cpp:175
K3ListBox::slotOnItem
void slotOnItem(Q3ListBoxItem *item)
Definition: k3listbox.cpp:46
K3ListBox::doubleClicked
void doubleClicked(Q3ListBoxItem *item, const QPoint &pos)
This signal gets emitted whenever the user double clicks into the listbox.
K3ListBox::m_bChangeCursorOverItem
bool m_bChangeCursorOverItem
Definition: k3listbox.h:110
K3ListBox::m_autoSelectDelay
int m_autoSelectDelay
Definition: k3listbox.h:115
K3ListBox::m_pCurrentItem
Q3ListBoxItem * m_pCurrentItem
Definition: k3listbox.h:112
K3ListBox::focusOutEvent
virtual void focusOutEvent(QFocusEvent *fe)
Definition: k3listbox.cpp:211
K3ListBox::m_pAutoSelect
QTimer * m_pAutoSelect
Definition: k3listbox.h:114
K3ListBox::slotAutoSelect
void slotAutoSelect()
Auto selection happend.
Definition: k3listbox.cpp:105
KGlobalSettings::singleClick
static bool singleClick()
KGlobalSettings::autoSelectDelay
static int autoSelectDelay()
KGlobalSettings::self
static KGlobalSettings * self()
KGlobalSettings::changeCursorOverIcon
static bool changeCursorOverIcon()
KGlobalSettings::SETTINGS_MOUSE
SETTINGS_MOUSE
Q3ListBox
QEvent
QWidget
kDebug
#define kDebug
k3listbox.h
kdebug.h
kglobalsettings.h
timeout
int timeout
name
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal