From 0cefed0eb56c107d351c2809528ae00c1d18fe5a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 11 Oct 2010 19:29:03 +0200 Subject: [PATCH] onVerseTypeComboBoxChanged --- openlp/plugins/songs/forms/editverseform.py | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/openlp/plugins/songs/forms/editverseform.py b/openlp/plugins/songs/forms/editverseform.py index e995407a3..3e1ff7857 100644 --- a/openlp/plugins/songs/forms/editverseform.py +++ b/openlp/plugins/songs/forms/editverseform.py @@ -53,6 +53,9 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog): QtCore.QObject.connect(self.verseTextEdit, QtCore.SIGNAL(u'cursorPositionChanged()'), self.onCursorPositionChanged) + QtCore.QObject.connect(self.verseTypeComboBox, + QtCore.SIGNAL(u'currentIndexChanged(int)'), + self.onVerseTypeComboBoxChanged) self.verse_regex = re.compile(r'---\[([-\w]+):([\d]+)\]---') def contextMenu(self, point): @@ -71,6 +74,32 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog): self.insertVerse(VerseType.to_string(verse_type), self.verseNumberBox.value()) + def onVerseTypeComboBoxChanged(self): + """ + Adjusts the verse number SpinBox in regard to the selected verse type. + """ + 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): """ Determines the previous verse type and number in regard to the cursor's