if (m_model->supportsDropping(index)) {
newHoveredWidget->setHovered(true);
} else if (m_model->sortRole().isEmpty()) {
- // The model supports the inserting of items on
- // the given index as no sort-role has been
- // specified. Assure that a drag-indicator
+ // The model supports inserting of items on
+ // the given index. Assure that a drop-indicator
// is shown by the view.
- const int dropIndex = m_view->showDropIndicator(pos);
- Q_UNUSED(dropIndex); // TODO
+ m_view->showDropIndicator(pos);
}
emit itemHovered(index);
m_view->setAutoScroll(false);
const QPointF pos = transform.map(event->pos());
- const int index = m_view->itemAt(pos);
- emit itemDropEvent(index, event);
+ if (m_model->sortRole().isEmpty()) {
+ // The model supports inserting of items on
+ // a given index.
+ const int dropIndex = m_view->showDropIndicator(pos);
+ m_view->hideDropIndicator();
+ emit itemDropEvent(dropIndex, event);
+ } else {
+ emit itemDropEvent(m_view->itemAt(pos), event);
+ }
return true;
}
const QPointF mappedPos = widget->mapFromItem(this, pos);
const QRectF rect = itemRect(widget->index());
if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
- const qreal y = (mappedPos.y () < rect.height() / 2) ?
- rect.top() : rect.bottom();
+ const bool isAboveItem = (mappedPos.y () < rect.height() / 2);
+ const qreal y = isAboveItem ? rect.top() : rect.bottom();
const QRectF draggingInsertIndicator(rect.left(), y, rect.width(), 1);
if (m_dropIndicator != draggingInsertIndicator) {
m_dropIndicator = draggingInsertIndicator;
update();
}
- return widget->index();
+
+ int index = widget->index();
+ if (!isAboveItem) {
+ ++index;
+ }
+ return index;
}
}
if (!urls.isEmpty()) {
urls.populateMimeData(mimeData);
}
-
- const QString internalMimeType = "application/x-dolphinplacesmodel-" +
- QString::number((qptrdiff)this);
- mimeData->setData(internalMimeType, itemData);
+ mimeData->setData(internalMimeType(), itemData);
return mimeData;
}
+void PlacesItemModel::dropMimeData(int index, const QMimeData* mimeData)
+{
+ Q_UNUSED(index); // TODO
+ if (mimeData->hasFormat(internalMimeType())) {
+ // TODO
+ } else if (mimeData->hasFormat("text/uri-list")) {
+ // TODO
+ }
+}
+
KUrl PlacesItemModel::convertedUrl(const KUrl& url)
{
KUrl newUrl = url;
}
}
+QString PlacesItemModel::internalMimeType() const
+{
+ return "application/x-dolphinplacesmodel-" +
+ QString::number((qptrdiff)this);
+}
+
bool PlacesItemModel::equalBookmarkIdentifiers(const KBookmark& b1, const KBookmark& b2)
{
const QString udi1 = b1.metaDataItem("UDI");
/** @reimp */
virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
+ void dropMimeData(int index, const QMimeData* mimeData);
+
/**
* @return Converts the URL, which contains "virtual" URLs for system-items like
* "search:/documents" into a Nepomuk-Query-URL that will be handled by
*/
void triggerBookmarksSaving();
+ QString internalMimeType() const;
+
/**
* @return True if the bookmarks have the same identifiers. The identifier
* is the unique "ID"-property in case if no UDI is set, otherwise
#include "placesitemlistwidget.h"
#include "placesitemmodel.h"
#include <views/draganddrophelper.h>
+#include <QGraphicsSceneDragDropEvent>
#include <QVBoxLayout>
#include <QShowEvent>
connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
+ connect(m_controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
KItemListContainer* container = new KItemListContainer(m_controller, this);
container->setEnabledFrame(false);
selectClosestItem();
}
+void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+{
+ m_model->dropMimeData(index, event->mimeData());
+}
+
void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
{
Q_UNUSED(parent);
class PlacesItemEditDialog;
class PlacesItem;
class PlacesItemModel;
+class QGraphicsSceneDragDropEvent;
/**
* @brief Combines bookmarks and mounted devices as list.
void slotItemMiddleClicked(int index);
void slotItemContextMenuRequested(int index, const QPointF& pos);
void slotViewContextMenuRequested(const QPointF& pos);
+ void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
void slotTrashUpdated(KJob* job);
if (previewsShown()) {
// Optimize the width for previews with a 3:2 aspect ratio instead
// of a 1:1 ratio to avoid wasting too much vertical space when
- // photos.
+ // showing photos.
const int minWidth = iconSize * 3 / 2;
itemWidth = qMax(itemWidth, minWidth);
}