forked from openlp/openlp
Implemented drag&drop between image groups
This commit is contained in:
parent
d09b9edcc9
commit
34455239ef
@ -356,6 +356,12 @@ class MediaManagerItem(QtGui.QWidget):
|
|||||||
if new_files:
|
if new_files:
|
||||||
self.validateAndLoad(new_files)
|
self.validateAndLoad(new_files)
|
||||||
|
|
||||||
|
def dndMoveInternal(self, target):
|
||||||
|
"""
|
||||||
|
Handle internal moving of media manager items
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def validateAndLoad(self, files):
|
def validateAndLoad(self, files):
|
||||||
"""
|
"""
|
||||||
Process a list for files either from the File Dialog or from Drag and
|
Process a list for files either from the File Dialog or from Drag and
|
||||||
|
@ -45,6 +45,7 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
"""
|
"""
|
||||||
QtGui.QTreeWidget.__init__(self, parent)
|
QtGui.QTreeWidget.__init__(self, parent)
|
||||||
self.mimeDataText = name
|
self.mimeDataText = name
|
||||||
|
self.allowInternalDnD = False
|
||||||
self.header().close()
|
self.header().close()
|
||||||
self.defaultIndentation = self.indentation()
|
self.defaultIndentation = self.indentation()
|
||||||
self.setIndentation(0)
|
self.setIndentation(0)
|
||||||
@ -58,6 +59,11 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
|
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_dnd' % self.mimeDataText),
|
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_dnd' % self.mimeDataText),
|
||||||
self.parent().loadFile)
|
self.parent().loadFile)
|
||||||
|
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_dnd_internal' % self.mimeDataText),
|
||||||
|
self.parent().dndMoveInternal)
|
||||||
|
|
||||||
|
def doInternalDnD(self, accept):
|
||||||
|
self.allowInternalDnD = accept
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
"""
|
"""
|
||||||
@ -80,6 +86,8 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
def dragEnterEvent(self, event):
|
def dragEnterEvent(self, event):
|
||||||
if event.mimeData().hasUrls():
|
if event.mimeData().hasUrls():
|
||||||
event.accept()
|
event.accept()
|
||||||
|
elif self.allowInternalDnD:
|
||||||
|
event.accept()
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
@ -87,12 +95,15 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
if event.mimeData().hasUrls():
|
if event.mimeData().hasUrls():
|
||||||
event.setDropAction(QtCore.Qt.CopyAction)
|
event.setDropAction(QtCore.Qt.CopyAction)
|
||||||
event.accept()
|
event.accept()
|
||||||
|
elif self.allowInternalDnD:
|
||||||
|
event.setDropAction(QtCore.Qt.CopyAction)
|
||||||
|
event.accept()
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
def dropEvent(self, event):
|
def dropEvent(self, event):
|
||||||
"""
|
"""
|
||||||
Receive drop event check if it is a file and process it if it is.
|
Receive drop event, check if it is a file or internal object and process it if it is.
|
||||||
|
|
||||||
``event``
|
``event``
|
||||||
Handle of the event pint passed
|
Handle of the event pint passed
|
||||||
@ -110,5 +121,9 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
|
|||||||
for file in listing:
|
for file in listing:
|
||||||
files.append(os.path.join(localFile, file))
|
files.append(os.path.join(localFile, file))
|
||||||
Receiver.send_message(u'%s_dnd' % self.mimeDataText, files)
|
Receiver.send_message(u'%s_dnd' % self.mimeDataText, files)
|
||||||
|
elif self.allowInternalDnD:
|
||||||
|
event.setDropAction(QtCore.Qt.CopyAction)
|
||||||
|
event.accept()
|
||||||
|
Receiver.send_message(u'%s_dnd_internal' % self.mimeDataText, self.itemAt(event.pos()))
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
@ -85,6 +85,7 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
self.listView.clear()
|
self.listView.clear()
|
||||||
self.listView.setIconSize(QtCore.QSize(88, 50))
|
self.listView.setIconSize(QtCore.QSize(88, 50))
|
||||||
self.listView.setIndentation(self.listView.defaultIndentation)
|
self.listView.setIndentation(self.listView.defaultIndentation)
|
||||||
|
self.listView.doInternalDnD(True)
|
||||||
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settingsSection), u'thumbnails')
|
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settingsSection), u'thumbnails')
|
||||||
check_directory_exists(self.servicePath)
|
check_directory_exists(self.servicePath)
|
||||||
# Import old images list
|
# Import old images list
|
||||||
@ -259,6 +260,31 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
|
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
|
||||||
initialLoad)
|
initialLoad)
|
||||||
|
|
||||||
|
def dndMoveInternal(self, target):
|
||||||
|
"""
|
||||||
|
Handle drag-and-drop moving of images within the media manager
|
||||||
|
"""
|
||||||
|
items_to_move = self.listView.selectedItems()
|
||||||
|
# Determine group to move images to
|
||||||
|
target_group = target
|
||||||
|
if isinstance(target_group.data(0, QtCore.Qt.UserRole), ImageFilenames):
|
||||||
|
target_group = target.parent()
|
||||||
|
# Don't allow moving to the Imported group
|
||||||
|
if target_group.data(0, QtCore.Qt.UserRole) is None:
|
||||||
|
return
|
||||||
|
# Move images in the treeview
|
||||||
|
items_to_save = []
|
||||||
|
for item in items_to_move:
|
||||||
|
if isinstance(item.data(0, QtCore.Qt.UserRole), ImageFilenames):
|
||||||
|
item.parent().removeChild(item)
|
||||||
|
target_group.addChild(item)
|
||||||
|
item_data = item.data(0, QtCore.Qt.UserRole)
|
||||||
|
item_data.group_id = target_group.data(0, QtCore.Qt.UserRole).id
|
||||||
|
items_to_save.append(item_data)
|
||||||
|
target_group.sortChildren(0, QtCore.Qt.AscendingOrder)
|
||||||
|
# Update the group ID's of the images in the database
|
||||||
|
self.manager.save_objects(items_to_save)
|
||||||
|
|
||||||
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
def generateSlideData(self, service_item, item=None, xmlVersion=False,
|
||||||
remote=False, context=ServiceItemContext.Service):
|
remote=False, context=ServiceItemContext.Service):
|
||||||
background = QtGui.QColor(Settings().value(self.settingsSection + u'/background color'))
|
background = QtGui.QColor(Settings().value(self.settingsSection + u'/background color'))
|
||||||
|
Loading…
Reference in New Issue
Block a user