mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 09:16:38 -04:00
added foreground setting / remove formatting and some icons
foreground setting is not sticky due to webkit issues
This commit is contained in:
parent
a2ea00ef43
commit
e0c4c9e896
6 changed files with 41 additions and 47 deletions
|
@ -34,8 +34,8 @@ String.prototype.format = function() {
|
||||||
var currentField = null;
|
var currentField = null;
|
||||||
var changeTimer = null;
|
var changeTimer = null;
|
||||||
|
|
||||||
function keyUp() {
|
function onKey() {
|
||||||
// esc clears focus
|
// esc clears focus, allowing dialog to close
|
||||||
if (window.event.which == 27) {
|
if (window.event.which == 27) {
|
||||||
currentField.blur();
|
currentField.blur();
|
||||||
return;
|
return;
|
||||||
|
@ -103,7 +103,7 @@ function setFields(fields) {
|
||||||
var n = fields[i][0];
|
var n = fields[i][0];
|
||||||
var f = fields[i][1];
|
var f = fields[i][1];
|
||||||
txt += "<tr><td class=fname>{0}</td><td width=100%%>".format(n);
|
txt += "<tr><td class=fname>{0}</td><td width=100%%>".format(n);
|
||||||
txt += "<div id=f{0} onkeyup='keyUp();' onmouseup='keyUp();'".format(i);
|
txt += "<div id=f{0} onkeydown='onKey();' onmouseup='onKey();'".format(i);
|
||||||
txt += " onfocus='onFocus(this);' onblur='onBlur();' class=field ";
|
txt += " onfocus='onFocus(this);' onblur='onBlur();' class=field ";
|
||||||
txt += "contentEditable=true>{0}</div>".format(f);
|
txt += "contentEditable=true>{0}</div>".format(f);
|
||||||
txt += "</td></tr>";
|
txt += "</td></tr>";
|
||||||
|
@ -211,7 +211,10 @@ class Editor(object):
|
||||||
_("Superscript (Ctrl+=)"), check=True)
|
_("Superscript (Ctrl+=)"), check=True)
|
||||||
b("text_sub", self.toggleSub, "Ctrl+Shift+=",
|
b("text_sub", self.toggleSub, "Ctrl+Shift+=",
|
||||||
_("Subscript (Ctrl+Shift+=)"), check=True)
|
_("Subscript (Ctrl+Shift+=)"), check=True)
|
||||||
#self.setupForegroundButton()
|
b("text_remove", self.removeFormat, "Ctrl+r",
|
||||||
|
_("Subscript (Ctrl+r)"))
|
||||||
|
but = b("foreground", self.onForeground, "F7", text=" ")
|
||||||
|
self.setupForegroundButton(but)
|
||||||
but = b("cloze", self.onCloze, "F9", _("Cloze (F9)"), text="[...]")
|
but = b("cloze", self.onCloze, "F9", _("Cloze (F9)"), text="[...]")
|
||||||
but.setFixedWidth(24)
|
but.setFixedWidth(24)
|
||||||
# fixme: better image names
|
# fixme: better image names
|
||||||
|
@ -222,27 +225,14 @@ class Editor(object):
|
||||||
# insertLatex, insertLatexEqn, insertLatexMathEnv
|
# insertLatex, insertLatexEqn, insertLatexMathEnv
|
||||||
but = b("text-xml", self.onHtmlEdit, "Ctrl+x", _("Source (Ctrl+x)"))
|
but = b("text-xml", self.onHtmlEdit, "Ctrl+x", _("Source (Ctrl+x)"))
|
||||||
|
|
||||||
def setupForegroundButton(self):
|
def setupForegroundButton(self, but):
|
||||||
# foreground color
|
|
||||||
self.foreground = QPushButton()
|
|
||||||
self.foreground.connect(self.foreground, SIGNAL("clicked()"), self.onForeground)
|
|
||||||
self.foreground.setToolTip(
|
|
||||||
_("Set colour (F7; repeat to choose next; F6 to use)"))
|
|
||||||
self.foreground.setShortcut(_("F7"))
|
|
||||||
self.foreground.setFocusPolicy(Qt.NoFocus)
|
|
||||||
self.foreground.setEnabled(False)
|
|
||||||
self.foreground.setFixedWidth(20)
|
|
||||||
self.foreground.setFixedHeight(20)
|
|
||||||
self.foregroundFrame = QFrame()
|
self.foregroundFrame = QFrame()
|
||||||
self.foregroundFrame.setAutoFillBackground(True)
|
self.foregroundFrame.setAutoFillBackground(True)
|
||||||
self.colourChanged()
|
self.colourChanged()
|
||||||
hbox = QHBoxLayout()
|
hbox = QHBoxLayout()
|
||||||
hbox.addWidget(self.foregroundFrame)
|
hbox.addWidget(self.foregroundFrame)
|
||||||
hbox.setMargin(5)
|
hbox.setMargin(5)
|
||||||
self.foreground.setLayout(hbox)
|
but.setLayout(hbox)
|
||||||
self.iconsBox.addWidget(self.foreground)
|
|
||||||
self.foreground.setStyle(self.plastiqueStyle)
|
|
||||||
self.iconsBox.addItem(QSpacerItem(5,1, QSizePolicy.Fixed))
|
|
||||||
|
|
||||||
def setupWeb(self):
|
def setupWeb(self):
|
||||||
self.web = AnkiWebView(self.widget)
|
self.web = AnkiWebView(self.widget)
|
||||||
|
@ -417,7 +407,7 @@ class Editor(object):
|
||||||
self.fact.setModified(textChanged=True, deck=self.deck)
|
self.fact.setModified(textChanged=True, deck=self.deck)
|
||||||
self.loadFields(font=False)
|
self.loadFields(font=False)
|
||||||
if modified:
|
if modified:
|
||||||
aqt.mw.reset(runHooks=False)
|
self.mw.reset(runHooks=False)
|
||||||
|
|
||||||
def onTextChanged(self):
|
def onTextChanged(self):
|
||||||
interval = 250
|
interval = 250
|
||||||
|
@ -509,7 +499,7 @@ class Editor(object):
|
||||||
self.deck.updateFactTags([self.fact.id])
|
self.deck.updateFactTags([self.fact.id])
|
||||||
self.fact.setModified(textChanged=True, deck=self.deck)
|
self.fact.setModified(textChanged=True, deck=self.deck)
|
||||||
self.deck.flushMod()
|
self.deck.flushMod()
|
||||||
aqt.mw.reset(runHooks=False)
|
self.mw.reset(runHooks=False)
|
||||||
if self.onChange:
|
if self.onChange:
|
||||||
self.onChange('tag')
|
self.onChange('tag')
|
||||||
|
|
||||||
|
@ -574,19 +564,21 @@ class Editor(object):
|
||||||
def toggleSub(self, bool):
|
def toggleSub(self, bool):
|
||||||
self.web.eval("setFormat('subscript');")
|
self.web.eval("setFormat('subscript');")
|
||||||
|
|
||||||
|
def removeFormat(self):
|
||||||
|
self.web.eval("setFormat('removeFormat');")
|
||||||
|
|
||||||
def _updateForegroundButton(self, txtcol):
|
def _updateForegroundButton(self, txtcol):
|
||||||
self.foregroundFrame.setPalette(QPalette(QColor(txtcol)))
|
self.foregroundFrame.setPalette(QPalette(QColor(txtcol)))
|
||||||
self.foregroundFrame.setStyleSheet("* {background-color: %s}" %
|
self.foregroundFrame.setStyleSheet("* {background-color: %s}" %
|
||||||
txtcol)
|
txtcol)
|
||||||
|
|
||||||
def colourChanged(self):
|
def colourChanged(self):
|
||||||
recent = aqt.mw.config['recentColours']
|
recent = self.mw.config['recentColours']
|
||||||
self._updateForegroundButton(recent[-1])
|
self._updateForegroundButton(recent[-1])
|
||||||
|
|
||||||
def onForeground(self):
|
def onForeground(self):
|
||||||
self.lastFocusedEdit = self.focusedEdit()
|
p = ColourPopup(self.widget)
|
||||||
p = ColourPopup(self.parent)
|
p.move(self.foregroundFrame.mapToGlobal(QPoint(0,0)))
|
||||||
p.move(self.foreground.mapToGlobal(QPoint(0,0)))
|
|
||||||
g = QGridLayout(p)
|
g = QGridLayout(p)
|
||||||
g.setMargin(4)
|
g.setMargin(4)
|
||||||
g.setSpacing(0)
|
g.setSpacing(0)
|
||||||
|
@ -598,7 +590,7 @@ class Editor(object):
|
||||||
self.colourChoose = QShortcut(QKeySequence("F6"), p)
|
self.colourChoose = QShortcut(QKeySequence("F6"), p)
|
||||||
p.connect(self.colourChoose, SIGNAL("activated()"),
|
p.connect(self.colourChoose, SIGNAL("activated()"),
|
||||||
self.onChooseColourKey)
|
self.onChooseColourKey)
|
||||||
for n, c in enumerate(reversed(aqt.mw.config['recentColours'])):
|
for n, c in enumerate(reversed(self.mw.config['recentColours'])):
|
||||||
col = QToolButton()
|
col = QToolButton()
|
||||||
col.setAutoRaise(True)
|
col.setAutoRaise(True)
|
||||||
col.setFixedWidth(64)
|
col.setFixedWidth(64)
|
||||||
|
@ -632,7 +624,7 @@ class Editor(object):
|
||||||
p.show()
|
p.show()
|
||||||
|
|
||||||
def onRemoveColour(self, colour):
|
def onRemoveColour(self, colour):
|
||||||
recent = aqt.mw.config['recentColours']
|
recent = self.mw.config['recentColours']
|
||||||
recent.remove(colour)
|
recent.remove(colour)
|
||||||
if not recent:
|
if not recent:
|
||||||
recent.append("#000000")
|
recent.append("#000000")
|
||||||
|
@ -654,18 +646,17 @@ class Editor(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def onChooseColour(self, colour):
|
def onChooseColour(self, colour):
|
||||||
recent = aqt.mw.config['recentColours']
|
recent = self.mw.config['recentColours']
|
||||||
recent.remove(colour)
|
recent.remove(colour)
|
||||||
recent.append(colour)
|
recent.append(colour)
|
||||||
w = self.lastFocusedEdit
|
self.web.eval("setFormat('forecolor', '%s')" % colour)
|
||||||
w.setTextColor(QColor(colour))
|
|
||||||
self.colourDiag.close()
|
self.colourDiag.close()
|
||||||
runHook("colourChanged")
|
runHook("colourChanged")
|
||||||
|
|
||||||
def onNewColour(self):
|
def onNewColour(self):
|
||||||
new = QColorDialog.getColor(Qt.white, self.parent)
|
new = QColorDialog.getColor(Qt.white, self.widget)
|
||||||
self.parent.raise_()
|
self.widget.raise_()
|
||||||
recent = aqt.mw.config['recentColours']
|
recent = self.mw.config['recentColours']
|
||||||
if new.isValid():
|
if new.isValid():
|
||||||
txtcol = unicode(new.name())
|
txtcol = unicode(new.name())
|
||||||
if txtcol not in recent:
|
if txtcol not in recent:
|
||||||
|
@ -712,7 +703,7 @@ class Editor(object):
|
||||||
def onMore(self, toggle=None):
|
def onMore(self, toggle=None):
|
||||||
if toggle is None:
|
if toggle is None:
|
||||||
toggle = not self.latex.isVisible()
|
toggle = not self.latex.isVisible()
|
||||||
aqt.mw.config['factEditorAdvanced'] = toggle
|
self.mw.config['factEditorAdvanced'] = toggle
|
||||||
self.latex.setShown(toggle)
|
self.latex.setShown(toggle)
|
||||||
self.latexEqn.setShown(toggle)
|
self.latexEqn.setShown(toggle)
|
||||||
self.latexMathEnv.setShown(toggle)
|
self.latexMathEnv.setShown(toggle)
|
||||||
|
@ -777,14 +768,14 @@ class Editor(object):
|
||||||
ui.utils.showInfo(
|
ui.utils.showInfo(
|
||||||
_("Next field must be blank."),
|
_("Next field must be blank."),
|
||||||
help="ClozeDeletion",
|
help="ClozeDeletion",
|
||||||
parent=self.parent)
|
parent=self.widget)
|
||||||
return
|
return
|
||||||
# check if there's anything to change
|
# check if there's anything to change
|
||||||
if not re.search("\[.+?\]", unicode(src.toPlainText())):
|
if not re.search("\[.+?\]", unicode(src.toPlainText())):
|
||||||
ui.utils.showInfo(
|
ui.utils.showInfo(
|
||||||
_("You didn't specify anything to occlude."),
|
_("You didn't specify anything to occlude."),
|
||||||
help="ClozeDeletion",
|
help="ClozeDeletion",
|
||||||
parent=self.parent)
|
parent=self.widget)
|
||||||
return
|
return
|
||||||
# create
|
# create
|
||||||
s = unicode(src.toHtml())
|
s = unicode(src.toHtml())
|
||||||
|
@ -809,7 +800,7 @@ class Editor(object):
|
||||||
w = self.focusedEdit()
|
w = self.focusedEdit()
|
||||||
if w:
|
if w:
|
||||||
self.saveFields()
|
self.saveFields()
|
||||||
d = QDialog(self.parent)
|
d = QDialog(self.widget)
|
||||||
form = aqt.forms.edithtml.Ui_Dialog()
|
form = aqt.forms.edithtml.Ui_Dialog()
|
||||||
form.setupUi(d)
|
form.setupUi(d)
|
||||||
d.connect(form.buttonBox, SIGNAL("helpRequested()"),
|
d.connect(form.buttonBox, SIGNAL("helpRequested()"),
|
||||||
|
@ -833,7 +824,7 @@ class Editor(object):
|
||||||
w = self.focusedEdit()
|
w = self.focusedEdit()
|
||||||
key = (_("Images") +
|
key = (_("Images") +
|
||||||
" (*.jpg *.png *.gif *.tiff *.svg *.tif *.jpeg)")
|
" (*.jpg *.png *.gif *.tiff *.svg *.tif *.jpeg)")
|
||||||
file = ui.utils.getFile(self.parent, _("Add an image"), "picture", key)
|
file = ui.utils.getFile(self.widget, _("Add an image"), "picture", key)
|
||||||
if not file:
|
if not file:
|
||||||
return
|
return
|
||||||
if file.lower().endswith(".svg"):
|
if file.lower().endswith(".svg"):
|
||||||
|
@ -864,7 +855,7 @@ class Editor(object):
|
||||||
return self.deck.addMedia(file)
|
return self.deck.addMedia(file)
|
||||||
except (IOError, OSError), e:
|
except (IOError, OSError), e:
|
||||||
ui.utils.showWarning(_("Unable to add media: %s") % unicode(e),
|
ui.utils.showWarning(_("Unable to add media: %s") % unicode(e),
|
||||||
parent=self.parent)
|
parent=self.widget)
|
||||||
|
|
||||||
def onAddSound(self):
|
def onAddSound(self):
|
||||||
# get this before we open the dialog
|
# get this before we open the dialog
|
||||||
|
@ -872,7 +863,7 @@ class Editor(object):
|
||||||
key = (_("Sounds/Videos") +
|
key = (_("Sounds/Videos") +
|
||||||
" (*.mp3 *.ogg *.wav *.avi *.ogv *.mpg *.mpeg *.mov *.mp4 " +
|
" (*.mp3 *.ogg *.wav *.avi *.ogv *.mpg *.mpeg *.mov *.mp4 " +
|
||||||
"*.mkv *.ogx *.ogv *.oga *.flv *.swf *.flac)")
|
"*.mkv *.ogx *.ogv *.oga *.flv *.swf *.flac)")
|
||||||
file = ui.utils.getFile(self.parent, _("Add audio"), "audio", key)
|
file = ui.utils.getFile(self.widget, _("Add audio"), "audio", key)
|
||||||
if not file:
|
if not file:
|
||||||
return
|
return
|
||||||
self._addSound(file, widget=w)
|
self._addSound(file, widget=w)
|
||||||
|
@ -892,7 +883,7 @@ class Editor(object):
|
||||||
w.insertHtml('[sound:%s]' % path)
|
w.insertHtml('[sound:%s]' % path)
|
||||||
|
|
||||||
def maybeDelete(self, new, old):
|
def maybeDelete(self, new, old):
|
||||||
if not aqt.mw.config['deleteMedia']:
|
if not self.mw.config['deleteMedia']:
|
||||||
return
|
return
|
||||||
if new == os.path.basename(old):
|
if new == os.path.basename(old):
|
||||||
return
|
return
|
||||||
|
@ -905,12 +896,12 @@ class Editor(object):
|
||||||
self.initMedia()
|
self.initMedia()
|
||||||
w = self.focusedEdit()
|
w = self.focusedEdit()
|
||||||
try:
|
try:
|
||||||
file = getAudio(self.parent)
|
file = getAudio(self.widget)
|
||||||
except:
|
except:
|
||||||
if sys.platform.startswith("darwin"):
|
if sys.platform.startswith("darwin"):
|
||||||
ui.utils.showInfo(_('''\
|
ui.utils.showInfo(_('''\
|
||||||
Please install <a href="http://www.thalictrum.com/software/lame-3.97.dmg.gz">lame</a>
|
Please install <a href="http://www.thalictrum.com/software/lame-3.97.dmg.gz">lame</a>
|
||||||
to enable recording.'''), parent=self.parent)
|
to enable recording.'''), parent=self.widget)
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
if file:
|
if file:
|
||||||
|
@ -942,7 +933,7 @@ class FactEdit(QTextEdit):
|
||||||
if source.hasHtml() and "qrichtext" in unicode(source.html()):
|
if source.hasHtml() and "qrichtext" in unicode(source.html()):
|
||||||
self.insertHtml(source.html())
|
self.insertHtml(source.html())
|
||||||
return True
|
return True
|
||||||
if source.hasText() and (aqt.mw.config['stripHTML'] or
|
if source.hasText() and (self.mw.config['stripHTML'] or
|
||||||
not source.hasHtml()):
|
not source.hasHtml()):
|
||||||
txt = unicode(source.text())
|
txt = unicode(source.text())
|
||||||
l = txt.lower()
|
l = txt.lower()
|
||||||
|
@ -1022,7 +1013,7 @@ class FactEdit(QTextEdit):
|
||||||
def simplifyHTML(self, html):
|
def simplifyHTML(self, html):
|
||||||
"Remove all style information and P tags."
|
"Remove all style information and P tags."
|
||||||
# fixme
|
# fixme
|
||||||
if not aqt.mw.config['stripHTML']:
|
if not self.mw.config['stripHTML']:
|
||||||
return html
|
return html
|
||||||
html = re.sub("\n", " ", html)
|
html = re.sub("\n", " ", html)
|
||||||
html = re.sub("<br ?/?>", "\n", html)
|
html = re.sub("<br ?/?>", "\n", html)
|
||||||
|
@ -1038,7 +1029,7 @@ class FactEdit(QTextEdit):
|
||||||
self.parent.lastFocusedEdit = self
|
self.parent.lastFocusedEdit = self
|
||||||
self.parent.resetFormatButtons()
|
self.parent.resetFormatButtons()
|
||||||
self.parent.disableButtons()
|
self.parent.disableButtons()
|
||||||
if aqt.mw.config['preserveKeyboard'] and sys.platform.startswith("win32"):
|
if self.mw.config['preserveKeyboard'] and sys.platform.startswith("win32"):
|
||||||
self._ownLayout = GetKeyboardLayout(0)
|
self._ownLayout = GetKeyboardLayout(0)
|
||||||
ActivateKeyboardLayout(self._programLayout, 0)
|
ActivateKeyboardLayout(self._programLayout, 0)
|
||||||
self.emit(SIGNAL("lostFocus"))
|
self.emit(SIGNAL("lostFocus"))
|
||||||
|
@ -1058,7 +1049,7 @@ class FactEdit(QTextEdit):
|
||||||
QTextEdit.focusInEvent(self, evt)
|
QTextEdit.focusInEvent(self, evt)
|
||||||
self.parent.formatChanged(None)
|
self.parent.formatChanged(None)
|
||||||
self.parent.enableButtons()
|
self.parent.enableButtons()
|
||||||
if aqt.mw.config['preserveKeyboard'] and sys.platform.startswith("win32"):
|
if self.mw.config['preserveKeyboard'] and sys.platform.startswith("win32"):
|
||||||
self._programLayout = GetKeyboardLayout(0)
|
self._programLayout = GetKeyboardLayout(0)
|
||||||
if self._ownLayout == None:
|
if self._ownLayout == None:
|
||||||
self._ownLayout = self._programLayout
|
self._ownLayout = self._programLayout
|
||||||
|
|
|
@ -94,5 +94,8 @@
|
||||||
<file>icons/text_under.png</file>
|
<file>icons/text_under.png</file>
|
||||||
<file>icons/view-pim-news.png</file>
|
<file>icons/view-pim-news.png</file>
|
||||||
<file>icons/view_text.png</file>
|
<file>icons/view_text.png</file>
|
||||||
|
<file>icons/text_sub.png</file>
|
||||||
|
<file>icons/text_super.png</file>
|
||||||
|
<file>icons/text_remove.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 4.2 KiB |
BIN
designer/icons/text_remove.png
Normal file
BIN
designer/icons/text_remove.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
designer/icons/text_sub.png
Normal file
BIN
designer/icons/text_sub.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
designer/icons/text_super.png
Normal file
BIN
designer/icons/text_super.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in a new issue