mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
allow browser font customization on a per-template basis
This commit is contained in:
parent
eced132aa2
commit
d11a1e0d54
4 changed files with 55 additions and 7 deletions
|
@ -62,6 +62,8 @@ defaultTemplate = {
|
|||
'did': None,
|
||||
'bqfmt': "",
|
||||
'bafmt': "",
|
||||
'bfont': "Arial",
|
||||
'bsize': 12,
|
||||
}
|
||||
|
||||
class ModelManager(object):
|
||||
|
|
|
@ -64,8 +64,17 @@ class DataModel(QAbstractTableModel):
|
|||
if not index.isValid():
|
||||
return
|
||||
if role == Qt.FontRole:
|
||||
return
|
||||
if role == Qt.TextAlignmentRole:
|
||||
if self.activeCols[index.column()] not in (
|
||||
"question", "answer", "noteFld"):
|
||||
return
|
||||
f = QFont()
|
||||
row = index.row()
|
||||
c = self.getCard(index)
|
||||
t = c.template()
|
||||
f.setFamily(t.get("bfont", "Arial"))
|
||||
f.setPixelSize(t.get("bsize", 12))
|
||||
return f
|
||||
elif role == Qt.TextAlignmentRole:
|
||||
align = Qt.AlignVCenter
|
||||
if self.activeCols[index.column()] not in ("question", "answer",
|
||||
"template", "deck", "noteFld", "note"):
|
||||
|
|
|
@ -320,7 +320,7 @@ adjust the template manually to switch the question and answer."""))
|
|||
a = m.addAction(_("Deck Override") + s)
|
||||
a.connect(a, SIGNAL("triggered()"),
|
||||
self.onTargetDeck)
|
||||
a = m.addAction(_("Column Templates"))
|
||||
a = m.addAction(_("Browser Appearance"))
|
||||
a.connect(a, SIGNAL("triggered()"),
|
||||
self.onBrowserDisplay)
|
||||
if self.model['type'] != MODEL_CLOZE:
|
||||
|
@ -336,6 +336,8 @@ adjust the template manually to switch the question and answer."""))
|
|||
t = self.card.template()
|
||||
f.qfmt.setText(t.get('bqfmt', ""))
|
||||
f.afmt.setText(t.get('bafmt', ""))
|
||||
f.font.setCurrentFont(QFont(t.get('bfont', "Arial")))
|
||||
f.fontSize.setValue(t.get('bsize', 12))
|
||||
d.connect(f.buttonBox, SIGNAL("accepted()"),
|
||||
lambda: self.onBrowserDisplayOk(f))
|
||||
d.exec_()
|
||||
|
@ -344,6 +346,8 @@ adjust the template manually to switch the question and answer."""))
|
|||
t = self.card.template()
|
||||
t['bqfmt'] = f.qfmt.text().strip()
|
||||
t['bafmt'] = f.afmt.text().strip()
|
||||
t['bfont'] = f.font.currentFont().family()
|
||||
t['bsize'] = f.fontSize.value()
|
||||
|
||||
def onTargetDeck(self):
|
||||
from aqt.tagedit import TagEdit
|
||||
|
|
|
@ -7,17 +7,17 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>412</width>
|
||||
<height>204</height>
|
||||
<height>241</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Column Templates</string>
|
||||
<string>Browser Appearance</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Template for front column in browser:</string>
|
||||
<string>Override front template:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -27,13 +27,44 @@
|
|||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Template for back column in browser:</string>
|
||||
<string>Override back template:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="afmt"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Override font:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFontComboBox" name="font">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>5</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="fontSize">
|
||||
<property name="minimum">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>18</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
@ -62,6 +93,8 @@
|
|||
<tabstops>
|
||||
<tabstop>qfmt</tabstop>
|
||||
<tabstop>afmt</tabstop>
|
||||
<tabstop>font</tabstop>
|
||||
<tabstop>fontSize</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
|
Loading…
Reference in a new issue