diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index eca60a22b..28e56fff5 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -390,6 +390,7 @@ from uistrings import UiStrings from eventreceiver import Receiver from screen import ScreenList from settings import Settings +from listwidgetwithdnd import ListWidgetWithDnD from treewidgetwithdnd import TreeWidgetWithDnD from formattingtags import FormattingTags from spelltextedit import SpellTextEdit diff --git a/openlp/core/lib/listwidgetwithdnd.py b/openlp/core/lib/listwidgetwithdnd.py new file mode 100644 index 000000000..daff870ee --- /dev/null +++ b/openlp/core/lib/listwidgetwithdnd.py @@ -0,0 +1,117 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Extend QListWidget to handle drag and drop functionality +""" +import os + +from PyQt4 import QtCore, QtGui + +from openlp.core.lib import Receiver + + +class ListWidgetWithDnD(QtGui.QListWidget): + """ + Provide a list widget to store objects and handle drag and drop events + """ + def __init__(self, parent=None, name=u''): + """ + Initialise the list widget + """ + QtGui.QListWidget.__init__(self, parent) + self.mimeDataText = name + assert(self.mimeDataText) + + def activateDnD(self): + """ + Activate DnD of widget + """ + self.setAcceptDrops(True) + self.setDragDropMode(QtGui.QAbstractItemView.DragDrop) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_dnd' % self.mimeDataText), + self.parent().loadFile) + + def mouseMoveEvent(self, event): + """ + Drag and drop event does not care what data is selected as the recipient will use events to request the data + move just tell it what plugin to call + """ + if event.buttons() != QtCore.Qt.LeftButton: + event.ignore() + return + if not self.selectedItems(): + event.ignore() + return + drag = QtGui.QDrag(self) + mimeData = QtCore.QMimeData() + drag.setMimeData(mimeData) + mimeData.setText(self.mimeDataText) + drag.start(QtCore.Qt.CopyAction) + + def dragEnterEvent(self, event): + """ + When something is dragged into this object, check if you should be able to drop it in here. + """ + if event.mimeData().hasUrls(): + event.accept() + else: + event.ignore() + + def dragMoveEvent(self, event): + """ + Make an object droppable, and set it to copy the contents of the object, not move it. + """ + if event.mimeData().hasUrls(): + event.setDropAction(QtCore.Qt.CopyAction) + event.accept() + else: + event.ignore() + + def dropEvent(self, event): + """ + Receive drop event check if it is a file and process it if it is. + + ``event`` + Handle of the event pint passed + """ + if event.mimeData().hasUrls(): + event.setDropAction(QtCore.Qt.CopyAction) + event.accept() + files = [] + for url in event.mimeData().urls(): + localFile = url.toLocalFile() + if os.path.isfile(localFile): + files.append(localFile) + elif os.path.isdir(localFile): + listing = os.listdir(localFile) + for file in listing: + files.append(os.path.join(localFile, file)) + Receiver.send_message(u'%s_dnd' % self.mimeDataText, files) + else: + event.ignore() diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 94c891a51..0372e1d2a 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -35,7 +35,7 @@ import re from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, ServiceItem, StringContent, Receiver, TreeWidgetWithDnD, \ +from openlp.core.lib import OpenLPToolbar, ServiceItem, StringContent, Receiver, ListWidgetWithDnD, \ ServiceItemContext, Settings, Registry, UiStrings, build_icon, translate from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import create_widget_action, critical_error_message_box @@ -213,7 +213,8 @@ class MediaManagerItem(QtGui.QWidget): Creates the main widget for listing items the media item is tracking """ # Add the List widget - self.listView = TreeWidgetWithDnD(self, self.plugin.name) + self.listView = ListWidgetWithDnD(self, self.plugin.name) + self.listView.setSpacing(1) self.listView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.listView.setAlternatingRowColors(True) self.listView.setObjectName(u'%sListView' % self.plugin.name) @@ -372,9 +373,9 @@ class MediaManagerItem(QtGui.QWidget): """ names = [] full_list = [] - for count in range(self.listView.topLevelItemCount()): - names.append(self.listView.topLevelItem(count).text(0)) - full_list.append(self.listView.topLevelItem(count).data(0, QtCore.Qt.UserRole)) + for count in range(self.listView.count()): + names.append(self.listView.item(count).text()) + full_list.append(self.listView.item(count).data(QtCore.Qt.UserRole)) duplicates_found = False files_added = False for file_path in files: @@ -413,9 +414,9 @@ class MediaManagerItem(QtGui.QWidget): """ count = 0 file_list = [] - while count < self.listView.topLevelItemCount(): - bitem = self.listView.topLevelItem(count) - filename = bitem.data(0, QtCore.Qt.UserRole) + while count < self.listView.count(): + bitem = self.listView.item(count) + filename = bitem.data(QtCore.Qt.UserRole) file_list.append(filename) count += 1 return file_list @@ -523,8 +524,8 @@ class MediaManagerItem(QtGui.QWidget): """ Create a media item from an item id. """ - item = QtGui.QTreeWidgetItem() - item.setData(0, QtCore.Qt.UserRole, item_id) + item = QtGui.QListWidgetItem() + item.setData(QtCore.Qt.UserRole, item_id) return item def onAddClick(self): @@ -597,16 +598,15 @@ class MediaManagerItem(QtGui.QWidget): """ Checks if the listView is empty and adds a "No Search Results" item. """ - if self.listView.topLevelItemCount(): + if self.listView.count(): return message = translate('OpenLP.MediaManagerItem', 'No Search Results') - item = QtGui.QTreeWidgetItem(message) - item.setText(0, message) + item = QtGui.QListWidgetItem(message) item.setFlags(QtCore.Qt.NoItemFlags) font = QtGui.QFont() font.setItalic(True) - item.setFont(0, font) - self.listView.addTopLevelItem(item) + item.setFont(font) + self.listView.addItem(item) def _getIdOfItemToGenerate(self, item, remoteItem): """ @@ -623,7 +623,7 @@ class MediaManagerItem(QtGui.QWidget): item = self.listView.currentItem() if item is None: return False - item_id = item.data(0, QtCore.Qt.UserRole) + item_id = item.data(QtCore.Qt.UserRole) else: item_id = remoteItem else: @@ -638,7 +638,7 @@ class MediaManagerItem(QtGui.QWidget): if self.autoSelectId == -1: item = self.listView.currentItem() if item: - self.autoSelectId = item.data(0, QtCore.Qt.UserRole) + self.autoSelectId = item.data(QtCore.Qt.UserRole) def search(self, string, showError=True): """ diff --git a/openlp/core/lib/treewidgetwithdnd.py b/openlp/core/lib/treewidgetwithdnd.py index 0eca98c01..09d96600e 100644 --- a/openlp/core/lib/treewidgetwithdnd.py +++ b/openlp/core/lib/treewidgetwithdnd.py @@ -50,6 +50,7 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget): self.header().close() self.defaultIndentation = self.indentation() self.setIndentation(0) + self.setAnimated(True) assert(self.mimeDataText) def activateDnD(self): @@ -126,3 +127,13 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget): Receiver.send_message(u'%s_dnd_internal' % self.mimeDataText, self.itemAt(event.pos())) else: event.ignore() + + # Convenience methods for emulating a QListWidget. This helps keeping MediaManagerItem simple. + def addItem(self, item): + self.addTopLevelItem(item) + + def count(self): + return self.topLevelItemCount() + + def item(self, index): + return self.topLevelItem(index) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index afd2abb27..f9a49ebb1 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -76,7 +76,7 @@ class BibleMediaItem(MediaManagerItem): """ Check if the first item is a second bible item or not. """ - bitem = self.listView.topLevelItem(0) + bitem = self.listView.item(0) if not bitem.flags() & QtCore.Qt.ItemIsSelectable: # The item is the "No Search Results" item. self.listView.clear() @@ -95,7 +95,7 @@ class BibleMediaItem(MediaManagerItem): self.displayResults(bible, second_bible) def _decodeQtObject(self, bitem, key): - reference = bitem.data(0, QtCore.Qt.UserRole) + reference = bitem.data(QtCore.Qt.UserRole) obj = reference[unicode(key)] return unicode(obj).strip() @@ -634,7 +634,7 @@ class BibleMediaItem(MediaManagerItem): self.second_search_results = self.plugin.manager.get_verses(second_bible, versetext, book_ref_id) if not self.advancedLockButton.isChecked(): self.listView.clear() - if self.listView.topLevelItemCount() != 0: + if self.listView.count() != 0: self.__checkSecondBible(bible, second_bible) elif self.search_results: self.displayResults(bible, second_bible) @@ -691,7 +691,7 @@ class BibleMediaItem(MediaManagerItem): self.second_search_results = bibles[second_bible].get_verses(text) if not self.quickLockButton.isChecked(): self.listView.clear() - if self.listView.topLevelItemCount() != 0 and self.search_results: + if self.listView.count() != 0 and self.search_results: self.__checkSecondBible(bible, second_bible) elif self.search_results: self.displayResults(bible, second_bible) @@ -707,7 +707,7 @@ class BibleMediaItem(MediaManagerItem): """ items = self.buildDisplayResults(bible, second_bible, self.search_results) for bible_verse in items: - self.listView.addTopLevelItem(bible_verse) + self.listView.addItem(bible_verse) self.listView.selectAll() self.search_results = {} self.second_search_results = {} @@ -766,9 +766,8 @@ class BibleMediaItem(MediaManagerItem): second_version) else: bible_text = u'%s %d%s%d (%s)' % (book, verse.chapter, verse_separator, verse.verse, version) - bible_verse = QtGui.QTreeWidgetItem(bible_text) - bible_verse.setText(0, bible_text) - bible_verse.setData(0, QtCore.Qt.UserRole, data) + bible_verse = QtGui.QListWidgetItem(bible_text) + bible_verse.setData(QtCore.Qt.UserRole, data) items.append(bible_verse) return items @@ -972,7 +971,7 @@ class BibleMediaItem(MediaManagerItem): return [] def createItemFromId(self, item_id): - item = QtGui.QTreeWidgetItem() + item = QtGui.QListWidgetItem() bible = self.quickVersionComboBox.currentText() search_results = self.plugin.manager.get_verses(bible, item_id, False) items = self.buildDisplayResults(bible, u'', search_results) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 86cef59ed..7c604e322 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -103,10 +103,9 @@ class CustomMediaItem(MediaManagerItem): self.listView.clear() custom_slides.sort() for custom_slide in custom_slides: - custom_name = QtGui.QTreeWidgetItem(custom_slide.title) - custom_name.setText(0, custom_slide.title) - custom_name.setData(0, QtCore.Qt.UserRole, custom_slide.id) - self.listView.addTopLevelItem(custom_name) + custom_name = QtGui.QListWidgetItem(custom_slide.title) + custom_name.setData(QtCore.Qt.UserRole, custom_slide.id) + self.listView.addItem(custom_name) # Auto-select the custom. if custom_slide.id == self.autoSelectId: self.listView.setCurrentItem(custom_name) @@ -149,7 +148,7 @@ class CustomMediaItem(MediaManagerItem): """ if check_item_selected(self.listView, UiStrings().SelectEdit): item = self.listView.currentItem() - item_id = item.data(0, QtCore.Qt.UserRole) + item_id = item.data(QtCore.Qt.UserRole) self.edit_custom_form.loadCustom(item_id, False) self.edit_custom_form.exec_() self.autoSelectId = -1 diff --git a/openlp/plugins/images/forms/choosegroupdialog.py b/openlp/plugins/images/forms/choosegroupdialog.py index 0bbec6cc8..3ddfb6bb1 100644 --- a/openlp/plugins/images/forms/choosegroupdialog.py +++ b/openlp/plugins/images/forms/choosegroupdialog.py @@ -34,28 +34,61 @@ from openlp.core.lib.ui import create_button_box class Ui_ChooseGroupDialog(object): + """ + The UI for the "Choose Image Group" form. + """ def setupUi(self, choose_group_dialog): + """ + Set up the UI. + + ``choose_group_dialog`` + The form object (not the class). + """ choose_group_dialog.setObjectName(u'choose_group_dialog') - choose_group_dialog.resize(440, 119) + choose_group_dialog.resize(399, 119) self.choose_group_layout = QtGui.QFormLayout(choose_group_dialog) self.choose_group_layout.setFieldGrowthPolicy(QtGui.QFormLayout.ExpandingFieldsGrow) self.choose_group_layout.setMargin(8) self.choose_group_layout.setSpacing(8) + self.choose_group_layout.setLabelAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.choose_group_layout.setObjectName(u'choose_group_layout') self.group_question_label = QtGui.QLabel(choose_group_dialog) self.group_question_label.setWordWrap(True) self.group_question_label.setObjectName(u'group_question_label') self.choose_group_layout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.group_question_label) + self.nogroup_radio_button = QtGui.QRadioButton(choose_group_dialog) + self.nogroup_radio_button.setChecked(True) + self.nogroup_radio_button.setObjectName(u'nogroup_radio_button') + self.choose_group_layout.setWidget(2, QtGui.QFormLayout.LabelRole, self.nogroup_radio_button) + self.existing_radio_button = QtGui.QRadioButton(choose_group_dialog) + self.existing_radio_button.setChecked(False) + self.existing_radio_button.setObjectName(u'existing_radio_button') + self.choose_group_layout.setWidget(3, QtGui.QFormLayout.LabelRole, self.existing_radio_button) self.group_combobox = QtGui.QComboBox(choose_group_dialog) self.group_combobox.setObjectName(u'group_combobox') - self.choose_group_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.group_combobox) + self.choose_group_layout.setWidget(3, QtGui.QFormLayout.FieldRole, self.group_combobox) + self.new_radio_button = QtGui.QRadioButton(choose_group_dialog) + self.new_radio_button.setChecked(False) + self.new_radio_button.setObjectName(u'new_radio_button') + self.choose_group_layout.setWidget(4, QtGui.QFormLayout.LabelRole, self.new_radio_button) + self.new_group_edit = QtGui.QLineEdit(choose_group_dialog) + self.new_group_edit.setObjectName(u'new_group_edit') + self.choose_group_layout.setWidget(4, QtGui.QFormLayout.FieldRole, self.new_group_edit) self.group_button_box = create_button_box(choose_group_dialog, u'buttonBox', [u'ok']) - self.choose_group_layout.setWidget(3, QtGui.QFormLayout.FieldRole, self.group_button_box) + self.choose_group_layout.setWidget(5, QtGui.QFormLayout.FieldRole, self.group_button_box) self.retranslateUi(choose_group_dialog) QtCore.QMetaObject.connectSlotsByName(choose_group_dialog) def retranslateUi(self, choose_group_dialog): - choose_group_dialog.setWindowTitle(translate('ImagePlugin.ChooseGroupForm', 'Choose group')) - self.group_question_label.setText(translate('ImagePlugin.ChooseGroupForm', - 'To which group do you want these images to be added?')) + """ + Translate the UI on the fly. + + ``choose_group_dialog`` + The form object (not the class). + """ + choose_group_dialog.setWindowTitle(translate('ImagePlugin.ChooseGroupForm', 'Select Image Group')) + self.group_question_label.setText(translate('ImagePlugin.ChooseGroupForm', 'Add images to group:')) + self.nogroup_radio_button.setText(translate('ImagePlugin.ChooseGroupForm', 'No group')) + self.existing_radio_button.setText(translate('ImagePlugin.ChooseGroupForm', 'Existing group')) + self.new_radio_button.setText(translate('ImagePlugin.ChooseGroupForm', 'New group')) diff --git a/openlp/plugins/images/forms/choosegroupform.py b/openlp/plugins/images/forms/choosegroupform.py index eed92e360..15a900c06 100644 --- a/openlp/plugins/images/forms/choosegroupform.py +++ b/openlp/plugins/images/forms/choosegroupform.py @@ -29,8 +29,6 @@ from PyQt4 import QtGui -from openlp.core.lib import translate -from openlp.core.lib.ui import critical_error_message_box from openlp.plugins.images.forms.choosegroupdialog import Ui_ChooseGroupDialog diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index ebb57d3f4..b668e9c34 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -34,8 +34,8 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, SettingsManager, translate, \ check_item_selected, check_directory_exists, Receiver, create_thumb, validate_thumb, ServiceItemContext, Settings, \ - UiStrings -from openlp.core.lib.ui import critical_error_message_box + StringContent, TreeWidgetWithDnD, UiStrings +from openlp.core.lib.ui import create_widget_action, critical_error_message_box from openlp.core.utils import AppLocation, delete_file, locale_compare, get_images_filter from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups @@ -55,10 +55,10 @@ class ImageMediaItem(MediaManagerItem): self.quickPreviewAllowed = True self.hasSearch = True self.manager = plugin.manager - self.choosegroupform = ChooseGroupForm(self) - self.addgroupform = AddGroupForm(self) - self.fill_groups_combobox(self.choosegroupform.group_combobox) - self.fill_groups_combobox(self.addgroupform.parent_group_combobox) + self.choose_group_form = ChooseGroupForm(self) + self.add_group_form = AddGroupForm(self) + self.fill_groups_combobox(self.choose_group_form.group_combobox) + self.fill_groups_combobox(self.add_group_form.parent_group_combobox) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_theme_changed'), self.liveThemeChanged) # Allow DnD from the desktop self.listView.activateDnD() @@ -106,7 +106,63 @@ class ImageMediaItem(MediaManagerItem): initial_load=True) def addListViewToToolBar(self): - MediaManagerItem.addListViewToToolBar(self) + """ + Creates the main widget for listing items the media item is tracking. + This method overloads MediaManagerItem.addListViewToToolBar + """ + # Add the List widget + self.listView = TreeWidgetWithDnD(self, self.plugin.name) + self.listView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) + self.listView.setAlternatingRowColors(True) + self.listView.setObjectName(u'%sTreeView' % self.plugin.name) + # Add to pageLayout + self.pageLayout.addWidget(self.listView) + # define and add the context menu + self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + if self.hasEditIcon: + create_widget_action(self.listView, + text=self.plugin.getString(StringContent.Edit)[u'title'], + icon=u':/general/general_edit.png', + triggers=self.onEditClick) + create_widget_action(self.listView, separator=True) + if self.hasDeleteIcon: + create_widget_action(self.listView, + text=self.plugin.getString(StringContent.Delete)[u'title'], + icon=u':/general/general_delete.png', + shortcuts=[QtCore.Qt.Key_Delete], triggers=self.onDeleteClick) + create_widget_action(self.listView, separator=True) + create_widget_action(self.listView, + text=self.plugin.getString(StringContent.Preview)[u'title'], + icon=u':/general/general_preview.png', + shortcuts=[QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], + triggers=self.onPreviewClick) + create_widget_action(self.listView, + text=self.plugin.getString(StringContent.Live)[u'title'], + icon=u':/general/general_live.png', + shortcuts=[QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter, + QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return], + triggers=self.onLiveClick) + create_widget_action(self.listView, + text=self.plugin.getString(StringContent.Service)[u'title'], + icon=u':/general/general_add.png', + shortcuts=[QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal], + triggers=self.onAddClick) + if self.addToServiceItem: + create_widget_action(self.listView, separator=True) + create_widget_action(self.listView, + text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'), + icon=u':/general/general_add.png', + triggers=self.onAddEditClick) + self.addCustomContextActions() + # Create the context menu and add all actions from the listView. + self.menu = QtGui.QMenu() + self.menu.addActions(self.listView.actions()) + QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), + self.onDoubleClicked) + QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'itemSelectionChanged()'), + self.onSelectionChange) + QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'customContextMenuRequested(QPoint)'), + self.contextMenu) self.listView.addAction(self.replaceAction) def addStartHeaderBar(self): @@ -148,7 +204,10 @@ class ImageMediaItem(MediaManagerItem): item_data = row_item.data(0, QtCore.Qt.UserRole) if isinstance(item_data, ImageFilenames): delete_file(os.path.join(self.servicePath, row_item.text(0))) - row_item.parent().removeChild(row_item) + if item_data.group_id == 0: + self.listView.takeTopLevelItem(self.listView.indexOfTopLevelItem(row_item)) + else: + row_item.parent().removeChild(row_item) self.manager.delete_object(ImageFilenames, row_item.data(0, QtCore.Qt.UserRole).id) elif isinstance(item_data, ImageGroups): if QtGui.QMessageBox.question(self.listView.parent(), @@ -163,13 +222,8 @@ class ImageMediaItem(MediaManagerItem): self.listView.takeTopLevelItem(self.listView.indexOfTopLevelItem(row_item)) else: row_item.parent().removeChild(row_item) - self.fill_groups_combobox(self.choosegroupform.group_combobox) - self.fill_groups_combobox(self.addgroupform.parent_group_combobox) - elif item_data == u'Imported': - QtGui.QMessageBox.information(self, translate('ImagePlugin.MediaItem', 'Can\'t delete group'), - translate('ImagePlugin.MediaItem', 'The Imported group is a special group and can not be ' - 'deleted. It will disappear when it doesn\'t contain any images anymore.'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.fill_groups_combobox(self.choose_group_form.group_combobox) + self.fill_groups_combobox(self.add_group_form.parent_group_combobox) self.main_window.incrementProgressBar() self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') @@ -177,14 +231,16 @@ class ImageMediaItem(MediaManagerItem): def add_sub_groups(self, group_list, parent_group_id): """ - Recursively add subgroups to the given parent group + Recursively add subgroups to the given parent group in a QTreeWidget """ image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parent_group_id) image_groups.sort(cmp=locale_compare, key=lambda group_object: group_object.group_name) + folder_icon = build_icon(u':/images/image_group.png') for image_group in image_groups: group = QtGui.QTreeWidgetItem() group.setText(0, image_group.group_name) group.setData(0, QtCore.Qt.UserRole, image_group) + group.setIcon(0, folder_icon) if parent_group_id is 0: self.listView.addTopLevelItem(group) else: @@ -252,15 +308,9 @@ class ImageMediaItem(MediaManagerItem): item_name.setToolTip(0, imageFile.filename) item_name.setData(0, QtCore.Qt.UserRole, imageFile) if imageFile.group_id is 0: - if 0 not in group_items: - # The 'Imported' group is only displayed when there are files that were imported from the - # configuration file - imported_group = QtGui.QTreeWidgetItem() - imported_group.setText(0, translate('ImagePlugin.MediaItem', 'Imported')) - imported_group.setData(0, QtCore.Qt.UserRole, u'Imported') - self.listView.insertTopLevelItem(0, imported_group) - group_items[0] = imported_group - group_items[imageFile.group_id].addChild(item_name) + self.listView.addTopLevelItem(item_name) + else: + group_items[imageFile.group_id].addChild(item_name) if not initial_load: self.main_window.incrementProgressBar() if not initial_load: @@ -285,19 +335,36 @@ class ImageMediaItem(MediaManagerItem): """ Add new images to the database. This method is called when adding images using the Add button or DnD. """ - if self.manager.get_object_count(ImageGroups) == 0: - QtGui.QMessageBox.warning(self, translate('ImagePlugin.MediaItem', 'No image groups'), - translate('ImagePlugin.MediaItem', 'No image groups exist yet. Please create one before adding images.'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) - self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), - initial_load=initial_load) - return if target_group is None: # Ask which group the images should be saved in - if self.choosegroupform.exec_(): - group_id = self.choosegroupform.group_combobox.itemData( - self.choosegroupform.group_combobox.currentIndex(), QtCore.Qt.UserRole) - parent_group = self.manager.get_object_filtered(ImageGroups, ImageGroups.id == group_id) + if self.manager.get_object_count(ImageGroups) == 0: + self.choose_group_form.nogroup_radio_button.setChecked(True) + self.choose_group_form.existing_radio_button.setChecked(False) + self.choose_group_form.new_radio_button.setChecked(False) + self.choose_group_form.existing_radio_button.setDisabled(True) + self.choose_group_form.group_combobox.setDisabled(True) + else: + self.choose_group_form.nogroup_radio_button.setChecked(True) + self.choose_group_form.existing_radio_button.setChecked(False) + self.choose_group_form.new_radio_button.setChecked(False) + self.choose_group_form.existing_radio_button.setDisabled(False) + self.choose_group_form.group_combobox.setDisabled(False) + if self.choose_group_form.exec_(): + if self.choose_group_form.nogroup_radio_button.isChecked(): + # User chose 'No group' + parent_group = ImageGroups() + parent_group.id = 0 + elif self.choose_group_form.existing_radio_button.isChecked(): + # User chose 'Existing group' + group_id = self.choose_group_form.group_combobox.itemData( + self.choose_group_form.group_combobox.currentIndex(), QtCore.Qt.UserRole) + parent_group = self.manager.get_object_filtered(ImageGroups, ImageGroups.id == group_id) + elif self.choose_group_form.new_radio_button.isChecked(): + # User chose 'New group' + parent_group = ImageGroups() + parent_group.parent_id = 0 + parent_group.group_name = self.choose_group_form.new_group_edit.text() + self.manager.save_object(parent_group) else: parent_group = target_group.data(0, QtCore.Qt.UserRole) if isinstance(parent_group, ImageFilenames): @@ -313,7 +380,7 @@ class ImageMediaItem(MediaManagerItem): imageFile = ImageFilenames() imageFile.group_id = parent_group.id imageFile.filename = unicode(filename) - success = self.manager.save_object(imageFile) + self.manager.save_object(imageFile) self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), initial_load=initial_load, open_group=parent_group) @@ -430,32 +497,20 @@ class ImageMediaItem(MediaManagerItem): groups = self.manager.get_all_objects(ImageGroups, ImageGroups.group_name == newGroup.group_name) return self.__checkObject(groups, newGroup, edit) - def onFileClick(self): - """ - Called when the user clicks the 'Load images' button. This method is overloaded from MediaManagerItem. - """ - if self.manager.get_object_count(ImageGroups) == 0: - QtGui.QMessageBox.warning(self, translate('ImagePlugin.MediaItem', 'No image groups'), - translate('ImagePlugin.MediaItem', 'No image groups exist yet. Please create one before adding images.'), - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) - else: - # At least one group exists, so we run the regular file adding code - MediaManagerItem.onFileClick(self) - def onAddGroupClick(self): """ Called to add a new group """ - if self.addgroupform.exec_(show_top_level_group=True): - new_group = ImageGroups.populate(parent_id=self.addgroupform.parent_group_combobox.itemData( - self.addgroupform.parent_group_combobox.currentIndex(), QtCore.Qt.UserRole), - group_name=self.addgroupform.name_edit.text()) + if self.add_group_form.exec_(show_top_level_group=True): + new_group = ImageGroups.populate(parent_id=self.add_group_form.parent_group_combobox.itemData( + self.add_group_form.parent_group_combobox.currentIndex(), QtCore.Qt.UserRole), + group_name=self.add_group_form.name_edit.text()) if self.checkGroupName(new_group): if self.manager.save_object(new_group): self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename)) - self.fill_groups_combobox(self.choosegroupform.group_combobox) - self.fill_groups_combobox(self.addgroupform.parent_group_combobox) + self.fill_groups_combobox(self.choose_group_form.group_combobox) + self.fill_groups_combobox(self.add_group_form.parent_group_combobox) else: critical_error_message_box( message=translate('ImagePlugin.AddGroupForm', 'Could not add the new group.')) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index f0fb559b8..e4021a4ea 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -147,7 +147,7 @@ class MediaMediaItem(MediaManagerItem): if check_item_selected(self.listView, translate('MediaPlugin.MediaItem', 'You must select a media file to replace the background with.')): item = self.listView.currentItem() - filename = item.data(0, QtCore.Qt.UserRole) + filename = item.data(QtCore.Qt.UserRole) if os.path.exists(filename): service_item = ServiceItem() service_item.title = u'webkit' @@ -171,7 +171,7 @@ class MediaMediaItem(MediaManagerItem): item = self.listView.currentItem() if item is None: return False - filename = item.data(0, QtCore.Qt.UserRole) + filename = item.data(QtCore.Qt.UserRole) if not os.path.exists(filename): if not remote: # File is no longer present @@ -253,7 +253,7 @@ class MediaMediaItem(MediaManagerItem): row_list = [item.row() for item in self.listView.selectedIndexes()] row_list.sort(reverse=True) for row in row_list: - self.listView.takeTopLevelItem(row) + self.listView.takeItem(row) Settings().setValue(self.settingsSection + u'/media files', self.getFileList()) def loadList(self, media, target_group=None): @@ -264,27 +264,24 @@ class MediaMediaItem(MediaManagerItem): track_info = QtCore.QFileInfo(track) if not os.path.exists(track): filename = os.path.split(unicode(track))[1] - item_name = QtGui.QTreeWidgetItem(filename) - item_name.setText(0, filename) - item_name.setIcon(0, ERROR) - item_name.setData(0, QtCore.Qt.UserRole, track) + item_name = QtGui.QListWidgetItem(filename) + item_name.setIcon(ERROR) + item_name.setData(QtCore.Qt.UserRole, track) elif track_info.isFile(): filename = os.path.split(unicode(track))[1] - item_name = QtGui.QTreeWidgetItem(filename) - item_name.setText(0, filename) + item_name = QtGui.QListWidgetItem(filename) if u'*.%s' % (filename.split(u'.')[-1].lower()) in self.media_controller.audio_extensions_list: - item_name.setIcon(0, AUDIO) + item_name.setIcon(AUDIO) else: - item_name.setIcon(0, VIDEO) - item_name.setData(0, QtCore.Qt.UserRole, track) + item_name.setIcon(VIDEO) + item_name.setData(QtCore.Qt.UserRole, track) else: filename = os.path.split(unicode(track))[1] - item_name = QtGui.QTreeWidgetItem(filename) - item_name.setText(0, filename) - item_name.setIcon(0, build_icon(DVDICON)) - item_name.setData(0, QtCore.Qt.UserRole, track) - item_name.setToolTip(0, track) - self.listView.addTopLevelItem(item_name) + item_name = QtGui.QListWidgetItem(filename) + item_name.setIcon(build_icon(DVDICON)) + item_name.setData(QtCore.Qt.UserRole, track) + item_name.setToolTip(track) + self.listView.addItem(item_name) def getList(self, type=MediaType.Audio): media = Settings().value(self.settingsSection + u'/media files') diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 2ba5f40a7..21d48a89e 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -164,12 +164,11 @@ class PresentationMediaItem(MediaManagerItem): continue filename = os.path.split(unicode(file))[1] if not os.path.exists(file): - item_name = QtGui.QTreeWidgetItem(filename) - item_name.setText(0, filename) - item_name.setIcon(0, build_icon(ERROR)) - item_name.setData(0, QtCore.Qt.UserRole, file) - item_name.setToolTip(0, file) - self.listView.addTopLevelItem(item_name) + item_name = QtGui.QListWidgetItem(filename) + item_name.setIcon(build_icon(ERROR)) + item_name.setData(QtCore.Qt.UserRole, file) + item_name.setToolTip(file) + self.listView.addItem(item_name) else: if titles.count(filename) > 0: if not initialLoad: @@ -202,12 +201,11 @@ class PresentationMediaItem(MediaManagerItem): critical_error_message_box(UiStrings().UnsupportedFile, translate('PresentationPlugin.MediaItem', 'This type of presentation is not supported.')) continue - item_name = QtGui.QTreeWidgetItem(filename) - item_name.setText(0, filename) - item_name.setData(0, QtCore.Qt.UserRole, file) - item_name.setIcon(0, icon) - item_name.setToolTip(0, file) - self.listView.addTopLevelItem(item_name) + item_name = QtGui.QListWidgetItem(filename) + item_name.setData(QtCore.Qt.UserRole, file) + item_name.setIcon(icon) + item_name.setToolTip(file) + self.listView.addItem(item_name) Receiver.send_message(u'cursor_normal') if not initialLoad: self.main_window.finishedProgressBar() @@ -233,7 +231,7 @@ class PresentationMediaItem(MediaManagerItem): self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') for row in row_list: - self.listView.takeTopLevelItem(row) + self.listView.takeItem(row) Settings().setValue(self.settingsSection + u'/presentations files', self.getFileList()) def generateSlideData(self, service_item, item=None, xmlVersion=False, diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 833d14013..de1ad22ff 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -226,10 +226,9 @@ class SongMediaItem(MediaManagerItem): author_list = [author.display_name for author in song.authors] song_title = unicode(song.title) song_detail = u'%s (%s)' % (song_title, create_separated_list(author_list)) - song_name = QtGui.QTreeWidgetItem(song_detail) - song_name.setText(0, song_detail) - song_name.setData(0, QtCore.Qt.UserRole, song.id) - self.listView.addTopLevelItem(song_name) + song_name = QtGui.QListWidgetItem(song_detail) + song_name.setData(QtCore.Qt.UserRole, song.id) + self.listView.addItem(song_name) # Auto-select the item if name has been set if song.id == self.autoSelectId: self.listView.setCurrentItem(song_name) @@ -244,10 +243,9 @@ class SongMediaItem(MediaManagerItem): if song.temporary: continue song_detail = u'%s (%s)' % (author.display_name, song.title) - song_name = QtGui.QTreeWidgetItem(song_detail) - song_name.setText(0, song_detail) - song_name.setData(0, QtCore.Qt.UserRole, song.id) - self.listView.addTopLevelItem(song_name) + song_name = QtGui.QListWidgetItem(song_detail) + song_name.setData(QtCore.Qt.UserRole, song.id) + self.listView.addItem(song_name) def displayResultsBook(self, searchresults, song_number=False): log.debug(u'display results Book') @@ -262,10 +260,9 @@ class SongMediaItem(MediaManagerItem): if song_number and not song_number in song.song_number: continue song_detail = u'%s - %s (%s)' % (book.name, song.song_number, song.title) - song_name = QtGui.QTreeWidgetItem(song_detail) - song_name.setText(0, song_detail) - song_name.setData(0, QtCore.Qt.UserRole, song.id) - self.listView.addTopLevelItem(song_name) + song_name = QtGui.QListWidgetItem(song_detail) + song_name.setData(QtCore.Qt.UserRole, song.id) + self.listView.addItem(song_name) def onClearTextButtonClick(self): """ @@ -344,7 +341,7 @@ class SongMediaItem(MediaManagerItem): log.debug(u'onEditClick') if check_item_selected(self.listView, UiStrings().SelectEdit): self.editItem = self.listView.currentItem() - item_id = self.editItem.data(0, QtCore.Qt.UserRole) + item_id = self.editItem.data(QtCore.Qt.UserRole) self.editSongForm.loadSong(item_id, False) self.editSongForm.exec_() self.autoSelectId = -1 @@ -393,7 +390,7 @@ class SongMediaItem(MediaManagerItem): log.debug(u'onCloneClick') if check_item_selected(self.listView, UiStrings().SelectEdit): self.editItem = self.listView.currentItem() - item_id = self.editItem.data(0, QtCore.Qt.UserRole) + item_id = self.editItem.data(QtCore.Qt.UserRole) old_song = self.plugin.manager.get_object(Song, item_id) song_xml = self.openLyrics.song_to_xml(old_song) new_song = self.openLyrics.xml_to_song(song_xml) diff --git a/resources/images/image_group.png b/resources/images/image_group.png new file mode 100644 index 000000000..352c3b0e2 Binary files /dev/null and b/resources/images/image_group.png differ diff --git a/resources/images/openlp-2.qrc b/resources/images/openlp-2.qrc index d98f1e534..8b8456b1f 100644 --- a/resources/images/openlp-2.qrc +++ b/resources/images/openlp-2.qrc @@ -22,6 +22,7 @@ song_book_edit.png + image_group.png image_new_group.png