Implement underline and strikethrough

This commit is contained in:
Kovid Goyal 2019-07-02 18:34:30 +05:30
parent fcb72c0075
commit 5ac8d64c55
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -283,8 +283,10 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
vert = tcf.verticalAlignment() vert = tcf.verticalAlignment()
self.action_superscript.setChecked(vert == QTextCharFormat.AlignSuperScript) self.action_superscript.setChecked(vert == QTextCharFormat.AlignSuperScript)
self.action_subscript.setChecked(vert == QTextCharFormat.AlignSubScript) self.action_subscript.setChecked(vert == QTextCharFormat.AlignSubScript)
self.action_bold.setChecked(tcf.intProperty(QTextCharFormat.FontWeight) == QFont.Bold) self.action_bold.setChecked(tcf.fontWeight() == QFont.Bold)
self.action_italic.setChecked(tcf.boolProperty(QTextCharFormat.FontItalic)) self.action_italic.setChecked(tcf.fontItalic())
self.action_underline.setChecked(tcf.fontUnderline())
self.action_strikethrough.setChecked(tcf.fontStrikeOut())
def set_readonly(self, what): def set_readonly(self, what):
self.readonly = what self.readonly = what
@ -316,10 +318,16 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
c.mergeCharFormat(fmt) c.mergeCharFormat(fmt)
def do_underline(self): def do_underline(self):
raise NotImplementedError('TODO') with self.editing_cursor() as c:
fmt = QTextCharFormat()
fmt.setFontUnderline(not c.charFormat().fontUnderline())
c.mergeCharFormat(fmt)
def do_strikethrough(self): def do_strikethrough(self):
raise NotImplementedError('TODO') with self.editing_cursor() as c:
fmt = QTextCharFormat()
fmt.setFontStrikeOut(not c.charFormat().fontStrikeOut())
c.mergeCharFormat(fmt)
def do_vertical_align(self, which): def do_vertical_align(self, which):
with self.editing_cursor() as c: with self.editing_cursor() as c: