Fixed alignment of filepathEdit widget by adjusting spacer size according to label width.

This commit is contained in:
Samuel Findlay 2012-05-31 22:42:44 +10:00
parent d86caecbbf
commit dddd883ede

View File

@ -177,7 +177,7 @@ class SongImportForm(OpenLPWizard):
UiStrings().Browse) UiStrings().Browse)
f_label = 'Filename:' f_label = 'Filename:'
if select_mode == SongFormatSelect.SingleFolder: if select_mode == SongFormatSelect.SingleFolder:
f_label = 'Folder:' f_label = 'Folders:'
self.formatWidgets[format][u'filepathLabel'].setText( self.formatWidgets[format][u'filepathLabel'].setText(
translate('SongsPlugin.ImportWizardForm', f_label)) translate('SongsPlugin.ImportWizardForm', f_label))
for format in self.disablableFormats: for format in self.disablableFormats:
@ -194,11 +194,19 @@ class SongImportForm(OpenLPWizard):
self.errorSaveToButton.setText(translate('SongsPlugin.ImportWizardForm', self.errorSaveToButton.setText(translate('SongsPlugin.ImportWizardForm',
'Save to File')) 'Save to File'))
# Align all QFormLayouts towards each other. # Align all QFormLayouts towards each other.
filepathLabel = self.formatWidgets[SongFormat.OpenLP2][u'filepathLabel'] formats = filter(lambda f: u'filepathLabel' in
width = max(self.formatLabel.minimumSizeHint().width(), self.formatWidgets[f], SongFormat.get_format_list())
filepathLabel.minimumSizeHint().width()) labels = [self.formatWidgets[f][u'filepathLabel'] for f in formats]
self.formatSpacer.changeSize(width, 0, QtGui.QSizePolicy.Fixed, # Get max width of all labels
QtGui.QSizePolicy.Fixed) max_label_width = max(self.formatLabel.minimumSizeHint().width(),
max([label.minimumSizeHint().width() for label in labels]))
self.formatSpacer.changeSize(max_label_width, 0,
QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
spacers = [self.formatWidgets[f][u'filepathSpacer'] for f in formats]
for index, spacer in enumerate(spacers):
spacer.changeSize(
max_label_width - labels[index].minimumSizeHint().width(), 0,
QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
def customPageChanged(self, pageId): def customPageChanged(self, pageId):
""" """
@ -211,8 +219,8 @@ class SongImportForm(OpenLPWizard):
""" """
Validate the current page before moving on to the next page. Validate the current page before moving on to the next page.
For sourcePage, provide the song format class with a chance to validate Provides each song format class with a chance to validate its input by
its input via isValidSource(). overriding isValidSource().
""" """
if self.currentPage() == self.welcomePage: if self.currentPage() == self.welcomePage:
return True return True
@ -414,6 +422,9 @@ class SongImportForm(OpenLPWizard):
filepathLabel = QtGui.QLabel(importWidget) filepathLabel = QtGui.QLabel(importWidget)
filepathLabel.setObjectName(obj_prefix + u'FilepathLabel') filepathLabel.setObjectName(obj_prefix + u'FilepathLabel')
filepathLayout.addWidget(filepathLabel) filepathLayout.addWidget(filepathLabel)
filepathSpacer = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed)
filepathLayout.addSpacerItem(filepathSpacer)
filepathEdit = QtGui.QLineEdit(importWidget) filepathEdit = QtGui.QLineEdit(importWidget)
filepathEdit.setObjectName(obj_prefix + u'FilepathEdit') filepathEdit.setObjectName(obj_prefix + u'FilepathEdit')
filepathLayout.addWidget(filepathEdit) filepathLayout.addWidget(filepathEdit)
@ -424,6 +435,7 @@ class SongImportForm(OpenLPWizard):
importLayout.addLayout(filepathLayout) importLayout.addLayout(filepathLayout)
importLayout.addSpacerItem(self.stackSpacer) importLayout.addSpacerItem(self.stackSpacer)
self.formatWidgets[format][u'filepathLabel'] = filepathLabel self.formatWidgets[format][u'filepathLabel'] = filepathLabel
self.formatWidgets[format][u'filepathSpacer'] = filepathSpacer
self.formatWidgets[format][u'filepathLayout'] = filepathLayout self.formatWidgets[format][u'filepathLayout'] = filepathLayout
self.formatWidgets[format][u'filepathEdit'] = filepathEdit self.formatWidgets[format][u'filepathEdit'] = filepathEdit
self.formatWidgets[format][u'browseButton'] = browseButton self.formatWidgets[format][u'browseButton'] = browseButton