update Add Field button

This commit is contained in:
Damien Elmes 2020-05-14 18:01:15 +10:00
parent c5d574e9f4
commit 9a222e620a
2 changed files with 35 additions and 70 deletions

View File

@ -258,11 +258,14 @@ class CardLayout(QDialog):
if self.tform.front_button.isChecked(): if self.tform.front_button.isChecked():
self.current_editor_index = 0 self.current_editor_index = 0
self.pform.preview_front.setChecked(True) self.pform.preview_front.setChecked(True)
self.add_field_button.setHidden(False)
elif self.tform.back_button.isChecked(): elif self.tform.back_button.isChecked():
self.current_editor_index = 1 self.current_editor_index = 1
self.pform.preview_back.setChecked(True) self.pform.preview_back.setChecked(True)
self.add_field_button.setHidden(False)
else: else:
self.current_editor_index = 2 self.current_editor_index = 2
self.add_field_button.setHidden(True)
self.fill_fields_from_template() self.fill_fields_from_template()
@ -329,10 +332,10 @@ class CardLayout(QDialog):
l.addWidget(help) l.addWidget(help)
qconnect(help.clicked, self.onHelp) qconnect(help.clicked, self.onHelp)
l.addStretch() l.addStretch()
addField = QPushButton(_("Add Field")) self.add_field_button = QPushButton(_("Add Field"))
addField.setAutoDefault(False) self.add_field_button.setAutoDefault(False)
l.addWidget(addField) l.addWidget(self.add_field_button)
qconnect(addField.clicked, self.onAddField) qconnect(self.add_field_button.clicked, self.onAddField)
if not self._isCloze(): if not self._isCloze():
flip = QPushButton(_("Flip")) flip = QPushButton(_("Flip"))
flip.setAutoDefault(False) flip.setAutoDefault(False)
@ -662,38 +665,27 @@ Enter deck to place new %s cards in, or leave blank:"""
form.setupUi(diag) form.setupUi(diag)
fields = [f["name"] for f in self.model["flds"]] fields = [f["name"] for f in self.model["flds"]]
form.fields.addItems(fields) form.fields.addItems(fields)
form.fields.setCurrentRow(0)
form.font.setCurrentFont(QFont("Arial")) form.font.setCurrentFont(QFont("Arial"))
form.size.setValue(20) form.size.setValue(20)
diag.show()
# Work around a Qt bug,
# https://bugreports.qt-project.org/browse/QTBUG-1894
if isMac or isWin:
# No problems on Macs or Windows.
form.fields.showPopup()
else:
# Delay showing the pop-up.
self.mw.progress.timer(200, form.fields.showPopup, False)
if not diag.exec_(): if not diag.exec_():
return return
if form.radioQ.isChecked(): row = form.fields.currentIndex().row()
obj = self.tform.front if row >= 0:
else:
obj = self.tform.back
self._addField( self._addField(
obj, fields[row],
fields[form.fields.currentIndex()],
form.font.currentFont().family(), form.font.currentFont().family(),
form.size.value(), form.size.value(),
) )
def _addField(self, widg, field, font, size): def _addField(self, field, font, size):
t = widg.toPlainText() text = self.tform.edit_area.toPlainText()
t += "\n<div style='font-family: %s; font-size: %spx;'>{{%s}}</div>\n" % ( text += "\n<div style='font-family: %s; font-size: %spx;'>{{%s}}</div>\n" % (
font, font,
size, size,
field, field,
) )
widg.setPlainText(t) self.tform.edit_area.setPlainText(text)
self.changed = True self.changed = True
self.write_edits_to_template_and_redraw() self.write_edits_to_template_and_redraw()

View File

@ -16,26 +16,6 @@
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QRadioButton" name="radioQ">
<property name="text">
<string>Front</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="size">
<property name="minimum">
<number>6</number>
</property>
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -43,16 +23,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Font:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFontComboBox" name="font"/>
</item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
@ -60,10 +30,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="fields"/> <widget class="QFontComboBox" name="font"/>
</item> </item>
<item row="5" column="1"> <item row="3" column="1">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -76,17 +46,23 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="4" column="1"> <item row="1" column="0">
<widget class="QRadioButton" name="radioA"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Back</string> <string>Font:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="0" column="1">
<widget class="QLabel" name="label_4"> <widget class="QListWidget" name="fields"/>
<property name="text"> </item>
<string>Add to:</string> <item row="2" column="1">
<widget class="QSpinBox" name="size">
<property name="minimum">
<number>6</number>
</property>
<property name="maximum">
<number>200</number>
</property> </property>
</widget> </widget>
</item> </item>
@ -108,9 +84,6 @@
<tabstop>fields</tabstop> <tabstop>fields</tabstop>
<tabstop>font</tabstop> <tabstop>font</tabstop>
<tabstop>size</tabstop> <tabstop>size</tabstop>
<tabstop>radioQ</tabstop>
<tabstop>radioA</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>