openlp/openlp/core/ui/serviceitemeditform.py

147 lines
5.2 KiB
Python
Raw Normal View History

2010-03-03 17:48:37 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 OpenLP Developers #
# ---------------------------------------------------------------------- #
# 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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
2013-02-01 21:34:23 +00:00
"""
The service item edit dialog
"""
from PyQt5 import QtCore, QtWidgets
2015-11-07 00:49:40 +00:00
2017-10-23 22:09:57 +00:00
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.registry import Registry
2017-10-07 07:05:07 +00:00
from openlp.core.ui.serviceitemeditdialog import Ui_ServiceItemEditDialog
2010-03-03 17:48:37 +00:00
2013-02-01 21:34:23 +00:00
2015-11-07 00:49:40 +00:00
class ServiceItemEditForm(QtWidgets.QDialog, Ui_ServiceItemEditDialog, RegistryProperties):
2010-03-03 17:48:37 +00:00
"""
This is the form that is used to edit the verses of the song.
"""
2013-01-27 07:36:04 +00:00
def __init__(self):
2010-03-03 17:48:37 +00:00
"""
Constructor
"""
super(ServiceItemEditForm, self).__init__(Registry().get('main_window'), QtCore.Qt.WindowSystemMenuHint |
QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint)
self.setup_ui(self)
2013-01-27 20:36:18 +00:00
self.item_list = []
2013-03-05 13:55:50 +00:00
self.list_widget.currentRowChanged.connect(self.on_current_row_changed)
2010-03-18 21:50:20 +00:00
2013-01-27 20:36:18 +00:00
def set_service_item(self, item):
2013-02-01 21:34:23 +00:00
"""
Set the service item to be edited.
"""
2010-03-18 21:50:20 +00:00
self.item = item
2013-01-27 20:36:18 +00:00
self.item_list = []
2010-03-18 21:50:20 +00:00
if self.item.is_image():
self.data = True
2018-10-28 16:34:17 +00:00
self.item_list.extend(self.item.slides)
2013-01-27 20:36:18 +00:00
self.load_data()
self.list_widget.setCurrentItem(self.list_widget.currentItem())
2010-03-18 21:50:20 +00:00
2013-01-27 20:36:18 +00:00
def get_service_item(self):
2013-02-01 21:34:23 +00:00
"""
Get the modified service item.
"""
2010-03-18 21:50:20 +00:00
if self.data:
2018-10-28 16:34:17 +00:00
self.item.slides = []
2010-03-18 21:50:20 +00:00
if self.item.is_image():
2013-01-27 20:36:18 +00:00
for item in self.item_list:
2013-08-31 18:17:38 +00:00
self.item.add_from_image(item['path'], item['title'])
2010-03-18 21:50:20 +00:00
self.item.render()
return self.item
2013-01-27 20:36:18 +00:00
def load_data(self):
2011-01-17 18:51:26 +00:00
"""
Loads the image list.
"""
2013-01-27 20:36:18 +00:00
self.list_widget.clear()
for frame in self.item_list:
2015-11-07 00:49:40 +00:00
item_name = QtWidgets.QListWidgetItem(frame['title'])
2013-01-27 20:36:18 +00:00
self.list_widget.addItem(item_name)
2010-03-18 21:50:20 +00:00
2013-01-27 20:36:18 +00:00
def on_delete_button_clicked(self):
2010-03-18 21:50:20 +00:00
"""
2011-01-17 18:51:26 +00:00
Delete the current row.
2010-03-18 21:50:20 +00:00
"""
2013-01-27 20:36:18 +00:00
item = self.list_widget.currentItem()
2011-01-17 18:51:26 +00:00
if not item:
return
2013-01-27 20:36:18 +00:00
row = self.list_widget.row(item)
self.item_list.pop(row)
self.load_data()
if row == self.list_widget.count():
row -= 1
self.list_widget.setCurrentRow(row)
2010-03-18 21:50:20 +00:00
2013-01-27 20:36:18 +00:00
def on_up_button_clicked(self):
2010-03-18 21:50:20 +00:00
"""
2011-01-17 18:51:26 +00:00
Move the current row up in the list.
2010-03-18 21:50:20 +00:00
"""
2013-08-31 18:17:38 +00:00
self.__move_item('up')
2010-03-18 21:50:20 +00:00
2013-01-27 20:36:18 +00:00
def on_down_button_clicked(self):
2010-03-18 21:50:20 +00:00
"""
2011-01-17 18:51:26 +00:00
Move the current row down in the list
2010-03-18 21:50:20 +00:00
"""
2013-08-31 18:17:38 +00:00
self.__move_item('down')
2011-02-01 00:33:50 +00:00
2013-08-31 18:17:38 +00:00
def __move_item(self, direction=''):
2011-02-01 00:33:50 +00:00
"""
Move the current item.
"""
if not direction:
return
2013-01-27 20:36:18 +00:00
item = self.list_widget.currentItem()
2011-01-17 18:51:26 +00:00
if not item:
return
2013-01-27 20:36:18 +00:00
row = self.list_widget.row(item)
temp = self.item_list[row]
self.item_list.pop(row)
2013-08-31 18:17:38 +00:00
if direction == 'up':
2011-02-11 18:35:25 +00:00
row -= 1
2011-02-01 00:33:50 +00:00
else:
2011-02-11 18:35:25 +00:00
row += 1
2013-01-27 20:36:18 +00:00
self.item_list.insert(row, temp)
self.load_data()
self.list_widget.setCurrentRow(row)
2011-01-17 18:51:26 +00:00
2013-01-27 20:36:18 +00:00
def on_current_row_changed(self, row):
2011-01-17 18:51:26 +00:00
"""
Called when the currentRow has changed.
2014-03-17 19:05:55 +00:00
:param row: The row number (int).
2011-01-17 18:51:26 +00:00
"""
# Disable all buttons, as no row is selected or only one image is left.
2013-01-27 20:36:18 +00:00
if row == -1 or self.list_widget.count() == 1:
self.down_button.setEnabled(False)
self.up_button.setEnabled(False)
self.delete_button.setEnabled(False)
2011-01-17 18:51:26 +00:00
else:
# Check if we are at the end of the list.
2013-01-27 20:36:18 +00:00
if self.list_widget.count() == row + 1:
self.down_button.setEnabled(False)
2011-01-17 18:51:26 +00:00
else:
2013-01-27 20:36:18 +00:00
self.down_button.setEnabled(True)
2011-01-17 18:51:26 +00:00
# Check if we are at the beginning of the list.
if row == 0:
2013-01-27 20:36:18 +00:00
self.up_button.setEnabled(False)
2011-01-17 18:51:26 +00:00
else:
2013-01-27 20:36:18 +00:00
self.up_button.setEnabled(True)
self.delete_button.setEnabled(True)