forked from openlp/openlp
Fixed bug #841752 'song editor: increment verse number automatically'.
bzr-revno: 2137 Fixes: https://launchpad.net/bugs/841752
This commit is contained in:
commit
a884bfdfee
@ -93,6 +93,12 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
self.verseNumberBox.value())
|
self.verseNumberBox.value())
|
||||||
|
|
||||||
def onVerseTypeComboBoxChanged(self):
|
def onVerseTypeComboBoxChanged(self):
|
||||||
|
self.updateSuggestedVerseNumber()
|
||||||
|
|
||||||
|
def onCursorPositionChanged(self):
|
||||||
|
self.updateSuggestedVerseNumber()
|
||||||
|
|
||||||
|
def updateSuggestedVerseNumber(self):
|
||||||
"""
|
"""
|
||||||
Adjusts the verse number SpinBox in regard to the selected verse type
|
Adjusts the verse number SpinBox in regard to the selected verse type
|
||||||
and the cursor's position.
|
and the cursor's position.
|
||||||
@ -116,43 +122,10 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
if match:
|
if match:
|
||||||
verse_tag = match.group(1)
|
verse_tag = match.group(1)
|
||||||
try:
|
try:
|
||||||
verse_num = int(match.group(2))
|
verse_num = int(match.group(2)) + 1
|
||||||
except ValueError:
|
except ValueError:
|
||||||
verse_num = 1
|
verse_num = 1
|
||||||
if VerseType.from_loose_input(verse_tag, False):
|
self.verseNumberBox.setValue(verse_num)
|
||||||
self.verseNumberBox.setValue(verse_num)
|
|
||||||
|
|
||||||
def onCursorPositionChanged(self):
|
|
||||||
"""
|
|
||||||
Determines the previous verse type and number in regard to the cursor's
|
|
||||||
position and adjusts the ComboBox and SpinBox to these values.
|
|
||||||
"""
|
|
||||||
position = self.verseTextEdit.textCursor().position()
|
|
||||||
text = self.verseTextEdit.toPlainText()
|
|
||||||
if not text:
|
|
||||||
return
|
|
||||||
if text.rfind(u'[', 0, position) > text.rfind(u']', 0, position) and \
|
|
||||||
text.find(u']', position) < text.find(u'[', position):
|
|
||||||
return
|
|
||||||
position = text.rfind(u'---[', 0, position)
|
|
||||||
if position == -1:
|
|
||||||
return
|
|
||||||
text = text[position:]
|
|
||||||
position = text.find(u']---')
|
|
||||||
if position == -1:
|
|
||||||
return
|
|
||||||
text = text[:position + 4]
|
|
||||||
match = VERSE_REGEX.match(text)
|
|
||||||
if match:
|
|
||||||
verse_type = match.group(1)
|
|
||||||
verse_type_index = VerseType.from_loose_input(verse_type, None)
|
|
||||||
try:
|
|
||||||
verse_number = int(match.group(2))
|
|
||||||
except ValueError:
|
|
||||||
verse_number = 1
|
|
||||||
if verse_type_index is not None:
|
|
||||||
self.verseTypeComboBox.setCurrentIndex(verse_type_index)
|
|
||||||
self.verseNumberBox.setValue(verse_number)
|
|
||||||
|
|
||||||
def setVerse(self, text, single=False,
|
def setVerse(self, text, single=False,
|
||||||
tag=u'%s1' % VerseType.Tags[VerseType.Verse]):
|
tag=u'%s1' % VerseType.Tags[VerseType.Verse]):
|
||||||
|
Loading…
Reference in New Issue
Block a user