This commit is contained in:
Andreas Preikschat 2011-02-06 08:16:42 +01:00
parent 75e4d34db6
commit 1933144731
2 changed files with 207 additions and 71 deletions

View File

@ -38,14 +38,13 @@ class PrintServiceOrderForm(QtGui.QDialog):
""" """
Constructor Constructor
""" """
self.serviceManager = parent
QtGui.QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, parent)
self.setupUi() self.serviceManager = parent
self.retranslateUi()
self.html = u''
self.printer = QtGui.QPrinter() self.printer = QtGui.QPrinter()
self.printDialog = QtGui.QPrintDialog(self.printer, self) self.printDialog = QtGui.QPrintDialog(self.printer, self)
self.document = QtGui.QTextDocument() self.document = QtGui.QTextDocument()
self.setupUi()
self.retranslateUi()
# Load the settings for this dialog. # Load the settings for this dialog.
settings = QtCore.QSettings() settings = QtCore.QSettings()
settings.beginGroup(u'advanced') settings.beginGroup(u'advanced')
@ -56,37 +55,109 @@ class PrintServiceOrderForm(QtGui.QDialog):
self.printNotesCheckBox.setChecked(settings.value( self.printNotesCheckBox.setChecked(settings.value(
u'print notes', QtCore.QVariant(False)).toBool()) u'print notes', QtCore.QVariant(False)).toBool())
settings.endGroup() settings.endGroup()
# Signals
QtCore.QObject.connect(self.printButton,
QtCore.SIGNAL('clicked()'), self.printServiceOrder)
QtCore.QObject.connect(self.zoomOutButton,
QtCore.SIGNAL('clicked()'), self.zoomOut)
QtCore.QObject.connect(self.zoomInButton,
QtCore.SIGNAL('clicked()'), self.zoomIn)
QtCore.QObject.connect(self.previewWidget,
QtCore.SIGNAL('paintRequested(QPrinter *)'), self.paintRequested)
QtCore.QObject.connect(self.serviceTitleLineEdit,
QtCore.SIGNAL('textChanged(const QString)'), self.updatePreviewText)
QtCore.QObject.connect(self.printSlideTextCheckBox,
QtCore.SIGNAL('stateChanged(int)'), self.updatePreviewText)
QtCore.QObject.connect(self.printNotesCheckBox,
QtCore.SIGNAL('stateChanged(int)'), self.updatePreviewText)
QtCore.QObject.connect(self.printMetaDataCheckBox,
QtCore.SIGNAL('stateChanged(int)'), self.updatePreviewText)
self.updatePreviewText()
def setupUi(self): def setupUi(self):
self.dialogLayout = QtGui.QHBoxLayout(self) self.dialogLayout = QtGui.QHBoxLayout(self)
self.dialogLayout.setObjectName(u'dialogLayout') self.dialogLayout.setObjectName(u'dialogLayout')
self.verticalLayout = QtGui.QVBoxLayout() self.perviewLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(u'verticalLayout') self.perviewLayout.setObjectName(u'perviewLayout')
self.previewLabel = QtGui.QLabel(self)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.previewLabel.sizePolicy().hasHeightForWidth())
self.previewLabel.setSizePolicy(sizePolicy)
self.previewLabel.setObjectName(u'previewLabel')
self.perviewLayout.addWidget(self.previewLabel)
self.previewWidget = QtGui.QPrintPreviewWidget(self.printer, self, QtCore.Qt.Widget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.previewWidget.sizePolicy().hasHeightForWidth())
self.previewWidget.setSizePolicy(sizePolicy)
self.previewWidget.setObjectName(u'previewWidget')
self.previewWidget.fitToWidth()
self.perviewLayout.addWidget(self.previewWidget)
self.dialogLayout.addLayout(self.perviewLayout)
self.settingsLayout = QtGui.QVBoxLayout()
self.settingsLayout.setObjectName(u'settingsLayout')
self.serviceTitleLayout = QtGui.QHBoxLayout() self.serviceTitleLayout = QtGui.QHBoxLayout()
self.serviceTitleLayout.setObjectName(u'serviceTitleLayout') self.serviceTitleLayout.setObjectName(u'serviceTitleLayout')
self.serviceTitleLabel = QtGui.QLabel(self) self.serviceTitleLabel = QtGui.QLabel(self)
self.serviceTitleLabel.setObjectName(u'serviceTitleLabel') self.serviceTitleLabel.setObjectName(u'serviceTitleLabel')
self.serviceTitleLayout.addWidget(self.serviceTitleLabel) self.serviceTitleLayout.addWidget(self.serviceTitleLabel)
self.serviceTitleLineEdit = QtGui.QLineEdit(self) self.serviceTitleLineEdit = QtGui.QLineEdit(self)
self.serviceTitleLineEdit.setSizePolicy(
QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
self.serviceTitleLineEdit.setObjectName(u'serviceTitleLineEdit') self.serviceTitleLineEdit.setObjectName(u'serviceTitleLineEdit')
self.serviceTitleLayout.addWidget(self.serviceTitleLineEdit) self.serviceTitleLayout.addWidget(self.serviceTitleLineEdit)
self.verticalLayout.addLayout(self.serviceTitleLayout) self.settingsLayout.addLayout(self.serviceTitleLayout)
self.printSlideTextCheckBox = QtGui.QCheckBox(self) self.printSlideTextCheckBox = QtGui.QCheckBox(self)
self.printSlideTextCheckBox.setObjectName(u'printSlideTextCheckBox') self.printSlideTextCheckBox.setObjectName(u'printSlideTextCheckBox')
self.verticalLayout.addWidget(self.printSlideTextCheckBox) self.settingsLayout.addWidget(self.printSlideTextCheckBox)
self.printNotesCheckBox = QtGui.QCheckBox(self) self.printNotesCheckBox = QtGui.QCheckBox(self)
self.printNotesCheckBox.setObjectName(u'printNotesCheckBox') self.printNotesCheckBox.setObjectName(u'printNotesCheckBox')
self.verticalLayout.addWidget(self.printNotesCheckBox) self.settingsLayout.addWidget(self.printNotesCheckBox)
self.printMetaDataCheckBox = QtGui.QCheckBox(self) self.printMetaDataCheckBox = QtGui.QCheckBox(self)
self.printMetaDataCheckBox.setObjectName(u'printMetaDataCheckBox') self.printMetaDataCheckBox.setObjectName(u'printMetaDataCheckBox')
self.verticalLayout.addWidget(self.printMetaDataCheckBox) self.settingsLayout.addWidget(self.printMetaDataCheckBox)
self.verticalLayout.addWidget(save_cancel_button_box(self)) self.buttonLayout = QtGui.QHBoxLayout()
self.dialogLayout.addLayout(self.verticalLayout) self.zoomOutButton = QtGui.QToolButton(self)
icon = QtGui.QIcon()
#icon.addPixmap(QtGui.QPixmap(u':/exports/export_move_to_list.png'),
icon.addPixmap(QtGui.QPixmap(u'/home/andreas/zoom-out.png'),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.zoomOutButton.setIcon(icon)
self.zoomOutButton.setObjectName(u'zoomOutButton')
self.buttonLayout.addWidget(self.zoomOutButton)
self.zoomInButton = QtGui.QToolButton(self)
icon = QtGui.QIcon()
#icon.addPixmap(QtGui.QPixmap(u':/exports/export_remove.png'),
icon.addPixmap(QtGui.QPixmap(u'/home/andreas/zoom-in.png'),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.zoomInButton.setIcon(icon)
self.zoomInButton.setObjectName(u'toolButton')
self.buttonLayout.addWidget(self.zoomInButton)
spacerItem = QtGui.QSpacerItem(20, 40,
QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.settingsLayout.addItem(spacerItem)
self.buttonLayout.setObjectName(u'buttonLayout')
spacerItem = QtGui.QSpacerItem(40, 20,
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.buttonLayout.addItem(spacerItem)
self.cancelButton = QtGui.QPushButton(self)
self.cancelButton.setObjectName(u'cancelButton')
self.buttonLayout.addWidget(self.cancelButton)
self.printButton = QtGui.QPushButton(self)
self.printButton.setObjectName(u'printButton')
self.buttonLayout.addWidget(self.printButton)
self.settingsLayout.addLayout(self.buttonLayout)
self.dialogLayout.addLayout(self.settingsLayout)
QtCore.QMetaObject.connectSlotsByName(self) QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self): def retranslateUi(self):
self.setWindowTitle( self.setWindowTitle(
translate('OpenLP.PrintServiceOrderForm', 'Print Service Order')) translate('OpenLP.PrintServiceOrderForm', 'Print Service Order'))
self.previewLabel.setText(
translate('OpenLP.ServiceManager', '<b>Preview:</b>'))
self.printSlideTextCheckBox.setText(translate( self.printSlideTextCheckBox.setText(translate(
'OpenLP.PrintServiceOrderForm', 'Include slide text if avaialbe')) 'OpenLP.PrintServiceOrderForm', 'Include slide text if avaialbe'))
self.printNotesCheckBox.setText(translate( self.printNotesCheckBox.setText(translate(
@ -95,14 +166,17 @@ class PrintServiceOrderForm(QtGui.QDialog):
translate('OpenLP.PrintServiceOrderForm', translate('OpenLP.PrintServiceOrderForm',
'Include play lenght of media items')) 'Include play lenght of media items'))
self.serviceTitleLabel.setText(translate( self.serviceTitleLabel.setText(translate(
'OpenLP.PrintServiceOrderForm', 'Service Order Title:')) 'OpenLP.PrintServiceOrderForm', 'Title:'))
self.serviceTitleLineEdit.setText(translate('OpenLP.ServiceManager', self.serviceTitleLineEdit.setText(translate('OpenLP.ServiceManager',
'Service Order Sheet')) 'Service Order Sheet'))
self.printButton.setText(translate('OpenLP.ServiceManager', 'Print'))
self.cancelButton.setText(translate('OpenLP.ServiceManager', 'Cancel'))
def serviceOrderText(self): def updatePreviewText(self):
""" """
Creates the html text, to print the service items. Creates the html text, to print the service items.
""" """
text = u''
if self.serviceTitleLineEdit.text(): if self.serviceTitleLineEdit.text():
text += u'<h2>%s</h2>' % unicode(self.serviceTitleLineEdit.text()) text += u'<h2>%s</h2>' % unicode(self.serviceTitleLineEdit.text())
for item in self.serviceManager.serviceItems: for item in self.serviceManager.serviceItems:
@ -129,8 +203,9 @@ class PrintServiceOrderForm(QtGui.QDialog):
# Add service items' notes. # Add service items' notes.
if self.printNotesCheckBox.isChecked(): if self.printNotesCheckBox.isChecked():
if item.notes: if item.notes:
text += u'<p><b>%s</b> %s</p>' % (translate( text += u'<p><b>%s</b></p><br />%s' % (translate(
'OpenLP.ServiceManager', 'Notes:'), item.notes) 'OpenLP.ServiceManager', 'Notes:'),
item.notes.replace(u'\n', u'<br />'))
# Add play length of media files. # Add play length of media files.
if item.is_media() and self.printMetaDataCheckBox.isChecked(): if item.is_media() and self.printMetaDataCheckBox.isChecked():
path = os.path.join(item.get_frames()[0][u'path'], path = os.path.join(item.get_frames()[0][u'path'],
@ -143,6 +218,19 @@ class PrintServiceOrderForm(QtGui.QDialog):
text += u'<p><b>%s</b> %s</p>' % (translate( text += u'<p><b>%s</b> %s</p>' % (translate(
'OpenLP.ServiceManager', u'Playing time:'), 'OpenLP.ServiceManager', u'Playing time:'),
unicode(datetime.timedelta(seconds=length))) unicode(datetime.timedelta(seconds=length)))
self.document.setHtml(text)
self.previewWidget.updatePreview()
def paintRequested(self, printer):
"""
Paint the preview.
"""
self.document.print_(printer)
def printServiceOrder(self):
if not self.printDialog.exec_():
return
self.document.print_(self.printer)
# Save the settings for this dialog. # Save the settings for this dialog.
settings = QtCore.QSettings() settings = QtCore.QSettings()
settings.beginGroup(u'advanced') settings.beginGroup(u'advanced')
@ -153,12 +241,9 @@ class PrintServiceOrderForm(QtGui.QDialog):
settings.setValue(u'print notes', settings.setValue(u'print notes',
QtCore.QVariant(self.printNotesCheckBox.isChecked())) QtCore.QVariant(self.printNotesCheckBox.isChecked()))
settings.endGroup() settings.endGroup()
self.document.setHtml(text)
def printServiceOrder(self): def zoomIn(self):
serviceDocument = QtGui.QTextDocument() self.previewWidget.zoomIn()
serviceDocument.setHtml(settingDialog.serviceOrderText())
printDialog = QtGui.QPrintDialog() def zoomOut(self):
if not printDialog.exec_(): self.previewWidget.zoomOut()
return
serviceDocument.print_(printDialog.printer())

View File

@ -13,10 +13,10 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<layout class="QHBoxLayout" name="dialogLayout"> <layout class="QGridLayout" name="dialogLayout">
<item> <item row="0" column="0">
<layout class="QVBoxLayout" name="perviewLayout"> <layout class="QVBoxLayout" name="perviewLayout">
<item> <item>
<widget class="QLabel" name="previewLabel"> <widget class="QLabel" name="previewLabel">
@ -33,37 +33,47 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="previewWidget" native="true"> <widget class="QWidget" name="previewWidget" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<zorder></zorder>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="0" column="3">
<layout class="QVBoxLayout" name="settingsLayout"> <layout class="QVBoxLayout" name="settingsLayout">
<item> <item>
<layout class="QHBoxLayout" name="serviceTitleLayout"> <layout class="QGridLayout" name="serviceTitleLayout">
<item> <item row="1" column="1">
<widget class="QLabel" name="serviceTitleLabel">
<property name="text">
<string>Service Title:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="serviceTitleLineEdit"> <widget class="QLineEdit" name="serviceTitleLineEdit">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="serviceTitleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Service Title:</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -81,14 +91,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="metaDataCheckBox"> <widget class="QCheckBox" name="printMetaDataCheckBox">
<property name="text"> <property name="text">
<string>Include play lenght of media items</string> <string>Include play lenght of media items</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="spacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
@ -100,36 +110,75 @@
</property> </property>
</spacer> </spacer>
</item> </item>
</layout>
</item>
<item row="1" column="3">
<layout class="QHBoxLayout" name="buttonLayout">
<item> <item>
<layout class="QHBoxLayout" name="buttonLayout"> <spacer name="spacer_3">
<item> <property name="orientation">
<spacer name="horizontalSpacer"> <enum>Qt::Horizontal</enum>
<property name="orientation"> </property>
<enum>Qt::Horizontal</enum> <property name="sizeHint" stdset="0">
</property> <size>
<property name="sizeHint" stdset="0"> <width>40</width>
<size> <height>20</height>
<width>40</width> </size>
<height>20</height> </property>
</size> </spacer>
</property> </item>
</spacer> <item>
</item> <widget class="QPushButton" name="cancelButton">
<item> <property name="text">
<widget class="QPushButton" name="cancelButton"> <string>Cancel</string>
<property name="text"> </property>
<string>Cancel</string> </widget>
</property> </item>
</widget> <item>
</item> <widget class="QPushButton" name="printButton">
<item> <property name="text">
<widget class="QPushButton" name="printButton"> <string>Print</string>
<property name="text"> </property>
<string>Print</string> </widget>
</property> </item>
</widget> </layout>
</item> </item>
</layout> <item row="1" column="0">
<layout class="QHBoxLayout" name="zoomButtonLayout">
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="zoomOutButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset>
<normaloff>../../../../../zoom-out.png</normaloff>../../../../../zoom-out.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="zoomInButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset>
<normaloff>../../../../../zoom-in.png</normaloff>../../../../../zoom-in.png</iconset>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -137,6 +186,8 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/> <resources>
<include location="../images/openlp-2.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>