Beispiel #1
0
 def mouseMoveEvent(self, event):
     dex = self.indexAt(event.pos())
     if dex.isValid():
         self.setCursor(Qt.PointingHandCursor)
     else:
         self.unsetCursor()
     if not event.buttons() & Qt.LeftButton:
         return
     if self.in_drag_drop or not dex.isValid():
         QTreeView.mouseMoveEvent(self, event)
         return
     # Must deal with odd case where the node being dragged is 'virtual',
     # created to form a hierarchy. We can't really drag this node, but in
     # addition we can't allow drag recognition to notice going over some
     # other node and grabbing that one. So we set in_drag_drop to prevent
     # this from happening, turning it off when the user lifts the button.
     self.in_drag_drop = True
     if not self._model.flags(dex) & Qt.ItemIsDragEnabled:
         QTreeView.mouseMoveEvent(self, event)
         return
     md = self._model.mimeData([dex])
     pixmap = dex.data(DRAG_IMAGE_ROLE).pixmap(self.iconSize())
     drag = QDrag(self)
     drag.setPixmap(pixmap)
     drag.setMimeData(md)
     if self._model.is_in_user_category(dex):
         drag.exec_(Qt.CopyAction|Qt.MoveAction, Qt.CopyAction)
     else:
         drag.exec_(Qt.CopyAction)
Beispiel #2
0
 def mouseMoveEvent(self, event):
     dex = self.indexAt(event.pos())
     if dex.isValid():
         self.setCursor(Qt.PointingHandCursor)
     else:
         self.unsetCursor()
     if not event.buttons() & Qt.LeftButton:
         return
     if self.in_drag_drop or not dex.isValid():
         QTreeView.mouseMoveEvent(self, event)
         return
     # Must deal with odd case where the node being dragged is 'virtual',
     # created to form a hierarchy. We can't really drag this node, but in
     # addition we can't allow drag recognition to notice going over some
     # other node and grabbing that one. So we set in_drag_drop to prevent
     # this from happening, turning it off when the user lifts the button.
     self.in_drag_drop = True
     if not self._model.flags(dex) & Qt.ItemIsDragEnabled:
         QTreeView.mouseMoveEvent(self, event)
         return
     md = self._model.mimeData([dex])
     pixmap = dex.data(DRAG_IMAGE_ROLE).pixmap(self.iconSize())
     drag = QDrag(self)
     drag.setPixmap(pixmap)
     drag.setMimeData(md)
     if self._model.is_in_user_category(dex):
         drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)
     else:
         drag.exec_(Qt.CopyAction)
Beispiel #3
0
    def mouseMoveEvent(self, event):
        '''
        @param: event QMouseEvent
        '''
        if not self._locationBar or event.buttons() != Qt.LeftButton:
            super().mouseMoveEvent(event)
            return

        manhattanLength = (event.pos() -
                           self._drawStartPosition).manhattanLength()
        if manhattanLength <= QApplication.startDragDistance():
            super().mouseMoveEvent(event)
            return

        url = self._locationBar.webView().url()
        title = self._locationBar.webView().title()

        if url.isEmpty() or not title:
            super().mouseMoveEvent(event)
            return

        drag = QDrag(self)
        mime = QMimeData()
        mime.setUrls([url])
        mime.setText(title)
        mime.setImageData(self.icon.pixmap(16).toImage())

        drag.setMimeData(mime)
        drag.setPixmap(
            gVar.appTools.createPixmapForSite(self.icon, title,
                                              url.toString()))
        drag.exec_()

        # Restore Down State
        self.setDown(False)
Beispiel #4
0
 def mousePressEvent(self, ev):
     if ev.button() == QtCore.Qt.LeftButton:
         drag = QDrag(self)
         mimeData = QMimeData()
         mimeData.setText(self.content)
         drag.setMimeData(mimeData)
         drag.setPixmap(iconPixmap)
         dropAction = drag.exec()
Beispiel #5
0
 def drag_data(self):
     m = self.model()
     rows = self.selectionModel().selectedRows()
     paths = [force_unicode(p, enc=filesystem_encoding) for p in m.paths(rows) if p]
     md = QMimeData()
     md.setData("application/calibre+from_device", b"dummy")
     md.setUrls([QUrl.fromLocalFile(p) for p in paths])
     drag = QDrag(self)
     drag.setMimeData(md)
     cover = self.drag_icon(m.cover(self.currentIndex().row()), len(paths) > 1)
     drag.setHotSpot(QPoint(-15, -15))
     drag.setPixmap(cover)
     return drag
Beispiel #6
0
 def drag_data(self):
     m = self.model()
     rows = self.selectionModel().selectedRows()
     paths = [force_unicode(p, enc=filesystem_encoding) for p in m.paths(rows) if p]
     md = QMimeData()
     md.setData('application/calibre+from_device', 'dummy')
     md.setUrls([QUrl.fromLocalFile(p) for p in paths])
     drag = QDrag(self)
     drag.setMimeData(md)
     cover = self.drag_icon(m.cover(self.currentIndex().row()), len(paths) >
             1)
     drag.setHotSpot(QPoint(-15, -15))
     drag.setPixmap(cover)
     return drag
    def mouseMoveEvent(self, event):
        '''
        @param: event QMouseEvent
        '''
        if (event.pos() - self._dragStartPosition
            ).manhattanLength() < QApplication.startDragDistance():
            super().mouseMoveEvent(event)
            return

        self.setDown(False)

        drag = QDrag(self)
        mime = BookmarksButtonMimeData()
        mime.setBookmarkItem(self._bookmark)
        drag.setMimeData(mime)
        drag.setPixmap(self.grab())
        drag.exec_()
Beispiel #8
0
 def mouseMoveEvent(self, event):
     if not (event.buttons() & Qt.LeftButton):
         return
     if (event.pos() - self.drag_start_position).manhattanLength() < QApplication.startDragDistance():
         return
     drag = QDrag(self)
     
     mimedata = QMimeData()
     mimedata.setParent(self)
     mimedata.setText(self.text())
     drag.setMimeData(mimedata)
     pixmap = QPixmap(self.size())
     painter = QPainter(pixmap)
     painter.drawPixmap(self.rect(), self.grab())
     painter.end()
     drag.setPixmap(pixmap)
     drag.setHotSpot(event.pos())
     drag.exec_(Qt.CopyAction | Qt.MoveAction)
Beispiel #9
0
def drag_data(self):
    m = self.model()
    db = m.db
    selected = self.get_selected_ids()
    ids = ' '.join(map(str, selected))
    md = QMimeData()
    md.setData('application/calibre+from_library', ids.encode('utf-8'))
    fmt = prefs['output_format']

    def url_for_id(i):
        try:
            ans = db.format_path(i, fmt, index_is_id=True)
        except:
            ans = None
        if ans is None:
            fmts = db.formats(i, index_is_id=True)
            if fmts:
                fmts = fmts.split(',')
            else:
                fmts = []
            for f in fmts:
                try:
                    ans = db.format_path(i, f, index_is_id=True)
                except:
                    ans = None
        if ans is None:
            ans = db.abspath(i, index_is_id=True)
        return QUrl.fromLocalFile(ans)

    md.setUrls([url_for_id(i) for i in selected])
    drag = QDrag(self)
    col = self.selectionModel().currentIndex().column()
    try:
        md.column_name = self.column_map[col]
    except AttributeError:
        md.column_name = 'title'
    drag.setMimeData(md)
    cover = self.drag_icon(m.cover(self.currentIndex().row()),
            len(selected) > 1)
    drag.setHotSpot(QPoint(-15, -15))
    drag.setPixmap(cover)
    return drag
Beispiel #10
0
def drag_data(self):
    m = self.model()
    db = m.db
    selected = self.get_selected_ids()
    ids = ' '.join(map(str, selected))
    md = QMimeData()
    md.setData('application/calibre+from_library', ids.encode('utf-8'))
    fmt = prefs['output_format']

    def url_for_id(i):
        try:
            ans = db.format_path(i, fmt, index_is_id=True)
        except:
            ans = None
        if ans is None:
            fmts = db.formats(i, index_is_id=True)
            if fmts:
                fmts = fmts.split(',')
            else:
                fmts = []
            for f in fmts:
                try:
                    ans = db.format_path(i, f, index_is_id=True)
                except:
                    ans = None
        if ans is None:
            ans = db.abspath(i, index_is_id=True)
        return QUrl.fromLocalFile(ans)

    md.setUrls([url_for_id(i) for i in selected])
    drag = QDrag(self)
    col = self.selectionModel().currentIndex().column()
    try:
        md.column_name = self.column_map[col]
    except AttributeError:
        md.column_name = 'title'
    drag.setMimeData(md)
    cover = self.drag_icon(m.cover(self.currentIndex().row()),
            len(selected) > 1)
    drag.setHotSpot(QPoint(-15, -15))
    drag.setPixmap(cover)
    return drag
Beispiel #11
0
 def mouseMoveEvent(self, event):
     dex = self.indexAt(event.pos())
     if dex.isValid():
         self.setCursor(Qt.PointingHandCursor)
     else:
         self.unsetCursor()
     if not event.buttons() & Qt.LeftButton:
         return
     if self.in_drag_drop or not dex.isValid():
         QTreeView.mouseMoveEvent(self, event)
         return
     # don't start drag/drop until the mouse has moved a bit.
     if ((event.pos() - self.possible_drag_start).manhattanLength() <
                                 QApplication.startDragDistance()):
         QTreeView.mouseMoveEvent(self, event)
         return
     # Must deal with odd case where the node being dragged is 'virtual',
     # created to form a hierarchy. We can't really drag this node, but in
     # addition we can't allow drag recognition to notice going over some
     # other node and grabbing that one. So we set in_drag_drop to prevent
     # this from happening, turning it off when the user lifts the button.
     self.in_drag_drop = True
     if not self._model.flags(dex) & Qt.ItemIsDragEnabled:
         QTreeView.mouseMoveEvent(self, event)
         return
     md = self._model.mimeData([dex])
     pixmap = dex.data(DRAG_IMAGE_ROLE).pixmap(self.iconSize())
     drag = QDrag(self)
     drag.setPixmap(pixmap)
     drag.setMimeData(md)
     if (self._model.is_in_user_category(dex) or
                 self._model.is_index_on_a_hierarchical_category(dex)):
         '''
         Things break if we specify MoveAction as the default, which is
         what we want for drag on hierarchical categories. Dragging user
         categories stops working. Don't know why. To avoid the problem
         we fix the action in dragMoveEvent.
         '''
         drag.exec_(Qt.CopyAction|Qt.MoveAction, Qt.CopyAction)
     else:
         drag.exec_(Qt.CopyAction)
Beispiel #12
0
    def mouseMoveEvent(self, event):
        '''
        @param: event QMouseEvent
        '''
        super().mouseMoveEvent(event)

        if gVar.app.plugins().processMouseMove(const.ON_TabBar, self, event):
            return

        if self.count() == 1 and gVar.app.windowCount() == 1:
            return

        if not self._dragStartPosition.isNull():
            offset = 0
            eventY = event.pos().y()
            if eventY < 0:
                offset = abs(eventY)
            elif eventY > self.height():
                offset = eventY - self.height()
            if offset > QApplication.startDragDistance() * 3:
                global_ = self.mapToGlobal(self._dragStartPosition)
                w = QApplication.widgetAt(global_)
                if w:
                    mouse = QMouseEvent(QEvent.MouseButtonRelease,
                                        w.mapFromGlobal(global_),
                                        Qt.LeftButton, Qt.LeftButton,
                                        event.modifiers())
                    QApplication.sendEvent(w, mouse)
                drag = QDrag(self)
                mime = QMimeData()
                mime.setData(self.MIMETYPE, b'')
                drag.setMimeData(mime)
                drag.setPixmap(self.tabPixmap(self.currentIndex()))
                if drag.exec_() == Qt.IgnoreAction:
                    self._tabWidget.detachTabByIndex(self.currentIndex())
                return