26 #include <Qt3Support/Q3ColorDrag>
27 #include <QtGui/QActionEvent>
28 #include <QtCore/QTimer>
29 #include <Qt3Support/Q3Header>
30 #include <QtGui/QCursor>
32 #include <QtGui/QStyle>
33 #include <QStyleOptionFocusRect>
34 #include <QApplication>
35 #include <QtGui/QPainter>
45 class K3ListView::Tooltip :
public QToolTip
55 virtual void maybeTip (
const QPoint&);
61 K3ListView::Tooltip::Tooltip (
K3ListView* parent, QToolTipGroup* group)
62 : QToolTip (parent, group),
67 void K3ListView::Tooltip::maybeTip (
const QPoint&)
74 class K3ListView::K3ListViewPrivate
83 cursorInExecuteArea(false),
85 selectedBySimpleMove(false),
86 selectedUsingMouse(false),
94 pressedOnSelected (false),
95 wasShiftEvent (false),
100 selectionDirection(0),
104 mDropVisualizerWidth (4),
111 renameable.append(0);
114 ~K3ListViewPrivate ()
140 bool cursorInExecuteArea:1;
142 bool bChangeCursorOverItem:1;
144 bool selectedBySimpleMove : 1;
145 bool selectedUsingMouse:1;
153 bool pressedOnSelected:1;
154 bool wasShiftEvent:1;
156 bool sortAscending:1;
162 int selectionDirection;
166 bool showContextMenusOnPress;
168 QRect mOldDropVisualizer;
169 int mDropVisualizerWidth;
170 QRect mOldDropHighlighter;
185 :
KLineEdit(parent->viewport()), item(0), col(0), p(parent)
206 QRect rect(
p->itemRect(i));
210 int fieldX = rect.x() - 1;
211 int fieldW =
p->columnWidth(
col) + 2;
213 Q3Header*
const pHeader =
p->header();
215 const int pos = pHeader->mapToIndex(
col);
216 for (
int index = 0; index < pos; ++index )
217 fieldX +=
p->columnWidth( pHeader->mapToSection( index ));
220 int d = i->depth() + (
p->rootIsDecorated() ? 1 : 0);
221 d *=
p->treeStepSize();
226 if ( i->pixmap(
col ) ) {
227 int d = i->pixmap(
col )->width();
232 setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2);
246 for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir)
261 if (pa && pa->parent() == pi->parent())
275 for (
Q3ListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling())
284 const int ncols =
p->columns();
285 const int dir = forward ? +1 : -1;
286 const int restart = forward ? 0 : (ncols - 1);
288 ? pitem->parent()->firstChild()
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)
308 p->setCurrentItem(pi);
332 if (pe->type() == QEvent::KeyPress)
334 QKeyEvent *k = (QKeyEvent *) pe;
336 if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) &&
338 !(k->modifiers() & Qt::ControlModifier || k->modifiers() & Qt::AltModifier))
341 (k->key() == Qt::Key_Tab && !(k->modifiers() & Qt::ShiftModifier)));
351 if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter )
353 else if(e->key() == Qt::Key_Escape)
355 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up)
389 QFocusEvent * focusEv =
static_cast<QFocusEvent*
>(ev);
391 if (focusEv->reason() != Qt::PopupFocusReason && focusEv->reason() != Qt::ActiveWindowFocusReason)
403 p.setClipRegion( e->region() );
404 p.drawRect( rect() );
421 d (new K3ListViewPrivate)
423 d->createEditor(
this);
424 setDragAutoScroll(
true);
426 connect(
this, SIGNAL(onViewport()),
431 connect (
this, SIGNAL(contentsMoving(
int,
int)),
433 connect (
this, SIGNAL(contentsMoving(
int,
int)),
439 d->autoSelect.setSingleShot(
true );
440 connect(&d->autoSelect, SIGNAL(
timeout()),
442 connect(&d->dragExpand, SIGNAL(
timeout()),
446 if (d->showContextMenusOnPress)
484 if( allColumnsShowFocus() )
490 int width = columnWidth( 0 );
492 Q3Header*
const thisHeader =
header();
493 const int pos = thisHeader->mapToIndex( 0 );
495 for (
int index = 0; index < pos; ++index )
496 offset += columnWidth( thisHeader->mapToSection( index ) );
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 );
512 return ( x > offset && x < ( offset + width ) );
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;
527 if ( d->bChangeCursorOverItem )
528 viewport()->unsetCursor();
530 d->autoSelect.stop();
531 d->pCurrentItem = 0L;
550 if ( !d->disableAutoSelection )
553 if( !d->bUseSingle || !d->bChangeCursorOverItem )
554 viewport()->unsetCursor();
561 if (d->showContextMenusOnPress)
588 if (!isActiveWindow())
590 d->autoSelect.stop();
598 Qt::KeyboardModifiers keybstate = QApplication::keyboardModifiers();
601 setCurrentItem( d->pCurrentItem );
603 if( d->pCurrentItem ) {
605 if( (keybstate & Qt::ShiftModifier) ) {
606 bool block = signalsBlocked();
607 blockSignals(
true );
610 if( !(keybstate & Qt::ControlModifier) )
613 bool select = !d->pCurrentItem->isSelected();
614 bool update = viewport()->updatesEnabled();
615 viewport()->setUpdatesEnabled(
false );
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 );
624 if ( !down && lit.current() == previousItem ) {
625 previousItem->setSelected( select );
628 lit.current()->setSelected( select );
631 blockSignals( block );
632 viewport()->setUpdatesEnabled( update );
635 emit selectionChanged();
637 if( selectionMode() == Q3ListView::Single )
638 emit selectionChanged( d->pCurrentItem );
640 else if( (keybstate & Qt::ControlModifier) )
641 setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() );
643 bool block = signalsBlocked();
644 blockSignals(
true );
646 if( !d->pCurrentItem->isSelected() )
649 blockSignals( block );
651 setSelected( d->pCurrentItem,
true );
655 kDebug() <<
"K3ListView::slotAutoSelect: That's not supposed to happen!!!!";
661 const int colCount = columns();
662 if (d->fullWidth && colCount)
665 const int lastColumn = colCount - 1;
666 for (
int i = 0; i < lastColumn; ++i) w += columnWidth(i);
667 setColumnWidth( lastColumn, viewport()->width() - w - 1 );
677 if ( !d->bUseSingle )
679 viewport()->unsetCursor();
685 Qt::KeyboardModifiers keybstate = QApplication::keyboardModifiers();
687 d->autoSelect.stop();
690 if( !( ((keybstate & Qt::ShiftModifier) || (keybstate & Qt::ControlModifier)) ) ) {
691 viewport()->unsetCursor();
702 Q3ListView::focusInEvent( fe );
703 if ((d->selectedBySimpleMove)
705 && (fe->reason()!=Qt::PopupFocusReason)
706 && (fe->reason()!=Qt::ActiveWindowFocusReason)
709 currentItem()->setSelected(
true);
710 currentItem()->repaint();
711 emit selectionChanged();
720 d->autoSelect.stop();
722 if ((d->selectedBySimpleMove)
724 && (fe->reason()!=Qt::PopupFocusReason)
725 && (fe->reason()!=Qt::ActiveWindowFocusReason)
727 && (!d->editor->isVisible()))
729 currentItem()->setSelected(
false);
730 currentItem()->repaint();
731 emit selectionChanged();
734 Q3ListView::focusOutEvent( fe );
739 d->autoSelect.stop();
741 Q3ListView::leaveEvent( e );
746 if (e->type() == QEvent::ApplicationPaletteChange)
749 return Q3ListView::event(e);
754 if( (
selectionModeExt() ==
Extended) && (e->modifiers() & Qt::ShiftModifier) && !(e->modifiers() & Qt::ControlModifier) )
756 bool block = signalsBlocked();
757 blockSignals(
true );
761 blockSignals( block );
765 d->selectedBySimpleMove=
false;
766 d->selectedUsingMouse=
true;
769 currentItem()->setSelected(
false);
770 currentItem()->repaint();
775 QPoint p( contentsToViewport( e->pos() ) );
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 ) ) );
784 if (e->button() == Qt::LeftButton && !rootDecoClicked)
787 d->startDragPos = e->pos();
792 d->pressedOnSelected = at->isSelected();
796 Q3ListView::contentsMousePressEvent( e );
801 if (!
dragEnabled() || d->startDragPos.isNull() || !d->validDrag)
802 Q3ListView::contentsMouseMoveEvent (e);
804 QPoint vp = contentsToViewport(e->pos());
808 if ( item && d->bChangeCursorOverItem && d->bUseSingle )
811 if( (item != d->pCurrentItem) ||
816 if( d->cursorInExecuteArea )
817 viewport()->setCursor(Qt::PointingHandCursor);
819 viewport()->unsetCursor();
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))
832 Q3ListView::contentsMouseReleaseEvent( 0 );
834 d->startDragPos =
QPoint();
835 d->validDrag =
false;
841 if (e->button() == Qt::LeftButton)
846 QPoint p( contentsToViewport( e->pos() ) );
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 ) ) );
856 if (!rootDecoClicked)
858 int col =
header()->mapToLogical(
header()->cellAt( p.x() ) );
859 if ( d->renameable.contains(col) )
865 d->pressedOnSelected =
false;
866 d->validDrag =
false;
867 d->startDragPos =
QPoint();
869 Q3ListView::contentsMouseReleaseEvent( e );
877 if ( !e || e->button() != Qt::LeftButton )
880 QPoint vp = contentsToViewport(e->pos());
882 emit Q3ListView::doubleClicked( item );
884 int col = item ?
header()->mapToLogical(
header()->cellAt( vp.x() ) ) : -1;
889 if( (e->button() == Qt::LeftButton) && !d->bUseSingle )
896 if( (btn == Qt::LeftButton) && item )
904 d->dragExpand.stop();
908 e->acceptProposedAction();
912 findDrop(e->pos(), parent, afterme);
919 emit
dropped(
this, e, afterme);
920 emit
dropped(e, parent, afterme);
921 emit
dropped(
this, e, parent, afterme);
933 iNext=i->itemBelow();
934 if (!i->isSelected())
942 i->setSelected(
false);
956 emit
moved(i, afterFirst, afterme);
959 afterFirsts.append (afterFirst);
960 afterNows.append (afterme);
966 i->setSelected(
true);
968 setCurrentItem(current);
970 emit
moved(items,afterFirsts,afterNows);
980 event->acceptProposedAction();
983 findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop);
984 QPoint vp = contentsToViewport( event->pos() );
987 if ( item != d->dragOverItem )
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() );
1000 if (tmpRect != d->mOldDropVisualizer)
1003 d->mOldDropVisualizer=tmpRect;
1004 viewport()->repaint(tmpRect);
1010 if (tmpRect != d->mOldDropHighlighter)
1013 d->mOldDropHighlighter=tmpRect;
1014 viewport()->repaint(tmpRect);
1024 if ( itemAt( d->dragOverPoint ) == d->dragOverItem )
1025 d->dragOverItem->setOpen(
true );
1030 d->dragExpand.stop();
1037 if (d->mOldDropVisualizer.isValid())
1039 QRect rect=d->mOldDropVisualizer;
1040 d->mOldDropVisualizer =
QRect();
1041 viewport()->repaint(rect);
1047 return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin();
1052 QPoint p (contentsToViewport(pos));
1063 if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2))
1064 above = atpos->itemAbove();
1073 if (above->firstChild() && above->isOpen())
1082 if (above->isExpandable())
1086 (above->isOpen() && above->childCount() > 0) )
1098 while ( betterAbove )
1102 if ( !last->nextSibling() )
1105 above = betterAbove;
1109 betterAbove = betterAbove->parent();
1116 parent = after ? after->parent() : 0L ;
1124 for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()) ;
1133 for (Q3ListViewItemIterator it (last); it.current(); ++it)
1134 last = it.current();
1151 if (drag->drag() && drag->target() != viewport())
1161 return new Q3StoredDrag(
"application/x-qlistviewitem", viewport());
1171 return d->itemsMovable;
1176 d->itemsRenameable=b;
1181 return d->itemsRenameable;
1192 return d->dragEnabled;
1207 return d->dropVisualizer;
1212 d->dropVisualizer=b;
1223 switch(selectionMode())
1228 if(selectedItem() && (includeHiddenItems || selectedItem()->isVisible()))
1229 list.append(selectedItem());
1233 int flags = Q3ListViewItemIterator::Selected;
1234 if (!includeHiddenItems)
1236 flags |= Q3ListViewItemIterator::Visible;
1239 Q3ListViewItemIterator it(const_cast<K3ListView *>(
this), flags);
1241 for(; it.current(); ++it)
1242 list.append(it.current());
1265 item->moveItem(after);
1272 item->parent()->takeItem(item);
1277 parent->insertItem(item);
1289 Q3ListView::contentsContextMenuEvent(event);
1291 if (event->reason() == QContextMenuEvent::Keyboard) {
1298 d->mDropVisualizerWidth = w > 0 ? w : 1;
1306 if (!after && !parent)
1307 insertmarker =
QRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2);
1314 if (after->isOpen())
1317 it = after->firstChild();
1319 while (it->nextSibling() || it->firstChild())
1320 if ( it->nextSibling() )
1321 it = it->nextSibling();
1323 it = it->firstChild();
1326 insertmarker = itemRect (it ? it : after);
1327 level = after->depth();
1331 insertmarker = itemRect (parent);
1332 level = parent->depth() + 1;
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);
1343 p->fillRect(insertmarker, Qt::Dense4Pattern);
1345 return insertmarker;
1355 r.setLeft(r.left()+(item->depth()+(rootIsDecorated() ? 1 : 0))*treeStepSize());
1358 QStyleOptionFocusRect frOpt;
1360 frOpt.state = QStyle::State_FocusAtBorder;
1362 frOpt.backgroundColor = palette().color( QPalette::Highlight );
1363 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &frOpt, painter);
1372 if (d->mOldDropHighlighter.isValid())
1374 QRect rect=d->mOldDropHighlighter;
1375 d->mOldDropHighlighter =
QRect();
1376 viewport()->repaint(rect);
1382 if (d->renameable.contains(c))
1384 ensureItemVisible(item);
1385 d->editor->load(item,c);
1391 return d->renameable.contains(col);
1396 if (col>=
header()->count())
return;
1398 d->renameable.removeAll(col);
1411 return acceptDrops() &&
itemsMovable() && (e->source()==viewport());
1416 return d->tooltipColumn;
1421 d->tooltipColumn=column;
1426 d->dropHighlighter=b;
1431 return d->dropHighlighter;
1441 return item->text(column);
1451 return d->tabRename;
1456 return (p.y() > (rect.top() + (rect.bottom() - rect.top())/2));
1461 return below (itemRect(i), contentsToViewport(p));
1467 Q3ListView::keyPressEvent (e);
1474 d->selectedBySimpleMove=
true;
1475 d->selectedUsingMouse=
false;
1478 currentItem()->setSelected(
true);
1479 currentItem()->repaint();
1480 emit selectionChanged();
1486 d->selectedBySimpleMove=
false;
1491 return d->selectedBySimpleMove;
1497 int e_state=(e->modifiers() & ~Qt::KeypadModifier);
1499 int oldSelectionDirection(d->selectionDirection);
1501 if ((e->key()!=Qt::Key_Shift) && (e->key()!=Qt::Key_Control)
1502 && (e->key()!=Qt::Key_Meta) && (e->key()!=Qt::Key_Alt))
1504 if ((e_state==Qt::ShiftModifier) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove))
1506 d->selectionDirection=0;
1507 d->wasShiftEvent = (e_state == Qt::ShiftModifier);
1523 bool shiftOrCtrl((e_state==Qt::ControlModifier) || (e_state==Qt::ShiftModifier));
1525 for (
Q3ListViewItem *tmpItem=firstChild(); tmpItem; tmpItem=tmpItem->nextSibling())
1526 if (tmpItem->isSelected()) selectedItems++;
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)))
1537 d->selectedBySimpleMove=
true;
1538 d->selectedUsingMouse=
false;
1540 else if (selectedItems>1)
1541 d->selectedBySimpleMove=
false;
1543 bool emitSelectionChanged(
false);
1547 case Qt::Key_Escape:
1549 emitSelectionChanged=
true;
1554 if (d->selectedBySimpleMove)
1555 d->selectedBySimpleMove=
false;
1556 item->setSelected(!item->isSelected());
1557 emitSelectionChanged=
true;
1560 case Qt::Key_Insert:
1562 if (d->selectedBySimpleMove)
1564 d->selectedBySimpleMove=
false;
1565 if (!item->isSelected()) item->setSelected(
true);
1569 item->setSelected(!item->isSelected());
1572 nextItem=item->itemBelow();
1576 repaintItem2=nextItem;
1578 setCurrentItem(nextItem);
1580 d->selectionDirection=1;
1581 emitSelectionChanged=
true;
1585 nextItem=item->itemBelow();
1589 d->selectionDirection=1;
1590 if (d->selectedBySimpleMove)
1591 d->selectedBySimpleMove=
false;
1594 if (oldSelectionDirection!=-1)
1596 item->setSelected(!item->isSelected());
1597 emitSelectionChanged=
true;
1601 else if ((d->selectedBySimpleMove) && (nextItem))
1603 item->setSelected(
false);
1604 emitSelectionChanged=
true;
1609 if (d->selectedBySimpleMove)
1610 nextItem->setSelected(
true);
1611 repaintItem2=nextItem;
1613 setCurrentItem(nextItem);
1618 nextItem=item->itemAbove();
1619 d->selectionDirection=-1;
1625 if (d->selectedBySimpleMove)
1626 d->selectedBySimpleMove=
false;
1629 if (oldSelectionDirection!=1)
1631 item->setSelected(!item->isSelected());
1632 emitSelectionChanged=
true;
1636 else if ((d->selectedBySimpleMove) && (nextItem))
1638 item->setSelected(
false);
1639 emitSelectionChanged=
true;
1644 if (d->selectedBySimpleMove)
1645 nextItem->setSelected(
true);
1646 repaintItem2=nextItem;
1648 setCurrentItem(nextItem);
1655 if (d->selectedBySimpleMove)
1656 item->setSelected(
false);
1658 d->selectedBySimpleMove=
false;
1663 nextItem->setSelected(!nextItem->isSelected());
1664 if (!nextItem->itemBelow())
1666 if (d->selectedBySimpleMove)
1667 nextItem->setSelected(
true);
1668 repaintItem2=nextItem;
1670 setCurrentItem(nextItem);
1672 nextItem=nextItem->itemBelow();
1674 emitSelectionChanged=
true;
1679 nextItem = firstChild();
1681 repaintItem2 = visItem;
1682 if (d->selectedBySimpleMove)
1683 item->setSelected(
false);
1686 d->selectedBySimpleMove=
false;
1688 while ( nextItem != item )
1690 nextItem->setSelected( !nextItem->isSelected() );
1691 nextItem = nextItem->itemBelow();
1693 item->setSelected( !item->isSelected() );
1695 setCurrentItem( firstChild() );
1696 emitSelectionChanged=
true;
1699 case Qt::Key_PageDown:
1700 items=visibleHeight()/item->height();
1702 if (d->selectedBySimpleMove)
1703 item->setSelected(
false);
1706 d->selectedBySimpleMove=
false;
1707 d->selectionDirection=1;
1710 for (
int i=0; i<items; i++)
1713 nextItem->setSelected(!nextItem->isSelected());
1715 if ((i==items-1) || (!nextItem->itemBelow()))
1719 nextItem->setSelected(!nextItem->isSelected());
1720 if (d->selectedBySimpleMove)
1721 nextItem->setSelected(
true);
1722 ensureItemVisible(nextItem);
1723 setCurrentItem(nextItem);
1725 if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1727 emit selectionChanged();
1731 nextItem=nextItem->itemBelow();
1735 case Qt::Key_PageUp:
1736 items=visibleHeight()/item->height();
1738 if (d->selectedBySimpleMove)
1739 item->setSelected(
false);
1742 d->selectionDirection=-1;
1743 d->selectedBySimpleMove=
false;
1746 for (
int i=0; i<items; i++)
1748 if ((nextItem!=item) &&(shiftOrCtrl))
1749 nextItem->setSelected(!nextItem->isSelected());
1751 if ((i==items-1) || (!nextItem->itemAbove()))
1754 if (d->selectedBySimpleMove)
1755 nextItem->setSelected(
true);
1756 ensureItemVisible(nextItem);
1757 setCurrentItem(nextItem);
1759 if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1761 emit selectionChanged();
1765 nextItem=nextItem->itemAbove();
1770 if ( item->isOpen() )
1771 setOpen( item,
false );
1774 if ( !item->isOpen() && (item->isExpandable() || item->childCount()) )
1775 setOpen( item,
true );
1778 bool realKey = ((e->key()!=Qt::Key_Shift) && (e->key()!=Qt::Key_Control)
1779 && (e->key()!=Qt::Key_Meta) && (e->key()!=Qt::Key_Alt));
1781 bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected());
1782 if (realKey && selectCurrentItem)
1783 item->setSelected(
false);
1785 Q3ListView::SelectionMode oldSelectionMode = selectionMode();
1786 setSelectionMode (Q3ListView::Multi);
1787 Q3ListView::keyPressEvent (e);
1788 setSelectionMode (oldSelectionMode);
1789 if (realKey && selectCurrentItem)
1791 currentItem()->setSelected(
true);
1792 emitSelectionChanged=
true;
1794 repaintItem2=currentItem();
1796 visItem=currentItem();
1801 ensureItemVisible(visItem);
1805 ir = ir.unite( itemRect(repaintItem1) );
1807 ir = ir.unite( itemRect(repaintItem2) );
1809 if ( !ir.isEmpty() )
1812 ir.translate( -ir.x(), 0 );
1813 viewport()->repaint( ir );
1820 if (emitSelectionChanged)
1821 emit selectionChanged();
1826 d->selectionMode = mode;
1834 setSelectionMode (static_cast<Q3ListView::SelectionMode>(static_cast<int>(mode)));
1838 setSelectionMode (Q3ListView::Extended);
1842 kWarning () <<
"Warning: illegal selection mode " << int(mode) <<
" set!";
1849 return d->selectionMode;
1857 if ( item == firstChild() )
1860 Q3ListViewItemIterator it(firstChild());
1862 for (; it.current() && it.current() != item; ++it, ++j ) ;
1877 for (Q3ListViewItemIterator it=firstChild(); it.current(); ++it)
1880 return it.current();
1892 p = viewport()->mapToGlobal(itemRect(i).center());
1894 p = mapToGlobal(rect().center());
1906 Q3ListView::setAcceptDrops (val);
1907 viewport()->setAcceptDrops (val);
1912 return d->mDropVisualizerWidth;
1919 d->paintCurrent = 0;
1923 Q3ListView::viewportPaintEvent(e);
1925 if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer))
1927 QPainter painter(viewport());
1930 painter.fillRect(d->mOldDropVisualizer, Qt::Dense4Pattern);
1932 if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter))
1934 QPainter painter(viewport());
1937 QStyleOptionFocusRect frOpt;
1939 frOpt.state = QStyle::State_FocusAtBorder;
1940 frOpt.rect = d->mOldDropHighlighter;
1941 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &frOpt, &painter);
1943 d->painting =
false;
1954 header()->setStretchEnabled(fullWidth, columns()-1);
1959 return d->fullWidth;
1964 int result = Q3ListView::addColumn(label, width);
1966 header()->setStretchEnabled(
false, columns()-2);
1967 header()->setStretchEnabled(
true, columns()-1);
1974 int result = Q3ListView::addColumn(iconset, label, width);
1976 header()->setStretchEnabled(
false, columns()-2);
1977 header()->setStretchEnabled(
true, columns()-1);
1984 Q3ListView::removeColumn(index);
1985 if (d->fullWidth && index == columns())
header()->setStretchEnabled(
true, columns()-1);
1990 Q3ListView::viewportResizeEvent(e);
1995 return d->alternateBackground;
2000 d->alternateBackground = c;
2012 return d->shadeSortColumn;
2026 const int colCount = columns();
2027 Q3Header*
const thisHeader =
header();
2028 for (
int i = 0; i < colCount; ++i)
2030 widths << QString::number(columnWidth(i));
2031 order << QString::number(thisHeader->mapToIndex(i));
2036 cg.
writeEntry(
"SortAscending", d->sortAscending);
2050 QStringList::ConstIterator it = cols.constBegin();
2051 const QStringList::ConstIterator itEnd = cols.constEnd();
2052 for (; it != itEnd; ++it)
2053 setColumnWidth(i++, (*it).toInt());
2060 const int colCount = columns();
2061 for (i = 0; i < colCount; ++i)
2063 QStringList::ConstIterator it = cols.constBegin();
2064 const QStringList::ConstIterator itEnd = cols.constEnd();
2067 for (; (it != itEnd) && ((*it).toInt() != i); ++it, ++section) ;
2069 if ( it != itEnd ) {
2071 header()->moveSection(section, i);
2075 if (cg.
hasKey(
"SortColumn"))
2083 if (selectionMode() == Q3ListView::Single) {
2084 selected = selectedItem();
2085 if (selected && !selected->isVisible())
2088 else if (selectionMode() != Q3ListView::NoSelection) {
2090 while (item && !selected) {
2091 if (item->isSelected() && item->isVisible())
2093 item = item->itemBelow();
2097 d->sortColumn = column;
2098 d->sortAscending = ascending;
2099 Q3ListView::setSorting(column, ascending);
2102 ensureItemVisible(selected);
2107 if (kItem) kItem->m_known =
false;
2108 item = item->itemBelow();
2114 return d->sortColumn;
2119 return d->sortAscending;
2124 if(item && item == d->editor->currentItem())
2125 d->editor->terminate();
2127 Q3ListView::takeItem(item);
2132 if ( d->disableAutoSelection )
2135 d->disableAutoSelection =
true;
2136 d->autoSelect.stop();
2137 d->autoSelectDelay = -1;
2142 if ( !d->disableAutoSelection )
2145 d->disableAutoSelection =
false;
2151 emit Q3ListView::doubleClicked( item, pos, c );
2181 :
Q3ListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2189 :
Q3ListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2197 :
Q3ListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2205 :
Q3ListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2213 emit
static_cast<K3ListView *
>(listView())->itemRemoved(
this);
2216 void K3ListViewItem::init()
2218 m_odd = m_known =
false;
2220 setDragEnabled( dragEnabled() || lv->
dragEnabled() );
2226 Q3ListViewItem::insertItem(item);
2228 emit
static_cast<K3ListView *
>(listView())->itemAdded(item);
2233 Q3ListViewItem::takeItem(item);
2235 emit
static_cast<K3ListView *
>(listView())->itemRemoved(item);
2241 return static_cast< K3ListView*
>(listView())->alternateBackground();
2242 return listView()->viewport()->palette().color(QPalette::Base);
2250 view->viewport()->palette().color(QPalette::Base);
2255 if ( color == Qt::black )
2256 color =
QColor(55, 55, 55);
2260 color.getHsv(&h, &s, &v);
2262 color = color.dark(104);
2264 color = color.light(120);
2278 K3ListView::K3ListViewPrivate*
const lvD = lv->d;
2297 if (lvD->painting) {
2298 if (lvD->paintCurrent !=
this)
2300 lvD->paintAbove = lvD->paintBelow ==
this ? lvD->paintCurrent : itemAbove();
2301 lvD->paintCurrent =
this;
2302 lvD->paintBelow = itemBelow();
2312 m_known = above ? above->m_known :
true;
2315 m_odd = above ? !above->m_odd :
false;
2320 bool previous =
true;
2325 previous = item->m_odd;
2335 item->m_odd = (previous = !previous);
2336 item->m_known =
true;
2347 QColorGroup _cg = cg;
2350 Q3ListViewItem::paintCell(p, _cg, column, width, alignment);
2353 #include "k3listview.moc"
2354 #include "k3listviewlineedit.moc"
void done(Q3ListViewItem *, int)
void saveLayout(KConfig *config, const QString &group) const
Saves the list view's layout (column widtsh, column order, sort column) to a KConfig group...
void emitContextMenu(Q3ListViewItem *, const QPoint &, int)
Emit the contextMenu signal.
virtual void setDropVisualizer(bool b)
Enable/Disable the drawing of a drop-visualizer (a bar that shows where a dropped item would be inser...
virtual void takeItem(Q3ListViewItem *i)
Reimplemented for internal reasons.
void cleanDropVisualizer()
Repaint the rect where I was drawing the drop line.
virtual void keyPressEvent(QKeyEvent *)
Reimplemented for internal reasons.
bool ascendingSort(void) const
const QColor & backgroundColor()
returns the background color for this item
bool isRenameable(int column) const
void selectNextCell(Q3ListViewItem *pi, int column, bool forward)
QBrush background(BackgroundRole=NormalBackground) const
bool fullWidth() const
Returns whether the last column is set to fit the available width.
void slotHeaderChanged()
Reacts to header changes in full width mode.
int tooltipColumn() const
virtual bool showTooltip(Q3ListViewItem *item, const QPoint &pos, int column) const
static bool singleClick()
void moveItem(Q3ListViewItem *item, Q3ListViewItem *parent, Q3ListViewItem *after)
Arbitrarily move item to parent, positioned immediately after item after.
virtual void focusOutEvent(QFocusEvent *)
SelectionModeExt selectionModeExt() const
void menuShortCutPressed(K3ListView *list, Q3ListViewItem *item)
This signal is emitted when the shortcut key for popup-menus is pressed.
virtual void setDragEnabled(bool b)
Enable/Disable the dragging of items.
const QColor & alternateBackground() const
virtual void contentsContextMenuEvent(QContextMenuEvent *)
Reimplemented for internal reasons.
bool dropVisualizer() const
virtual void setDropHighlighter(bool b)
Enable/Disable the drawing of a drop-highlighter (a rectangle around the item under the mouse cursor)...
static Q3ListViewItem * prevItem(Q3ListViewItem *pi)
virtual void focusOutEvent(QFocusEvent *ev)
virtual void viewportPaintEvent(QPaintEvent *)
Reimplemented for internal reasons.
bool isAlternate()
returns true if this item is to be drawn with the alternate background
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
virtual void paintEvent(QPaintEvent *e)
static bool showContextMenusOnPress()
virtual void contentsDragEnterEvent(QDragEnterEvent *)
Reimplemented for internal reasons.
static KGlobalSettings * self()
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KLineEdit * renameLineEdit() const
virtual void leaveEvent(QEvent *e)
Reimplemented for internal reasons.
A listview item with support for alternate background colors.
virtual void keyPressEvent(QKeyEvent *)
virtual void setAutoOpen(bool b)
Enable/Disable AutoOpen (not implemented currently).
virtual void focusInEvent(QFocusEvent *fe)
Reimplemented for internal reasons.
bool tabOrderedRenaming() const
Returns whether tab ordered renaming is enabled.
int depthToPixels(int depth)
Convert the depth of an item into its indentation in pixels.
virtual void viewportResizeEvent(QResizeEvent *e)
Reimplemented for setFullWidth()
void setAlternateBackground(const QColor &c)
sets the alternate background background color.
virtual void contentsMousePressEvent(QMouseEvent *e)
Reimplemented for internal reasons.
void activateAutomaticSelection()
In FileManager selection mode: explicitly activate the mode in which the current item is automaticall...
virtual ~K3ListView()
Destructor.
void slotSelectionChanged()
bool automaticSelection() const
In FileManager selection mode: return whether it is currently in the mode where the current item is s...
virtual void setAcceptDrops(bool)
Reimplemented for internal reasons.
virtual bool isExecuteArea(const QPoint &point)
This function determines whether the given coordinates are within the execute area.
int columnSorted(void) const
void setShadeSortColumn(bool shadeSortColumn)
Set to true if the currently sorted column should be drawn shaded.
void emitExecute(Q3ListViewItem *item, const QPoint &pos, int c)
Emit signal executed.
bool itemsMovable() const
virtual void startDrag()
This method calls dragObject() and starts the drag.
void doneEditing(Q3ListViewItem *item, int row)
void deactivateAutomaticSelection()
In FileManager selection mode: explicitly deactivate the mode in which the current item is automatica...
virtual void contentsMouseReleaseEvent(QMouseEvent *)
Reimplemented for internal reasons.
void setTabOrderedRenaming(bool b)
Enable/disable tabbing between editable cells.
virtual void contentsMouseDoubleClickEvent(QMouseEvent *e)
Reimplemented for internal reasons.
Q3ListViewItem * lastChild() const
virtual bool event(QEvent *)
Reimplemented to reload the alternate background in palette changes.
the editor for a K3ListView.
virtual void removeColumn(int index)
Reimplemented for full width support.
KAction * home(const QObject *recvr, const char *slot, QObject *parent)
virtual void contentsDragMoveEvent(QDragMoveEvent *event)
Reimplemented for internal reasons.
virtual void contentsDropEvent(QDropEvent *)
Reimplemented for internal reasons.
void doubleClicked(Q3ListViewItem *item, const QPoint &pos, int c)
virtual void setTooltipColumn(int column)
Set which column should be used for automatic tooltips.
void dropped(QDropEvent *e, Q3ListViewItem *after)
This signal gets emitted whenever something acceptable is dropped onto the listview.
virtual bool event(QEvent *pe)
void fileManagerKeyPressEvent(QKeyEvent *)
A special keyPressEvent (for FileManager selection mode).
void slotSettingsChanged(int)
Update internal settings whenever the global ones change.
virtual QString tooltip(Q3ListViewItem *item, int column) const
virtual void setItemsRenameable(bool b)
Enables inplace-renaming of items.
void disableAutoSelection()
Disable AutoSelection.
This Widget extends the functionality of Q3ListView to honor the system wide settings for Single Clic...
Q3ListViewItem * itemAtIndex(int index)
Returns the item of index within the item tree or 0 if index doesn't exist in this list view...
void itemRenamed(Q3ListViewItem *item, const QString &str, int col)
This signal gets emitted when an item is renamed via in-place renaming.
virtual void findDrop(const QPoint &pos, Q3ListViewItem *&parent, Q3ListViewItem *&after)
Where is the nearest Q3ListViewItem that I'm going to drop?
Q3ListViewItem * lastItem() const
K3ListViewItem(Q3ListView *parent)
constructors.
virtual void contentsDragLeaveEvent(QDragLeaveEvent *event)
Reimplemented for internal reasons.
void executed(Q3ListViewItem *item)
This signal is emitted whenever the user executes an listview item.
virtual void keyPressEvent(QKeyEvent *e)
void setSelectionModeExt(SelectionModeExt mode)
Set the selection mode.
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...
bool hasKey(const QString &key) const
virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
void slotMouseButtonClicked(int btn, Q3ListViewItem *item, const QPoint &pos, int c)
virtual void movableDropEvent(Q3ListViewItem *parent, Q3ListViewItem *afterme)
Handle dropEvent when itemsMovable() is set to true.
void slotOnItem(Q3ListViewItem *item)
Accessory slot for AutoSelect.
virtual Q3DragObject * dragObject()
static bool changeCursorOverIcon()
void cleanItemHighlighter()
Repaint the rect where I was drawing the drop rectangle.
virtual ~K3ListViewItem()
K3ListViewLineEdit(K3ListView *parent)
virtual bool acceptDrag(QDropEvent *event) const
int dropVisualizerWidth() const
The dropVisualizerWidth defaults to 4.
QString dir(const QString &fileClass)
virtual void insertItem(Q3ListViewItem *item)
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...
bool itemsRenameable() const
bool dropHighlighter() const
void load(Q3ListViewItem *i, int c)
virtual void takeItem(Q3ListViewItem *item)
static int autoSelectDelay()
void slotOnViewport()
Accessory slot for AutoSelect/ChangeCursorOverItem.
void slotAutoSelect()
Process AutoSelection.
virtual bool event(QEvent *)
virtual void contentsMouseMoveEvent(QMouseEvent *e)
Reimplemented for internal reasons.
virtual void paintEvent(QPaintEvent *ev)
KAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
virtual int addColumn(const QString &label, int width=-1)
Reimplemented for full width support.
void setRenameable(int column, bool yesno=true)
By default, if you called setItemsRenameable(true), only the first column is renameable.
void resetAutoSelection()
Reset AutoSelection to the system wide setting.
bool shadeSortColumn(void) const
See if the sort column should be drawn shaded.
Q3ListViewItem * currentItem() const
void aboutToMove()
Connect to this signal if you want to do some preprocessing before a move is made, for example, to disable sorting.
void contextMenu(K3ListView *l, Q3ListViewItem *i, const QPoint &p)
This signal is emitted whenever a context-menu should be shown for item i.
virtual void focusOutEvent(QFocusEvent *fe)
Reimplemented for internal reasons.
void itemAdded(Q3ListViewItem *item)
virtual void setSorting(int column, bool ascending=true)
Reimplemented to remember the current sort column and order.
virtual void rename(Q3ListViewItem *item, int c)
Rename column c of item.
static int nextCol(K3ListView *pl, Q3ListViewItem *pi, int start, int dir)
void moved()
This signal is emitted when ever the user moves an item in the list via DnD.
QList< Q3ListViewItem * > selectedItems(bool includeHiddenItems=true) const
virtual void setText(const QString &)
static int dndEventDelay()
virtual void setItemsMovable(bool b)
Set whether items in the list view can be moved.
T readEntry(const QString &key, const T &aDefault) const
void restoreLayout(KConfig *config, const QString &group)
Reads the list view's layout from a KConfig group as stored with saveLayout.
static Q3ListViewItem * lastQChild(Q3ListViewItem *pi)
QColor alternateBackground
void setDropVisualizerWidth(int w)
Set the width of the (default) drop-visualizer.
virtual QRect drawDropVisualizer(QPainter *p, Q3ListViewItem *parent, Q3ListViewItem *after)
Paint the drag line.
SelectionModeExt
Possible selection modes.
K3ListView(QWidget *parent=0)
Constructor.
QStringList list(const QString &fileClass)
virtual QRect drawItemHighlighter(QPainter *painter, Q3ListViewItem *item)
Paint the drag rectangle.