• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
klistview.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3  Copyright (C) 2000,2003 Charles Samuels <charles@kde.org>
4  Copyright (C) 2000 Peter Putzer
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 #include "config.h"
21 
22 #include <tqdragobject.h>
23 #include <tqtimer.h>
24 #include <tqheader.h>
25 #include <tqcursor.h>
26 #include <tqtooltip.h>
27 #include <tqstyle.h>
28 #include <tqpainter.h>
29 
30 #include <kglobalsettings.h>
31 #include <kconfig.h>
32 #include <kcursor.h>
33 #include <kapplication.h>
34 #include <kipc.h>
35 #include <kdebug.h>
36 
37 #include "klistview.h"
38 #include "klistviewlineedit.h"
39 
40 class KListView::Tooltip : public TQToolTip
41 {
42 public:
43  Tooltip (KListView* parent, TQToolTipGroup* group = 0L);
44  virtual ~Tooltip () {}
45 
46 protected:
50  virtual void maybeTip (const TQPoint&);
51 
52 private:
53  KListView* mParent;
54 };
55 
56 KListView::Tooltip::Tooltip (KListView* parent, TQToolTipGroup* group)
57  : TQToolTip (parent, group),
58  mParent (parent)
59 {
60 }
61 
62 void KListView::Tooltip::maybeTip (const TQPoint&)
63 {
64  // FIXME
65 }
66 
67 class KListView::KListViewPrivate
68 {
69 public:
70  KListViewPrivate (KListView* listview)
71  : pCurrentItem (0),
72  autoSelectDelay(0),
73  dragOverItem(0),
74  dragDelay (KGlobalSettings::dndEventDelay()),
75  editor (new KListViewLineEdit (listview)),
76  cursorInExecuteArea(false),
77  itemsMovable (true),
78  selectedBySimpleMove(false),
79  selectedUsingMouse(false),
80  itemsRenameable (false),
81  validDrag (false),
82  dragEnabled (false),
83  autoOpen (true),
84  disableAutoSelection (false),
85  dropVisualizer (true),
86  dropHighlighter (false),
87  createChildren (true),
88  pressedOnSelected (false),
89  wasShiftEvent (false),
90  fullWidth (false),
91  sortAscending(true),
92  tabRename(true),
93  sortColumn(0),
94  selectionDirection(0),
95  tooltipColumn (0),
96  selectionMode (Single),
97  contextMenuKey (KGlobalSettings::contextMenuKey()),
98  showContextMenusOnPress (KGlobalSettings::showContextMenusOnPress()),
99  mDropVisualizerWidth (4),
100  paintAbove (0),
101  paintCurrent (0),
102  paintBelow (0),
103  painting (false),
104  shadeSortColumn(KGlobalSettings::shadeSortColumn())
105  {
106  renameable.append(0);
107  connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int)));
108  }
109 
110  ~KListViewPrivate ()
111  {
112  delete editor;
113  }
114 
115  TQListViewItem* pCurrentItem;
116 
117  TQTimer autoSelect;
118  int autoSelectDelay;
119 
120  TQTimer dragExpand;
121  TQListViewItem* dragOverItem;
122  TQPoint dragOverPoint;
123 
124  TQPoint startDragPos;
125  int dragDelay;
126 
127  KListViewLineEdit *editor;
128  TQValueList<int> renameable;
129 
130  bool cursorInExecuteArea:1;
131  bool bUseSingle:1;
132  bool bChangeCursorOverItem:1;
133  bool itemsMovable:1;
134  bool selectedBySimpleMove : 1;
135  bool selectedUsingMouse:1;
136  bool itemsRenameable:1;
137  bool validDrag:1;
138  bool dragEnabled:1;
139  bool autoOpen:1;
140  bool disableAutoSelection:1;
141  bool dropVisualizer:1;
142  bool dropHighlighter:1;
143  bool createChildren:1;
144  bool pressedOnSelected:1;
145  bool wasShiftEvent:1;
146  bool fullWidth:1;
147  bool sortAscending:1;
148  bool tabRename:1;
149 
150  int sortColumn;
151 
152  //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX
153  int selectionDirection;
154  int tooltipColumn;
155 
156  SelectionModeExt selectionMode;
157  int contextMenuKey;
158  bool showContextMenusOnPress;
159 
160  TQRect mOldDropVisualizer;
161  int mDropVisualizerWidth;
162  TQRect mOldDropHighlighter;
163  TQListViewItem *afterItemDrop;
164  TQListViewItem *parentItemDrop;
165 
166  TQListViewItem *paintAbove;
167  TQListViewItem *paintCurrent;
168  TQListViewItem *paintBelow;
169  bool painting:1;
170  bool shadeSortColumn:1;
171 
172  TQColor alternateBackground;
173 };
174 
175 
176 KListViewLineEdit::KListViewLineEdit(KListView *parent)
177  : KLineEdit(parent->viewport()), item(0), col(0), p(parent)
178 {
179  setFrame( false );
180  hide();
181  connect( parent, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( slotSelectionChanged() ));
182  connect( parent, TQT_SIGNAL( itemRemoved( TQListViewItem * ) ),
183  TQT_SLOT( slotItemRemoved( TQListViewItem * ) ));
184 }
185 
186 KListViewLineEdit::~KListViewLineEdit()
187 {
188 }
189 
190 TQListViewItem *KListViewLineEdit::currentItem() const
191 {
192  return item;
193 }
194 
195 void KListViewLineEdit::load(TQListViewItem *i, int c)
196 {
197  item=i;
198  col=c;
199 
200  TQRect rect(p->itemRect(i));
201  setText(item->text(c));
202  home( true );
203 
204  int fieldX = rect.x() - 1;
205  int fieldW = p->columnWidth(col) + 2;
206 
207  TQHeader* const pHeader = p->header();
208 
209  const int pos = pHeader->mapToIndex(col);
210  for ( int index = 0; index < pos; ++index )
211  fieldX += p->columnWidth( pHeader->mapToSection( index ));
212 
213  if ( col == 0 ) {
214  int d = i->depth() + (p->rootIsDecorated() ? 1 : 0);
215  d *= p->treeStepSize();
216  fieldX += d;
217  fieldW -= d;
218  }
219 
220  if ( i->pixmap( col ) ) {// add width of pixmap
221  int d = i->pixmap( col )->width();
222  fieldX += d;
223  fieldW -= d;
224  }
225 
226  setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2);
227  show();
228  setFocus();
229 }
230 
231 /* Helper functions to for
232  * tabOrderedRename functionality.
233  */
234 
235 static int nextCol (KListView *pl, TQListViewItem *pi, int start, int dir)
236 {
237  if (pi)
238  {
239  // Find the next renameable column in the current row
240  for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir)
241  if (pl->isRenameable(start))
242  return start;
243  }
244 
245  return -1;
246 }
247 
248 static TQListViewItem *prevItem (TQListViewItem *pi)
249 {
250  TQListViewItem *pa = pi->itemAbove();
251 
252  /* Does what the TQListViewItem::previousSibling()
253  * of my dreams would do.
254  */
255  if (pa && pa->parent() == pi->parent())
256  return pa;
257 
258  return 0;
259 }
260 
261 static TQListViewItem *lastQChild (TQListViewItem *pi)
262 {
263  if (pi)
264  {
265  /* Since there's no TQListViewItem::lastChild().
266  * This finds the last sibling for the given
267  * item.
268  */
269  for (TQListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling())
270  pi = pt;
271  }
272 
273  return pi;
274 }
275 
276 void KListViewLineEdit::selectNextCell (TQListViewItem *pitem, int column, bool forward)
277 {
278  const int ncols = p->columns();
279  const int dir = forward ? +1 : -1;
280  const int restart = forward ? 0 : (ncols - 1);
281  TQListViewItem *top = (pitem && pitem->parent())
282  ? pitem->parent()->firstChild()
283  : p->firstChild();
284  TQListViewItem *pi = pitem;
285 
286  terminate(); // Save current changes
287 
288  do
289  {
290  /* Check the rest of the current row for an editable column,
291  * if that fails, check the entire next/previous row. The
292  * last case goes back to the first item in the current branch
293  * or the last item in the current branch depending on the
294  * direction.
295  */
296  if ((column = nextCol(p, pi, column + dir, dir)) != -1 ||
297  (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 ||
298  (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1)
299  {
300  if (pi)
301  {
302  p->setCurrentItem(pi); // Calls terminate
303  p->rename(pi, column);
304 
305  /* Some listviews may override rename() to
306  * prevent certain items from being renamed,
307  * if this is done, [m_]item will be NULL
308  * after the rename() call... try again.
309  */
310  if (!item)
311  continue;
312 
313  break;
314  }
315  }
316  }
317  while (pi && !item);
318 }
319 
320 #ifdef KeyPress
321 #undef KeyPress
322 #endif
323 
324 bool KListViewLineEdit::event (TQEvent *pe)
325 {
326  if (pe->type() == TQEvent::KeyPress)
327  {
328  TQKeyEvent *k = (TQKeyEvent *) pe;
329 
330  if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) &&
331  p->tabOrderedRenaming() && p->itemsRenameable() &&
332  !(k->state() & ControlButton || k->state() & AltButton))
333  {
334  selectNextCell(item, col,
335  (k->key() == Key_Tab && !(k->state() & ShiftButton)));
336  return true;
337  }
338  }
339 
340  return KLineEdit::event(pe);
341 }
342 
343 void KListViewLineEdit::keyPressEvent(TQKeyEvent *e)
344 {
345  if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter )
346  terminate(true);
347  else if(e->key() == Qt::Key_Escape)
348  terminate(false);
349  else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up)
350  {
351  terminate(true);
352  KLineEdit::keyPressEvent(e);
353  }
354  else
355  KLineEdit::keyPressEvent(e);
356 }
357 
358 void KListViewLineEdit::terminate()
359 {
360  terminate(true);
361 }
362 
363 void KListViewLineEdit::terminate(bool commit)
364 {
365  if ( item )
366  {
367  //kdDebug() << "KListViewLineEdit::terminate " << commit << endl;
368  if (commit)
369  item->setText(col, text());
370  int c=col;
371  TQListViewItem *i=item;
372  col=0;
373  item=0;
374  p->setFocus();// will call focusOutEvent, that's why we set item=0 before
375  hide();
376  if (commit)
377  emit done(i,c);
378  }
379 }
380 
381 void KListViewLineEdit::focusOutEvent(TQFocusEvent *ev)
382 {
383  TQFocusEvent * focusEv = static_cast<TQFocusEvent*>(ev);
384  // Don't let a RMB close the editor
385  if (focusEv->reason() != TQFocusEvent::Popup && focusEv->reason() != TQFocusEvent::ActiveWindow)
386  terminate(true);
387  else
388  KLineEdit::focusOutEvent(ev);
389 }
390 
391 void KListViewLineEdit::paintEvent( TQPaintEvent *e )
392 {
393  KLineEdit::paintEvent( e );
394 
395  if ( !frame() ) {
396  TQPainter p( this );
397  p.setClipRegion( e->region() );
398  p.drawRect( rect() );
399  }
400 }
401 
402 // selection changed -> terminate. As our "item" can be already deleted,
403 // we can't call terminate(false), because that would emit done() with
404 // a dangling pointer to "item".
405 void KListViewLineEdit::slotSelectionChanged()
406 {
407  item = 0;
408  col = 0;
409  hide();
410 }
411 
412 // if the current item was removed -> terminate. Can't call terminate(false)
413 // due to same reason as slotSelectionChanged().
414 void KListViewLineEdit::slotItemRemoved(TQListViewItem *i)
415 {
416  if (currentItem() != i)
417  return;
418 
419  item = 0;
420  col = 0;
421  hide();
422 }
423 
424 
425 KListView::KListView( TQWidget *parent, const char *name )
426  : TQListView( parent, name ),
427  d (new KListViewPrivate (this))
428 {
429  setDragAutoScroll(true);
430 
431  connect( this, TQT_SIGNAL( onViewport() ),
432  this, TQT_SLOT( slotOnViewport() ) );
433  connect( this, TQT_SIGNAL( onItem( TQListViewItem * ) ),
434  this, TQT_SLOT( slotOnItem( TQListViewItem * ) ) );
435 
436  connect (this, TQT_SIGNAL(contentsMoving(int,int)),
437  this, TQT_SLOT(cleanDropVisualizer()));
438  connect (this, TQT_SIGNAL(contentsMoving(int,int)),
439  this, TQT_SLOT(cleanItemHighlighter()));
440 
441  slotSettingsChanged(KApplication::SETTINGS_MOUSE);
442  if (kapp)
443  {
444  connect( kapp, TQT_SIGNAL( settingsChanged(int) ), TQT_SLOT( slotSettingsChanged(int) ) );
445  kapp->addKipcEventMask( KIPC::SettingsChanged );
446  }
447 
448  connect(&d->autoSelect, TQT_SIGNAL( timeout() ),
449  this, TQT_SLOT( slotAutoSelect() ) );
450  connect(&d->dragExpand, TQT_SIGNAL( timeout() ),
451  this, TQT_SLOT( slotDragExpand() ) );
452 
453  // context menu handling
454  if (d->showContextMenusOnPress)
455  {
456  connect (this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)),
457  this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int)));
458  }
459  else
460  {
461  connect (this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)),
462  this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int)));
463  }
464 
465  connect (this, TQT_SIGNAL (menuShortCutPressed (KListView*, TQListViewItem*)),
466  this, TQT_SLOT (emitContextMenu (KListView*, TQListViewItem*)));
467  d->alternateBackground = KGlobalSettings::alternateBackgroundColor();
468 }
469 
470 KListView::~KListView()
471 {
472  delete d;
473 }
474 
475 bool KListView::isExecuteArea( const TQPoint& point )
476 {
477  TQListViewItem* item = itemAt( point );
478  if ( item ) {
479  return isExecuteArea( point.x(), item );
480  }
481 
482  return false;
483 }
484 
485 bool KListView::isExecuteArea( int x )
486 {
487  return isExecuteArea( x, 0 );
488 }
489 
490 bool KListView::isExecuteArea( int x, TQListViewItem* item )
491 {
492  if( allColumnsShowFocus() )
493  return true;
494  else {
495  int offset = 0;
496 
497 
498  int width = columnWidth( 0 );
499 
500  TQHeader* const thisHeader = header();
501  const int pos = thisHeader->mapToIndex( 0 );
502 
503  for ( int index = 0; index < pos; ++index )
504  offset += columnWidth( thisHeader->mapToSection( index ) );
505 
506  x += contentsX(); // in case of a horizontal scrollbar
507 
508  if ( item )
509  {
510  width = treeStepSize()*( item->depth() + ( rootIsDecorated() ? 1 : 0 ) );
511  width += itemMargin();
512  int ca = AlignHorizontal_Mask & columnAlignment( 0 );
513  if ( ca == AlignLeft || ca == AlignAuto ) {
514  width += item->width( fontMetrics(), this, 0 );
515  if ( width > columnWidth( 0 ) )
516  width = columnWidth( 0 );
517  }
518  }
519 
520  return ( x > offset && x < ( offset + width ) );
521  }
522 }
523 
524 void KListView::slotOnItem( TQListViewItem *item )
525 {
526  TQPoint vp = viewport()->mapFromGlobal( TQCursor::pos() );
527  if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) {
528  d->autoSelect.start( d->autoSelectDelay, true );
529  d->pCurrentItem = item;
530  }
531 }
532 
533 void KListView::slotOnViewport()
534 {
535  if ( d->bChangeCursorOverItem )
536  viewport()->unsetCursor();
537 
538  d->autoSelect.stop();
539  d->pCurrentItem = 0L;
540 }
541 
542 void KListView::slotSettingsChanged(int category)
543 {
544  switch (category)
545  {
546  case KApplication::SETTINGS_MOUSE:
547  d->dragDelay = KGlobalSettings::dndEventDelay();
548  d->bUseSingle = KGlobalSettings::singleClick();
549 
550  disconnect(this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)),
551  this, TQT_SLOT (slotMouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)));
552 
553  if( d->bUseSingle )
554  connect (this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)),
555  this, TQT_SLOT (slotMouseButtonClicked( int, TQListViewItem*, const TQPoint &, int)));
556 
557  d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon();
558  if ( !d->disableAutoSelection )
559  d->autoSelectDelay = KGlobalSettings::autoSelectDelay();
560 
561  if( !d->bUseSingle || !d->bChangeCursorOverItem )
562  viewport()->unsetCursor();
563 
564  break;
565 
566  case KApplication::SETTINGS_POPUPMENU:
567  d->contextMenuKey = KGlobalSettings::contextMenuKey ();
568  d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress ();
569 
570  if (d->showContextMenusOnPress)
571  {
572  disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int)));
573 
574  connect(this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)),
575  this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int)));
576  }
577  else
578  {
579  disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int)));
580 
581  connect(this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)),
582  this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int)));
583  }
584  break;
585 
586  default:
587  break;
588  }
589 }
590 
591 void KListView::slotAutoSelect()
592 {
593  // check that the item still exists
594  if( itemIndex( d->pCurrentItem ) == -1 )
595  return;
596 
597  if (!isActiveWindow())
598  {
599  d->autoSelect.stop();
600  return;
601  }
602 
603  //Give this widget the keyboard focus.
604  if( !hasFocus() )
605  setFocus();
606 
607  ButtonState keybstate = KApplication::keyboardMouseState();
608 
609  TQListViewItem* previousItem = currentItem();
610  setCurrentItem( d->pCurrentItem );
611 
612  if( d->pCurrentItem ) {
613  //Shift pressed?
614  if( (keybstate & TQt::ShiftButton) ) {
615  bool block = signalsBlocked();
616  blockSignals( true );
617 
618  //No Ctrl? Then clear before!
619  if( !(keybstate & TQt::ControlButton) )
620  clearSelection();
621 
622  bool select = !d->pCurrentItem->isSelected();
623  bool update = viewport()->isUpdatesEnabled();
624  viewport()->setUpdatesEnabled( false );
625 
626  bool down = previousItem->itemPos() < d->pCurrentItem->itemPos();
627  TQListViewItemIterator lit( down ? previousItem : d->pCurrentItem );
628  for ( ; lit.current(); ++lit ) {
629  if ( down && lit.current() == d->pCurrentItem ) {
630  d->pCurrentItem->setSelected( select );
631  break;
632  }
633  if ( !down && lit.current() == previousItem ) {
634  previousItem->setSelected( select );
635  break;
636  }
637  lit.current()->setSelected( select );
638  }
639 
640  blockSignals( block );
641  viewport()->setUpdatesEnabled( update );
642  triggerUpdate();
643 
644  emit selectionChanged();
645 
646  if( selectionMode() == TQListView::Single )
647  emit selectionChanged( d->pCurrentItem );
648  }
649  else if( (keybstate & KApplication::ControlModifier) )
650  setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() );
651  else {
652  bool block = signalsBlocked();
653  blockSignals( true );
654 
655  if( !d->pCurrentItem->isSelected() )
656  clearSelection();
657 
658  blockSignals( block );
659 
660  setSelected( d->pCurrentItem, true );
661  }
662  }
663  else
664  kdDebug() << "KListView::slotAutoSelect: That�s not supposed to happen!!!!" << endl;
665 }
666 
667 void KListView::slotHeaderChanged()
668 {
669 
670  const int colCount = columns();
671  if (d->fullWidth && colCount)
672  {
673  int w = 0;
674  const int lastColumn = colCount - 1;
675  for (int i = 0; i < lastColumn; ++i) w += columnWidth(i);
676  setColumnWidth( lastColumn, viewport()->width() - w - 1 );
677  }
678 }
679 
680 void KListView::emitExecute( TQListViewItem *item, const TQPoint &pos, int c )
681 {
682  if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) {
683  d->validDrag=false;
684 
685  // Double click mode ?
686  if ( !d->bUseSingle )
687  {
688  viewport()->unsetCursor();
689  emit executed( item );
690  emit executed( item, pos, c );
691  }
692  else
693  {
694  ButtonState keybstate = KApplication::keyboardMouseState();
695 
696  d->autoSelect.stop();
697 
698  //Don't emit executed if in SC mode and Shift or Ctrl are pressed
699  if( !( ((keybstate & TQt::ShiftButton) || (keybstate & TQt::ControlButton)) ) ) {
700  viewport()->unsetCursor();
701  emit executed( item );
702  emit executed( item, pos, c );
703  }
704  }
705  }
706 }
707 
708 void KListView::focusInEvent( TQFocusEvent *fe )
709 {
710  // kdDebug()<<"KListView::focusInEvent()"<<endl;
711  TQListView::focusInEvent( fe );
712  if ((d->selectedBySimpleMove)
713  && (d->selectionMode == FileManager)
714  && (fe->reason()!=TQFocusEvent::Popup)
715  && (fe->reason()!=TQFocusEvent::ActiveWindow)
716  && (currentItem()))
717  {
718  currentItem()->setSelected(true);
719  currentItem()->repaint();
720  emit selectionChanged();
721  };
722 }
723 
724 void KListView::focusOutEvent( TQFocusEvent *fe )
725 {
726  cleanDropVisualizer();
727  cleanItemHighlighter();
728 
729  d->autoSelect.stop();
730 
731  if ((d->selectedBySimpleMove)
732  && (d->selectionMode == FileManager)
733  && (fe->reason()!=TQFocusEvent::Popup)
734  && (fe->reason()!=TQFocusEvent::ActiveWindow)
735  && (currentItem())
736  && (!d->editor->isVisible()))
737  {
738  currentItem()->setSelected(false);
739  currentItem()->repaint();
740  emit selectionChanged();
741  };
742 
743  TQListView::focusOutEvent( fe );
744 }
745 
746 void KListView::leaveEvent( TQEvent *e )
747 {
748  d->autoSelect.stop();
749 
750  TQListView::leaveEvent( e );
751 }
752 
753 bool KListView::event( TQEvent *e )
754 {
755  if (e->type() == TQEvent::ApplicationPaletteChange)
756  d->alternateBackground=KGlobalSettings::alternateBackgroundColor();
757 
758  return TQListView::event(e);
759 }
760 
761 void KListView::contentsMousePressEvent( TQMouseEvent *e )
762 {
763  if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) )
764  {
765  bool block = signalsBlocked();
766  blockSignals( true );
767 
768  clearSelection();
769 
770  blockSignals( block );
771  }
772  else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove))
773  {
774  d->selectedBySimpleMove=false;
775  d->selectedUsingMouse=true;
776  if (currentItem())
777  {
778  currentItem()->setSelected(false);
779  currentItem()->repaint();
780 // emit selectionChanged();
781  }
782  }
783 
784  TQPoint p( contentsToViewport( e->pos() ) );
785  TQListViewItem *at = itemAt (p);
786 
787  // true if the root decoration of the item "at" was clicked (i.e. the +/- sign)
788  bool rootDecoClicked = at
789  && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) +
790  treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() )
791  && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) );
792 
793  if (e->button() == Qt::LeftButton && !rootDecoClicked)
794  {
795  //Start a drag
796  d->startDragPos = e->pos();
797 
798  if (at)
799  {
800  d->validDrag = true;
801  d->pressedOnSelected = at->isSelected();
802  }
803  }
804 
805  TQListView::contentsMousePressEvent( e );
806 }
807 
808 void KListView::contentsMouseMoveEvent( TQMouseEvent *e )
809 {
810  if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag)
811  TQListView::contentsMouseMoveEvent (e);
812 
813  TQPoint vp = contentsToViewport(e->pos());
814  TQListViewItem *item = itemAt( vp );
815 
816  //do we process cursor changes at all?
817  if ( item && d->bChangeCursorOverItem && d->bUseSingle )
818  {
819  //Cursor moved on a new item or in/out the execute area
820  if( (item != d->pCurrentItem) ||
821  (isExecuteArea(vp) != d->cursorInExecuteArea) )
822  {
823  d->cursorInExecuteArea = isExecuteArea(vp);
824 
825  if( d->cursorInExecuteArea ) //cursor moved in execute area
826  viewport()->setCursor( KCursor::handCursor() );
827  else //cursor moved out of execute area
828  viewport()->unsetCursor();
829  }
830  }
831 
832  bool dragOn = dragEnabled();
833  TQPoint newPos = e->pos();
834  if (dragOn && d->validDrag &&
835  (newPos.x() > d->startDragPos.x()+d->dragDelay ||
836  newPos.x() < d->startDragPos.x()-d->dragDelay ||
837  newPos.y() > d->startDragPos.y()+d->dragDelay ||
838  newPos.y() < d->startDragPos.y()-d->dragDelay))
839  //(d->startDragPos - e->pos()).manhattanLength() > TQApplication::startDragDistance())
840  {
841  TQListView::contentsMouseReleaseEvent( 0 );
842  startDrag();
843  d->startDragPos = TQPoint();
844  d->validDrag = false;
845  }
846 }
847 
848 void KListView::contentsMouseReleaseEvent( TQMouseEvent *e )
849 {
850  if (e->button() == Qt::LeftButton)
851  {
852  // If the row was already selected, maybe we want to start an in-place editing
853  if ( d->pressedOnSelected && itemsRenameable() )
854  {
855  TQPoint p( contentsToViewport( e->pos() ) );
856  TQListViewItem *at = itemAt (p);
857  if ( at )
858  {
859  // true if the root decoration of the item "at" was clicked (i.e. the +/- sign)
860  bool rootDecoClicked =
861  ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) +
862  treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() )
863  && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) );
864 
865  if (!rootDecoClicked)
866  {
867  int col = header()->mapToLogical( header()->cellAt( p.x() ) );
868  if ( d->renameable.contains(col) )
869  rename(at, col);
870  }
871  }
872  }
873 
874  d->pressedOnSelected = false;
875  d->validDrag = false;
876  d->startDragPos = TQPoint();
877  }
878  TQListView::contentsMouseReleaseEvent( e );
879 }
880 
881 void KListView::contentsMouseDoubleClickEvent ( TQMouseEvent *e )
882 {
883  // We don't want to call the parent method because it does setOpen,
884  // whereas we don't do it in single click mode... (David)
885  //TQListView::contentsMouseDoubleClickEvent( e );
886  if ( !e || e->button() != Qt::LeftButton )
887  return;
888 
889  TQPoint vp = contentsToViewport(e->pos());
890  TQListViewItem *item = itemAt( vp );
891  emit TQListView::doubleClicked( item ); // we do it now
892 
893  int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1;
894 
895  if( item ) {
896  emit doubleClicked( item, e->globalPos(), col );
897 
898  if( (e->button() == Qt::LeftButton) && !d->bUseSingle )
899  emitExecute( item, e->globalPos(), col );
900  }
901 }
902 
903 void KListView::slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c )
904 {
905  if( (btn == Qt::LeftButton) && item )
906  emitExecute(item, pos, c);
907 }
908 
909 void KListView::contentsDropEvent(TQDropEvent* e)
910 {
911  cleanDropVisualizer();
912  cleanItemHighlighter();
913  d->dragExpand.stop();
914 
915  if (acceptDrag (e))
916  {
917  e->acceptAction();
918  TQListViewItem *afterme;
919  TQListViewItem *parent;
920 
921  findDrop(e->pos(), parent, afterme);
922 
923  if (e->source() == viewport() && itemsMovable())
924  movableDropEvent(parent, afterme);
925  else
926  {
927  emit dropped(e, afterme);
928  emit dropped(this, e, afterme);
929  emit dropped(e, parent, afterme);
930  emit dropped(this, e, parent, afterme);
931  }
932  }
933 }
934 
935 void KListView::movableDropEvent (TQListViewItem* parent, TQListViewItem* afterme)
936 {
937  TQPtrList<TQListViewItem> items, afterFirsts, afterNows;
938  TQListViewItem *current=currentItem();
939  bool hasMoved=false;
940  for (TQListViewItem *i = firstChild(), *iNext=0; i; i = iNext)
941  {
942  iNext=i->itemBelow();
943  if (!i->isSelected())
944  continue;
945 
946  // don't drop an item after itself, or else
947  // it moves to the top of the list
948  if (i==afterme)
949  continue;
950 
951  i->setSelected(false);
952 
953  TQListViewItem *afterFirst = i->itemAbove();
954 
955  if (!hasMoved)
956  {
957  emit aboutToMove();
958  hasMoved=true;
959  }
960 
961  moveItem(i, parent, afterme);
962 
963  // ###### This should include the new parent !!! -> KDE 3.0
964  // If you need this right now, have a look at keditbookmarks.
965  emit moved(i, afterFirst, afterme);
966 
967  items.append (i);
968  afterFirsts.append (afterFirst);
969  afterNows.append (afterme);
970 
971  afterme = i;
972  }
973  clearSelection();
974  for (TQListViewItem *i=items.first(); i; i=items.next() )
975  i->setSelected(true);
976  if (current)
977  setCurrentItem(current);
978 
979  emit moved(items,afterFirsts,afterNows);
980 
981  if (firstChild())
982  emit moved();
983 }
984 
985 void KListView::contentsDragMoveEvent(TQDragMoveEvent *event)
986 {
987  if (acceptDrag(event))
988  {
989  event->acceptAction();
990  //Clean up the view
991 
992  findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop);
993  TQPoint vp = contentsToViewport( event->pos() );
994  TQListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L;
995 
996  if ( item != d->dragOverItem )
997  {
998  d->dragExpand.stop();
999  d->dragOverItem = item;
1000  d->dragOverPoint = vp;
1001  if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() )
1002  d->dragExpand.start( TQApplication::startDragTime(), true );
1003  }
1004  if (dropVisualizer())
1005  {
1006  TQRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop);
1007  if (tmpRect != d->mOldDropVisualizer)
1008  {
1009  cleanDropVisualizer();
1010  d->mOldDropVisualizer=tmpRect;
1011  viewport()->repaint(tmpRect);
1012  }
1013  }
1014  if (dropHighlighter())
1015  {
1016  TQRect tmpRect = drawItemHighlighter(0, itemAt( vp ));
1017  if (tmpRect != d->mOldDropHighlighter)
1018  {
1019  cleanItemHighlighter();
1020  d->mOldDropHighlighter=tmpRect;
1021  viewport()->repaint(tmpRect);
1022  }
1023  }
1024  }
1025  else
1026  event->ignore();
1027 }
1028 
1029 void KListView::slotDragExpand()
1030 {
1031  if ( itemAt( d->dragOverPoint ) == d->dragOverItem )
1032  d->dragOverItem->setOpen( true );
1033 }
1034 
1035 void KListView::contentsDragLeaveEvent (TQDragLeaveEvent*)
1036 {
1037  d->dragExpand.stop();
1038  cleanDropVisualizer();
1039  cleanItemHighlighter();
1040 }
1041 
1042 void KListView::cleanDropVisualizer()
1043 {
1044  if (d->mOldDropVisualizer.isValid())
1045  {
1046  TQRect rect=d->mOldDropVisualizer;
1047  d->mOldDropVisualizer = TQRect();
1048  viewport()->repaint(rect, true);
1049  }
1050 }
1051 
1052 int KListView::depthToPixels( int depth )
1053 {
1054  return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin();
1055 }
1056 
1057 void KListView::findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after)
1058 {
1059  TQPoint p (contentsToViewport(pos));
1060 
1061  // Get the position to put it in
1062  TQListViewItem *atpos = itemAt(p);
1063 
1064  TQListViewItem *above;
1065  if (!atpos) // put it at the end
1066  above = lastItem();
1067  else
1068  {
1069  // Get the closest item before us ('atpos' or the one above, if any)
1070  if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2))
1071  above = atpos->itemAbove();
1072  else
1073  above = atpos;
1074  }
1075 
1076  if (above)
1077  {
1078  // if above has children, I might need to drop it as the first item there
1079 
1080  if (above->firstChild() && above->isOpen())
1081  {
1082  parent = above;
1083  after = 0;
1084  return;
1085  }
1086 
1087  // Now, we know we want to go after "above". But as a child or as a sibling ?
1088  // We have to ask the "above" item if it accepts children.
1089  if (above->isExpandable())
1090  {
1091  // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children
1092  if (p.x() >= depthToPixels( above->depth() + 1 ) ||
1093  (above->isOpen() && above->childCount() > 0) )
1094  {
1095  parent = above;
1096  after = 0L;
1097  return;
1098  }
1099  }
1100 
1101  // Ok, there's one more level of complexity. We may want to become a new
1102  // sibling, but of an upper-level group, rather than the "above" item
1103  TQListViewItem * betterAbove = above->parent();
1104  TQListViewItem * last = above;
1105  while ( betterAbove )
1106  {
1107  // We are allowed to become a sibling of "betterAbove" only if we are
1108  // after its last child
1109  if ( !last->nextSibling() )
1110  {
1111  if (p.x() < depthToPixels ( betterAbove->depth() + 1 ))
1112  above = betterAbove; // store this one, but don't stop yet, there may be a better one
1113  else
1114  break; // not enough on the left, so stop
1115  last = betterAbove;
1116  betterAbove = betterAbove->parent(); // up one level
1117  } else
1118  break; // we're among the child of betterAbove, not after the last one
1119  }
1120  }
1121  // set as sibling
1122  after = above;
1123  parent = after ? after->parent() : 0L ;
1124 }
1125 
1126 TQListViewItem* KListView::lastChild () const
1127 {
1128  TQListViewItem* lastchild = firstChild();
1129 
1130  if (lastchild)
1131  for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling());
1132 
1133  return lastchild;
1134 }
1135 
1136 TQListViewItem *KListView::lastItem() const
1137 {
1138  TQListViewItem* last = lastChild();
1139 
1140  for (TQListViewItemIterator it (last); it.current(); ++it)
1141  last = it.current();
1142 
1143  return last;
1144 }
1145 
1146 KLineEdit *KListView::renameLineEdit() const
1147 {
1148  return d->editor;
1149 }
1150 
1151 void KListView::startDrag()
1152 {
1153  TQDragObject *drag = dragObject();
1154 
1155  if (!drag)
1156  return;
1157 
1158  if (drag->drag() && drag->target() != viewport())
1159  emit moved();
1160 }
1161 
1162 TQDragObject *KListView::dragObject()
1163 {
1164  if (!currentItem())
1165  return 0;
1166 
1167 
1168  return new TQStoredDrag("application/x-qlistviewitem", viewport());
1169 }
1170 
1171 void KListView::setItemsMovable(bool b)
1172 {
1173  d->itemsMovable=b;
1174 }
1175 
1176 bool KListView::itemsMovable() const
1177 {
1178  return d->itemsMovable;
1179 }
1180 
1181 void KListView::setItemsRenameable(bool b)
1182 {
1183  d->itemsRenameable=b;
1184 }
1185 
1186 bool KListView::itemsRenameable() const
1187 {
1188  return d->itemsRenameable;
1189 }
1190 
1191 
1192 void KListView::setDragEnabled(bool b)
1193 {
1194  d->dragEnabled=b;
1195 }
1196 
1197 bool KListView::dragEnabled() const
1198 {
1199  return d->dragEnabled;
1200 }
1201 
1202 void KListView::setAutoOpen(bool b)
1203 {
1204  d->autoOpen=b;
1205 }
1206 
1207 bool KListView::autoOpen() const
1208 {
1209  return d->autoOpen;
1210 }
1211 
1212 bool KListView::dropVisualizer() const
1213 {
1214  return d->dropVisualizer;
1215 }
1216 
1217 void KListView::setDropVisualizer(bool b)
1218 {
1219  d->dropVisualizer=b;
1220 }
1221 
1222 TQPtrList<TQListViewItem> KListView::selectedItems() const
1223 {
1224  return selectedItems(true);
1225 }
1226 
1227 TQPtrList<TQListViewItem> KListView::selectedItems(bool includeHiddenItems) const
1228 {
1229  TQPtrList<TQListViewItem> list;
1230 
1231  // Using selectionMode() instead of selectionModeExt() since for the cases that
1232  // we're interested in selectionMode() should work for either variety of the
1233  // setSelectionMode().
1234 
1235  switch(selectionMode())
1236  {
1237  case NoSelection:
1238  break;
1239  case Single:
1240  if(selectedItem() && (includeHiddenItems || selectedItem()->isVisible()))
1241  list.append(selectedItem());
1242  break;
1243  default:
1244  {
1245  int flags = TQListViewItemIterator::Selected;
1246  if (!includeHiddenItems)
1247  {
1248  flags |= TQListViewItemIterator::Visible;
1249  }
1250 
1251  TQListViewItemIterator it(const_cast<KListView *>(this), flags);
1252 
1253  for(; it.current(); ++it)
1254  list.append(it.current());
1255 
1256  break;
1257  }
1258  }
1259 
1260  return list;
1261 }
1262 
1263 
1264 void KListView::moveItem(TQListViewItem *item, TQListViewItem *parent, TQListViewItem *after)
1265 {
1266  // sanity check - don't move a item into its own child structure
1267  TQListViewItem *i = parent;
1268  while(i)
1269  {
1270  if(i == item)
1271  return;
1272  i = i->parent();
1273  }
1274 
1275  if (after)
1276  {
1277  item->moveItem(after);
1278  return;
1279  }
1280 
1281  // Basically reimplementing the TQListViewItem(TQListViewItem*, TQListViewItem*) constructor
1282  // in here, without ever deleting the item.
1283  if (item->parent())
1284  item->parent()->takeItem(item);
1285  else
1286  takeItem(item);
1287 
1288  if (parent)
1289  parent->insertItem(item);
1290  else
1291  insertItem(item);
1292 }
1293 
1294 void KListView::contentsDragEnterEvent(TQDragEnterEvent *event)
1295 {
1296  if (acceptDrag (event))
1297  event->accept();
1298 }
1299 
1300 void KListView::setDropVisualizerWidth (int w)
1301 {
1302  d->mDropVisualizerWidth = w > 0 ? w : 1;
1303 }
1304 
1305 TQRect KListView::drawDropVisualizer(TQPainter *p, TQListViewItem *parent,
1306  TQListViewItem *after)
1307 {
1308  TQRect insertmarker;
1309 
1310  if (!after && !parent)
1311  insertmarker = TQRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2);
1312  else
1313  {
1314  int level = 0;
1315  if (after)
1316  {
1317  TQListViewItem* it = 0L;
1318  if (after->isOpen())
1319  {
1320  // Look for the last child (recursively)
1321  it = after->firstChild();
1322  if (it)
1323  while (it->nextSibling() || it->firstChild())
1324  if ( it->nextSibling() )
1325  it = it->nextSibling();
1326  else
1327  it = it->firstChild();
1328  }
1329 
1330  insertmarker = itemRect (it ? it : after);
1331  level = after->depth();
1332  }
1333  else if (parent)
1334  {
1335  insertmarker = itemRect (parent);
1336  level = parent->depth() + 1;
1337  }
1338  insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() );
1339  insertmarker.setRight (viewport()->width());
1340  insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1);
1341  insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2);
1342  }
1343 
1344  // This is not used anymore, at least by KListView itself (see viewportPaintEvent)
1345  // Remove for KDE 4.0.
1346  if (p)
1347  p->fillRect(insertmarker, Dense4Pattern);
1348 
1349  return insertmarker;
1350 }
1351 
1352 TQRect KListView::drawItemHighlighter(TQPainter *painter, TQListViewItem *item)
1353 {
1354  TQRect r;
1355 
1356  if (item)
1357  {
1358  r = itemRect(item);
1359  r.setLeft(r.left()+(item->depth()+(rootIsDecorated() ? 1 : 0))*treeStepSize());
1360  if (painter)
1361  style().tqdrawPrimitive(TQStyle::PE_FocusRect, painter, r, colorGroup(),
1362  TQStyle::Style_FocusAtBorder, colorGroup().highlight());
1363  }
1364 
1365  return r;
1366 }
1367 
1368 void KListView::cleanItemHighlighter ()
1369 {
1370  if (d->mOldDropHighlighter.isValid())
1371  {
1372  TQRect rect=d->mOldDropHighlighter;
1373  d->mOldDropHighlighter = TQRect();
1374  viewport()->repaint(rect, true);
1375  }
1376 }
1377 
1378 void KListView::rename(TQListViewItem *item, int c)
1379 {
1380  if (d->renameable.contains(c))
1381  {
1382  ensureItemVisible(item);
1383  d->editor->load(item,c);
1384  }
1385 }
1386 
1387 bool KListView::isRenameable (int col) const
1388 {
1389  return d->renameable.contains(col);
1390 }
1391 
1392 void KListView::setRenameable (int col, bool renameable)
1393 {
1394  if (col>=header()->count()) return;
1395 
1396  d->renameable.remove(col);
1397  if (renameable)
1398  d->renameable+=col;
1399 }
1400 
1401 void KListView::doneEditing(TQListViewItem *item, int row)
1402 {
1403  emit itemRenamed(item, item->text(row), row);
1404  emit itemRenamed(item);
1405 }
1406 
1407 bool KListView::acceptDrag(TQDropEvent* e) const
1408 {
1409  return acceptDrops() && itemsMovable() && (e->source()==viewport());
1410 }
1411 
1412 void KListView::setCreateChildren(bool b)
1413 {
1414  d->createChildren=b;
1415 }
1416 
1417 bool KListView::createChildren() const
1418 {
1419  return d->createChildren;
1420 }
1421 
1422 
1423 int KListView::tooltipColumn() const
1424 {
1425  return d->tooltipColumn;
1426 }
1427 
1428 void KListView::setTooltipColumn(int column)
1429 {
1430  d->tooltipColumn=column;
1431 }
1432 
1433 void KListView::setDropHighlighter(bool b)
1434 {
1435  d->dropHighlighter=b;
1436 }
1437 
1438 bool KListView::dropHighlighter() const
1439 {
1440  return d->dropHighlighter;
1441 }
1442 
1443 bool KListView::showTooltip(TQListViewItem *item, const TQPoint &, int column) const
1444 {
1445  return ((column==tooltipColumn()) && !tooltip(item, column).isEmpty());
1446 }
1447 
1448 TQString KListView::tooltip(TQListViewItem *item, int column) const
1449 {
1450  return item->text(column);
1451 }
1452 
1453 void KListView::setTabOrderedRenaming(bool b)
1454 {
1455  d->tabRename = b;
1456 }
1457 
1458 bool KListView::tabOrderedRenaming() const
1459 {
1460  return d->tabRename;
1461 }
1462 
1463 void KListView::keyPressEvent (TQKeyEvent* e)
1464 {
1465  //don't we need a contextMenuModifier too ? (aleXXX)
1466  if (e->key() == d->contextMenuKey)
1467  {
1468  emit menuShortCutPressed (this, currentItem());
1469  return;
1470  }
1471 
1472  if (d->selectionMode != FileManager)
1473  TQListView::keyPressEvent (e);
1474  else
1475  fileManagerKeyPressEvent (e);
1476 }
1477 
1478 void KListView::activateAutomaticSelection()
1479 {
1480  d->selectedBySimpleMove=true;
1481  d->selectedUsingMouse=false;
1482  if (currentItem())
1483  {
1484  currentItem()->setSelected(true);
1485  currentItem()->repaint();
1486  emit selectionChanged();
1487  };
1488 }
1489 
1490 void KListView::deactivateAutomaticSelection()
1491 {
1492  d->selectedBySimpleMove=false;
1493 }
1494 
1495 bool KListView::automaticSelection() const
1496 {
1497  return d->selectedBySimpleMove;
1498 }
1499 
1500 void KListView::fileManagerKeyPressEvent (TQKeyEvent* e)
1501 {
1502  //don't care whether it's on the keypad or not
1503  int e_state=(e->state() & ~Keypad);
1504 
1505  int oldSelectionDirection(d->selectionDirection);
1506 
1507  if ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
1508  && (e->key()!=Key_Meta) && (e->key()!=Key_Alt))
1509  {
1510  if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove))
1511  selectAll(false);
1512  d->selectionDirection=0;
1513  d->wasShiftEvent = (e_state == ShiftButton);
1514  };
1515 
1516  //d->wasShiftEvent = (e_state == ShiftButton);
1517 
1518 
1519  TQListViewItem* item = currentItem();
1520  if (!item) return;
1521 
1522  TQListViewItem* repaintItem1 = item;
1523  TQListViewItem* repaintItem2 = 0L;
1524  TQListViewItem* visItem = 0L;
1525 
1526  TQListViewItem* nextItem = 0L;
1527  int items = 0;
1528 
1529  bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton));
1530  int selectedItems(0);
1531  for (TQListViewItem *tmpItem=firstChild(); tmpItem; tmpItem=tmpItem->nextSibling())
1532  if (tmpItem->isSelected()) selectedItems++;
1533 
1534  if (((!selectedItems) || ((selectedItems==1) && (d->selectedUsingMouse)))
1535  && (e_state==Qt::NoButton)
1536  && ((e->key()==Key_Down)
1537  || (e->key()==Key_Up)
1538  || (e->key()==Key_Next)
1539  || (e->key()==Key_Prior)
1540  || (e->key()==Key_Home)
1541  || (e->key()==Key_End)))
1542  {
1543  d->selectedBySimpleMove=true;
1544  d->selectedUsingMouse=false;
1545  }
1546  else if (selectedItems>1)
1547  d->selectedBySimpleMove=false;
1548 
1549  bool emitSelectionChanged(false);
1550 
1551  switch (e->key())
1552  {
1553  case Key_Escape:
1554  selectAll(false);
1555  emitSelectionChanged=true;
1556  break;
1557 
1558  case Key_Space:
1559  //toggle selection of current item
1560  if (d->selectedBySimpleMove)
1561  d->selectedBySimpleMove=false;
1562  item->setSelected(!item->isSelected());
1563  emitSelectionChanged=true;
1564  break;
1565 
1566  case Key_Insert:
1567  //toggle selection of current item and move to the next item
1568  if (d->selectedBySimpleMove)
1569  {
1570  d->selectedBySimpleMove=false;
1571  if (!item->isSelected()) item->setSelected(true);
1572  }
1573  else
1574  {
1575  item->setSelected(!item->isSelected());
1576  };
1577 
1578  nextItem=item->itemBelow();
1579 
1580  if (nextItem)
1581  {
1582  repaintItem2=nextItem;
1583  visItem=nextItem;
1584  setCurrentItem(nextItem);
1585  };
1586  d->selectionDirection=1;
1587  emitSelectionChanged=true;
1588  break;
1589 
1590  case Key_Down:
1591  nextItem=item->itemBelow();
1592  //toggle selection of current item and move to the next item
1593  if (shiftOrCtrl)
1594  {
1595  d->selectionDirection=1;
1596  if (d->selectedBySimpleMove)
1597  d->selectedBySimpleMove=false;
1598  else
1599  {
1600  if (oldSelectionDirection!=-1)
1601  {
1602  item->setSelected(!item->isSelected());
1603  emitSelectionChanged=true;
1604  };
1605  };
1606  }
1607  else if ((d->selectedBySimpleMove) && (nextItem))
1608  {
1609  item->setSelected(false);
1610  emitSelectionChanged=true;
1611  };
1612 
1613  if (nextItem)
1614  {
1615  if (d->selectedBySimpleMove)
1616  nextItem->setSelected(true);
1617  repaintItem2=nextItem;
1618  visItem=nextItem;
1619  setCurrentItem(nextItem);
1620  };
1621  break;
1622 
1623  case Key_Up:
1624  nextItem=item->itemAbove();
1625  d->selectionDirection=-1;
1626  //move to the prev. item and toggle selection of this one
1627  // => No, can't select the last item, with this. For symmetry, let's
1628  // toggle selection and THEN move up, just like we do in down (David)
1629  if (shiftOrCtrl)
1630  {
1631  if (d->selectedBySimpleMove)
1632  d->selectedBySimpleMove=false;
1633  else
1634  {
1635  if (oldSelectionDirection!=1)
1636  {
1637  item->setSelected(!item->isSelected());
1638  emitSelectionChanged=true;
1639  };
1640  }
1641  }
1642  else if ((d->selectedBySimpleMove) && (nextItem))
1643  {
1644  item->setSelected(false);
1645  emitSelectionChanged=true;
1646  };
1647 
1648  if (nextItem)
1649  {
1650  if (d->selectedBySimpleMove)
1651  nextItem->setSelected(true);
1652  repaintItem2=nextItem;
1653  visItem=nextItem;
1654  setCurrentItem(nextItem);
1655  };
1656  break;
1657 
1658  case Key_End:
1659  //move to the last item and toggle selection of all items inbetween
1660  nextItem=item;
1661  if (d->selectedBySimpleMove)
1662  item->setSelected(false);
1663  if (shiftOrCtrl)
1664  d->selectedBySimpleMove=false;
1665 
1666  while(nextItem)
1667  {
1668  if (shiftOrCtrl)
1669  nextItem->setSelected(!nextItem->isSelected());
1670  if (!nextItem->itemBelow())
1671  {
1672  if (d->selectedBySimpleMove)
1673  nextItem->setSelected(true);
1674  repaintItem2=nextItem;
1675  visItem=nextItem;
1676  setCurrentItem(nextItem);
1677  }
1678  nextItem=nextItem->itemBelow();
1679  }
1680  emitSelectionChanged=true;
1681  break;
1682 
1683  case Key_Home:
1684  // move to the first item and toggle selection of all items inbetween
1685  nextItem = firstChild();
1686  visItem = nextItem;
1687  repaintItem2 = visItem;
1688  if (d->selectedBySimpleMove)
1689  item->setSelected(false);
1690  if (shiftOrCtrl)
1691  {
1692  d->selectedBySimpleMove=false;
1693 
1694  while ( nextItem != item )
1695  {
1696  nextItem->setSelected( !nextItem->isSelected() );
1697  nextItem = nextItem->itemBelow();
1698  }
1699  item->setSelected( !item->isSelected() );
1700  }
1701  setCurrentItem( firstChild() );
1702  emitSelectionChanged=true;
1703  break;
1704 
1705  case Key_Next:
1706  items=visibleHeight()/item->height();
1707  nextItem=item;
1708  if (d->selectedBySimpleMove)
1709  item->setSelected(false);
1710  if (shiftOrCtrl)
1711  {
1712  d->selectedBySimpleMove=false;
1713  d->selectionDirection=1;
1714  };
1715 
1716  for (int i=0; i<items; i++)
1717  {
1718  if (shiftOrCtrl)
1719  nextItem->setSelected(!nextItem->isSelected());
1720  //the end
1721  if ((i==items-1) || (!nextItem->itemBelow()))
1722 
1723  {
1724  if (shiftOrCtrl)
1725  nextItem->setSelected(!nextItem->isSelected());
1726  if (d->selectedBySimpleMove)
1727  nextItem->setSelected(true);
1728  ensureItemVisible(nextItem);
1729  setCurrentItem(nextItem);
1730  update();
1731  if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1732  {
1733  emit selectionChanged();
1734  }
1735  return;
1736  }
1737  nextItem=nextItem->itemBelow();
1738  }
1739  break;
1740 
1741  case Key_Prior:
1742  items=visibleHeight()/item->height();
1743  nextItem=item;
1744  if (d->selectedBySimpleMove)
1745  item->setSelected(false);
1746  if (shiftOrCtrl)
1747  {
1748  d->selectionDirection=-1;
1749  d->selectedBySimpleMove=false;
1750  };
1751 
1752  for (int i=0; i<items; i++)
1753  {
1754  if ((nextItem!=item) &&(shiftOrCtrl))
1755  nextItem->setSelected(!nextItem->isSelected());
1756  //the end
1757  if ((i==items-1) || (!nextItem->itemAbove()))
1758 
1759  {
1760  if (d->selectedBySimpleMove)
1761  nextItem->setSelected(true);
1762  ensureItemVisible(nextItem);
1763  setCurrentItem(nextItem);
1764  update();
1765  if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1766  {
1767  emit selectionChanged();
1768  }
1769  return;
1770  }
1771  nextItem=nextItem->itemAbove();
1772  }
1773  break;
1774 
1775  case Key_Minus:
1776  if ( item->isOpen() )
1777  setOpen( item, false );
1778  break;
1779  case Key_Plus:
1780  if ( !item->isOpen() && (item->isExpandable() || item->childCount()) )
1781  setOpen( item, true );
1782  break;
1783  default:
1784  bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
1785  && (e->key()!=Key_Meta) && (e->key()!=Key_Alt));
1786 
1787  bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected());
1788  if (realKey && selectCurrentItem)
1789  item->setSelected(false);
1790  //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX)
1791  TQListView::SelectionMode oldSelectionMode = selectionMode();
1792  setSelectionMode (TQListView::Multi);
1793  TQListView::keyPressEvent (e);
1794  setSelectionMode (oldSelectionMode);
1795  if (realKey && selectCurrentItem)
1796  {
1797  currentItem()->setSelected(true);
1798  emitSelectionChanged=true;
1799  }
1800  repaintItem2=currentItem();
1801  if (realKey)
1802  visItem=currentItem();
1803  break;
1804  }
1805 
1806  if (visItem)
1807  ensureItemVisible(visItem);
1808 
1809  TQRect ir;
1810  if (repaintItem1)
1811  ir = ir.unite( itemRect(repaintItem1) );
1812  if (repaintItem2)
1813  ir = ir.unite( itemRect(repaintItem2) );
1814 
1815  if ( !ir.isEmpty() )
1816  { // rectangle to be repainted
1817  if ( ir.x() < 0 )
1818  ir.moveBy( -ir.x(), 0 );
1819  viewport()->repaint( ir, false );
1820  }
1821  /*if (repaintItem1)
1822  repaintItem1->repaint();
1823  if (repaintItem2)
1824  repaintItem2->repaint();*/
1825  update();
1826  if (emitSelectionChanged)
1827  emit selectionChanged();
1828 }
1829 
1830 void KListView::setSelectionModeExt (SelectionModeExt mode)
1831 {
1832  d->selectionMode = mode;
1833 
1834  switch (mode)
1835  {
1836  case Single:
1837  case Multi:
1838  case Extended:
1839  case NoSelection:
1840  setSelectionMode (static_cast<TQListView::SelectionMode>(static_cast<int>(mode)));
1841  break;
1842 
1843  case FileManager:
1844  setSelectionMode (TQListView::Extended);
1845  break;
1846 
1847  default:
1848  kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl;
1849  break;
1850  }
1851 }
1852 
1853 KListView::SelectionModeExt KListView::selectionModeExt () const
1854 {
1855  return d->selectionMode;
1856 }
1857 
1858 int KListView::itemIndex( const TQListViewItem *item ) const
1859 {
1860  if ( !item )
1861  return -1;
1862 
1863  if ( item == firstChild() )
1864  return 0;
1865  else {
1866  TQListViewItemIterator it(firstChild());
1867  uint j = 0;
1868  for (; it.current() && it.current() != item; ++it, ++j );
1869 
1870  if( !it.current() )
1871  return -1;
1872 
1873  return j;
1874  }
1875 }
1876 
1877 TQListViewItem* KListView::itemAtIndex(int index)
1878 {
1879  if (index<0)
1880  return 0;
1881 
1882  int j(0);
1883  for (TQListViewItemIterator it=firstChild(); it.current(); ++it)
1884  {
1885  if (j==index)
1886  return it.current();
1887  ++j;
1888  };
1889  return 0;
1890 }
1891 
1892 
1893 void KListView::emitContextMenu (KListView*, TQListViewItem* i)
1894 {
1895  TQPoint p;
1896 
1897  if (i)
1898  p = viewport()->mapToGlobal(itemRect(i).center());
1899  else
1900  p = mapToGlobal(rect().center());
1901 
1902  emit contextMenu (this, i, p);
1903 }
1904 
1905 void KListView::emitContextMenu (TQListViewItem* i, const TQPoint& p, int)
1906 {
1907  emit contextMenu (this, i, p);
1908 }
1909 
1910 void KListView::setAcceptDrops (bool val)
1911 {
1912  TQListView::setAcceptDrops (val);
1913  viewport()->setAcceptDrops (val);
1914 }
1915 
1916 int KListView::dropVisualizerWidth () const
1917 {
1918  return d->mDropVisualizerWidth;
1919 }
1920 
1921 
1922 void KListView::viewportPaintEvent(TQPaintEvent *e)
1923 {
1924  d->paintAbove = 0;
1925  d->paintCurrent = 0;
1926  d->paintBelow = 0;
1927  d->painting = true;
1928 
1929  TQListView::viewportPaintEvent(e);
1930 
1931  if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer))
1932  {
1933  TQPainter painter(viewport());
1934 
1935  // This is where we actually draw the drop-visualizer
1936  painter.fillRect(d->mOldDropVisualizer, Dense4Pattern);
1937  }
1938  if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter))
1939  {
1940  TQPainter painter(viewport());
1941 
1942  // This is where we actually draw the drop-highlighter
1943  style().tqdrawPrimitive(TQStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(),
1944  TQStyle::Style_FocusAtBorder);
1945  }
1946  d->painting = false;
1947 }
1948 
1949 void KListView::setFullWidth()
1950 {
1951  setFullWidth(true);
1952 }
1953 
1954 void KListView::setFullWidth(bool fullWidth)
1955 {
1956  d->fullWidth = fullWidth;
1957  header()->setStretchEnabled(fullWidth, columns()-1);
1958 }
1959 
1960 bool KListView::fullWidth() const
1961 {
1962  return d->fullWidth;
1963 }
1964 
1965 int KListView::addColumn(const TQString& label, int width)
1966 {
1967  int result = TQListView::addColumn(label, width);
1968  if (d->fullWidth) {
1969  header()->setStretchEnabled(false, columns()-2);
1970  header()->setStretchEnabled(true, columns()-1);
1971  }
1972  return result;
1973 }
1974 
1975 int KListView::addColumn(const TQIconSet& iconset, const TQString& label, int width)
1976 {
1977  int result = TQListView::addColumn(iconset, label, width);
1978  if (d->fullWidth) {
1979  header()->setStretchEnabled(false, columns()-2);
1980  header()->setStretchEnabled(true, columns()-1);
1981  }
1982  return result;
1983 }
1984 
1985 void KListView::removeColumn(int index)
1986 {
1987  TQListView::removeColumn(index);
1988  if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1);
1989 }
1990 
1991 void KListView::viewportResizeEvent(TQResizeEvent* e)
1992 {
1993  TQListView::viewportResizeEvent(e);
1994 }
1995 
1996 const TQColor &KListView::alternateBackground() const
1997 {
1998  return d->alternateBackground;
1999 }
2000 
2001 void KListView::setAlternateBackground(const TQColor &c)
2002 {
2003  d->alternateBackground = c;
2004  repaint();
2005 }
2006 
2007 void KListView::setShadeSortColumn(bool shadeSortColumn)
2008 {
2009  d->shadeSortColumn = shadeSortColumn;
2010  repaint();
2011 }
2012 
2013 bool KListView::shadeSortColumn() const
2014 {
2015  return d->shadeSortColumn;
2016 }
2017 
2018 void KListView::saveLayout(KConfig *config, const TQString &group) const
2019 {
2020  KConfigGroupSaver saver(config, group);
2021  TQStringList widths, order;
2022 
2023  const int colCount = columns();
2024  TQHeader* const thisHeader = header();
2025  for (int i = 0; i < colCount; ++i)
2026  {
2027  widths << TQString::number(columnWidth(i));
2028  order << TQString::number(thisHeader->mapToIndex(i));
2029  }
2030  config->writeEntry("ColumnWidths", widths);
2031  config->writeEntry("ColumnOrder", order);
2032  config->writeEntry("SortColumn", d->sortColumn);
2033  config->writeEntry("SortAscending", d->sortAscending);
2034 }
2035 
2036 void KListView::restoreLayout(KConfig *config, const TQString &group)
2037 {
2038  KConfigGroupSaver saver(config, group);
2039  TQStringList cols = config->readListEntry("ColumnWidths");
2040  int i = 0;
2041  { // scope the iterators
2042  TQStringList::ConstIterator it = cols.constBegin();
2043  const TQStringList::ConstIterator itEnd = cols.constEnd();
2044  for (; it != itEnd; ++it)
2045  setColumnWidth(i++, (*it).toInt());
2046  }
2047 
2048  // move sections in the correct sequence: from lowest to highest index position
2049  // otherwise we move a section from an index, which modifies
2050  // all index numbers to the right of the moved one
2051  cols = config->readListEntry("ColumnOrder");
2052  const int colCount = columns();
2053  for (i = 0; i < colCount; ++i) // final index positions from lowest to highest
2054  {
2055  TQStringList::ConstIterator it = cols.constBegin();
2056  const TQStringList::ConstIterator itEnd = cols.constEnd();
2057 
2058  int section = 0;
2059  for (; (it != itEnd) && ((*it).toInt() != i); ++it, ++section) ;
2060 
2061  if ( it != itEnd ) {
2062  // found the section to move to position i
2063  header()->moveSection(section, i);
2064  }
2065  }
2066 
2067  if (config->hasKey("SortColumn"))
2068  setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true));
2069 }
2070 
2071 void KListView::setSorting(int column, bool ascending)
2072 {
2073  TQListViewItem *selected = 0;
2074 
2075  if (selectionMode() == TQListView::Single) {
2076  selected = selectedItem();
2077  if (selected && !selected->isVisible())
2078  selected = 0;
2079  }
2080  else if (selectionMode() != TQListView::NoSelection) {
2081  TQListViewItem *item = firstChild();
2082  while (item && !selected) {
2083  if (item->isSelected() && item->isVisible())
2084  selected = item;
2085  item = item->itemBelow();
2086  }
2087  }
2088 
2089  d->sortColumn = column;
2090  d->sortAscending = ascending;
2091  TQListView::setSorting(column, ascending);
2092 
2093  if (selected)
2094  ensureItemVisible(selected);
2095 
2096  TQListViewItem* item = firstChild();
2097  while ( item ) {
2098  KListViewItem *kItem = dynamic_cast<KListViewItem*>(item);
2099  if (kItem) kItem->m_known = false;
2100  item = item->itemBelow();
2101  }
2102 }
2103 
2104 int KListView::columnSorted(void) const
2105 {
2106  return d->sortColumn;
2107 }
2108 
2109 bool KListView::ascendingSort(void) const
2110 {
2111  return d->sortAscending;
2112 }
2113 
2114 void KListView::takeItem(TQListViewItem *item)
2115 {
2116  if(item && item == d->editor->currentItem())
2117  d->editor->terminate();
2118 
2119  TQListView::takeItem(item);
2120 }
2121 
2122 void KListView::disableAutoSelection()
2123 {
2124  if ( d->disableAutoSelection )
2125  return;
2126 
2127  d->disableAutoSelection = true;
2128  d->autoSelect.stop();
2129  d->autoSelectDelay = -1;
2130 }
2131 
2132 void KListView::resetAutoSelection()
2133 {
2134  if ( !d->disableAutoSelection )
2135  return;
2136 
2137  d->disableAutoSelection = false;
2138  d->autoSelectDelay = KGlobalSettings::autoSelectDelay();
2139 }
2140 
2141 void KListView::doubleClicked( TQListViewItem *item, const TQPoint &pos, int c )
2142 {
2143  emit TQListView::doubleClicked( item, pos, c );
2144 }
2145 
2146 KListViewItem::KListViewItem(TQListView *parent)
2147  : TQListViewItem(parent)
2148 {
2149  init();
2150 }
2151 
2152 KListViewItem::KListViewItem(TQListViewItem *parent)
2153  : TQListViewItem(parent)
2154 {
2155  init();
2156 }
2157 
2158 KListViewItem::KListViewItem(TQListView *parent, TQListViewItem *after)
2159  : TQListViewItem(parent, after)
2160 {
2161  init();
2162 }
2163 
2164 KListViewItem::KListViewItem(TQListViewItem *parent, TQListViewItem *after)
2165  : TQListViewItem(parent, after)
2166 {
2167  init();
2168 }
2169 
2170 KListViewItem::KListViewItem(TQListView *parent,
2171  TQString label1, TQString label2, TQString label3, TQString label4,
2172  TQString label5, TQString label6, TQString label7, TQString label8)
2173  : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2174 {
2175  init();
2176 }
2177 
2178 KListViewItem::KListViewItem(TQListViewItem *parent,
2179  TQString label1, TQString label2, TQString label3, TQString label4,
2180  TQString label5, TQString label6, TQString label7, TQString label8)
2181  : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2182 {
2183  init();
2184 }
2185 
2186 KListViewItem::KListViewItem(TQListView *parent, TQListViewItem *after,
2187  TQString label1, TQString label2, TQString label3, TQString label4,
2188  TQString label5, TQString label6, TQString label7, TQString label8)
2189  : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2190 {
2191  init();
2192 }
2193 
2194 KListViewItem::KListViewItem(TQListViewItem *parent, TQListViewItem *after,
2195  TQString label1, TQString label2, TQString label3, TQString label4,
2196  TQString label5, TQString label6, TQString label7, TQString label8)
2197  : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2198 {
2199  init();
2200 }
2201 
2202 KListViewItem::~KListViewItem()
2203 {
2204  if(listView())
2205  emit static_cast<KListView *>(listView())->itemRemoved(this);
2206 }
2207 
2208 void KListViewItem::init()
2209 {
2210  m_odd = m_known = false;
2211  KListView *lv = static_cast<KListView *>(listView());
2212  setDragEnabled( dragEnabled() || lv->dragEnabled() );
2213  emit lv->itemAdded(this);
2214 }
2215 
2216 void KListViewItem::insertItem(TQListViewItem *item)
2217 {
2218  TQListViewItem::insertItem(item);
2219  if(listView())
2220  emit static_cast<KListView *>(listView())->itemAdded(item);
2221 }
2222 
2223 void KListViewItem::takeItem(TQListViewItem *item)
2224 {
2225  TQListViewItem::takeItem(item);
2226  if(listView())
2227  emit static_cast<KListView *>(listView())->itemRemoved(item);
2228 }
2229 
2230 const TQColor &KListViewItem::backgroundColor()
2231 {
2232  if (isAlternate())
2233  return static_cast< KListView* >(listView())->alternateBackground();
2234  return listView()->viewport()->colorGroup().base();
2235 }
2236 
2237 TQColor KListViewItem::backgroundColor(int column)
2238 {
2239  KListView* view = static_cast< KListView* >(listView());
2240  TQColor color = isAlternate() ?
2241  view->alternateBackground() :
2242  view->viewport()->colorGroup().base();
2243 
2244  // calculate a different color if the current column is sorted (only if more than 1 column)
2245  if ( (view->columns() > 1) && view->shadeSortColumn() && (column == view->columnSorted()) )
2246  {
2247  if ( color == Qt::black )
2248  color = TQColor(55, 55, 55); // dark gray
2249  else
2250  {
2251  int h,s,v;
2252  color.hsv(&h, &s, &v);
2253  if ( v > 175 )
2254  color = color.dark(104);
2255  else
2256  color = color.light(120);
2257  }
2258  }
2259 
2260  return color;
2261 }
2262 
2263 bool KListViewItem::isAlternate()
2264 {
2265  KListView* const lv = static_cast<KListView *>(listView());
2266  if (lv && lv->alternateBackground().isValid())
2267  {
2268  KListViewItem *above;
2269 
2270  KListView::KListViewPrivate* const lvD = lv->d;
2271 
2272  // Ok, there's some weirdness here that requires explanation as this is a
2273  // speed hack. itemAbove() is a O(n) operation (though this isn't
2274  // immediately clear) so we want to call it as infrequently as possible --
2275  // especially in the case of painting a cell.
2276  //
2277  // So, in the case that we *are* painting a cell: (1) we're assuming that
2278  // said painting is happening top to bottem -- this assumption is present
2279  // elsewhere in the implementation of this class, (2) itemBelow() is fast --
2280  // roughly constant time.
2281  //
2282  // Given these assumptions we can do a mixture of caching and telling the
2283  // next item that the when that item is the current item that the now
2284  // current item will be the item above it.
2285  //
2286  // Ideally this will make checking to see if the item above the current item
2287  // is the alternate color a constant time operation rather than 0(n).
2288 
2289  if (lvD->painting) {
2290  if (lvD->paintCurrent != this)
2291  {
2292  lvD->paintAbove = lvD->paintBelow == this ? lvD->paintCurrent : itemAbove();
2293  lvD->paintCurrent = this;
2294  lvD->paintBelow = itemBelow();
2295  }
2296 
2297  above = dynamic_cast<KListViewItem *>(lvD->paintAbove);
2298  }
2299  else
2300  {
2301  above = dynamic_cast<KListViewItem *>(itemAbove());
2302  }
2303 
2304  m_known = above ? above->m_known : true;
2305  if (m_known)
2306  {
2307  m_odd = above ? !above->m_odd : false;
2308  }
2309  else
2310  {
2311  KListViewItem *item;
2312  bool previous = true;
2313  if (parent())
2314  {
2315  item = dynamic_cast<KListViewItem *>(parent());
2316  if (item)
2317  previous = item->m_odd;
2318  item = dynamic_cast<KListViewItem *>(parent()->firstChild());
2319  }
2320  else
2321  {
2322  item = dynamic_cast<KListViewItem *>(lv->firstChild());
2323  }
2324 
2325  while(item)
2326  {
2327  previous = !previous;
2328  item->m_odd = previous;
2329  item->m_known = true;
2330  item = dynamic_cast<KListViewItem *>(item->nextSibling());
2331  }
2332  }
2333  return m_odd;
2334  }
2335  return false;
2336 }
2337 
2338 void KListViewItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment)
2339 {
2340  TQColorGroup _cg = cg;
2341  TQListView* lv = listView();
2342  const TQPixmap *pm = lv->viewport()->backgroundPixmap();
2343 
2344  if (pm && !pm->isNull())
2345  {
2346  _cg.setBrush(TQColorGroup::Base, TQBrush(backgroundColor(column), *pm));
2347  TQPoint o = p->brushOrigin();
2348  p->setBrushOrigin( o.x()-lv->contentsX(), o.y()-lv->contentsY() );
2349  }
2350  else
2351  {
2352  _cg.setColor((lv->viewport()->backgroundMode() == TQt::FixedColor) ?
2353  TQColorGroup::Background : TQColorGroup::Base,
2354  backgroundColor(column));
2355  }
2356  TQListViewItem::paintCell(p, _cg, column, width, alignment);
2357 }
2358 
2366 void KListView::selectAll( bool select )
2367 {
2368  if ( selectionMode() == Multi || selectionMode() == Extended ) {
2369  bool b = signalsBlocked();
2370  blockSignals( TRUE );
2371  bool anything = FALSE;
2372  TQListViewItemIterator it( this );
2373  while ( it.current() ) {
2374  TQListViewItem *i = it.current();
2375  if ( select == TRUE ) {
2376  if ( (bool)i->isVisible() == TRUE ) {
2377  i->setSelected( TRUE );
2378  anything = TRUE;
2379  }
2380  if ( (bool)i->isVisible() == FALSE ) {
2381  i->setSelected( FALSE );
2382  anything = TRUE;
2383  }
2384  }
2385  else {
2386  if ( (bool)i->isSelected() != select ) {
2387  i->setSelected( select );
2388  anything = TRUE;
2389  }
2390  }
2391  ++it;
2392  }
2393  blockSignals( b );
2394  if ( anything ) {
2395  emit selectionChanged();
2396 // d->useDoubleBuffer = TRUE;
2397  triggerUpdate();
2398  }
2399  } else if ( currentItem() ) {
2400  TQListViewItem * i = currentItem();
2401  setSelected( i, select );
2402  }
2403 }
2404 
2405 void KListView::virtual_hook( int, void* )
2406 { /*BASE::virtual_hook( id, data );*/ }
2407 
2408 #include "klistview.moc"
2409 #include "klistviewlineedit.moc"
2410 
2411 // vim: noet

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |