Exemple #1
0
    def mouseMoveEvent(self, event):
        """Drag and drop layer with mouse movement.

        Parameters
        ----------
        event : qtpy.QtCore.QEvent
            Event from the Qt context.
        """
        position = np.array([event.pos().x(), event.pos().y()])
        distance = np.linalg.norm(position - self._drag_start_position)
        if (distance < QApplication.startDragDistance()
                or self._drag_name is None):
            return
        mimeData = QMimeData()
        mimeData.setText(self._drag_name)
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - self.rect().topLeft())
        drag.exec_()
        # Check if dragged layer still exists or was deleted during drag
        names = [layer.name for layer in self.layers]
        dragged_layer_exists = self._drag_name in names
        if self._drag_name is not None and dragged_layer_exists:
            index = self.layers.index(self._drag_name)
            layer = self.layers[index]
            self._ensure_visible(layer)
Exemple #2
0
 def startDrag(self, dropActions):
     """Reimplement Qt Method - handle drag event"""
     data = QMimeData()
     data.setUrls([QUrl(fname) for fname in self.get_selected_filenames()])
     drag = QDrag(self)
     drag.setMimeData(data)
     drag.exec_()
Exemple #3
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     drag = QDrag(event.widget())
     mime = QMimeData()
     mime.setText(str(self.id))
     drag.setMimeData(mime)
     # self.setCursor(Qt.ClosedHandCursor)
     drag.exec_()
Exemple #4
0
 def mouseMoveEvent(self, event):
     """Override Qt method"""
     if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
        (event.pos() - self.__drag_start_pos).manhattanLength() > \
             QApplication.startDragDistance():
         drag = QDrag(self)
         mimeData = QMimeData()
         # Converting id's to long to avoid an OverflowError with PySide
         if PY2:
             ancestor_id = long(id(self.ancestor))
             parent_widget_id = long(id(self.parentWidget()))
             self_id = long(id(self))
         else:
             ancestor_id = id(self.ancestor)
             parent_widget_id = id(self.parentWidget())
             self_id = id(self)
         mimeData.setData("parent-id", QByteArray.number(ancestor_id))
         mimeData.setData("tabwidget-id",
                          QByteArray.number(parent_widget_id))
         mimeData.setData("tabbar-id", QByteArray.number(self_id))
         mimeData.setData(
             "source-index",
             QByteArray.number(self.tabAt(self.__drag_start_pos)))
         drag.setMimeData(mimeData)
         drag.exec_()
     QTabBar.mouseMoveEvent(self, event)
Exemple #5
0
    def mouseMoveEvent(self, event):
        if (self._clickPos is None
                or (event.pos() - self._clickPos).manhattanLength() <
                QApplication.startDragDistance()):
            return

        # _log.debug("Drag move")
        # render before detachment otherwise it might look ugly
        pixmap = QPixmap(self.size())
        self.render(pixmap)

        self.setVisible(False)
        if len(self._dock.parentContainer.flatDockList) == 1:
            self._dock.parentContainer.setVisible(False)

        # Build drag object
        event.accept()
        drag = QDrag(self)
        mimeData = QMimeData()
        encodedData = QByteArray(pickle.dumps(self._dock.uid))
        mimeData.setData(MIME_TYPE, encodedData)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        action = drag.exec_(Qt.MoveAction)

        _log.debug("After drag. Action: {}".format(action))
        if Qt.IgnoreAction == action:
            _log.debug("D'n'D canceled")
            self.setVisible(True)
            self._dock.parentContainer.setVisible(True)
Exemple #6
0
    def mouseMoveEvent(self, event):
        distance = (event.pos() - self.dragStartPosition).manhattanLength()
        if distance < QApplication.startDragDistance():
            return
        mimeData = QMimeData()
        if not self.layer.selected:
            name = self.layer.name
        else:
            name = ''
            for layer in self.layer.viewer.layers:
                if layer.selected:
                    name = layer.name + '; ' + name
            name = name[:-2]
        mimeData.setText(name)
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(event.pos() - self.rect().topLeft())
        dropAction = drag.exec_(Qt.MoveAction | Qt.CopyAction)

        if dropAction == Qt.CopyAction:
            if not self.layer.selected:
                index = self.layer.viewer.layers.index(self.layer)
                self.layer.viewer.layers.pop(index)
            else:
                self.layer.viewer.layers.remove_selected()
Exemple #7
0
    def mouseMoveEvent(self, event):
        from qtpy.QtCore import QMimeData, QByteArray
        from qtpy.QtGui import QPixmap, QDrag

        if not (event.button() != Qt.LeftButton
                and isinstance(self.dragLabel, QLabel)):
            return

        if (event.pos() - self.dragStartPosition
            ).manhattanLength() < QApplication.startDragDistance():
            return

        axis_index = self.filters_layout.indexOf(self.dragLabel) // 2

        # prepare hotSpot, mimeData and pixmap objects
        mimeData = QMimeData()
        mimeData.setText(self.dragLabel.text())
        mimeData.setData("application/x-axis-index",
                         QByteArray.number(axis_index))
        pixmap = QPixmap(self.dragLabel.size())
        self.dragLabel.render(pixmap)

        # prepare drag object
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - self.dragStartPosition)

        drag.exec_(Qt.MoveAction | Qt.CopyAction, Qt.CopyAction)
Exemple #8
0
 def mouseMoveEvent(self, _event):
     item = self.currentItem()
     if item is not None:
         reaction: cobra.Reaction = item.data(3, 0)
         mime_data = QMimeData()
         mime_data.setText(reaction.id)
         drag = QDrag(self)
         drag.setMimeData(mime_data)
         drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)
Exemple #9
0
 def mouseMoveEvent(self, event):
     position = np.array([event.pos().x(), event.pos().y()])
     distance = np.linalg.norm(position - self.drag_start_position)
     if (distance < QApplication.startDragDistance()
             or self.drag_name is None):
         return
     mimeData = QMimeData()
     mimeData.setText(self.drag_name)
     drag = QDrag(self)
     drag.setMimeData(mimeData)
     drag.setHotSpot(event.pos() - self.rect().topLeft())
     dropAction = drag.exec_()
Exemple #10
0
 def mouseMoveEvent(self, event):
     position = np.array([event.pos().x(), event.pos().y()])
     distance = np.linalg.norm(position - self.drag_start_position)
     if (distance < QApplication.startDragDistance()
             or self.drag_name is None):
         return
     mimeData = QMimeData()
     mimeData.setText(self.drag_name)
     drag = QDrag(self)
     drag.setMimeData(mimeData)
     drag.setHotSpot(event.pos() - self.rect().topLeft())
     drag.exec_()
     if self.drag_name is not None:
         index = self.layers.index(self.drag_name)
         layer = self.layers[index]
         self._ensure_visible(layer)
Exemple #11
0
def drag_with_pixmap(list_widget: QListWidget) -> QDrag:
    """Create a QDrag object with a pixmap of the currently select list item.

    This method is useful when you have a QListWidget that displays custom
    widgets for each QListWidgetItem instance in the list (usually by calling
    ``QListWidget.setItemWidget(item, widget)``).  When used in a
    ``QListWidget.startDrag`` method, this function creates a QDrag object that
    shows an image of the item being dragged (rather than an empty rectangle).

    Parameters
    ----------
    list_widget : QListWidget
        The QListWidget for which to create a QDrag object.

    Returns
    -------
    QDrag
        A QDrag instance with a pixmap of the currently selected item.

    Examples
    --------
    >>> class QListWidget:
    ...     def startDrag(self, supportedActions):
    ...         drag = drag_with_pixmap(self)
    ...         drag.exec_(supportedActions, Qt.MoveAction)

    """
    drag = QDrag(list_widget)
    drag.setMimeData(list_widget.mimeData(list_widget.selectedItems()))
    size = list_widget.viewport().visibleRegion().boundingRect().size()
    pixmap = QPixmap(size)
    pixmap.fill(Qt.transparent)
    painter = QPainter(pixmap)
    for index in list_widget.selectedIndexes():
        rect = list_widget.visualRect(index)
        painter.drawPixmap(rect, list_widget.viewport().grab(rect))
    painter.end()
    drag.setPixmap(pixmap)
    drag.setHotSpot(list_widget.viewport().mapFromGlobal(QCursor.pos()))
    return drag
Exemple #12
0
    def mouseMoveEvent(self, event):
        """Override Qt method"""
        if event.buttons() == Qt.MouseButtons(Qt.LeftButton) and \
           (event.pos() - self.__drag_start_pos).manhattanLength() > \
                QApplication.startDragDistance():
            drag = QDrag(self)
            mimeData = QMimeData()

            ancestor_id = to_text_string(id(self.ancestor))
            parent_widget_id = to_text_string(id(self.parentWidget()))
            self_id = to_text_string(id(self))
            source_index = to_text_string(self.tabAt(self.__drag_start_pos))

            mimeData.setData("parent-id", to_binary_string(ancestor_id))
            mimeData.setData("tabwidget-id",
                             to_binary_string(parent_widget_id))
            mimeData.setData("tabbar-id", to_binary_string(self_id))
            mimeData.setData("source-index", to_binary_string(source_index))

            drag.setMimeData(mimeData)
            drag.exec_()
        QTabBar.mouseMoveEvent(self, event)