diff options
| author | Peter Penz <[email protected]> | 2012-05-21 21:43:26 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-05-21 21:48:45 +0200 |
| commit | 894232ebda5b2cf155a4f4e5bf1287eb700faa18 (patch) | |
| tree | 3eed796e481cb7d3f486d9032d46db57f172f803 /src/kitemviews/kitemlistview.cpp | |
| parent | 3b6892b68575e55cae4571f17ddc55dca4abba88 (diff) | |
Places Panel: Show drop indicator
The dropping itself has not been implemented yet.
Diffstat (limited to 'src/kitemviews/kitemlistview.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index ebcf48680..1586c9d96 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -84,7 +84,8 @@ KItemListView::KItemListView(QGraphicsWidget* parent) : m_autoScrollIncrement(0), m_autoScrollTimer(0), m_header(0), - m_headerWidget(0) + m_headerWidget(0), + m_dropIndicator() { setAcceptHoverEvents(true); @@ -622,6 +623,22 @@ void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt opt.rect = rubberBandRect.toRect(); style()->drawControl(QStyle::CE_RubberBand, &opt, painter); } + + if (!m_dropIndicator.isEmpty()) { + const QRectF r = m_dropIndicator.toRect(); + + QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color(); + painter->setPen(color); + + // TODO: The following implementation works only for a vertical scroll-orientation + // and assumes a height of the m_draggingInsertIndicator of 1. + Q_ASSERT(r.height() == 1); + painter->drawLine(r.left() + 1, r.top(), r.right() - 1, r.top()); + + color.setAlpha(128); + painter->setPen(color); + painter->drawRect(r.left(), r.top() - 1, r.width() - 1, 2); + } } void KItemListView::setItemSize(const QSizeF& size) @@ -2286,6 +2303,39 @@ bool KItemListView::scrollBarRequired(const QSizeF& size) const : maxOffset > size.width(); } +int KItemListView::showDropIndicator(const QPointF& pos) +{ + QHashIterator<int, KItemListWidget*> it(m_visibleItems); + while (it.hasNext()) { + it.next(); + const KItemListWidget* widget = it.value(); + + const QPointF mappedPos = widget->mapFromItem(this, pos); + const QRectF rect = itemRect(widget->index()); + if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) { + const qreal y = (mappedPos.y () < rect.height() / 2) ? + rect.top() : rect.bottom(); + + const QRectF draggingInsertIndicator(rect.left(), y, rect.width(), 1); + if (m_dropIndicator != draggingInsertIndicator) { + m_dropIndicator = draggingInsertIndicator; + update(); + } + return widget->index(); + } + } + + return -1; +} + +void KItemListView::hideDropIndicator() +{ + if (!m_dropIndicator.isNull()) { + m_dropIndicator = QRectF(); + update(); + } +} + void KItemListView::updateGroupHeaderHeight() { qreal groupHeaderHeight = m_styleOption.fontMetrics.height(); |
