add whitespace preservation option & stateChange handlers

This commit is contained in:
Damien Elmes 2010-11-30 03:30:21 +09:00
parent 59ab5f9abb
commit e8aa1432e2
3 changed files with 23 additions and 6 deletions

View file

@ -241,8 +241,7 @@ order by n""", id=card.id)
return
pass
styles = (self.deck.rebuildCSS() +
("\nhtml { background: %s }" % c.cardModel.lastFontColour) +
"\ndiv { white-space: pre-wrap; }")
("\nhtml { background: %s }" % c.cardModel.lastFontColour))
styles = runFilter("addStyles", styles, c)
self.form.preview.setHtml(
('<html><head>%s</head><body>' % getBase(self.deck, c)) +
@ -316,6 +315,14 @@ order by n""", id=card.id)
self.saveField)
self.connect(self.form.fieldName, SIGNAL("textEdited(QString)"),
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.connect(self.form.numeric, SIGNAL("stateChanged(int)"),
self.saveField)
w = self.form.fontColour
if self.plastiqueStyle:
w.setStyle(self.plastiqueStyle)
@ -346,11 +353,13 @@ order by n""", id=card.id)
self.form.fontColour.setPalette(QPalette(QColor(
field.quizFontColour or "#000000")))
self.form.rtl.setChecked(not not field.features)
self.form.preserveWhitespace.setChecked(not not field.editFontFamily)
def saveField(self, *args):
self.needFieldRebuild = True
if self.updatingFields:
return
self.updatingFields = True
field = self.field
name = unicode(self.form.fieldName.text()) or _("Field")
if field.name != name:
@ -370,10 +379,12 @@ order by n""", id=card.id)
field.features = u"rtl"
else:
field.features = u""
field.editFontFamily = self.form.preserveWhitespace.isChecked()
field.model.setModified()
self.deck.flushMod()
self.renderPreview()
self.fillFieldList()
self.updatingFields = False
def fillFieldList(self, row = None):
oldRow = self.form.fieldList.currentRow()

View file

@ -84,7 +84,6 @@ class View(object):
s = "<style>\n"
if self.main.deck:
s += self.main.deck.css
s += "div { white-space: pre-wrap; }\n"
s = runFilter("addStyles", s, self.main.currentCard)
s += "</style>"
return s

View file

@ -443,14 +443,14 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QCheckBox" name="rtl">
<property name="text">
<string>Reverse text direction (RTL)</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QCheckBox" name="numeric">
<property name="text">
<string>Sort as numbers in browser</string>
@ -471,6 +471,13 @@
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="preserveWhitespace">
<property name="text">
<string>Preserve whitespace</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -575,9 +582,9 @@
<tabstop>fontColour</tabstop>
<tabstop>fieldUnique</tabstop>
<tabstop>fieldRequired</tabstop>
<tabstop>preserveWhitespace</tabstop>
<tabstop>numeric</tabstop>
<tabstop>rtl</tabstop>
<tabstop>preview</tabstop>
</tabstops>
<resources>
<include location="../icons.qrc"/>