mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Comments editor: Fix the formatting buttons not showing the current state correctly
This commit is contained in:
parent
1e5b4d373d
commit
016a62b95e
@ -349,10 +349,10 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
|
|
||||||
def update_cursor_position_actions(self):
|
def update_cursor_position_actions(self):
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
|
tcf = c.charFormat()
|
||||||
ls = c.currentList()
|
ls = c.currentList()
|
||||||
self.action_ordered_list.setChecked(ls is not None and ls.format().style() == QTextListFormat.Style.ListDecimal)
|
self.action_ordered_list.setChecked(ls is not None and ls.format().style() == QTextListFormat.Style.ListDecimal)
|
||||||
self.action_unordered_list.setChecked(ls is not None and ls.format().style() == QTextListFormat.Style.ListDisc)
|
self.action_unordered_list.setChecked(ls is not None and ls.format().style() == QTextListFormat.Style.ListDisc)
|
||||||
tcf = c.charFormat()
|
|
||||||
vert = tcf.verticalAlignment()
|
vert = tcf.verticalAlignment()
|
||||||
self.action_superscript.setChecked(vert == QTextCharFormat.VerticalAlignment.AlignSuperScript)
|
self.action_superscript.setChecked(vert == QTextCharFormat.VerticalAlignment.AlignSuperScript)
|
||||||
self.action_subscript.setChecked(vert == QTextCharFormat.VerticalAlignment.AlignSubScript)
|
self.action_subscript.setChecked(vert == QTextCharFormat.VerticalAlignment.AlignSubScript)
|
||||||
@ -398,30 +398,35 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
fmt.setFontWeight(
|
fmt.setFontWeight(
|
||||||
QFont.Weight.Bold if c.charFormat().fontWeight() != QFont.Weight.Bold else QFont.Weight.Normal)
|
QFont.Weight.Bold if c.charFormat().fontWeight() != QFont.Weight.Bold else QFont.Weight.Normal)
|
||||||
c.mergeCharFormat(fmt)
|
c.mergeCharFormat(fmt)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_italic(self):
|
def do_italic(self):
|
||||||
with self.editing_cursor() as c:
|
with self.editing_cursor() as c:
|
||||||
fmt = QTextCharFormat()
|
fmt = QTextCharFormat()
|
||||||
fmt.setFontItalic(not c.charFormat().fontItalic())
|
fmt.setFontItalic(not c.charFormat().fontItalic())
|
||||||
c.mergeCharFormat(fmt)
|
c.mergeCharFormat(fmt)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_underline(self):
|
def do_underline(self):
|
||||||
with self.editing_cursor() as c:
|
with self.editing_cursor() as c:
|
||||||
fmt = QTextCharFormat()
|
fmt = QTextCharFormat()
|
||||||
fmt.setFontUnderline(not c.charFormat().fontUnderline())
|
fmt.setFontUnderline(not c.charFormat().fontUnderline())
|
||||||
c.mergeCharFormat(fmt)
|
c.mergeCharFormat(fmt)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_strikethrough(self):
|
def do_strikethrough(self):
|
||||||
with self.editing_cursor() as c:
|
with self.editing_cursor() as c:
|
||||||
fmt = QTextCharFormat()
|
fmt = QTextCharFormat()
|
||||||
fmt.setFontStrikeOut(not c.charFormat().fontStrikeOut())
|
fmt.setFontStrikeOut(not c.charFormat().fontStrikeOut())
|
||||||
c.mergeCharFormat(fmt)
|
c.mergeCharFormat(fmt)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_vertical_align(self, which):
|
def do_vertical_align(self, which):
|
||||||
with self.editing_cursor() as c:
|
with self.editing_cursor() as c:
|
||||||
fmt = QTextCharFormat()
|
fmt = QTextCharFormat()
|
||||||
fmt.setVerticalAlignment(which)
|
fmt.setVerticalAlignment(which)
|
||||||
c.mergeCharFormat(fmt)
|
c.mergeCharFormat(fmt)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_superscript(self):
|
def do_superscript(self):
|
||||||
self.do_vertical_align(QTextCharFormat.VerticalAlignment.AlignSuperScript)
|
self.do_vertical_align(QTextCharFormat.VerticalAlignment.AlignSuperScript)
|
||||||
@ -441,6 +446,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
ls.setFormat(lf)
|
ls.setFormat(lf)
|
||||||
else:
|
else:
|
||||||
ls = c.createList(fmt)
|
ls = c.createList(fmt)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_ordered_list(self):
|
def do_ordered_list(self):
|
||||||
self.do_list(QTextListFormat.Style.ListDecimal)
|
self.do_list(QTextListFormat.Style.ListDecimal)
|
||||||
@ -454,6 +460,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
fmt = QTextBlockFormat()
|
fmt = QTextBlockFormat()
|
||||||
fmt.setAlignment(which)
|
fmt.setAlignment(which)
|
||||||
c.mergeBlockFormat(fmt)
|
c.mergeBlockFormat(fmt)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_align_left(self):
|
def do_align_left(self):
|
||||||
self.do_alignment(Qt.AlignmentFlag.AlignLeft)
|
self.do_alignment(Qt.AlignmentFlag.AlignLeft)
|
||||||
@ -479,6 +486,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
with self.editing_cursor() as c:
|
with self.editing_cursor() as c:
|
||||||
c.setBlockFormat(QTextBlockFormat())
|
c.setBlockFormat(QTextBlockFormat())
|
||||||
c.setCharFormat(QTextCharFormat())
|
c.setCharFormat(QTextCharFormat())
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_copy(self):
|
def do_copy(self):
|
||||||
self.copy()
|
self.copy()
|
||||||
@ -502,6 +510,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
bf = c.blockFormat()
|
bf = c.blockFormat()
|
||||||
bf.setTextIndent(bf.textIndent() + 2 * self.em_size * mult)
|
bf.setTextIndent(bf.textIndent() + 2 * self.em_size * mult)
|
||||||
c.setBlockFormat(bf)
|
c.setBlockFormat(bf)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_indent(self):
|
def do_indent(self):
|
||||||
self.indent_block()
|
self.indent_block()
|
||||||
@ -562,6 +571,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
c.mergeBlockFormat(bf)
|
c.mergeBlockFormat(bf)
|
||||||
if pos is not None:
|
if pos is not None:
|
||||||
c.setPosition(pos)
|
c.setPosition(pos)
|
||||||
|
self.update_cursor_position_actions()
|
||||||
|
|
||||||
def do_color(self):
|
def do_color(self):
|
||||||
col = QColorDialog.getColor(Qt.GlobalColor.black, self,
|
col = QColorDialog.getColor(Qt.GlobalColor.black, self,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user