openlp/openlp/core/ui/serviceitemeditform.py
Andreas Preikschat 4dec90a419 added line
2011-01-18 17:09:34 +01:00

152 lines
5.9 KiB
Python

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
from PyQt4 import QtCore, QtGui
from serviceitemeditdialog import Ui_ServiceItemEditDialog
class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog):
"""
This is the form that is used to edit the verses of the song.
"""
def __init__(self, parent=None):
"""
Constructor
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.itemList = []
# enable drop
QtCore.QObject.connect(self.upButton,
QtCore.SIGNAL(u'clicked()'), self.onItemUp)
QtCore.QObject.connect(self.downButton,
QtCore.SIGNAL(u'clicked()'), self.onItemDown)
QtCore.QObject.connect(self.deleteButton,
QtCore.SIGNAL(u'clicked()'), self.onItemDelete)
QtCore.QObject.connect(self.buttonBox,
QtCore.SIGNAL(u'accepted()'), self.accept)
QtCore.QObject.connect(self.buttonBox,
QtCore.SIGNAL(u'rejected()'), self.reject)
QtCore.QObject.connect(self.listWidget,
QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged)
def setServiceItem(self, item):
self.item = item
self.itemList = []
if self.item.is_image():
self.data = True
for frame in self.item._raw_frames:
self.itemList.append(frame)
self.loadData()
self.listWidget.setCurrentItem(self.listWidget.currentItem())
def getServiceItem(self):
if self.data:
self.item._raw_frames = []
if self.item.is_image():
for item in self.itemList:
self.item.add_from_image(item[u'path'], item[u'title'])
self.item.render()
return self.item
def loadData(self):
"""
Loads the image list.
"""
self.listWidget.clear()
for frame in self.itemList:
item_name = QtGui.QListWidgetItem(frame[u'title'])
self.listWidget.addItem(item_name)
def onItemDelete(self):
"""
Delete the current row.
"""
item = self.listWidget.currentItem()
if not item:
return
row = self.listWidget.row(item)
self.itemList.remove(self.itemList[row])
self.loadData()
if row == self.listWidget.count():
self.listWidget.setCurrentRow(row - 1)
else:
self.listWidget.setCurrentRow(row)
def onItemUp(self):
"""
Move the current row up in the list.
"""
item = self.listWidget.currentItem()
if not item:
return
row = self.listWidget.row(item)
temp = self.itemList[row]
self.itemList.remove(self.itemList[row])
self.itemList.insert(row - 1, temp)
self.loadData()
self.listWidget.setCurrentRow(row - 1)
def onItemDown(self):
"""
Move the current row down in the list
"""
item = self.listWidget.currentItem()
if not item:
return
row = self.listWidget.row(item)
temp = self.itemList[row]
self.itemList.remove(self.itemList[row])
self.itemList.insert(row + 1, temp)
self.loadData()
self.listWidget.setCurrentRow(row + 1)
def onCurrentRowChanged(self, row):
"""
Called when the currentRow has changed.
``row``
The row number (int).
"""
# Disable all buttons, as no row is selected or only one image is left.
if row == -1 or self.listWidget.count() == 1:
self.downButton.setEnabled(False)
self.upButton.setEnabled(False)
self.deleteButton.setEnabled(False)
else:
# Check if we are at the end of the list.
if self.listWidget.count() == row + 1:
self.downButton.setEnabled(False)
else:
self.downButton.setEnabled(True)
# Check if we are at the beginning of the list.
if row == 0:
self.upButton.setEnabled(False)
else:
self.upButton.setEnabled(True)
self.deleteButton.setEnabled(True)