forked from openlp/openlp
Various bug fixes and code improvements.
bzr-revno: 493
This commit is contained in:
commit
9044e5c88c
@ -151,10 +151,70 @@ class Renderer(object):
|
||||
lines = verse.split(u'\n')
|
||||
for line in lines:
|
||||
text.append(line)
|
||||
split_text = self._split_set_of_lines(text, False)
|
||||
#print text
|
||||
split_text = self.pre_render_text(text)
|
||||
# print "-----------------------------"
|
||||
# print split_text
|
||||
# split_text = self._split_set_of_lines(text, False)
|
||||
# print "-----------------------------"
|
||||
# print split_text
|
||||
log.debug(u'format_slide - End')
|
||||
return split_text
|
||||
|
||||
def pre_render_text(self, text):
|
||||
metrics = QtGui.QFontMetrics(self.mainFont)
|
||||
#take the width work out approx how many characters and add 50%
|
||||
line_width = self._rect.width() - self._right_margin
|
||||
#number of lines on a page - adjust for rounding up.
|
||||
page_length = int(self._rect.height() / metrics.height()) - 1
|
||||
ave_line_width = line_width / metrics.averageCharWidth()
|
||||
#print ave_line_width
|
||||
ave_line_width = int(ave_line_width + (ave_line_width * 0.5))
|
||||
#print ave_line_width
|
||||
split_pages = []
|
||||
page = []
|
||||
split_lines = []
|
||||
count = 0
|
||||
for line in text:
|
||||
#print line , len(line)
|
||||
if len(line) > ave_line_width:
|
||||
while len(line) > 0:
|
||||
pos = line.find(u' ', ave_line_width)
|
||||
#print ave_line_width, pos, line[:pos]
|
||||
split_text = line[:pos]
|
||||
#print metrics.width(split_text, -1), line_width
|
||||
while metrics.width(split_text, -1) > line_width:
|
||||
#Find the next space to the left
|
||||
pos = line[:pos].rfind(u' ')
|
||||
#print ave_line_width, pos, line[:pos]
|
||||
#no more spaces found
|
||||
if pos == -1:
|
||||
split_text = line
|
||||
else:
|
||||
split_text = line[:pos]
|
||||
split_lines.append(split_text)
|
||||
line = line[pos:]
|
||||
#Text fits in a line now
|
||||
if len(line) <= ave_line_width:
|
||||
split_lines.append(line)
|
||||
line = u''
|
||||
# count += 1
|
||||
# if count == 50:
|
||||
# a = c
|
||||
#print split_lines
|
||||
#print line
|
||||
else:
|
||||
split_lines.append(line)
|
||||
line = u''
|
||||
for line in split_lines:
|
||||
page.append(line)
|
||||
if len(page) == page_length:
|
||||
split_pages.append(page)
|
||||
page = []
|
||||
if len(page) > 0:
|
||||
split_pages.append(page)
|
||||
return split_pages
|
||||
|
||||
def set_text_rectangle(self, rect_main, rect_footer):
|
||||
"""
|
||||
Sets the rectangle within which text should be rendered.
|
||||
@ -544,7 +604,6 @@ class Renderer(object):
|
||||
painter.setPen(QtGui.QColor(color))
|
||||
x, y = tlcorner
|
||||
metrics = QtGui.QFontMetrics(font)
|
||||
# xxx some fudges to make it exactly like wx! Take 'em out later
|
||||
w = metrics.width(line)
|
||||
h = metrics.height() - 2
|
||||
if draw:
|
||||
|
@ -138,12 +138,12 @@ class RenderManager(object):
|
||||
main_rect = None
|
||||
footer_rect = None
|
||||
if theme.font_main_override == False:
|
||||
main_rect = QtCore.QRect(10,0, self.width-1, self.height-1)
|
||||
main_rect = QtCore.QRect(10,0, self.width - 1, self.footer_start - 20)
|
||||
else:
|
||||
main_rect = QtCore.QRect(int(theme.font_main_x) , int(theme.font_main_y),
|
||||
int(theme.font_main_width)-1, int(theme.font_main_height)-1)
|
||||
int(theme.font_main_width)-1, int(theme.font_main_height) - 1)
|
||||
if theme.font_footer_override == False:
|
||||
footer_rect = QtCore.QRect(10,self.footer_start, self.width-1, self.height-self.footer_start)
|
||||
footer_rect = QtCore.QRect(10,self.footer_start, self.width - 1, self.height-self.footer_start)
|
||||
else:
|
||||
footer_rect = QtCore.QRect(int(theme.font_footer_x),int(theme.font_footer_y),
|
||||
int(theme.font_footer_width)-1, int(theme.font_footer_height)-1)
|
||||
|
@ -71,29 +71,29 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
QtCore.SIGNAL(u'activated(int)'), self.onVerticalComboBoxSelected)
|
||||
|
||||
QtCore.QObject.connect(self.FontMainSizeSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontMainSizeSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontMainSizeSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontFooterSizeSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontFooterSizeSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontFooterSizeSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontMainDefaultCheckBox,
|
||||
QtCore.SIGNAL(u'stateChanged(int)'), self.onFontMainDefaultCheckBoxChanged)
|
||||
QtCore.QObject.connect(self.FontMainXSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontMainXSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontMainXSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontMainYSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontMainYSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontMainYSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontMainWidthSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontMainWidthSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontMainWidthSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontMainHeightSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontMainHeightSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontMainHeightSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontFooterDefaultCheckBox,
|
||||
QtCore.SIGNAL(u'stateChanged(int)'), self.onFontFooterDefaultCheckBoxChanged)
|
||||
QtCore.QObject.connect(self.FontFooterXSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontFooterXSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontFooterXSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontFooterYSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontFooterYSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontFooterYSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontFooterWidthSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontFooterWidthSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontFooterWidthSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.FontFooterHeightSpinBox,
|
||||
QtCore.SIGNAL(u'valueChanged(int)'), self.onFontFooterHeightSpinBoxChanged)
|
||||
QtCore.SIGNAL(u'editingFinished()'), self.onFontFooterHeightSpinBoxChanged)
|
||||
QtCore.QObject.connect(self.OutlineCheckBox,
|
||||
QtCore.SIGNAL(u'stateChanged(int)'), self.onOutlineCheckBoxChanged)
|
||||
QtCore.QObject.connect(self.ShadowCheckBox,
|
||||
@ -167,9 +167,10 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
u'background-color: %s' % unicode(self.theme.font_main_color))
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontMainSizeSpinBoxChanged(self, value):
|
||||
self.theme.font_main_proportion = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontMainSizeSpinBoxChanged(self):
|
||||
if self.theme.font_main_proportion != self.FontMainSizeSpinBox.value():
|
||||
self.theme.font_main_proportion = self.FontMainSizeSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontMainDefaultCheckBoxChanged(self, value):
|
||||
if value == 2: # checked
|
||||
@ -190,21 +191,25 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
self.stateChanging(self.theme)
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontMainXSpinBoxChanged(self, value):
|
||||
self.theme.font_main_x = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontMainXSpinBoxChanged(self):
|
||||
if self.theme.font_main_x != self.FontMainXSpinBox.value():
|
||||
self.theme.font_main_x = self.FontMainXSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontMainYSpinBoxChanged(self, value):
|
||||
self.theme.font_main_y = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontMainYSpinBoxChanged(self):
|
||||
if self.theme.font_main_y != self.FontMainYSpinBox.value():
|
||||
self.theme.font_main_y = self.FontMainYSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontMainWidthSpinBoxChanged(self, value):
|
||||
self.theme.font_main_width = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontMainWidthSpinBoxChanged(self):
|
||||
if self.theme.font_main_width != self.FontMainWidthSpinBox.value():
|
||||
self.theme.font_main_width = self.FontMainWidthSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontMainHeightSpinBoxChanged(self, value):
|
||||
self.theme.font_main_height = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontMainHeightSpinBoxChanged(self):
|
||||
if self.theme.font_main_height != self.FontMainHeightSpinBox.value():
|
||||
self.theme.font_main_height = self.FontMainHeightSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
#
|
||||
#Footer Font Tab
|
||||
#
|
||||
@ -220,9 +225,10 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
'background-color: %s' % unicode(self.theme.font_footer_color))
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontFooterSizeSpinBoxChanged(self, value):
|
||||
self.theme.font_footer_proportion = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontFooterSizeSpinBoxChanged(self):
|
||||
if self.theme.font_footer_proportion != self.FontFooterSizeSpinBox.value():
|
||||
self.theme.font_footer_proportion = self.FontFooterSizeSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontFooterDefaultCheckBoxChanged(self, value):
|
||||
if value == 2: # checked
|
||||
@ -245,22 +251,25 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
||||
self.stateChanging(self.theme)
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontFooterXSpinBoxChanged(self, value):
|
||||
self.theme.font_footer_x = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontFooterXSpinBoxChanged(self):
|
||||
if self.theme.font_footer_x != self.FontFooterXSpinBox.value():
|
||||
self.theme.font_footer_x = self.FontFooterXSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontFooterYSpinBoxChanged(self, value):
|
||||
self.theme.font_footer_y = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontFooterYSpinBoxChanged(self):
|
||||
if self.theme.font_footer_y != self.FontFooterYSpinBox.value():
|
||||
self.theme.font_footer_y = self.FontFooterYSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontFooterWidthSpinBoxChanged(self, value):
|
||||
self.theme.font_footer_width = value
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontFooterHeightSpinBoxChanged(self, value):
|
||||
self.theme.font_footer_height = value
|
||||
self.previewTheme(self.theme)
|
||||
def onFontFooterWidthSpinBoxChanged(self):
|
||||
if self.theme.font_footer_width != self.FontFooterWidthSpinBox.value():
|
||||
self.theme.font_footer_width = self.FontFooterWidthSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
|
||||
def onFontFooterHeightSpinBoxChanged(self):
|
||||
if self.theme.font_footer_height != self.FontFooterHeightSpinBox.value():
|
||||
self.theme.font_footer_height = self.FontFooterHeightSpinBox.value()
|
||||
self.previewTheme(self.theme)
|
||||
#
|
||||
#Background Tab
|
||||
#
|
||||
|
@ -154,6 +154,8 @@ class MigrateSongs():
|
||||
author = Author()
|
||||
authors_temp = self.session.query(TAuthor).get(a)
|
||||
author.display_name = authors_temp.authorname
|
||||
author.first_name = u''
|
||||
author.last_name = u''
|
||||
song.authors.append(author)
|
||||
try:
|
||||
self.session.add(song)
|
||||
|
@ -97,6 +97,7 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
self.DeleteButton.setEnabled(False)
|
||||
self.author = None
|
||||
self._validate_form()
|
||||
self.DisplayEdit.setFocus()
|
||||
|
||||
def onAuthorListWidgetItemClicked(self, index):
|
||||
"""
|
||||
@ -108,8 +109,14 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
|
||||
self.author = self.songmanager.get_author(item_id)
|
||||
self.DisplayEdit.setText(self.author.display_name)
|
||||
self.FirstNameEdit.setText(self.author.first_name)
|
||||
self.LastNameEdit.setText(self.author.last_name)
|
||||
if self.author.first_name is None:
|
||||
self.FirstNameEdit.setText(u'')
|
||||
else:
|
||||
self.FirstNameEdit.setText(self.author.first_name)
|
||||
if self.author.last_name is None:
|
||||
self.LastNameEdit.setText(u'')
|
||||
else:
|
||||
self.LastNameEdit.setText(self.author.last_name)
|
||||
if len(self.author.songs) > 0:
|
||||
self.MessageLabel.setText(translate(u'AuthorForm', u'Author in use "Delete" is disabled'))
|
||||
self.DeleteButton.setEnabled(False)
|
||||
@ -117,6 +124,7 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
self.MessageLabel.setText(translate(u'AuthorForm', u'Author in not used'))
|
||||
self.DeleteButton.setEnabled(True)
|
||||
self._validate_form()
|
||||
self.DisplayEdit.setFocus()
|
||||
|
||||
def _validate_form(self):
|
||||
# We need at lease a display name
|
||||
|
@ -96,6 +96,7 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog):
|
||||
self.AddUpdateButton.setEnabled(True)
|
||||
self.Book = None
|
||||
self._validate_form()
|
||||
self.NameEdit.setFocus()
|
||||
|
||||
def onBooksListViewItemClicked(self, index):
|
||||
"""
|
||||
@ -115,6 +116,7 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog):
|
||||
self.MessageLabel.setText(translate(u'BookForm', u'Book in not used'))
|
||||
self.DeleteButton.setEnabled(True)
|
||||
self._validate_form()
|
||||
self.NameEdit.setFocus()
|
||||
|
||||
def _validate_form(self):
|
||||
# We need at lease a display name
|
||||
|
@ -95,6 +95,7 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
|
||||
self.DeleteButton.setEnabled(False)
|
||||
self.topic = None
|
||||
self._validate_form()
|
||||
self.TopicNameEdit.setFocus()
|
||||
|
||||
def onTopicsListWidgetItemClicked(self, index):
|
||||
"""
|
||||
@ -113,6 +114,7 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
|
||||
self.MessageLabel.setText(translate(u'TopicForm', u'Topic in not used'))
|
||||
self.DeleteButton.setEnabled(True)
|
||||
self._validate_form()
|
||||
self.TopicNameEdit.setFocus()
|
||||
|
||||
def _validate_form(self):
|
||||
# We need at lease a display name
|
||||
|
Loading…
Reference in New Issue
Block a user