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

View file

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

View file

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