Esempio n. 1
0
    def startDrag(self, event):
        item = self.itemAt(event.scenePos(), self.page_view_transform)
        if item is None:
            event.ignore()
            return
        self.item_being_dragged = item.parent
        self.remove_component_controller(item.parent)

        hotspot = event.scenePos() - item.scenePos()
        hot_spot_point = hotspot.toPoint()
        hot_spot_point = self.page_view_transform.map(hot_spot_point)
        item_data = QByteArray()
        data_stream = QDataStream(item_data, QIODevice.WriteOnly)

        data_stream << hot_spot_point  # pixmap << location

        mime_data = QMimeData()
        mime_data.setData(config_controller.component_mime, item_data)

        drag = QDrag(self)
        drag.setMimeData(mime_data)
        horizontal_scaling = self.page_view_transform.m11()
        logger.info(f"sceneBoundingRect {item.sceneBoundingRect().width()}")
        logger.info(
            f"sceneBoundingRect {item.sceneBoundingRect().width()*horizontal_scaling}"
        )
        drag.setPixmap(
            item.parent.pixmap.scaledToWidth(item.sceneBoundingRect().width() *
                                             horizontal_scaling))
        drag.setHotSpot(hot_spot_point)

        result = drag.start(QtCore.Qt.MoveAction)
        if result:  # == QtCore.Qt.MoveAction:
            pass
Esempio n. 2
0
 def mouseMoveEvent(self, event):
     """Start dragging action if needed."""
     if not event.buttons() & Qt.LeftButton:
         return
     if not self.drag_start_pos:
         return
     if not self.drag_indexes:
         return
     if (event.pos() - self.drag_start_pos
         ).manhattanLength() < QApplication.startDragDistance():
         return
     drag = QDrag(self)
     mimeData = QMimeData()
     urls = list()
     for index in self.drag_indexes:
         file_path = index.data(Qt.UserRole)
         urls.append(QUrl.fromLocalFile(file_path))
     mimeData.setUrls(urls)
     drag.setMimeData(mimeData)
     icon = self.drag_indexes[0].data(Qt.DecorationRole)
     if icon:
         pixmap = icon.pixmap(32, 32)
         drag.setPixmap(pixmap)
         drag.setHotSpot(pixmap.rect().center())
     drag.exec_()
Esempio n. 3
0
    def startDrag(self, event: QEvent) -> None:
        item = self.currentItem()
        if item is None:
            event.ignore()
            return
        self.item_being_dragged = self.takeItem(self.row(item)).parent

        hot_spot_point = event.pos()

        item_data = QByteArray()
        data_stream = QDataStream(item_data, QIODevice.WriteOnly)

        data_stream << hot_spot_point  # pixmap << location

        mime_data = QMimeData()
        mime_data.setData(config_controller.component_mime, item_data)

        drag = QDrag(self)
        pixmap = item.parent.pixmap.scaledToWidth(64)
        drag.setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2))
        drag.setPixmap(pixmap)
        drag.setMimeData(mime_data)
        result = drag.start(QtCore.Qt.MoveAction)
        if result:  # == QtCore.Qt.MoveAction:
            pass
Esempio n. 4
0
    def mouseMoveEvent(self, e):
        if e.buttons() != Qt.RightButton:
            return

        mimeData = QMimeData

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())

        dropAction = drag.start(Qt.MoveAction)
Esempio n. 5
0
 def _handle_mouse_press_event_for_dispos(self, ev: QMouseEvent):
     if ev.button() != QtCore.Qt.LeftButton:
         return
     if self.spawns:
         self.spawn_selected.emit(self)
         mime_data = QMimeData()
         mime_data.setData("application/fe14-spawn", b"")
         drag = QDrag(self)
         drag.setMimeData(mime_data)
         drag.setHotSpot(ev.pos())
         drag.exec_(QtCore.Qt.MoveAction)
Esempio n. 6
0
    def mouseMoveEvent(self, e):

        if e.buttons() != Qt.RightButton:  # 联系Qt.Horizontal, 6.08
            return
        # if-return, 相当于if-else

        # 鼠标移动时, 应产生mime数据(拖放中传输的数据)
        # 用于QWidget的拖动释放时, 传输mime数据
        mimeData = QMimeData()

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())  # 光标位置
        dropAction = drag.exec_(Qt.MoveAction)
Esempio n. 7
0
 def mouseMoveEvent(self, event):
     """Start dragging action if needed"""
     if not event.buttons() & Qt.LeftButton:
         return
     if not self.drag_start_pos:
         return
     if (event.pos() - self.drag_start_pos
         ).manhattanLength() < QApplication.startDragDistance():
         return
     drag = QDrag(self)
     mimeData = QMimeData()
     mimeData.setText(self.text)
     drag.setMimeData(mimeData)
     drag.setPixmap(self.pixmap())
     drag.setHotSpot(self.pixmap().rect().center())
     dropAction = drag.exec_()
Esempio n. 8
0
 def mousePressEvent(self, event):
     # call to super needed for selections
     super().mousePressEvent(event)
     if event.button() == Qt.LeftButton:
         drag = QDrag(self)
         mimeData = QMimeData()
         item = self.itemAt(event.pos())
         if item is None:
             return
         mimeData.setText(item.data(Qt.UserRole)[0])  # should be path to file
         drag.setMimeData(mimeData)
         # set dragging pixmap
         drag.setPixmap(item.icon().pixmap(QSize(160, 120)))
         # roughly center the cursor relative to pixmap
         drag.setHotSpot(QPoint(60, 60))
         dropAction = drag.exec_()
Esempio n. 9
0
    def mouseMoveEvent(self, event):
        """event call when mouse movement (press and move) detected

        This is the core of the drag and drop for the element.
        The QDrag object will create a the pixel image of the widget
        HopSpot is set so that it remains where the grab point is
        """

        if event.buttons() == Qt.LeftButton:
            drag = QDrag(self)
            widget_image = self.grab()
            mimedata = QMimeData()
            drag.setMimeData(mimedata)
            drag.setPixmap(widget_image)
            drag.setHotSpot(event.pos() - self.rect().topLeft())
            drag.exec_()

        super().mouseMoveEvent(event)
 def mouseMoveEvent(self, event):
     """Start dragging action if needed"""
     super().mouseMoveEvent(event)
     if not event.buttons() & Qt.LeftButton:
         return
     if not self.drag_start_pos:
         return
     if (event.pos() - self.drag_start_pos
         ).manhattanLength() < QApplication.startDragDistance():
         return
     drag = QDrag(self)
     drag.setPixmap(self.pixmap)
     drag.setMimeData(self.mime_data)
     drag.setHotSpot(self.pixmap.rect().center())
     self.drag_start_pos = None
     self.pixmap = None
     self.mime_data = None
     self.drag_about_to_start.emit()
     drag.exec_()
Esempio n. 11
0
    def mousePressEvent(self, event):
        label = self.childAt(event.pos())
        if not label:
            return
        hot_spot = event.pos() - label.pos()
        mime_data = QMimeData()
        mime_data.setText(label.text())
        mime_data.setData("application/x-hotspot", str(hot_spot.x()))
        pixmap = QPixmap(label.size())
        label.render(pixmap)

        drag = QDrag(self)
        drag.setMimeData(mime_data)
        drag.setPixmap(pixmap)
        drag.setHotSpot(hot_spot)

        dropAction = drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)
        if dropAction == Qt.MoveAction:
            label.close()
    def mouseMoveEvent(self, e):

        if e.buttons() != Qt.LeftButton:
            return

        mimeData = QMimeData()

        self.__cursor_x = e.pos().x()
        self.__cursor_y = e.pos().y()

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        self.hide()
        drag.setPixmap(
            self.grab(QRect(2, 2,
                            self.width() - 3.5,
                            self.height() - 3.5)))
        drag.setHotSpot(e.pos())
        dropAction = drag.exec_(Qt.MoveAction)
        self.show()
Esempio n. 13
0
    def mousePressEvent(self, event):
        hotSpot = event.pos()

        mimeData = QMimeData()
        mimeData.setText(self.text())
        mimeData.setData('application/x-hotspot',
                         '%d %d' % (hotSpot.x(), hotSpot.y()))

        pixmap = QPixmap(self.size())
        self.render(pixmap)

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(hotSpot)

        dropAction = drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)

        if dropAction == Qt.MoveAction:
            self.close()
            self.update()
Esempio n. 14
0
    def mousePressEvent(self, event):
        hotSpot = event.pos()

        mimeData = QMimeData()
        mimeData.setText(self.text())
        mimeData.setData('application/x-hotspot',
                b'%d %d' % (hotSpot.x(), hotSpot.y()))

        pixmap = QPixmap(self.size())
        self.render(pixmap)

        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(hotSpot)

        dropAction = drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)

        if dropAction == Qt.MoveAction:
            self.close()
            self.update()
Esempio n. 15
0
    def startDrag(self, supportedActions):
        # We reimplement this to visualize a tooltip instead of entire rows while dragging.

        rows = self.selectionModel().selectedRows()
        data = self.model().mimeData(rows)

        label = QLabel(
            str(len(rows)) + " items" if len(rows) > 1 else "1 item")
        # Use QPalette.ColorRole?
        label.setStyleSheet(
            "font-weight: bold; color : white; background-color : black; border: 1px solid grey"
        )
        pixmap = label.grab()
        pixmap.rect().adjust(10, 10, 0, 0)

        drag = QDrag(self)
        drag.setPixmap(pixmap)
        # drag.setDragCursor(pixmap, Qt.CopyAction)
        drag.setMimeData(data)
        drag.setHotSpot(pixmap.rect().center())
        drag.exec_(Qt.CopyAction)
Esempio n. 16
0
    def mouseMoveEvent(self, event):
        """start Drag and prepare for Drop.

        :type event: QMoveEvent
        マウスを動かした嶺がQApplication.startDragDistance()を超えると、Drag開始されたと認識し、
        そのための準備を行う。QMimeDataを使って、データをやりとりする。
        """
        if not (event.buttons() & Qt.LeftButton):
            return
        if (event.pos() - self.dragStartPosition).manhattanLength() \
                < QApplication.startDragDistance():
            return

        if self.isDragging:
            indexes = self.selectedIndexes()
            urls = self.url_list(indexes)

            mimeData = QMimeData()
            # mimeData.setData(self.mime_URLS, convert_to_bytearray(urls))
            mimeData.setUrls(urls)

            file_icon = self.style().standardIcon(QStyle.SP_FileIcon)
            pixmap = file_icon.pixmap(32, 32)

            drag = QDrag(self)
            drag.setMimeData(mimeData)
            drag.setPixmap(pixmap)
            drag.setHotSpot(QPoint(0, 0))

            dropAction = drag.exec_(Qt.CopyAction | Qt.MoveAction,
                                    Qt.CopyAction)
            if dropAction == Qt.MoveAction:
                pass

        else:
            self.rubberBand.setGeometry(
                QRect(self.dragStartPosition, event.pos()).normalized())
            super(PlaylistView, self).mouseMoveEvent(event)