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): dex = self.indexAt(event.pos()) 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(Qt.DecorationRole).toPyObject().pixmap(25, 25) 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)
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): dex = self.indexAt(event.pos()) 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(Qt.DecorationRole).toPyObject().pixmap(25, 25) 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)
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) 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
def mouseMoveEvent(self, event): if not event.buttons() & Qt.LeftButton: return if (event.pos() - self.drag_pos).manhattanLength() < 100: return event.accept() drag = QDrag(self) mimedata = QMimeData() mimedata.setData("action", "window_drag") drag.setMimeData(mimedata) widget = self.current_widget pixmap = QPixmap.grabWidget(widget).scaledToWidth(300, Qt.SmoothTransformation) dragpixmap = DragPixmap(pixmap, 0.50, self) dragpixmap.move(QCursor().pos()) dragpixmap.show() drag.exec_() dragpixmap.deleteLater() self.widgetDnD.emit(self.current_widget, drag.target()) return
def drag_data(self): m = self.model() db = m.db rows = self.selectionModel().selectedRows() selected = list(map(m.id, rows)) ids = " ".join(map(str, selected)) md = QMimeData() md.setData("application/calibre+from_library", ids) 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() md.column_name = self.column_map[col] 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
def mouseMoveEvent(self, event): if self.drag is not None: QTreeView.mouseMoveEvent(self, event) return if ((event.globalPos() - self.mouse_press_qpoint).manhattanLength() < QApplication.startDragDistance()): return # # starting a drag # [logic bug, after bruce change 070507: should not do this # if we already started dragging out a selection. How can we tell? # Only by whether the initial press had eventInRect, I think # (not yet recorded), or at least, the initial move (#e could record here).] # index = self.indexAt(event.pos()) sellst = self.selectedList() # bruce 070507 move earlier DEBUG2 = True if index.isValid(): thisnode = index.internalPointer().node #bruce 070507 bring in some code from modelTreeGui.py alreadySelected = (thisnode in sellst) item = index.internalPointer() rect = self.visualRect(index) if DEBUG2: print "visualRect coords", rect.left(), rect.right(), rect.top( ), rect.bottom() qfm = QFontMetrics(QLineEdit(self).font()) rect.setWidth(qfm.width(item.node.name) + _ICONSIZE[0] + 4) if DEBUG2: print "visualRect coords, modified:", rect.left(), rect.right( ), rect.top(), rect.bottom() # looks like icon and text, a bit taller than text (guesses) eventInRect = rect.contains(event.pos()) if DEBUG2: print "valid index: eventInRect = %r, item = %r, index = %r, alreadySelected = %r" % \ (eventInRect, item, index, alreadySelected)####### else: thisnode = item = None alreadySelected = eventInRect = False if not eventInRect: # nothing to drag, but [bruce 070507] let super handle it (for dragging over nodes to select) self.drag_is_not_DND = True ### not yet used QTreeView.mouseMoveEvent(self, event) return if thisnode in sellst: # if dragging something selected, drag along all other selected ones dragged_nodes = sellst else: # if dragging something unselected, ignore any selected ones dragged_nodes = [thisnode] qdrag = QDrag(self) drag_type = 'move' # how do I decide between 'move' and 'copy'? self.drag = (dragged_nodes, drag_type, qdrag) mimedata = QMimeData() mimedata.setText("need a string here for a valid mimetype") qdrag.setMimeData(mimedata) display_prefs = {} pixmap = dragged_nodes[0].node_icon(display_prefs) qdrag.setPixmap(pixmap) qdrag.setHotSpot(QPoint(-8, 8)) qdrag.start()
def mouseMoveEvent(self, event): if self.drag is not None: QTreeView.mouseMoveEvent(self, event) return if ((event.globalPos() - self.mouse_press_qpoint).manhattanLength() < QApplication.startDragDistance()): return # # starting a drag # [logic bug, after bruce change 070507: should not do this # if we already started dragging out a selection. How can we tell? # Only by whether the initial press had eventInRect, I think # (not yet recorded), or at least, the initial move (#e could record here).] # index = self.indexAt(event.pos()) sellst = self.selectedList() # bruce 070507 move earlier DEBUG2 = True if index.isValid(): thisnode = index.internalPointer().node #bruce 070507 bring in some code from modelTreeGui.py alreadySelected = (thisnode in sellst) item = index.internalPointer() rect = self.visualRect(index) if DEBUG2: print "visualRect coords",rect.left(), rect.right(), rect.top(), rect.bottom() qfm = QFontMetrics(QLineEdit(self).font()) rect.setWidth(qfm.width(item.node.name) + _ICONSIZE[0] + 4) if DEBUG2: print "visualRect coords, modified:",rect.left(), rect.right(), rect.top(), rect.bottom() # looks like icon and text, a bit taller than text (guesses) eventInRect = rect.contains(event.pos()) if DEBUG2: print "valid index: eventInRect = %r, item = %r, index = %r, alreadySelected = %r" % \ (eventInRect, item, index, alreadySelected)####### else: thisnode = item = None alreadySelected = eventInRect = False if not eventInRect: # nothing to drag, but [bruce 070507] let super handle it (for dragging over nodes to select) self.drag_is_not_DND = True ### not yet used QTreeView.mouseMoveEvent(self, event) return if thisnode in sellst: # if dragging something selected, drag along all other selected ones dragged_nodes = sellst else: # if dragging something unselected, ignore any selected ones dragged_nodes = [ thisnode ] qdrag = QDrag(self) drag_type = 'move' # how do I decide between 'move' and 'copy'? self.drag = (dragged_nodes, drag_type, qdrag) mimedata = QMimeData() mimedata.setText("need a string here for a valid mimetype") qdrag.setMimeData(mimedata) display_prefs = { } pixmap = dragged_nodes[0].node_icon(display_prefs) qdrag.setPixmap(pixmap) qdrag.setHotSpot(QPoint(-8, 8)) qdrag.start()