def dropEvent(self, event: QtGui.QDropEvent) -> None: item: QtWidgets.QTreeWidgetItem = self.itemAt(event.pos()) if not item: return event.setDropAction(Qt.IgnoreAction) source = self.preset_for_item(self.currentItem()) target = self.preset_for_item(item) if source is None or target is None: return event.setDropAction(Qt.IgnoreAction) if source.game != target.game or source.base_preset_uuid is None: return event.setDropAction(Qt.IgnoreAction) try: source_preset = source.get_preset() except InvalidPreset: return event.setDropAction(Qt.IgnoreAction) self.window_manager.preset_manager.add_new_preset( VersionedPreset.with_preset( dataclasses.replace(source_preset, base_preset_uuid=target.uuid))) return super().dropEvent(event)
def dropEvent(self, event: QtGui.QDropEvent): if event.mimeData().hasText(): mime = event.mimeData() transectData = json.loads(mime.text()) transect = Transect(transectData["name"], transectData["numPhotos"]) if self.contains(transect): QtWidgets.QMessageBox.warning( self, "ImageWAO", f"Cannot move transect to this person because they already own the transect. {transect}", QtWidgets.QMessageBox.Ok, ) event.ignore() else: dragTransect = self.addTransect(transect) dragTransect.setBackgroundColor( QtGui.QColor(transectData["color"])) self._sortTransects() if event.source() in self.children(): event.setDropAction(QtCore.Qt.MoveAction) else: event.setDropAction(QtCore.Qt.MoveAction) event.accept() self.contentsChanged.emit() else: event.ignore()
def drop_event(self, e: QDropEvent): mime: QMimeData = e.mimeData() src = e.source() # -- File drop -- if mime.hasUrls(): destination_index = self.view.indexAt(e.pos()) for url in mime.urls(): local_path = Path(url.toLocalFile()) if not path_exists(local_path): continue self.file_drop(local_path, destination_index) e.accept() return # --- Internal View Drops --- if not isinstance(src, self.view.__class__): e.ignore() return e.setDropAction(Qt.MoveAction) if src is not self.view: e.setDropAction(Qt.CopyAction) if e.keyboardModifiers() == Qt.ShiftModifier: e.setDropAction(Qt.CopyAction) # -- Copy drop -- if e.dropAction() is Qt.CopyAction: destination_index = self.view.indexAt(e.pos()) self.copy_drop(src, destination_index) e.accept() # -- Drag move -- if e.dropAction() is Qt.MoveAction: destination_index = self.view.indexAt(e.pos()) self.move_drop(destination_index) # Ignore default view behaviour e.ignore()