X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a5cf21ff06aff44cde563eaceae3c6cef452ee48..2f0ceedae088158b8af24a5e94500a7d1c0edecb:/src/views/draganddrophelper.cpp diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index 0cca59ac4..bc1361b9a 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007 by Peter Penz * + * Copyright (C) 2007 by Peter Penz * * Copyright (C) 2007 by David Faure * * * * This program is free software; you can redistribute it and/or modify * @@ -20,10 +20,10 @@ #include "draganddrophelper.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include "views/dolphiniconsview.h" @@ -47,11 +47,6 @@ DragAndDropHelper& DragAndDropHelper::instance() return s_dragAndDropHelper->instance; } -bool DragAndDropHelper::isMimeDataSupported(const QMimeData* mimeData) const -{ - return mimeData->hasUrls() || mimeData->hasFormat("application/x-kde-dndextract"); -} - void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions, DolphinViewController* dolphinViewController) @@ -67,11 +62,11 @@ void DragAndDropHelper::startDrag(QAbstractItemView* itemView, const QModelIndexList indexes = itemView->selectionModel()->selectedIndexes(); if (!indexes.isEmpty()) { QMimeData *data = itemView->model()->mimeData(indexes); - if (data == 0) { + if (!data) { return; } - if (dolphinViewController != 0) { + if (dolphinViewController) { dolphinViewController->requestToolTipHiding(); } @@ -88,7 +83,7 @@ void DragAndDropHelper::startDrag(QAbstractItemView* itemView, bool DragAndDropHelper::isDragSource(QAbstractItemView* itemView) const { - return (m_dragSource != 0) && (m_dragSource == itemView); + return m_dragSource && (m_dragSource == itemView); } void DragAndDropHelper::dropUrls(const KFileItem& destItem, @@ -104,14 +99,12 @@ void DragAndDropHelper::dropUrls(const KFileItem& destItem, QString remoteDBusClient = mimeData->data("application/x-kde-dndextract"); QDBusMessage message = QDBusMessage::createMethodCall(remoteDBusClient, "/DndExtract", "org.kde.DndExtract", "extractSelectedFilesTo"); - message.setArguments(QVariantList() << destination.path()); + message.setArguments(QVariantList() << destination.pathOrUrl()); QDBusConnection::sessionBus().call(message); } else { const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); const int urlsCount = urls.count(); - if (urlsCount == 0) { - // TODO: handle dropping of other data - } else if ((urlsCount == 1) && (urls.first() == destination)) { + if ((urlsCount == 1) && (urls.first() == destination)) { emit errorMessage(i18nc("@info:status", "A folder cannot be dropped into itself")); } else if (dropToItem) { KonqOperations::doDrop(destItem, destination, event, widget); @@ -128,14 +121,14 @@ DragAndDropHelper::DragAndDropHelper() QPixmap DragAndDropHelper::createDragPixmap(QAbstractItemView* itemView) const { - const QModelIndexList selectedIndexes = itemView->selectionModel()->selectedIndexes(); + const QModelIndexList selectedIndexes = itemView->selectionModel()->selectedIndexes(); Q_ASSERT(!selectedIndexes.isEmpty()); - + QAbstractProxyModel* proxyModel = static_cast(itemView->model()); KDirModel* dirModel = static_cast(proxyModel->sourceModel()); - + const int itemCount = selectedIndexes.count(); - + // If more than one item is dragged, align the items inside a // rectangular grid. The maximum grid size is limited to 5 x 5 items. int xCount = 3; @@ -147,11 +140,11 @@ QPixmap DragAndDropHelper::createDragPixmap(QAbstractItemView* itemView) const xCount = 4; size = KIconLoader::SizeSmallMedium; } - + if (itemCount < xCount) { xCount = itemCount; } - + int yCount = itemCount / xCount; if (itemCount % xCount != 0) { ++yCount; @@ -160,10 +153,10 @@ QPixmap DragAndDropHelper::createDragPixmap(QAbstractItemView* itemView) const yCount = xCount; } - // Draw the selected items into the grid cells + // Draw the selected items into the grid cells QPixmap dragPixmap(xCount * size + xCount - 1, yCount * size + yCount - 1); dragPixmap.fill(Qt::transparent); - + QPainter painter(&dragPixmap); int x = 0; int y = 0; @@ -172,7 +165,7 @@ QPixmap DragAndDropHelper::createDragPixmap(QAbstractItemView* itemView) const const KFileItem item = dirModel->itemForIndex(index); const QPixmap pixmap = item.pixmap(size, size); painter.drawPixmap(x, y, pixmap); - + x += size + 1; if (x >= dragPixmap.width()) { x = 0; @@ -182,7 +175,7 @@ QPixmap DragAndDropHelper::createDragPixmap(QAbstractItemView* itemView) const break; } } - + return dragPixmap; }