Exemple #1
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
 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_()
Exemple #3
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
Exemple #4
0
    def mouseMoveEvent(self, e):  # noqa: N802 - Part of QT signature.

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

        mimedata = QMimeData()
        drag = QDrag(self)
        drag.setMimeData(mimedata)
        drag.exec_(Qt.MoveAction)
Exemple #5
0
    def startDrag(self, supportedActions):

        dragged = self.selectedItems()[0]
        mimeData = QMimeData()
        mimeData.setText(dragged.text(0))

        drag = QDrag(self)
        drag.setMimeData(mimeData)

        drag.exec_(supportedActions=supportedActions, defaultAction=Qt.MoveAction)
Exemple #6
0
 def mousePressEvent(self, event):
     if event.button() == Qt.LeftButton:
         drag = QDrag(self)
         mime_data = QMimeData()
         data_text = self.get_drag_data()
         data = QByteArray(bytes(data_text, 'utf-8'))
         mime_data.setData('text/plain', data)
         drag.setMimeData(mime_data)
         drop_action = drag.exec_()
         return
    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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
0
 def startDrag(self, dropActions):
     item = self.currentItem()
     # icon = item.icon()
     data = QByteArray()
     stream = QDataStream(data, QIODevice.WriteOnly)
     stream.writeQString(item.text())
     stream.writeInt16(item.data(1))
     # stream << icon
     mimeData = QMimeData()
     mimeData.setData("application/x-lista-item", data)
     drag = QDrag(self)
     drag.setMimeData(mimeData)
     if drag.exec_(Qt.MoveAction) == Qt.MoveAction:
         self.takeItem(self.row(item))
Exemple #11
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        if (QLineF(event.screenPos(), event.buttonDownScreenPos(
                Qt.LeftButton)).length() < QApplication.startDragDistance()):
            return

        self.parentItem().edgeDragStart()

        package = QMimeData()
        package.setData(self.DragMimeType, bytes())

        drag = QDrag(event.widget())
        drag.setMimeData(package)
        drag.exec_()

        self.parentItem().edgeDragStop()
Exemple #12
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_()
Exemple #13
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_()
    def mouseMoveEvent(self, event):
        if event.buttons() != Qt.LeftButton:
            return
        if (event.pos() - self._dragStartPosition
            ).manhattanLength() < QApplication.startDragDistance():
            return

        pixmap = QPixmap(23, 23)
        pixmap.fill(self._color_srgb)

        drag = QDrag(self)
        mime_data = QMimeData()
        text = encode_index(self.parentWidget().index)
        mime_data.setText(text)
        drag.setMimeData(mime_data)
        drag.setPixmap(pixmap)

        drop_action = drag.start(Qt.CopyAction)  # | Qt.MoveAction)
Exemple #15
0
 def startDrag(self):
     data = QByteArray()
     stream = QDataStream(data, QIODevice.WriteOnly)
     stream.writeQString(self._player_name)
     stream.writeInt16(self._player_id)
     mimedata = QMimeData()
     mimedata.setData("application/x-lista-item", data)
     drag = QDrag(self)
     drag.setMimeData(mimedata)
     if drag.exec_(Qt.MoveAction) == Qt.MoveAction:
         self._player_name = ""
         self._player_id = 0
         for i in range(self.sorok_szama):
             self.parent.eredmenyek[self._csoport_number][
                 self._csoport_sor][i]._set_p1_id(0)
             self.parent.eredmenyek[self._csoport_number][i][
                 self._csoport_sor]._set_p2_id(0)
         self.update()
Exemple #16
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)
Exemple #17
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, 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_()
    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()
Exemple #20
0
    def mouseMoveEvent(self, event):

        # we should have only a single item selected
        item = self.selectedItems()
        if len(item) != 1:
            return

        item = item[0]

        # item should not have a parent (should not be a value)
        if item.parent() is None:
            drag = QDrag(self)
            mime = QtCore.QMimeData()

            text = item.text(0)
            if text[0]=='.':
                text = "s['{}']{}".format(self.nodename, text)

            mime.setText(text)
            drag.setMimeData(mime)
            drag.start(QtCore.Qt.MoveAction)
Exemple #21
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()
    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()
Exemple #23
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)
Exemple #24
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)
Exemple #25
0
    def mouseMoveEvent(self, event):
        if not (event.buttons() & Qt.LeftButton):
            return super(ObjectIcon, self).mouseMoveEvent(event)

        drag = QDrag(self)

        mime_data = QMimeData()

        object_bytes = bytearray()

        if isinstance(self.object, LevelObject):
            object_bytes.append(0)
        else:
            object_bytes.append(1)

        object_bytes.extend(self.object.to_bytes())

        mime_data.setData("application/level-object", object_bytes)

        drag.setMimeData(mime_data)

        if drag.exec_() == Qt.MoveAction:
            self.object_placed.emit()
Exemple #26
0
 def itemCliked(self, item):
     drag = QDrag(self)
     mimeData = QMimeData()
     self.selected_project = item.text()
     mimeData.setText(item.text())
     drag.setMimeData(mimeData)
Exemple #27
0
class SnapWindow(QMainWindow):
    def __init__(self, app, flags):
        self.flag_snapped = False  # Picture snapped or loaded at start.
        self.flag_frame = True     # Window frame toggling.
        self.app = app
        self.winsize = None     # None-Conditional toggle on resize.
                                # Also the size the window should be.
        QMainWindow.__init__(self)
        self.dragicon = QIcon.fromTheme("folder-new").pixmap(QSize(24,24))
        self.imgdata = None
        self.setWindowTitle("Snap")
        self.cliplabel = QtWidgets.QLabel(self)
        self.cliplabel.show()
        self.cliplabel.setScaledContents(True)
        self.clip_pix = self.cliplabel.pixmap()
        self.clipboard = app.clipboard()
        self.clipboard.dataChanged.connect(self.clipboardChanged)
        self.clipboard.clear(mode=self.clipboard.Clipboard)
        p = self.palette()
        p.setColor(self.backgroundRole(), QtCore.Qt.white)
        self.setPalette(p)
        self.hide()
    
    def load_from_image(self):
        self.flag_snapped = True
        im = QtGui.QImage()
        im.load(shared['inputfp'])
        pm = QtGui.QPixmap().fromImage(im)
        self.original_snap = pm.copy()
        self.original_size = pm.width(), pm.height()
        mpos = shared['curpos']
        self.setGeometry(mpos.x(),mpos.y(), pm.width(), pm.height())
        self.cliplabel.resize(pm.width(),pm.height())
        self.cliplabel.setPixmap(pm)
        self.show()
        
    def clipboardChanged(self):
        if self.flag_snapped == False:
            self.clipboard = self.app.clipboard()
            pm = self.clipboard.pixmap()
            self.original_snap = pm.copy()
            self.original_size = pm.width(), pm.height()
            if pm.isNull():
                pass
            else:
                self.flag_snapped = True
                mpos = shared['curpos']
                self.setGeometry(mpos.x()-pm.width(),mpos.y()-pm.height(), pm.width(), pm.height())
                self.cliplabel.resize(pm.width(),pm.height())
                self.cliplabel.setPixmap(pm)
                self.show()
            
    def resizeEvent(self, event):
        super(SnapWindow, self).resizeEvent(event)
        if self.winsize:
            self.cliplabel.resize(self.savesize.width(),self.savesize.height())
            self.resize(self.savesize.width(),self.savesize.height())
            self.winsize = None
        else:
            self.cliplabel.resize(self.width(),self.height())
        
    def scale_ratio(self):
        winsize = QSize(self.width(),self.height())
        new_size = QSize(self.original_size[0],self.original_size[1])
        new_size.scale(winsize, QtCore.Qt.KeepAspectRatio)
        self.cliplabel.resize(new_size)
        self.resize(new_size)
        
    def reset_size(self):
        origsize = QSize(self.original_size[0],self.original_size[1])
        self.cliplabel.resize(origsize)
        self.cliplabel.setPixmap(self.original_snap)
        self.resize(origsize)
        
    def mousePressEvent(self, event):
        super(SnapWindow, self).mousePressEvent(event)
        if event.button() == QtCore.Qt.MouseButton.LeftButton:
            self.scale_ratio()
            self.QDrag = QDrag(self)
            self.QMimeData = QMimeData()
            self.imgdata = QByteArray()
            imgbuffer = QBuffer(self.imgdata)
            imgbuffer.open(QIODevice.WriteOnly)
            
            self.original_snap.save(imgbuffer, "PNG")
            
            self.QMimeData.setImageData(self.imgdata)
            self.QMimeData.setData("image/png", self.imgdata)
            self.QDrag.setMimeData(self.QMimeData)
            self.QDrag.setPixmap(self.dragicon)
            dropaction = self.QDrag.exec_(Qt.CopyAction)
            
    def contextMenuEvent(self, event):
        menu = QtWidgets.QMenu(self)
        action_rename = menu.addAction("Rename")
        action_clipboard = menu.addAction("Copy to Clipboard (Again)")
        action_save = menu.addAction("Save Original")
        action_reset = menu.addAction("Reset to Original")
        action_frame = menu.addAction("Toggle Frame")        
        action_close = menu.addAction("Close")
        action = menu.exec_(self.mapToGlobal(event.pos()))
        if action == action_save:
            self.save_copy()
        elif action == action_clipboard:
            self.clipboard.setPixmap(self.original_snap)
        elif action == action_reset:
            self.reset_size()
        elif action == action_frame:
            if self.flag_frame == True:
                self.flag_frame = False
                self.setWindowFlag(QtCore.Qt.FramelessWindowHint, True)
                self.hide()
                self.show()
                self.winsize = self.size()
            else:
                self.flag_frame = True
                self.setWindowFlag(QtCore.Qt.FramelessWindowHint, False)
                self.hide()
                self.show()
                self.winsize = self.size()
            self.reset_size()
        elif action == action_close:
            self.close()
        elif action == action_rename:
            name, tmp = QInputDialog.getText(self, "", "Name this window:")
            self.setWindowTitle(name)
            
    def save_copy(self):
        fd = QtWidgets.QFileDialog()
        fd.setDirectory(QtCore.QDir('~/'))
        savefn = fd.getSaveFileName(self, 'Save File')[0]
        pixmap = self.original_snap
        barray = QtCore.QByteArray()
        qbuffer = QtCore.QBuffer(barray)
        qbuffer.open(QtCore.QIODevice.WriteOnly)
        pixmap.save(qbuffer, "PNG")
        bytesio = BytesIO(barray.data())
        bytesio.seek(0)
        with open(savefn, 'wb') as savefile:
            savefile.write(bytesio.read())