Skip to content

Commit

Permalink
Handle Qt drag and drop IgnoreAction
Browse files Browse the repository at this point in the history
Also ensure dragEnterEvent and dragMoveEvent indicate the actually
performed action (copy in our case). This influences the icon shown
to the user while dragging. On Windows this will then show the actual
copy icon even if the user has modifiers pressed.
  • Loading branch information
phw committed Aug 13, 2023
1 parent ddc695c commit ef58589
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions picard/ui/coverartbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def dragEnterEvent(self, event):
event.accept()

def dropEvent(self, event):
if event.proposedAction() == QtCore.Qt.DropAction.IgnoreAction:
event.acceptProposedAction()
return

accepted = False
# Chromium includes the actual data of the dragged image in the drop event. This
# is useful for Google Images, where the url links to the page that contains the image
Expand Down
14 changes: 11 additions & 3 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,16 @@ def mimeTypes(self):
return ["text/uri-list", "application/picard.album-list"]

def dragEnterEvent(self, event):
if not event.source() or event.mimeData().hasUrls():
super().dragEnterEvent(event)
if event.isAccepted() and (not event.source() or event.mimeData().hasUrls()):
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()

def dragMoveEvent(self, event):
super().dragMoveEvent(event)
if event.isAccepted() and (not event.source() or event.mimeData().hasUrls()):
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()
else:
event.acceptProposedAction()

def startDrag(self, supportedActions):
"""Start drag, *without* using pixmap."""
Expand Down Expand Up @@ -763,6 +768,9 @@ def drop_urls(urls, target, move_to_multi_tracks=True):
tagger.add_paths(new_paths, target=target)

def dropEvent(self, event):
if event.proposedAction() == QtCore.Qt.DropAction.IgnoreAction:
event.acceptProposedAction()
return
# Dropping with Alt key pressed forces all dropped files being
# assigned to the same track.
if event.keyboardModifiers() == QtCore.Qt.KeyboardModifier.AltModifier:
Expand Down
12 changes: 12 additions & 0 deletions picard/ui/options/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def __init__(self, parent=None):
plugins.mimeTypes = self.mimeTypes
plugins.dropEvent = self.dropEvent
plugins.dragEnterEvent = self.dragEnterEvent
plugins.dragMoveEvent = self.dragMoveEvent

self.ui.install_plugin.clicked.connect(self.open_plugins)
self.ui.folder_open.clicked.connect(self.open_plugin_dir)
Expand Down Expand Up @@ -700,9 +701,20 @@ def dragEnterEvent(self, event):
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()

def dragMoveEvent(self, event):
event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()

def dropEvent(self, event):
if event.proposedAction() == QtCore.Qt.DropAction.IgnoreAction:
event.acceptProposedAction()
return

for path in (os.path.normpath(u.toLocalFile()) for u in event.mimeData().urls()):
self.manager.install_plugin(path)

event.setDropAction(QtCore.Qt.DropAction.CopyAction)
event.accept()


register_options_page(PluginsOptionsPage)

0 comments on commit ef58589

Please sign in to comment.