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

KDE3Support

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

Skip menu "kdelibs 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

Search



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