openlp/openlp/core/ui/printserviceorderform.py

221 lines
9.4 KiB
Python
Raw Normal View History

2011-02-04 18:00:59 +00:00
# -*- 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 #
###############################################################################
import datetime
from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate
2011-02-15 18:51:37 +00:00
from openlp.core.lib.ui import UiStrings
2011-02-06 13:57:57 +00:00
from openlp.core.ui.printserviceorderdialog import Ui_PrintServiceOrderDialog
2011-02-04 18:00:59 +00:00
2011-02-06 13:57:57 +00:00
class PrintServiceOrderForm(QtGui.QDialog, Ui_PrintServiceOrderDialog):
2011-02-15 18:51:37 +00:00
2011-02-06 13:57:57 +00:00
def __init__(self, parent, serviceManager):
2011-02-04 18:00:59 +00:00
"""
Constructor
"""
QtGui.QDialog.__init__(self, parent)
2011-02-14 19:52:05 +00:00
self.parent = parent
2011-02-06 13:57:57 +00:00
self.serviceManager = serviceManager
2011-02-05 19:48:21 +00:00
self.printer = QtGui.QPrinter()
self.printDialog = QtGui.QPrintDialog(self.printer, self)
self.document = QtGui.QTextDocument()
2011-02-06 13:57:57 +00:00
self.setupUi(self)
2011-02-06 14:00:39 +00:00
# Load the settings for the dialog.
2011-02-04 20:10:32 +00:00
settings = QtCore.QSettings()
settings.beginGroup(u'advanced')
2011-02-19 08:36:24 +00:00
self.slideTextCheckBox.setChecked(settings.value(
2011-02-04 20:10:32 +00:00
u'print slide text', QtCore.QVariant(False)).toBool())
2011-02-19 08:36:24 +00:00
self.metaDataCheckBox.setChecked(settings.value(
2011-02-04 20:10:32 +00:00
u'print file meta data', QtCore.QVariant(False)).toBool())
2011-02-19 08:36:24 +00:00
self.notesCheckBox.setChecked(settings.value(
2011-02-04 20:10:32 +00:00
u'print notes', QtCore.QVariant(False)).toBool())
settings.endGroup()
2011-02-06 07:16:42 +00:00
# Signals
2011-02-19 08:36:24 +00:00
# QtCore.QObject.connect(self.printButton,
# QtCore.SIGNAL(u'clicked()'), self.printServiceOrder)
# QtCore.QObject.connect(self.zoomOutButton,
# QtCore.SIGNAL(u'clicked()'), self.zoomOut)
# QtCore.QObject.connect(self.zoomInButton,
# QtCore.SIGNAL(u'clicked()'), self.zoomIn)
# QtCore.QObject.connect(self.previewWidget,
# QtCore.SIGNAL(u'paintRequested(QPrinter *)'), self.paintRequested)
# QtCore.QObject.connect(self.serviceTitleLineEdit,
# QtCore.SIGNAL(u'textChanged(const QString)'),
# self.updatePreviewText)
# QtCore.QObject.connect(self.slideTextCheckBox,
# QtCore.SIGNAL(u'stateChanged(int)'), self.updatePreviewText)
# QtCore.QObject.connect(self.notesCheckBox,
# QtCore.SIGNAL(u'stateChanged(int)'), self.updatePreviewText)
# QtCore.QObject.connect(self.metaDataCheckBox,
# QtCore.SIGNAL(u'stateChanged(int)'), self.updatePreviewText)
# QtCore.QObject.connect(self.customNoteEdit,
# QtCore.SIGNAL(u'textChanged()'), self.updatePreviewText)
# QtCore.QObject.connect(self.cancelButton,
# QtCore.SIGNAL(u'clicked()'), self.reject)
# QtCore.QObject.connect(self.copyTextButton,
# QtCore.SIGNAL(u'clicked()'), self.copyText)
# QtCore.QObject.connect(self.copyHtmlButton,
# QtCore.SIGNAL(u'clicked()'), self.copyHtmlText)
# self.updatePreviewText()
def toggleOptions(self, checked):
self.optionsWidget.setVisible(checked)
if checked:
left = self.optionsButton.pos().x()
top = self.toolbar.height()
self.optionsWidget.move(left, top)
self.titleLineEdit.setFocus()
else:
self.saveOptions()
2011-02-04 18:00:59 +00:00
2011-02-06 07:16:42 +00:00
def updatePreviewText(self):
2011-02-04 18:00:59 +00:00
"""
2011-02-06 13:57:57 +00:00
Creates the html text and updates the html of *self.document*.
2011-02-04 18:00:59 +00:00
"""
2011-02-06 07:16:42 +00:00
text = u''
2011-02-04 18:00:59 +00:00
if self.serviceTitleLineEdit.text():
2011-02-04 18:34:22 +00:00
text += u'<h2>%s</h2>' % unicode(self.serviceTitleLineEdit.text())
2011-02-04 18:00:59 +00:00
for item in self.serviceManager.serviceItems:
item = item[u'service_item']
# Add the title of the service item.
2011-02-14 19:52:05 +00:00
text += u'<h3><img src="%s" /> %s</h3>' % (item.icon,
2011-02-04 18:00:59 +00:00
item.get_display_title())
# Add slide text of the service item.
2011-02-19 08:36:24 +00:00
if self.slideTextCheckBox.isChecked():
2011-02-04 18:00:59 +00:00
if item.is_text():
# Add the text of the service item.
2011-02-15 18:51:37 +00:00
verse = None
2011-02-04 18:00:59 +00:00
for slide in item.get_frames():
2011-02-15 18:51:37 +00:00
if not verse:
text += u'<p>' + slide[u'html']
verse = slide[u'verseTag']
elif verse != slide[u'verseTag']:
text += u'<\p><p>' + slide[u'html']
verse = slide[u'verseTag']
else:
text += u'<br/>' + slide[u'html']
text += u'</p>'
2011-02-04 18:00:59 +00:00
elif item.is_image():
# Add the image names of the service item.
text += u'<ol>'
for slide in range(len(item.get_frames())):
text += u'<li><p>%s</p></li>' % \
item.get_frame_title(slide)
text += u'</ol>'
if item.foot_text:
# add footer
text += u'<p>%s</p>' % item.foot_text
# Add service items' notes.
2011-02-19 08:36:24 +00:00
if self.notesCheckBox.isChecked():
2011-02-04 18:00:59 +00:00
if item.notes:
2011-02-06 14:26:13 +00:00
text += u'<p><b>%s</b></p>%s' % (translate(
2011-02-06 07:16:42 +00:00
'OpenLP.ServiceManager', 'Notes:'),
item.notes.replace(u'\n', u'<br />'))
2011-02-04 18:00:59 +00:00
# Add play length of media files.
2011-02-19 08:36:24 +00:00
if item.is_media() and self.metaDataCheckBox.isChecked():
2011-02-14 17:54:09 +00:00
text += u'<p><b>%s</b> %s</p>' % (translate(
'OpenLP.ServiceManager', u'Playing time:'),
unicode(datetime.timedelta(seconds=item.media_length)))
if self.customNoteEdit.toPlainText():
text += u'<h4>%s</h4>%s' % (translate('OpenLP.ServiceManager',
u'Custom Service Notes:'), self.customNoteEdit.toPlainText())
2011-02-06 07:16:42 +00:00
self.document.setHtml(text)
self.previewWidget.updatePreview()
def paintRequested(self, printer):
"""
2011-02-06 13:57:57 +00:00
Paint the preview of the *self.document*.
2011-02-07 17:27:38 +00:00
``printer``
A *QPrinter* object.
2011-02-06 07:16:42 +00:00
"""
self.document.print_(printer)
2011-02-06 07:16:42 +00:00
2011-02-15 18:51:37 +00:00
def copyText(self):
2011-02-18 17:38:39 +00:00
"""
Copies the display text to the clipboard as plain text
"""
self.parent.clipboard.setText(self.document.toPlainText())
def copyHtmlText(self):
"""
Copies the display text to the clipboard as Html
"""
self.parent.clipboard.setText(self.document.toHtml())
2011-02-15 18:51:37 +00:00
2011-02-06 07:16:42 +00:00
def printServiceOrder(self):
2011-02-06 13:57:57 +00:00
"""
Called, when the *printButton* is clicked. Opens the *printDialog*.
"""
2011-02-06 07:16:42 +00:00
if not self.printDialog.exec_():
return
2011-02-06 13:57:57 +00:00
# Print the document.
2011-02-06 07:16:42 +00:00
self.document.print_(self.printer)
2011-02-06 13:57:57 +00:00
def zoomIn(self):
"""
Called when *zoomInButton* is clicked.
"""
self.previewWidget.zoomIn()
2011-02-06 13:57:57 +00:00
def zoomOut(self):
"""
Called when *zoomOutButton* is clicked.
"""
self.previewWidget.zoomOut()
2011-02-15 18:51:37 +00:00
def updateTextFormat(self, value):
"""
Called when html copy check box is selected.
"""
if value == QtCore.Qt.Checked:
self.copyTextButton.setText(UiStrings.CopyToHtml)
else:
self.copyTextButton.setText(UiStrings.CopyToText)
2011-02-19 08:36:24 +00:00
def saveOptions(self):
2011-02-06 13:57:57 +00:00
"""
Save the settings and close the dialog.
"""
2011-02-04 20:10:32 +00:00
# Save the settings for this dialog.
settings = QtCore.QSettings()
settings.beginGroup(u'advanced')
settings.setValue(u'print slide text',
2011-02-19 08:36:24 +00:00
QtCore.QVariant(self.slideTextCheckBox.isChecked()))
2011-02-04 20:10:32 +00:00
settings.setValue(u'print file meta data',
2011-02-19 08:36:24 +00:00
QtCore.QVariant(self.metaDataCheckBox.isChecked()))
2011-02-04 20:10:32 +00:00
settings.setValue(u'print notes',
2011-02-19 08:36:24 +00:00
QtCore.QVariant(self.notesCheckBox.isChecked()))
2011-02-04 20:10:32 +00:00
settings.endGroup()
2011-02-19 08:36:24 +00:00
def close(self):
2011-02-06 13:57:57 +00:00
# Close the dialog.
return QtGui.QDialog.accept(self)
2011-02-05 19:48:21 +00:00