forked from openlp/openlp
Fixed a bug in the song editor where the last added verse would revert to the previous verse type.
bzr-revno: 1086
This commit is contained in:
commit
c4e6b4aaac
@ -53,6 +53,9 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
QtCore.QObject.connect(self.verseTextEdit,
|
QtCore.QObject.connect(self.verseTextEdit,
|
||||||
QtCore.SIGNAL(u'cursorPositionChanged()'),
|
QtCore.SIGNAL(u'cursorPositionChanged()'),
|
||||||
self.onCursorPositionChanged)
|
self.onCursorPositionChanged)
|
||||||
|
QtCore.QObject.connect(self.verseTypeComboBox,
|
||||||
|
QtCore.SIGNAL(u'currentIndexChanged(int)'),
|
||||||
|
self.onVerseTypeComboBoxChanged)
|
||||||
self.verse_regex = re.compile(r'---\[([-\w]+):([\d]+)\]---')
|
self.verse_regex = re.compile(r'---\[([-\w]+):([\d]+)\]---')
|
||||||
|
|
||||||
def contextMenu(self, point):
|
def contextMenu(self, point):
|
||||||
@ -71,6 +74,33 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
self.insertVerse(VerseType.to_string(verse_type),
|
self.insertVerse(VerseType.to_string(verse_type),
|
||||||
self.verseNumberBox.value())
|
self.verseNumberBox.value())
|
||||||
|
|
||||||
|
def onVerseTypeComboBoxChanged(self):
|
||||||
|
"""
|
||||||
|
Adjusts the verse number SpinBox in regard to the selected verse type
|
||||||
|
and the cursor's position.
|
||||||
|
"""
|
||||||
|
position = self.verseTextEdit.textCursor().position()
|
||||||
|
text = unicode(self.verseTextEdit.toPlainText())
|
||||||
|
verse_type = VerseType.to_string(self.verseTypeComboBox.currentIndex())
|
||||||
|
if not text:
|
||||||
|
return
|
||||||
|
position = text.rfind(u'---[%s' % verse_type, 0, position)
|
||||||
|
if position == -1:
|
||||||
|
self.verseNumberBox.setValue(1)
|
||||||
|
return
|
||||||
|
text = text[position:]
|
||||||
|
position = text.find(u']---')
|
||||||
|
if position == -1:
|
||||||
|
return
|
||||||
|
text = text[:position + 4]
|
||||||
|
match = self.verse_regex.match(text)
|
||||||
|
if match:
|
||||||
|
verse_type = match.group(1)
|
||||||
|
verse_number = int(match.group(2))
|
||||||
|
verse_type_index = VerseType.from_string(verse_type)
|
||||||
|
if verse_type_index is not None:
|
||||||
|
self.verseNumberBox.setValue(verse_number)
|
||||||
|
|
||||||
def onCursorPositionChanged(self):
|
def onCursorPositionChanged(self):
|
||||||
"""
|
"""
|
||||||
Determines the previous verse type and number in regard to the cursor's
|
Determines the previous verse type and number in regard to the cursor's
|
||||||
|
Loading…
Reference in New Issue
Block a user