QStyleOption optionCopy = option;
const QString category = proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString();
+ 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)
+ {
+ optionCopy.state |= QStyle::State_Selected;
+ }
+ }
categoryDrawer->drawCategory(index,
sortRole,
if (!flags)
return;
- selectionModel()->clear();
-
if (flags & QItemSelectionModel::Clear)
{
- d->lastSelection = QItemSelection();
+ if (!rect.intersects(d->categoryVisualRect(d->hoveredCategory)))
+ {
+ d->lastSelection = QItemSelection();
+ }
}
- QModelIndexList dirtyIndexes = d->intersectionSet(rect);
+ selectionModel()->clear();
- QItemSelection selection;
+ QModelIndexList dirtyIndexes = d->intersectionSet(rect);
if (!dirtyIndexes.count())
{
- if (d->lastSelection.count())
+ if (!d->lastSelection.isEmpty() &&
+ (rect.intersects(d->categoryVisualRect(d->hoveredCategory)) || d->mouseButtonPressed))
{
selectionModel()->select(d->lastSelection, flags);
}
return;
}
+ QItemSelection selection;
+
if (!d->mouseButtonPressed)
{
selection = QItemSelection(dirtyIndexes[0], dirtyIndexes[0]);
selection << QItemSelectionRange(first, last);
}
- if (d->lastSelection.count() && !d->mouseButtonPressed)
- {
- selection.merge(d->lastSelection, flags);
- }
- else if (d->lastSelection.count())
+ if (d->lastSelection.count())
{
- selection.merge(d->lastSelection, QItemSelectionModel::Select);
+ if ((selection.count() == 1) && (selection[0].indexes().count() == 1))
+ selection.merge(d->lastSelection, flags);
+ else
+ selection.merge(d->lastSelection, QItemSelectionModel::Select);
}
selectionModel()->select(selection, flags);
}
QListView::mousePressEvent(event);
+
+ viewport()->update(d->categoryVisualRect(d->hoveredCategory));
}
void KCategorizedView::mouseReleaseEvent(QMouseEvent *event)
initialPressPosition.setX(initialPressPosition.x() + horizontalOffset());
QItemSelection selection;
+ QItemSelection deselection;
if (initialPressPosition == d->initialPressPosition)
{
{
QModelIndex selectIndex = index.model()->index(index.row(), 0);
- selection << QItemSelectionRange(selectIndex);
+ if (!d->lastSelection.contains(selectIndex))
+ {
+ selection << QItemSelectionRange(selectIndex);
+ }
+ else
+ {
+ deselection << QItemSelectionRange(selectIndex);
+ }
}
selectionModel()->select(selection, QItemSelectionModel::Select);
+ selectionModel()->select(deselection, QItemSelectionModel::Deselect);
break;
}