┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2012-07-12 00:27:53 +0200
committerFrank Reininghaus <[email protected]>2012-07-12 00:41:20 +0200
commitb8ef5ebca1662526e994815d6e044652ce7ccf4a (patch)
tree5828ba44dc1b03d4d9e329b29358d4657fd56894 /src/kitemviews
parent56b992c48622102c19867294ca0930cba7879c7d (diff)
Re-implement dropping of files on folders in the Places Panel.
This resolves a regression caused by the Places Panel rewrite. There is a small glitch left when reordering items (dragging below the last or above the first item only shows the drop indicator when first dragging out of the item and then back), but I prefer not to fix this glitch right now because this would require a more intrusive change, and I do not want to risk regressions because is not much time left to fix them before 4.9.0 is released. Thanks to Peter Penz for providing some advice about this issue. BUG: 302557 FIXED-IN: 4.9.0 (cherry picked from commit f4c960025167b7c7e04e1290ac9d9fee03a9b62d)
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kitemlistcontroller.cpp41
-rw-r--r--src/kitemviews/kitemlistcontroller.h9
-rw-r--r--src/kitemviews/kitemlistview.cpp7
3 files changed, 40 insertions, 17 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp
index 76f7fa1cd..88f5d9f7c 100644
--- a/src/kitemviews/kitemlistcontroller.cpp
+++ b/src/kitemviews/kitemlistcontroller.cpp
@@ -778,7 +778,6 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con
bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
{
- Q_UNUSED(transform);
if (!m_model || !m_view) {
return false;
}
@@ -799,20 +798,23 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
}
if (newHoveredWidget) {
+ bool droppingBetweenItems = false;
+ if (m_model->sortRole().isEmpty()) {
+ // The model supports inserting items between other items.
+ droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0);
+ }
+
const int index = newHoveredWidget->index();
- if (m_model->supportsDropping(index)) {
+ if (!droppingBetweenItems && m_model->supportsDropping(index)) {
+ // Something has been dragged on an item.
+ m_view->hideDropIndicator();
newHoveredWidget->setHovered(true);
- } else if (m_model->sortRole().isEmpty()) {
- // The model supports inserting of items on
- // the given index. Assure that a drop-indicator
- // is shown by the view.
- m_view->showDropIndicator(pos);
- }
- emit itemHovered(index);
+ emit itemHovered(index);
- if (m_autoActivationTimer->interval() >= 0) {
- m_autoActivationTimer->setProperty("index", index);
- m_autoActivationTimer->start();
+ if (m_autoActivationTimer->interval() >= 0) {
+ m_autoActivationTimer->setProperty("index", index);
+ m_autoActivationTimer->start();
+ }
}
}
}
@@ -822,7 +824,6 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
{
- Q_UNUSED(transform)
if (!m_view) {
return false;
}
@@ -831,13 +832,19 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT
m_view->setAutoScroll(false);
const QPointF pos = transform.map(event->pos());
+
+ int dropAboveIndex = -1;
if (m_model->sortRole().isEmpty()) {
- // The model supports inserting of items on
- // a given index.
- const int dropIndex = m_view->showDropIndicator(pos);
+ // The model supports inserting of items between other items.
+ dropAboveIndex = m_view->showDropIndicator(pos);
+ }
+
+ if (dropAboveIndex >= 0) {
+ // Something has been dropped between two items.
m_view->hideDropIndicator();
- emit itemDropEvent(dropIndex, event);
+ emit aboveItemDropEvent(dropAboveIndex, event);
} else {
+ // Something has been dropped on an item or on an empty part of the view.
emit itemDropEvent(m_view->itemAt(pos), event);
}
diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h
index db31d50c3..a88152622 100644
--- a/src/kitemviews/kitemlistcontroller.h
+++ b/src/kitemviews/kitemlistcontroller.h
@@ -201,9 +201,18 @@ signals:
* Is emitted if a drop event is done above the item with the index
* \a index. If \a index is < 0 the drop event is done above an
* empty area of the view.
+ * TODO: Introduce a new signal viewDropEvent(QGraphicsSceneDragDropEvent),
+ * which is emitted if the drop event occurs on an empty area in
+ * the view, and make sure that index is always >= 0 in itemDropEvent().
*/
void itemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
+ /**
+ * Is emitted if a drop event is done between the item with the index
+ * \a index and the previous item.
+ */
+ void aboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
+
void modelChanged(KItemModelBase* current, KItemModelBase* previous);
void viewChanged(KItemListView* current, KItemListView* previous);
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index 64b33f96f..72b3fd8fc 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -2318,6 +2318,13 @@ int KItemListView::showDropIndicator(const QPointF& pos)
const QPointF mappedPos = widget->mapFromItem(this, pos);
const QRectF rect = itemRect(widget->index());
if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
+ if (m_model->supportsDropping(widget->index())) {
+ const int gap = qMax(4, m_styleOption.padding);
+ if (mappedPos.y() >= gap && mappedPos.y() <= rect.height() - gap) {
+ return -1;
+ }
+ }
+
const bool isAboveItem = (mappedPos.y () < rect.height() / 2);
const qreal y = isAboveItem ? rect.top() : rect.bottom();