diff options
Diffstat (limited to 'src/qgraphicslistview.cpp')
-rw-r--r-- | src/qgraphicslistview.cpp | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/qgraphicslistview.cpp b/src/qgraphicslistview.cpp index 1e3b8fd..162d691 100644 --- a/src/qgraphicslistview.cpp +++ b/src/qgraphicslistview.cpp @@ -208,7 +208,7 @@ void QtGraphicsListViewItem::initStyleOption(QStyleOptionViewItemV4 *option) con else option->state &= ~QStyle::State_HasFocus; // selectionManager - if (d->view->selectionManager()->isSelected(d->index)) + if (!d->view->highlight() && d->view->selectionManager()->isSelected(d->index)) option->state |= QStyle::State_Selected; else option->state &= ~QStyle::State_Selected; @@ -370,7 +370,7 @@ void QtGraphicsListViewItemCreatorBase::recycle(QGraphicsObject *item) QtGraphicsListViewPrivate::QtGraphicsListViewPrivate() : q_ptr(0), controller(0), model(0), selectionManager(0), orientation(Qt::Horizontal), textElideMode(Qt::ElideMiddle), - highlight(0), firstIndex(0), offset(0), + highlight(0), firstIndex(0), offset(0), transform(0), #if CACHING_ENABLED cachedIndexOffset(0), cachedCoordinateOffset(0), #endif @@ -491,7 +491,7 @@ void QtGraphicsListViewPrivate::_q_currentChanged(int current, int previous) return; //qDebug() << "QtGraphicsListViewPrivate::_q_currentChanged" << current << previous; if (highlight) { - // FIXME: update highlight geometry + updateHighlightGeometry(); } else { const int from = items.first().first; const int to = items.last().first; @@ -503,6 +503,29 @@ void QtGraphicsListViewPrivate::_q_currentChanged(int current, int previous) } /*! + \internal +*/ +void QtGraphicsListViewPrivate::updateHighlightGeometry() +{ + const int from = items.first().first; + const int to = items.last().first; + const int current = currentItem(); + if (from <= current && current <= to) { + highlight->show(); + highlight->setZValue(-1); + const QGraphicsObject *currentObject = items.at(current - from).second; + if (highlight->isWidget() && currentObject->isWidget()) { + const QRectF geometry = static_cast<const QGraphicsWidget*>(currentObject)->geometry(); + static_cast<QGraphicsWidget*>(highlight)->setGeometry(geometry); + } else { + highlight->setPos(currentObject->pos()); + } + } else { + highlight->hide(); + } +} + +/*! \internal */ void QtGraphicsListViewPrivate::checkCache(int index, int count) @@ -605,6 +628,7 @@ QtGraphicsListView::QtGraphicsListView(Qt::Orientation orientation, QGraphicsWid //setFlag(QGraphicsItem::ItemClipsChildrenToShape); d->q_ptr = this; d->orientation = orientation; + d->transform = new QtGraphicsTransform(this); } /*! @@ -617,6 +641,7 @@ QtGraphicsListView::QtGraphicsListView(QtGraphicsListViewPrivate &dd, Qt::Orient //setFlag(QGraphicsItem::ItemClipsChildrenToShape); d->q_ptr = this; d->orientation = orientation; + d->transform = new QtGraphicsTransform(this); } /*! @@ -788,6 +813,7 @@ void QtGraphicsListView::setHighlight(QGraphicsObject *highlight) Q_D(QtGraphicsListView); d->highlight = highlight; // update the highlight geometry + highlight->setParentItem(this); } /*! @@ -905,15 +931,24 @@ void QtGraphicsListView::doLayout() qreal coordinate = -d->offset; int index = d->firstIndex; + qDebug() << "coordinate" << coordinate; + qDebug() << "index" << index; + // find the visible items; caching helps us skip this most of the time - if (coordinate <= 0 && !d->items.isEmpty()) { + if (coordinate <= 0 && !d->items.isEmpty()) { // ### disabled #if CACHING_ENABLED // optimization: use the cached index and offset as starting points // The cached values are offsets from the start of the _contents_ // and the to index found at that offset. index += d->cachedIndexOffset; coordinate += d->cachedCoordinateOffset; + + qDebug() << "cachedIndexOffset" << d->cachedIndexOffset; + qDebug() << "index" << index; #endif + //index = d->items.first().first; + //coordinate = d->items.first().second->pos().y(); // ### vertical only + // the visible area starts at coordinate == 0 if (coordinate < 0) { // the cached offset was above or to the left of the visible area while (index < count) { @@ -1028,6 +1063,10 @@ void QtGraphicsListView::doLayout() const int visibleCount = index - firstVisibleIndex; while (visibleCount < d->items.count()) d->creator->recycle(d->items.takeLast().second); + + // update highlight + if (d->highlight) + d->updateHighlightGeometry(); } /*! @@ -1110,7 +1149,7 @@ qreal QtGraphicsListView::maximumOffset() const void QtGraphicsListView::setFirstIndex(int index) { Q_D(QtGraphicsListView); - if (d->firstIndex == index) + if (d->firstIndex == index || index < 0) return; d->firstIndex = index; emit firstIndexChanged(index); |