X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/c8072005fada01d772595ec64adca449134f421e..684678bd371f6fed0ae7d551afda97ea2c6b78d0:/src/kcategorizedview.cpp diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp index 7bc0055ae..7fe806055 100644 --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -1,6 +1,6 @@ /** * This file is part of the KDE project - * Copyright (C) 2007 Rafael Fernández López + * Copyright (C) 2007 Rafael Fernández López * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -357,10 +357,23 @@ void KCategorizedView::Private::drawNewCategory(const QModelIndex &index, 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, @@ -755,20 +768,22 @@ void KCategorizedView::setSelection(const QRect &rect, 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); } @@ -776,6 +791,8 @@ void KCategorizedView::setSelection(const QRect &rect, return; } + QItemSelection selection; + if (!d->mouseButtonPressed) { selection = QItemSelection(dirtyIndexes[0], dirtyIndexes[0]); @@ -803,13 +820,12 @@ void KCategorizedView::setSelection(const QRect &rect, selection << QItemSelectionRange(first, last); } - if (d->lastSelection.count() && !d->mouseButtonPressed) + if (d->lastSelection.count()) { - selection.merge(d->lastSelection, flags); - } - else 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); @@ -891,6 +907,8 @@ void KCategorizedView::mousePressEvent(QMouseEvent *event) } QListView::mousePressEvent(event); + + viewport()->update(d->categoryVisualRect(d->hoveredCategory)); } void KCategorizedView::mouseReleaseEvent(QMouseEvent *event) @@ -910,6 +928,7 @@ void KCategorizedView::mouseReleaseEvent(QMouseEvent *event) initialPressPosition.setX(initialPressPosition.x() + horizontalOffset()); QItemSelection selection; + QItemSelection deselection; if (initialPressPosition == d->initialPressPosition) { @@ -921,10 +940,18 @@ void KCategorizedView::mouseReleaseEvent(QMouseEvent *event) { 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; } @@ -949,7 +976,12 @@ void KCategorizedView::leaveEvent(QEvent *event) void KCategorizedView::startDrag(Qt::DropActions supportedActions) { - QListView::startDrag(supportedActions); + // FIXME: QAbstractItemView does far better here since it sets the + // pixmap of selected icons to the dragging cursor, but it sets a non + // ARGB window so it is no transparent. Use QAbstractItemView when + // this is fixed on Qt. + //QListView::startDrag(supportedActions); + QAbstractItemView::startDrag(supportedActions); d->isDragging = false; d->mouseButtonPressed = false; @@ -1033,7 +1065,7 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, break; } - if (category == d->elementsInfo[d->proxyModel->mapToSource(current).row()].category) + if (category == d->elementsInfo[current.row()].category) { theCategory = category; @@ -1045,22 +1077,21 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, lastCategory = category; } } -// ### FIXME !!! -#if 0 + switch (cursorAction) { case QAbstractItemView::MoveUp: { - if (d->elementsInfo[d->proxyModel->mapToSource(current).row()].relativeOffsetToCategory >= elementsPerRow) + if (d->elementsInfo[current.row()].relativeOffsetToCategory >= elementsPerRow) { - int indexToMove = d->invertedElementDictionary[current.row()].row(); - indexToMove -= qMin(((d->elementsInfo[d->proxyModel->mapToSource(current).row()].relativeOffsetToCategory) + d->forcedSelectionPosition), elementsPerRow - d->forcedSelectionPosition + (d->elementsInfo[d->proxyModel->mapToSource(current).row()].relativeOffsetToCategory % elementsPerRow)); + int indexToMove = current.row(); + indexToMove -= qMin(((d->elementsInfo[current.row()].relativeOffsetToCategory) + d->forcedSelectionPosition), elementsPerRow - d->forcedSelectionPosition + (d->elementsInfo[current.row()].relativeOffsetToCategory % elementsPerRow)); - return d->elementDictionary[indexToMove]; + return d->proxyModel->index(indexToMove, 0); } else { int lastCategoryLastRow = (d->categoriesIndexes[lastCategory].count() - 1) % elementsPerRow; - int indexToMove = d->invertedElementDictionary[current.row()].row() - d->elementsInfo[d->proxyModel->mapToSource(current).row()].relativeOffsetToCategory; + int indexToMove = current.row() - d->elementsInfo[current.row()].relativeOffsetToCategory; if (d->forcedSelectionPosition >= lastCategoryLastRow) { @@ -1071,22 +1102,22 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, indexToMove -= qMin((lastCategoryLastRow - d->forcedSelectionPosition + 1), d->forcedSelectionPosition + elementsPerRow + 1); } - return d->elementDictionary[indexToMove]; + return d->proxyModel->index(indexToMove, 0); } } case QAbstractItemView::MoveDown: { - if (d->elementsInfo[d->proxyModel->mapToSource(current).row()].relativeOffsetToCategory < (d->categoriesIndexes[theCategory].count() - 1 - ((d->categoriesIndexes[theCategory].count() - 1) % elementsPerRow))) + if (d->elementsInfo[current.row()].relativeOffsetToCategory < (d->categoriesIndexes[theCategory].count() - 1 - ((d->categoriesIndexes[theCategory].count() - 1) % elementsPerRow))) { - int indexToMove = d->invertedElementDictionary[current.row()].row(); - indexToMove += qMin(elementsPerRow, d->categoriesIndexes[theCategory].count() - 1 - d->elementsInfo[d->proxyModel->mapToSource(current).row()].relativeOffsetToCategory); + int indexToMove = current.row(); + indexToMove += qMin(elementsPerRow, d->categoriesIndexes[theCategory].count() - 1 - d->elementsInfo[current.row()].relativeOffsetToCategory); - return d->elementDictionary[indexToMove]; + return d->proxyModel->index(indexToMove, 0); } else { int afterCategoryLastRow = qMin(elementsPerRow, d->categoriesIndexes[afterCategory].count()); - int indexToMove = d->invertedElementDictionary[current.row()].row() + (d->categoriesIndexes[theCategory].count() - d->elementsInfo[d->proxyModel->mapToSource(current).row()].relativeOffsetToCategory); + int indexToMove = current.row() + (d->categoriesIndexes[theCategory].count() - d->elementsInfo[current.row()].relativeOffsetToCategory); if (d->forcedSelectionPosition >= afterCategoryLastRow) { @@ -1097,30 +1128,30 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, indexToMove += qMin(d->forcedSelectionPosition, elementsPerRow); } - return d->elementDictionary[indexToMove]; + return d->proxyModel->index(indexToMove, 0); } } case QAbstractItemView::MoveLeft: - d->forcedSelectionPosition = d->elementsInfo[d->proxyModel->mapToSource(d->elementDictionary[d->proxyModel->index(d->invertedElementDictionary[current.row()].row() - 1, 0).row()]).row()].relativeOffsetToCategory % elementsPerRow; + d->forcedSelectionPosition = d->elementsInfo[current.row() - 1].relativeOffsetToCategory % elementsPerRow; if (d->forcedSelectionPosition < 0) d->forcedSelectionPosition = (d->categoriesIndexes[theCategory].count() - 1) % elementsPerRow; - return d->elementDictionary[d->proxyModel->index(d->invertedElementDictionary[current.row()].row() - 1, 0).row()]; + return d->proxyModel->index(current.row() - 1, 0); case QAbstractItemView::MoveRight: - d->forcedSelectionPosition = d->elementsInfo[d->proxyModel->mapToSource(d->elementDictionary[d->proxyModel->index(d->invertedElementDictionary[current.row()].row() + 1, 0).row()]).row()].relativeOffsetToCategory % elementsPerRow; + d->forcedSelectionPosition = d->elementsInfo[current.row() + 1].relativeOffsetToCategory % elementsPerRow; if (d->forcedSelectionPosition < 0) d->forcedSelectionPosition = (d->categoriesIndexes[theCategory].count() - 1) % elementsPerRow; - return d->elementDictionary[d->proxyModel->index(d->invertedElementDictionary[current.row()].row() + 1, 0).row()]; + return d->proxyModel->index(current.row() + 1, 0); default: break; } -#endif + return QListView::moveCursor(cursorAction, modifiers); }