diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index acae55b74..499d86571 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -47,6 +47,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): """ QtGui.QDialog.__init__(self, parent) self.parent = parent + #can this be automated? + self.width = 400 self.setupUi(self) # Connecting signals and slots QtCore.QObject.connect(self.AuthorAddButton, @@ -182,7 +184,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.CommentsEdit.setText(u'') self.CCLNumberEdit.setText(u'') self.VerseListWidget.clear() - self.VerseListWidget.serRowCount(0) + self.VerseListWidget.setRowCount(0) self.AuthorsListView.clear() self.TopicsListView.clear() self.TitleEditItem.setFocus(QtCore.Qt.OtherFocusReason) @@ -240,9 +242,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): #lazy xml migration for now self.VerseListWidget.clear() self.VerseListWidget.setRowCount(0) - #can this be automated? - self.VerseListWidget.setColumnWidth(0, 400) - rowLabel = [] + self.VerseListWidget.setColumnWidth(0, self.width) if self.song.lyrics.startswith(u' -1: @@ -294,7 +306,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): author_item = QtGui.QListWidgetItem(unicode(author.display_name)) author_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id)) self.AuthorsListView.addItem(author_item) - self.VerseListWidget.resizeRowsToContents() def onAuthorsListViewPressed(self): if self.AuthorsListView.count() > 1: @@ -352,16 +363,19 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.VerseDeleteButton.setEnabled(True) def onVerseAddButtonClicked(self): - self.verse_form.setVerse(u'', self.VerseListWidget.count() + 1, True) + self.verse_form.setVerse(u'', self.VerseListWidget.rowCount() + 1, True) if self.verse_form.exec_(): afterText, verse, subVerse = self.verse_form.getVerse() data = u'%s:%s' % (verse, subVerse) - item = QtGui.QListWidgetItem(afterText) + item = QtGui.QTableWidgetItem(afterText) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(data)) item.setText(afterText) self.VerseListWidget.setRowCount( self.VerseListWidget.rowCount() + 1) - self.VerseListWidget.setItem(count, 0, item) + self.VerseListWidget.setItem(int(self.VerseListWidget.rowCount() - 1), 0, item) + self.VerseListWidget.setColumnWidth(0, self.width) + self.VerseListWidget.resizeRowsToContents() + self.tagRows() def onVerseEditButtonClicked(self): item = self.VerseListWidget.currentItem() @@ -379,18 +393,20 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): if len(tempText.split(u'\n')) != len(afterText.split(u'\n')): tempList = {} tempId = {} - for row in range(0, self.VerseListWidget.count()): - tempList[row] = self.VerseListWidget.item(row).text() - tempId[row] = self.VerseListWidget.item(row).\ + for row in range(0, self.VerseListWidget.rowCount()): + tempList[row] = self.VerseListWidget.item(row, 0).text() + tempId[row] = self.VerseListWidget.item(row, 0).\ data(QtCore.Qt.UserRole) self.VerseListWidget.clear() for row in range (0, len(tempList)): - item = QtGui.QListWidgetItem(tempList[row]) + item = QtGui.QTableWidgetItem(tempList[row], 0) item.setData(QtCore.Qt.UserRole, tempId[row]) - self.VerseListWidget.addItem(item) + self.VerseListWidget.setItem(row, 0, item) + self.VerseListWidget.resizeRowsToContents() self.VerseListWidget.repaint() self.VerseEditButton.setEnabled(False) self.VerseDeleteButton.setEnabled(False) + self.tagRows() def onVerseEditAllButtonClicked(self): verse_list = u'' @@ -408,7 +424,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): verse_list = self.verse_form.getVerseAll() verse_list = unicode(verse_list.replace(u'\r\n', u'\n')) self.VerseListWidget.clear() - listRow = 0 + self.VerseListWidget.setRowCount(0) for row in self.findVerseSplit.split(verse_list): for match in row.split(u'---['): for count, parts in enumerate(match.split(u']---\n')): @@ -420,15 +436,20 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): else: if parts.endswith(u'\n'): parts = parts.rstrip(u'\n') - item = QtGui.QListWidgetItem(parts) - item.setData(QtCore.Qt.UserRole, QtCore.QVariant(variant)) - self.VerseListWidget.setItem(listRow, 0, item) - self.VerseListWidget.repaint() + item = QtGui.QTableWidgetItem(parts) + item.setData( + QtCore.Qt.UserRole, QtCore.QVariant(variant)) + self.VerseListWidget.setRowCount( + self.VerseListWidget.rowCount() + 1) + self.VerseListWidget.setItem( + int(self.VerseListWidget.rowCount() - 1), 0, item) + self.VerseListWidget.setColumnWidth(0, self.width) + self.VerseListWidget.resizeRowsToContents() + self.VerseListWidget.repaint() + self.tagRows() def onVerseDeleteButtonClicked(self): - self.VerseListWidget.takeItem(self.VerseListWidget.currentRow(), 0) - self.VerseListWidget.setRowCount( - self.VerseListWidget.rowCount() - 1) + self.VerseListWidget.removeRow(self.VerseListWidget.currentRow()) self.VerseEditButton.setEnabled(False) self.VerseDeleteButton.setEnabled(False) @@ -448,7 +469,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.VerseListWidget.setFocus() return False, self.trUtf8('You need to enter some verses.') if self.AuthorsListView.count() == 0: - self.SongTabWidget.setCurrentIndex(2) + self.SongTabWidget.setCurrentIndex(1) self.AuthorsListView.setFocus() #split the verse list by space and mark lower case for testing taglist = unicode(self.trUtf8(' bitped')) @@ -501,6 +522,10 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.loadTopics() def onPreview(self, button): + """ + Save and Preview button pressed. + The Song is valid so as the plugin to add it to preview to see. + """ log.debug(u'onPreview') if button.text() == unicode(self.trUtf8('Save && Preview')) \ and self.saveSong(): @@ -543,11 +568,11 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): sxml.add_lyrics_to_song() text = u' ' for i in range (0, self.VerseListWidget.rowCount()): - item = self.VerseListWidget.item(i) + item = self.VerseListWidget.item(i, 0) verseId = unicode((item.data(QtCore.Qt.UserRole)).toString()) bits = verseId.split(u':') sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text())) - text = text + unicode(self.VerseListWidget.item(i).text()) + u' ' + text = text + unicode(self.VerseListWidget.item(i, 0).text()) + u' ' text = text.replace(u'\'', u'') text = text.replace(u',', u'') text = text.replace(u';', u'')