summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/klistbox.cpp
Unidiff
Diffstat (limited to 'microkde/kdeui/klistbox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/klistbox.cpp56
1 files changed, 31 insertions, 25 deletions
diff --git a/microkde/kdeui/klistbox.cpp b/microkde/kdeui/klistbox.cpp
index c65b892..71020b3 100644
--- a/microkde/kdeui/klistbox.cpp
+++ b/microkde/kdeui/klistbox.cpp
@@ -7,69 +7,75 @@
7 7
8 This library is distributed in the hope that it will be useful, 8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details. 11 Library General Public License for more details.
12 12
13 You should have received a copy of the GNU Library General Public License 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 14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA. 16 Boston, MA 02111-1307, USA.
17*/ 17*/
18#include <qtimer.h> 18#include <qtimer.h>
19//Added by qt3to4:
20#include <QEvent>
21#include <QMouseEvent>
22#include <QKeyEvent>
23#include <QFocusEvent>
19 24
20#include <kglobalsettings.h> 25#include <kglobalsettings.h>
21//US#include <kcursor.h> 26//US#include <kcursor.h>
22#include <kapplication.h> 27#include <kapplication.h>
23//US#include <kipc.h> 28//US#include <kipc.h>
24#include <kdebug.h> 29#include <kdebug.h>
25 30
26#include "klistbox.h" 31#include "klistbox.h"
27 32
28#ifdef Q_WS_X11 33#ifdef Q_WS_X11
34#include <QX11Info>
29#include <X11/Xlib.h> 35#include <X11/Xlib.h>
30#endif 36#endif
31#ifdef _WIN32_ 37#ifdef _WIN32_
32#define Q_WS_QWS 38#define Q_WS_QWS
33#endif 39#endif
34KListBox::KListBox( QWidget *parent, const char *name, WFlags f ) 40KListBox::KListBox( QWidget *parent, const char *name, Qt::WFlags f )
35 : QListBox( parent, name, f ) 41 : Q3ListBox( parent, name, f )
36{ 42{
37 connect( this, SIGNAL( onViewport() ), 43 connect( this, SIGNAL( onViewport() ),
38 this, SLOT( slotOnViewport() ) ); 44 this, SLOT( slotOnViewport() ) );
39 connect( this, SIGNAL( onItem( QListBoxItem * ) ), 45 connect( this, SIGNAL( onItem( Q3ListBoxItem * ) ),
40 this, SLOT( slotOnItem( QListBoxItem * ) ) ); 46 this, SLOT( slotOnItem( Q3ListBoxItem * ) ) );
41 47
42 connect( this, SIGNAL( mouseButtonClicked( int, QListBoxItem *, 48 connect( this, SIGNAL( mouseButtonClicked( int, Q3ListBoxItem *,
43 const QPoint & ) ), 49 const QPoint & ) ),
44 this, SLOT( slotMouseButtonClicked( int, QListBoxItem *, 50 this, SLOT( slotMouseButtonClicked( int, Q3ListBoxItem *,
45 const QPoint & ) ) ); 51 const QPoint & ) ) );
46/*US 52/*US
47 53
48 slotSettingsChanged(KApplication::SETTINGS_MOUSE); 54 slotSettingsChanged(KApplication::SETTINGS_MOUSE);
49 if (kapp) 55 if (kapp)
50 { 56 {
51 connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) ); 57 connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) );
52 kapp->addKipcEventMask( KIPC::SettingsChanged ); 58 kapp->addKipcEventMask( KIPC::SettingsChanged );
53 } 59 }
54*/ 60*/
55 m_pCurrentItem = 0L; 61 m_pCurrentItem = 0L;
56//US set single to true 62//US set single to true
57 m_bUseSingle = true; 63 m_bUseSingle = true;
58 m_pAutoSelect = new QTimer( this ); 64 m_pAutoSelect = new QTimer( this );
59 connect( m_pAutoSelect, SIGNAL( timeout() ), 65 connect( m_pAutoSelect, SIGNAL( timeout() ),
60 this, SLOT( slotAutoSelect() ) ); 66 this, SLOT( slotAutoSelect() ) );
61} 67}
62 68
63void KListBox::slotOnItem( QListBoxItem *item ) 69void KListBox::slotOnItem( Q3ListBoxItem *item )
64{ 70{
65/*US 71/*US
66 if ( item && m_bChangeCursorOverItem && m_bUseSingle ) 72 if ( item && m_bChangeCursorOverItem && m_bUseSingle )
67 viewport()->setCursor( KCursor().handCursor() ); 73 viewport()->setCursor( KCursor().handCursor() );
68*/ 74*/
69 if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) { 75 if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
70 m_pAutoSelect->start( m_autoSelectDelay, true ); 76 m_pAutoSelect->start( m_autoSelectDelay, true );
71 m_pCurrentItem = item; 77 m_pCurrentItem = item;
72 } 78 }
73} 79}
74 80
75void KListBox::slotOnViewport() 81void KListBox::slotOnViewport()
@@ -130,72 +136,72 @@ void KListBox::slotAutoSelect()
130 if( index( m_pCurrentItem ) == -1 ) 136 if( index( m_pCurrentItem ) == -1 )
131 return; 137 return;
132 138
133 //Give this widget the keyboard focus. 139 //Give this widget the keyboard focus.
134 if( !hasFocus() ) 140 if( !hasFocus() )
135 setFocus(); 141 setFocus();
136 142
137#ifdef Q_WS_X11 //FIXME 143#ifdef Q_WS_X11 //FIXME
138 Window root; 144 Window root;
139 Window child; 145 Window child;
140 int root_x, root_y, win_x, win_y; 146 int root_x, root_y, win_x, win_y;
141 uint keybstate; 147 uint keybstate;
142 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child, 148 XQueryPointer( x11Info().display(), x11Info().appRootWindow(), &root, &child,
143 &root_x, &root_y, &win_x, &win_y, &keybstate ); 149 &root_x, &root_y, &win_x, &win_y, &keybstate );
144#endif 150#endif
145 151
146 QListBoxItem* previousItem = item( currentItem() ); 152 Q3ListBoxItem* previousItem = item( currentItem() );
147 setCurrentItem( m_pCurrentItem ); 153 setCurrentItem( m_pCurrentItem );
148 154
149 if( m_pCurrentItem ) { 155 if( m_pCurrentItem ) {
150#ifndef Q_WS_QWS //FIXME 156#ifndef Q_WS_QWS //FIXME
151 //Shift pressed? 157 //Shift pressed?
152 if( (keybstate & ShiftMask) ) { 158 if( (keybstate & ShiftMask) ) {
153#endif 159#endif
154 bool block = signalsBlocked(); 160 bool block = signalsBlocked();
155 blockSignals( true ); 161 blockSignals( true );
156 162
157#ifndef Q_WS_QWS //FIXME 163#ifndef Q_WS_QWS //FIXME
158 //No Ctrl? Then clear before! 164 //No Ctrl? Then clear before!
159 if( !(keybstate & ControlMask) ) 165 if( !(keybstate & ControlMask) )
160 clearSelection(); 166 clearSelection();
161#endif 167#endif
162 168
163//US in my QT version it is called isSelected() So what is right? 169//US in my QT version it is called isSelected() So what is right?
164//US bool select = !m_pCurrentItem->isSelected(); 170//US bool select = !m_pCurrentItem->isSelected();
165 bool select = !m_pCurrentItem->selected(); 171 bool select = !m_pCurrentItem->selected();
166 bool update = viewport()->isUpdatesEnabled(); 172 bool update = viewport()->isUpdatesEnabled();
167 viewport()->setUpdatesEnabled( false ); 173 viewport()->setUpdatesEnabled( false );
168 174
169 bool down = index( previousItem ) < index( m_pCurrentItem ); 175 bool down = index( previousItem ) < index( m_pCurrentItem );
170 QListBoxItem* it = down ? previousItem : m_pCurrentItem; 176 Q3ListBoxItem* it = down ? previousItem : m_pCurrentItem;
171 for (;it ; it = it->next() ) { 177 for (;it ; it = it->next() ) {
172 if ( down && it == m_pCurrentItem ) { 178 if ( down && it == m_pCurrentItem ) {
173 setSelected( m_pCurrentItem, select ); 179 setSelected( m_pCurrentItem, select );
174 break; 180 break;
175 } 181 }
176 if ( !down && it == previousItem ) { 182 if ( !down && it == previousItem ) {
177 setSelected( previousItem, select ); 183 setSelected( previousItem, select );
178 break; 184 break;
179 } 185 }
180 setSelected( it, select ); 186 setSelected( it, select );
181 } 187 }
182 188
183 blockSignals( block ); 189 blockSignals( block );
184 viewport()->setUpdatesEnabled( update ); 190 viewport()->setUpdatesEnabled( update );
185 triggerUpdate( false ); 191 triggerUpdate( false );
186 192
187 emit selectionChanged(); 193 emit selectionChanged();
188 194
189 if( selectionMode() == QListBox::Single ) 195 if( selectionMode() == Q3ListBox::Single )
190 emit selectionChanged( m_pCurrentItem ); 196 emit selectionChanged( m_pCurrentItem );
191 } 197 }
192#ifndef Q_WS_QWS //FIXME 198#ifndef Q_WS_QWS //FIXME
193 else if( (keybstate & ControlMask) ) 199 else if( (keybstate & ControlMask) )
194 setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() ); 200 setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() );
195#endif 201#endif
196 else { 202 else {
197 bool block = signalsBlocked(); 203 bool block = signalsBlocked();
198 blockSignals( true ); 204 blockSignals( true );
199 205
200//US in my QT version it is called isSelected() So what is right? 206//US in my QT version it is called isSelected() So what is right?
201//US if( !m_pCurrentItem->isSelected() ) 207//US if( !m_pCurrentItem->isSelected() )
@@ -204,32 +210,32 @@ void KListBox::slotAutoSelect()
204 210
205 blockSignals( block ); 211 blockSignals( block );
206 212
207 setSelected( m_pCurrentItem, true ); 213 setSelected( m_pCurrentItem, true );
208 } 214 }
209#ifndef Q_WS_QWS //FIXME 215#ifndef Q_WS_QWS //FIXME
210 } 216 }
211 else 217 else
212 kdDebug() << "Thats not supposed to happen!!!!" << endl; 218 kdDebug() << "Thats not supposed to happen!!!!" << endl;
213#endif 219#endif
214} 220}
215 221
216void KListBox::emitExecute( QListBoxItem *item, const QPoint &pos ) 222void KListBox::emitExecute( Q3ListBoxItem *item, const QPoint &pos )
217{ 223{
218#ifdef Q_WS_X11 //FIXME 224#ifdef Q_WS_X11 //FIXME
219 Window root; 225 Window root;
220 Window child; 226 Window child;
221 int root_x, root_y, win_x, win_y; 227 int root_x, root_y, win_x, win_y;
222 uint keybstate; 228 uint keybstate;
223 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child, 229 XQueryPointer( x11Info().display(), x11Info().appRootWindow(), &root, &child,
224 &root_x, &root_y, &win_x, &win_y, &keybstate ); 230 &root_x, &root_y, &win_x, &win_y, &keybstate );
225#endif 231#endif
226 232
227 m_pAutoSelect->stop(); 233 m_pAutoSelect->stop();
228 234
229#ifndef Q_WS_QWS //FIXME 235#ifndef Q_WS_QWS //FIXME
230 //Dont emit executed if in SC mode and Shift or Ctrl are pressed 236 //Dont emit executed if in SC mode and Shift or Ctrl are pressed
231 if( !( m_bUseSingle && ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) { 237 if( !( m_bUseSingle && ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) {
232#endif 238#endif
233 emit executed( item ); 239 emit executed( item );
234 emit executed( item, pos ); 240 emit executed( item, pos );
235#ifndef Q_WS_QWS //FIXME 241#ifndef Q_WS_QWS //FIXME
@@ -237,78 +243,78 @@ void KListBox::emitExecute( QListBoxItem *item, const QPoint &pos )
237#endif 243#endif
238} 244}
239 245
240// 246//
241// 2000-16-01 Espen Sand 247// 2000-16-01 Espen Sand
242// This widget is used in dialogs. It should ignore 248// This widget is used in dialogs. It should ignore
243// F1 (and combinations) and Escape since these are used 249// F1 (and combinations) and Escape since these are used
244// to start help or close the dialog. This functionality 250// to start help or close the dialog. This functionality
245// should be done in QListView but it is not (at least now) 251// should be done in QListView but it is not (at least now)
246// 252//
247void KListBox::keyPressEvent(QKeyEvent *e) 253void KListBox::keyPressEvent(QKeyEvent *e)
248{ 254{
249 if( e->key() == Key_Escape ) 255 if( e->key() == Qt::Key_Escape )
250 { 256 {
251 e->ignore(); 257 e->ignore();
252 } 258 }
253 else if( e->key() == Key_F1 ) 259 else if( e->key() == Qt::Key_F1 )
254 { 260 {
255 e->ignore(); 261 e->ignore();
256 } 262 }
257 else 263 else
258 { 264 {
259 QListBox::keyPressEvent(e); 265 Q3ListBox::keyPressEvent(e);
260 } 266 }
261} 267}
262 268
263void KListBox::focusOutEvent( QFocusEvent *fe ) 269void KListBox::focusOutEvent( QFocusEvent *fe )
264{ 270{
265 m_pAutoSelect->stop(); 271 m_pAutoSelect->stop();
266 272
267 QListBox::focusOutEvent( fe ); 273 Q3ListBox::focusOutEvent( fe );
268} 274}
269 275
270void KListBox::leaveEvent( QEvent *e ) 276void KListBox::leaveEvent( QEvent *e )
271{ 277{
272 m_pAutoSelect->stop(); 278 m_pAutoSelect->stop();
273 279
274 QListBox::leaveEvent( e ); 280 Q3ListBox::leaveEvent( e );
275} 281}
276 282
277void KListBox::contentsMousePressEvent( QMouseEvent *e ) 283void KListBox::contentsMousePressEvent( QMouseEvent *e )
278{ 284{
279 if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) { 285 if( (selectionMode() == Extended) && (e->state() & Qt::ShiftButton) && !(e->state() & Qt::ControlButton) ) {
280 bool block = signalsBlocked(); 286 bool block = signalsBlocked();
281 blockSignals( true ); 287 blockSignals( true );
282 288
283 clearSelection(); 289 clearSelection();
284 290
285 blockSignals( block ); 291 blockSignals( block );
286 } 292 }
287 293
288 QListBox::contentsMousePressEvent( e ); 294 Q3ListBox::contentsMousePressEvent( e );
289} 295}
290 296
291void KListBox::contentsMouseDoubleClickEvent ( QMouseEvent * e ) 297void KListBox::contentsMouseDoubleClickEvent ( QMouseEvent * e )
292{ 298{
293 QListBox::contentsMouseDoubleClickEvent( e ); 299 Q3ListBox::contentsMouseDoubleClickEvent( e );
294 300
295 QListBoxItem* item = itemAt( e->pos() ); 301 Q3ListBoxItem* item = itemAt( e->pos() );
296 302
297 if( item ) { 303 if( item ) {
298 emit doubleClicked( item, e->globalPos() ); 304 emit doubleClicked( item, e->globalPos() );
299 305
300 if( (e->button() == LeftButton) && !m_bUseSingle ) 306 if( (e->button() == Qt::LeftButton) && !m_bUseSingle )
301 emitExecute( item, e->globalPos() ); 307 emitExecute( item, e->globalPos() );
302 } 308 }
303} 309}
304 310
305void KListBox::slotMouseButtonClicked( int btn, QListBoxItem *item, const QPoint &pos ) 311void KListBox::slotMouseButtonClicked( int btn, Q3ListBoxItem *item, const QPoint &pos )
306{ 312{
307 if( (btn == LeftButton) && item ) 313 if( (btn == Qt::LeftButton) && item )
308 emitExecute( item, pos ); 314 emitExecute( item, pos );
309} 315}
310 316
311void KListBox::virtual_hook( int, void* ) 317void KListBox::virtual_hook( int, void* )
312{ /*BASE::virtual_hook( id, data );*/ } 318{ /*BASE::virtual_hook( id, data );*/ }
313 319
314//US #include "klistbox.moc" 320//US #include "klistbox.moc"