if (listView->layoutDirection() == Qt::LeftToRight)
{
retRect = QRect(listView->spacing(), listView->spacing() * 2 +
- categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+ categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
}
else
{
retRect = QRect(listView->viewport()->width() - listView->spacing(), listView->spacing() * 2 +
- categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+ categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
}
int viewportWidth = listView->viewport()->width() - listView->spacing();
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
- categoryDrawer->categoryHeight(listView->viewOptions()) +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
- categoryDrawer->categoryHeight(listView->viewOptions()) +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
}
}
- retRect.setHeight(categoryDrawer->categoryHeight(listView->viewOptions()));
+ retRect.setHeight(categoryDrawer->categoryHeight(index, listView->viewOptions()));
return retRect;
}
optionCopy.state &= ~QStyle::State_Selected;
- if ((category == hoveredCategory) && !mouseButtonPressed)
- {
- optionCopy.state |= QStyle::State_MouseOver;
- }
- else if ((category == hoveredCategory) && mouseButtonPressed)
- {
- QPoint initialPressPosition = listView->viewport()->mapFromGlobal(QCursor::pos());
- initialPressPosition.setY(initialPressPosition.y() + listView->verticalOffset());
- initialPressPosition.setX(initialPressPosition.x() + listView->horizontalOffset());
-
- if (initialPressPosition == this->initialPressPosition)
+ if ((listView->selectionMode() != SingleSelection) && (listView->selectionMode() != NoSelection)) {
+ if ((category == hoveredCategory) && !mouseButtonPressed)
{
- optionCopy.state |= QStyle::State_Selected;
+ optionCopy.state |= QStyle::State_MouseOver;
+ }
+ else if ((category == hoveredCategory) && mouseButtonPressed)
+ {
+ QPoint initialPressPosition = listView->viewport()->mapFromGlobal(QCursor::pos());
+ initialPressPosition.setY(initialPressPosition.y() + listView->verticalOffset());
+ initialPressPosition.setX(initialPressPosition.x() + listView->horizontalOffset());
+
+ if (initialPressPosition == this->initialPressPosition)
+ {
+ optionCopy.state |= QStyle::State_Selected;
+ }
}
}
QModelIndex lastIndex = categoriesIndexes.isEmpty() ? QModelIndex() : categoriesIndexes[categories.last()].last();
int lastItemBottom = cachedRectIndex(lastIndex).top() +
- listView->spacing() + (listView->gridSize().isEmpty() ? 0 : listView->gridSize().height()) - listView->viewport()->height();
+ listView->spacing() + (listView->gridSize().isEmpty() ? biggestItemSize.height() : listView->gridSize().height()) - listView->viewport()->height();
listView->horizontalScrollBar()->setRange(0, 0);
index = item[0];
}
- d->hovered = index;
-
return index;
}
option.state |= QStyle::State_Editing;
}
- if ((index == d->hovered) && !d->mouseButtonPressed)
+ // we are only interested to give the mouse over feedback when no
+ // dragging is happening (ereslibre)
+ if ((index == d->hovered) && !d->mouseButtonPressed &&
+ (this->state() == QAbstractItemView::NoState))
option.state |= QStyle::State_MouseOver;
else
option.state &= ~QStyle::State_MouseOver;
else if (intersectedInThePast)
{
break; // the visible area has been finished, we don't need to keep asking, the rest won't intersect
- // this is doable because we know that categories are correctly ordered on the list
+ // this is doable because we know that categories are correctly ordered on the list
}
}
- if (d->mouseButtonPressed && !d->isDragging)
+ if ((selectionMode() != SingleSelection) && (selectionMode() != NoSelection))
{
- QPoint start, end, initialPressPosition;
+ if (d->mouseButtonPressed && !d->isDragging)
+ {
+ QPoint start, end, initialPressPosition;
- initialPressPosition = d->initialPressPosition;
+ initialPressPosition = d->initialPressPosition;
- initialPressPosition.setY(initialPressPosition.y() - verticalOffset());
- initialPressPosition.setX(initialPressPosition.x() - horizontalOffset());
+ initialPressPosition.setY(initialPressPosition.y() - verticalOffset());
+ initialPressPosition.setX(initialPressPosition.x() - horizontalOffset());
- if (d->initialPressPosition.x() > d->mousePosition.x() ||
- d->initialPressPosition.y() > d->mousePosition.y())
- {
- start = d->mousePosition;
- end = initialPressPosition;
- }
- else
- {
- start = initialPressPosition;
- end = d->mousePosition;
- }
+ if (d->initialPressPosition.x() > d->mousePosition.x() ||
+ d->initialPressPosition.y() > d->mousePosition.y())
+ {
+ start = d->mousePosition;
+ end = initialPressPosition;
+ }
+ else
+ {
+ start = initialPressPosition;
+ end = d->mousePosition;
+ }
- QStyleOptionRubberBand yetAnotherOption;
- yetAnotherOption.initFrom(this);
- yetAnotherOption.shape = QRubberBand::Rectangle;
- yetAnotherOption.opaque = false;
- yetAnotherOption.rect = QRect(start, end).intersected(viewport()->rect().adjusted(-16, -16, 16, 16));
- painter.save();
- style()->drawControl(QStyle::CE_RubberBand, &yetAnotherOption, &painter);
- painter.restore();
+ QStyleOptionRubberBand yetAnotherOption;
+ yetAnotherOption.initFrom(this);
+ yetAnotherOption.shape = QRubberBand::Rectangle;
+ yetAnotherOption.opaque = false;
+ yetAnotherOption.rect = QRect(start, end).intersected(viewport()->rect().adjusted(-16, -16, 16, 16));
+ painter.save();
+ style()->drawControl(QStyle::CE_RubberBand, &yetAnotherOption, &painter);
+ painter.restore();
+ }
}
if (d->isDragging && !d->dragLeftViewport)
return;
}
+ QModelIndexList item = d->intersectionSet(QRect(event->pos(), event->pos()));
+
+ if (item.count() == 1)
+ {
+ d->hovered = item[0];
+ }
+ else
+ {
+ d->hovered = QModelIndex();
+ }
+
const QString previousHoveredCategory = d->hoveredCategory;
d->mousePosition = event->pos();
end = d->mousePosition;
}
- rect = QRect(start, end).intersected(viewport()->rect().adjusted(-16, -16, 16, 16));
+ rect = QRect(start, end).adjusted(-16, -16, 16, 16);
+ rect = rect.united(QRect(start, end).adjusted(16, 16, -16, -16)).intersected(viewport()->rect());
+
+ viewport()->update(rect);
}
}
initialPressPosition.setY(initialPressPosition.y() + verticalOffset());
initialPressPosition.setX(initialPressPosition.x() + horizontalOffset());
- if (initialPressPosition == d->initialPressPosition)
+ if ((selectionMode() != SingleSelection) && (selectionMode() != NoSelection) &&
+ (initialPressPosition == d->initialPressPosition))
{
foreach(const QString &category, d->categories)
{
if (d->categoryVisualRect(category).contains(event->pos()))
{
- QItemSelection selection;
+ QItemSelection selection = selectionModel()->selection();
QModelIndexList indexList = d->categoriesIndexes[category];
foreach (const QModelIndex &index, indexList)
selection << QItemSelectionRange(selectIndex);
}
- selectionModel()->select(selection, QItemSelectionModel::Select);
+ selectionModel()->select(selection, QItemSelectionModel::SelectCurrent);
break;
}
}
}
+ QRect rect;
+ if (!d->isDragging)
+ {
+ QPoint start, end, initialPressPosition;
+
+ initialPressPosition = d->initialPressPosition;
+
+ initialPressPosition.setY(initialPressPosition.y() - verticalOffset());
+ initialPressPosition.setX(initialPressPosition.x() - horizontalOffset());
+
+ if (d->initialPressPosition.x() > d->mousePosition.x() ||
+ d->initialPressPosition.y() > d->mousePosition.y())
+ {
+ start = d->mousePosition;
+ end = initialPressPosition;
+ }
+ else
+ {
+ start = initialPressPosition;
+ end = d->mousePosition;
+ }
+
+ rect = QRect(start, end).adjusted(-16, -16, 16, 16);
+ rect = rect.united(QRect(start, end).adjusted(16, 16, -16, -16)).intersected(viewport()->rect());
+
+ viewport()->update(rect);
+ }
+
if (d->hovered.isValid())
viewport()->update(visualRect(d->hovered));
else if (!d->hoveredCategory.isEmpty())
d->dragLeftViewport = false;
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
- {
#if defined(DOLPHIN_DRAGANDDROP)
- QAbstractItemView::dragMoveEvent(event);
+ QAbstractItemView::dragMoveEvent(event);
#else
- QListView::dragMoveEvent(event);
+ QListView::dragMoveEvent(event);
#endif
+
+ if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
+ !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ {
return;
}
return QListView::moveCursor(cursorAction, modifiers);
}
- QModelIndex current = selectionModel()->currentIndex();
-
- if (!current.isValid())
- {
- current = model()->index(0, 0, QModelIndex());
- selectionModel()->select(current, QItemSelectionModel::NoUpdate);
- d->forcedSelectionPosition = 0;
-
- return current;
- }
-
int viewportWidth = viewport()->width() - spacing();
int itemWidth;
if (!elementsPerRow)
elementsPerRow++;
+ QModelIndex current = selectionModel()->currentIndex();
+
+ if (!current.isValid())
+ {
+ if (cursorAction == MoveEnd)
+ {
+ current = model()->index(model()->rowCount() - 1, 0, QModelIndex());
+ d->forcedSelectionPosition = d->elementsInfo[current.row()].relativeOffsetToCategory % elementsPerRow;
+ }
+ else
+ {
+ current = model()->index(0, 0, QModelIndex());
+ d->forcedSelectionPosition = 0;
+ }
+
+ return current;
+ }
+ else if (!current.isValid())
+ {
+ return QModelIndex();
+ }
+
QString lastCategory = d->categories.first();
QString theCategory = d->categories.first();
QString afterCategory = d->categories.first();
if (!elementsPerRow)
elementsPerRow++;
- d->forcedSelectionPosition = d->elementsInfo[current.row()].relativeOffsetToCategory % elementsPerRow;
+ if (d->mouseButtonPressed || d->rightMouseButtonPressed)
+ d->forcedSelectionPosition = d->elementsInfo[current.row()].relativeOffsetToCategory % elementsPerRow;
QListView::currentChanged(current, previous);
}