allow individual fields to be marked sticky instead of adding a separate button

This commit is contained in:
Damien Elmes 2011-04-17 05:22:21 +09:00
parent 4a931f811f
commit 9bae1503bb
3 changed files with 37 additions and 38 deletions

View file

@ -61,12 +61,6 @@ class AddCards(QDialog):
self.addButton.setShortcut(QKeySequence("Ctrl+Return")) self.addButton.setShortcut(QKeySequence("Ctrl+Return"))
self.addButton.setToolTip(shortcut(_("Add (shortcut: ctrl+enter)"))) self.addButton.setToolTip(shortcut(_("Add (shortcut: ctrl+enter)")))
self.connect(self.addButton, SIGNAL("clicked()"), self.addCards) self.connect(self.addButton, SIGNAL("clicked()"), self.addCards)
# add+keep
self.addKeepButton = bb.addButton(_("Add&&Keep"), ar)
self.addKeepButton.setShortcut(_("Ctrl+Shift+Return"))
self.addKeepButton.setToolTip(shortcut(
_("Add and keep entered text (shortcut: ctrl+shift+enter)")))
self.connect(self.addKeepButton, SIGNAL("clicked()"), self.addKeep)
# close # close
self.closeButton = QPushButton(_("Close")) self.closeButton = QPushButton(_("Close"))
self.closeButton.setAutoDefault(False) self.closeButton.setAutoDefault(False)
@ -98,13 +92,17 @@ class AddCards(QDialog):
def onReset(self, model=None, keep=False): def onReset(self, model=None, keep=False):
oldFact = self.editor.fact oldFact = self.editor.fact
fact = self.setupNewFact(set=False) fact = self.setupNewFact(set=False)
flds = fact.model().fields
# copy fields from old fact # copy fields from old fact
if oldFact: if oldFact:
if not keep: if not keep:
self.removeTempFact(oldFact) self.removeTempFact(oldFact)
for n in range(len(fact.fields)): for n in range(len(fact.fields)):
try: try:
fact.fields[n] = oldFact.fields[n] if not keep or flds[n]['sticky']:
fact.fields[n] = oldFact.fields[n]
else:
fact.fields[n] = ""
except IndexError: except IndexError:
break break
self.editor.setFact(fact) self.editor.setFact(fact)
@ -150,10 +148,7 @@ question or answer on all cards."""), help="AddItems")
# FIXME: return to overview on add? # FIXME: return to overview on add?
return fact return fact
def addKeep(self): def addCards(self):
self.addCards(keep=True)
def addCards(self, keep=False):
self.editor.saveNow() self.editor.saveNow()
fact = self.editor.fact fact = self.editor.fact
fact = self.addFact(fact) fact = self.addFact(fact)
@ -162,10 +157,7 @@ question or answer on all cards."""), help="AddItems")
tooltip("Added", period=500) tooltip("Added", period=500)
# stop anything playing # stop anything playing
clearAudioQueue() clearAudioQueue()
if keep: self.onReset(keep=True)
self.onReset(keep=True)
else:
self.setupNewFact()
self.mw.deck.autosave() self.mw.deck.autosave()
def keyPressEvent(self, evt): def keyPressEvent(self, evt):

View file

@ -277,36 +277,33 @@ class CardLayout(QDialog):
self.fieldOrdinalUpdatedIds = [] self.fieldOrdinalUpdatedIds = []
self.updatingFields = False self.updatingFields = False
self.needFieldRebuild = False self.needFieldRebuild = False
self.connect(self.form.fieldList, SIGNAL("currentRowChanged(int)"), c = self.connect; f = self.form
sc = SIGNAL("stateChanged(int)")
cl = SIGNAL("clicked()")
c(f.fieldAdd, cl, self.addField)
c(f.fieldDelete, cl, self.deleteField)
c(f.fieldUp, cl, self.moveFieldUp)
c(f.fieldDown, cl, self.moveFieldDown)
c(f.preserveWhitespace, sc, self.saveField)
c(f.fieldUnique, sc, self.saveField)
c(f.fieldRequired, sc, self.saveField)
c(f.sticky, sc, self.saveField)
c(f.fieldList, SIGNAL("currentRowChanged(int)"),
self.fieldChanged) self.fieldChanged)
self.connect(self.form.fieldAdd, SIGNAL("clicked()"), c(f.fieldName, SIGNAL("lostFocus()"),
self.addField)
self.connect(self.form.fieldDelete, SIGNAL("clicked()"),
self.deleteField)
self.connect(self.form.fieldUp, SIGNAL("clicked()"),
self.moveFieldUp)
self.connect(self.form.fieldDown, SIGNAL("clicked()"),
self.moveFieldDown)
self.connect(self.form.fieldName, SIGNAL("lostFocus()"),
self.saveField) self.saveField)
self.connect(self.form.fontFamily, SIGNAL("currentFontChanged(QFont)"), c(f.fontFamily, SIGNAL("currentFontChanged(QFont)"),
self.saveField) self.saveField)
self.connect(self.form.fontSize, SIGNAL("valueChanged(int)"), c(f.fontSize, SIGNAL("valueChanged(int)"),
self.saveField) self.saveField)
self.connect(self.form.fontSizeEdit, SIGNAL("valueChanged(int)"), c(f.fontSizeEdit, SIGNAL("valueChanged(int)"),
self.saveField)
self.connect(self.form.preserveWhitespace, SIGNAL("stateChanged(int)"),
self.saveField)
self.connect(self.form.fieldUnique, SIGNAL("stateChanged(int)"),
self.saveField)
self.connect(self.form.fieldRequired, SIGNAL("stateChanged(int)"),
self.saveField) self.saveField)
w = self.form.fontColour w = self.form.fontColour
if self.plastiqueStyle: if self.plastiqueStyle:
w.setStyle(self.plastiqueStyle) w.setStyle(self.plastiqueStyle)
self.connect(w, SIGNAL("clicked()"), c(w, SIGNAL("clicked()"),
lambda w=w: self.chooseColour(w)) lambda w=w: self.chooseColour(w))
self.connect(self.form.rtl, c(self.form.rtl,
SIGNAL("stateChanged(int)"), SIGNAL("stateChanged(int)"),
self.saveField) self.saveField)
@ -331,6 +328,7 @@ class CardLayout(QDialog):
f.fontColour.setPalette(QPalette(QColor(fld['qcol']))) f.fontColour.setPalette(QPalette(QColor(fld['qcol'])))
f.rtl.setChecked(fld['rtl']) f.rtl.setChecked(fld['rtl'])
f.preserveWhitespace.setChecked(fld['pre']) f.preserveWhitespace.setChecked(fld['pre'])
f.sticky.setChecked(fld['sticky'])
self.updatingFields = False self.updatingFields = False
def saveField(self, *args): def saveField(self, *args):
@ -353,6 +351,7 @@ class CardLayout(QDialog):
self.form.fontColour.palette().window().color().name()) self.form.fontColour.palette().window().color().name())
fld['rtl'] = self.form.rtl.isChecked() fld['rtl'] = self.form.rtl.isChecked()
fld['pre'] = self.form.preserveWhitespace.isChecked() fld['pre'] = self.form.preserveWhitespace.isChecked()
fld['sticky'] = self.form.sticky.isChecked()
self.updatingFields = False self.updatingFields = False
if fld['name'] != name: if fld['name'] != name:
self.model.renameField(fld, name) self.model.renameField(fld, name)

View file

@ -436,7 +436,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="8" column="1">
<widget class="QCheckBox" name="rtl"> <widget class="QCheckBox" name="rtl">
<property name="text"> <property name="text">
<string>Reverse text direction (RTL)</string> <string>Reverse text direction (RTL)</string>
@ -457,13 +457,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="7" column="1">
<widget class="QCheckBox" name="preserveWhitespace"> <widget class="QCheckBox" name="preserveWhitespace">
<property name="text"> <property name="text">
<string>Preserve whitespace</string> <string>Preserve whitespace</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1">
<widget class="QCheckBox" name="sticky">
<property name="text">
<string>Keep previous input when adding cards</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -565,6 +572,7 @@
<tabstop>fontColour</tabstop> <tabstop>fontColour</tabstop>
<tabstop>fieldUnique</tabstop> <tabstop>fieldUnique</tabstop>
<tabstop>fieldRequired</tabstop> <tabstop>fieldRequired</tabstop>
<tabstop>sticky</tabstop>
<tabstop>preserveWhitespace</tabstop> <tabstop>preserveWhitespace</tabstop>
<tabstop>rtl</tabstop> <tabstop>rtl</tabstop>
</tabstops> </tabstops>