Commit 131d2585 authored by Huon Imberger's avatar Huon Imberger
Browse files

Allow dragging files/folders to View mode

Summary:
Specifically accepts drop events within the viewport of {nav View} mode.
If a folder that contains images is dropped, it will open that folder
and remain in {nav View} mode with the first image selected. If the
folder doesn't contain images, it switches to {nav Browse} mode.
Dragging multiple items is supported but only the first item is opened.

BUG: 169408
FIXED-IN: 18.08.0

{F5781556}

Test Plan:
Test with different image formats, as well as unsupported format (Gwenview
should display a nice error).
Test with folder (with and without images within).
{nav Browse} mode and the {nav Thumbnail Bar} drag drop should work as before.
Drop operations should not be accepted anywhere else in the GUI where they aren't
already supported. In other words, this should only add drop functionality to the
{nav View} viewport.

Ensure drops are only accepted for URL mimetypes (e.g. ignore text).

Reviewers: #gwenview, rkflx, ngraham

Reviewed By: #gwenview, rkflx

Tags: #gwenview

Differential Revision: https://phabricator.kde.org/D11879
parent ed455f74
......@@ -322,6 +322,10 @@ struct MainWindow::Private
q, SLOT(goToPrevious()));
connect(mViewMainPage, SIGNAL(nextImageRequested()),
q, SLOT(goToNext()));
connect(mViewMainPage, &ViewMainPage::openUrlRequested,
q, &MainWindow::openUrl);
connect(mViewMainPage, &ViewMainPage::openDirUrlRequested,
q, &MainWindow::openDirUrl);
setupThumbnailBar(mViewMainPage->thumbnailBar());
}
......
......@@ -239,6 +239,8 @@ struct ViewMainPagePrivate
QObject::connect(view, &DocumentView::completed, q, &ViewMainPage::completed);
QObject::connect(view, &DocumentView::previousImageRequested, q, &ViewMainPage::previousImageRequested);
QObject::connect(view, &DocumentView::nextImageRequested, q, &ViewMainPage::nextImageRequested);
QObject::connect(view, &DocumentView::openUrlRequested, q, &ViewMainPage::openUrlRequested);
QObject::connect(view, &DocumentView::openDirUrlRequested, q, &ViewMainPage::openDirUrlRequested);
QObject::connect(view, &DocumentView::captionUpdateRequested, q, &ViewMainPage::captionUpdateRequested);
QObject::connect(view, &DocumentView::toggleFullScreenRequested, q, &ViewMainPage::toggleFullScreenRequested);
QObject::connect(view, &DocumentView::focused, q, &ViewMainPage::slotViewFocused);
......
......@@ -124,6 +124,10 @@ Q_SIGNALS:
void nextImageRequested();
void openUrlRequested(const QUrl&);
void openDirUrlRequested(const QUrl&);
void toggleFullScreenRequested();
void goToBrowseModeRequested();
......
......@@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <QDebug>
#include <QIcon>
#include <QUrl>
#include <QMimeData>
// KDE
#include <KLocalizedString>
......@@ -60,6 +61,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <lib/gwenviewconfig.h>
#include <lib/mimetypeutils.h>
#include <lib/signalblocker.h>
#include <lib/urlutils.h>
namespace Gwenview
{
......@@ -365,6 +367,8 @@ DocumentView::DocumentView(QGraphicsScene* scene)
d->setupHud();
d->setCurrentAdapter(new EmptyAdapter);
setAcceptDrops(true);
}
DocumentView::~DocumentView()
......@@ -827,4 +831,22 @@ void DocumentView::setGraphicsEffectOpacity(qreal opacity)
d->mOpacityEffect->setOpacity(opacity);
}
void DocumentView::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
{
QGraphicsWidget::dragEnterEvent(event);
event->setAccepted(event->mimeData()->hasUrls());
}
void DocumentView::dropEvent(QGraphicsSceneDragDropEvent* event)
{
QGraphicsWidget::dropEvent(event);
// Since we're capturing drops in View mode, we only support one url
const QUrl url = event->mimeData()->urls().first();
if (UrlUtils::urlIsDirectory(url)) {
emit openDirUrlRequested(url);
} else {
emit openUrlRequested(url);
}
}
} // namespace
......@@ -163,6 +163,10 @@ Q_SIGNALS:
void nextImageRequested();
void openUrlRequested(const QUrl&);
void openDirUrlRequested(const QUrl&);
void captionUpdateRequested(const QString&);
void toggleFullScreenRequested();
......@@ -201,6 +205,8 @@ protected:
void wheelEvent(QGraphicsSceneWheelEvent* event) Q_DECL_OVERRIDE;
void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) Q_DECL_OVERRIDE;
bool sceneEventFilter(QGraphicsItem*, QEvent*) Q_DECL_OVERRIDE;
void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override;
void dropEvent(QGraphicsSceneDragDropEvent* event) override;
private Q_SLOTS:
void finishOpenUrl();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment