Loading ui/scene_textlayout.py +3 −0 Original line number Diff line number Diff line Loading @@ -269,6 +269,9 @@ class SceneTextLayout(QAbstractTextDocumentLayout): def documentChanged(self, position: int, charsRemoved: int, charsAdded: int) -> None: if not self.relayout_on_changed: return self.reLayoutEverything() def reLayoutEverything(self): self._doc_text = self.document().toPlainText() self._max_font_size = -1 block = self.document().firstBlock() Loading ui/textedit_commands.py +11 −0 Original line number Diff line number Diff line Loading @@ -273,14 +273,25 @@ class TextItemEditCommand(QUndoCommand): if self.op_counter == 0: self.op_counter += 1 return self.blkitem.repaint_on_changed = False for _ in range(self.num_steps): self.blkitem.redo() self.blkitem.repaint_on_changed = True if self.num_steps > 0: self.blkitem.repaint_background() if self.edit is not None and not self.is_formatting: self.edit.redo() def undo(self): self.blkitem.repaint_on_changed = False for _ in range(self.num_steps): self.blkitem.undo() self.blkitem.repaint_on_changed = True if self.num_steps > 0: self.blkitem.repaint_background() if self.edit is not None: self.edit.undo() Loading ui/textitem.py +22 −14 Original line number Diff line number Diff line Loading @@ -125,6 +125,7 @@ class TextBlkItem(QGraphicsTextItem): def paint_stroke(self, painter: QPainter): doc = QTextDocument() doc.setUndoRedoEnabled(False) doc.setDocumentMargin(self.document().documentMargin()) doc.setDefaultFont(self.document().defaultFont()) doc.setHtml(self.document().toHtml()) Loading Loading @@ -496,11 +497,12 @@ class TextBlkItem(QGraphicsTextItem): return self.textInteractionFlags() == Qt.TextInteractionFlag.TextEditorInteraction def isMultiFontSize(self) -> bool: doc = QTextDocument() doc.setHtml(self.document().toHtml()) doc = self.document() block = doc.firstBlock() if block.isValid(): it = block.begin() # if it.atEnd(): # return False firstFontSize = it.fragment().charFormat().fontPointSize() else: return False Loading Loading @@ -692,7 +694,10 @@ class TextBlkItem(QGraphicsTextItem): def setFontFamily(self, value: str, repaint_background: bool = True, set_selected: bool = False, restore_cursor: bool = False): cursor, after_kwargs = self._before_set_ffmt(set_selected, restore_cursor) self.layout.relayout_on_changed = False self._doc_set_font_family(value, cursor) self.layout.relayout_on_changed = True self.layout.reLayoutEverything() self._after_set_ffmt(cursor, repaint_background, restore_cursor, **after_kwargs) def _doc_set_font_family(self, value: str, cursor: QTextCursor): Loading Loading @@ -822,11 +827,11 @@ class TextBlkItem(QGraphicsTextItem): self.update() def setRelFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): doc = QTextDocument() doc.setDocumentMargin(self.document().documentMargin()) doc.setDefaultFont(self.document().defaultFont()) doc.setHtml(self.document().toHtml()) doc.setDefaultTextOption(self.document().defaultTextOption()) self.is_formatting = True self.block_change_signal = True self.layout.relayout_on_changed = False old_undo_steps = self.document().availableUndoSteps() doc = self.document() cursor = QTextCursor(doc) block = doc.firstBlock() while block.isValid(): Loading @@ -844,14 +849,17 @@ class TextBlkItem(QGraphicsTextItem): cursor.mergeCharFormat(cfmt) it += 1 block = block.next() self.setHtml(doc.toHtml()) br = self.absBoundingRect(qrect=True) br_w, br_h = br.width(), br.height() self.set_size(br_w * value, br_h * value, set_layout_maxsize=True, set_blk_size=True) self.doc_size_changed.emit(self.idx) self.repaint_background() self.old_undo_steps = new_undo_steps = self.document().availableUndoSteps() self.layout.relayout_on_changed = True self.layout.reLayoutEverything() self.squeezeBoundingRect(True) self.repaint_background() new_steps = new_undo_steps - old_undo_steps self.push_undo_stack.emit(new_steps, self.is_formatting) self.is_formatting = False self.block_change_signal = False def setFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): ''' Loading Loading
ui/scene_textlayout.py +3 −0 Original line number Diff line number Diff line Loading @@ -269,6 +269,9 @@ class SceneTextLayout(QAbstractTextDocumentLayout): def documentChanged(self, position: int, charsRemoved: int, charsAdded: int) -> None: if not self.relayout_on_changed: return self.reLayoutEverything() def reLayoutEverything(self): self._doc_text = self.document().toPlainText() self._max_font_size = -1 block = self.document().firstBlock() Loading
ui/textedit_commands.py +11 −0 Original line number Diff line number Diff line Loading @@ -273,14 +273,25 @@ class TextItemEditCommand(QUndoCommand): if self.op_counter == 0: self.op_counter += 1 return self.blkitem.repaint_on_changed = False for _ in range(self.num_steps): self.blkitem.redo() self.blkitem.repaint_on_changed = True if self.num_steps > 0: self.blkitem.repaint_background() if self.edit is not None and not self.is_formatting: self.edit.redo() def undo(self): self.blkitem.repaint_on_changed = False for _ in range(self.num_steps): self.blkitem.undo() self.blkitem.repaint_on_changed = True if self.num_steps > 0: self.blkitem.repaint_background() if self.edit is not None: self.edit.undo() Loading
ui/textitem.py +22 −14 Original line number Diff line number Diff line Loading @@ -125,6 +125,7 @@ class TextBlkItem(QGraphicsTextItem): def paint_stroke(self, painter: QPainter): doc = QTextDocument() doc.setUndoRedoEnabled(False) doc.setDocumentMargin(self.document().documentMargin()) doc.setDefaultFont(self.document().defaultFont()) doc.setHtml(self.document().toHtml()) Loading Loading @@ -496,11 +497,12 @@ class TextBlkItem(QGraphicsTextItem): return self.textInteractionFlags() == Qt.TextInteractionFlag.TextEditorInteraction def isMultiFontSize(self) -> bool: doc = QTextDocument() doc.setHtml(self.document().toHtml()) doc = self.document() block = doc.firstBlock() if block.isValid(): it = block.begin() # if it.atEnd(): # return False firstFontSize = it.fragment().charFormat().fontPointSize() else: return False Loading Loading @@ -692,7 +694,10 @@ class TextBlkItem(QGraphicsTextItem): def setFontFamily(self, value: str, repaint_background: bool = True, set_selected: bool = False, restore_cursor: bool = False): cursor, after_kwargs = self._before_set_ffmt(set_selected, restore_cursor) self.layout.relayout_on_changed = False self._doc_set_font_family(value, cursor) self.layout.relayout_on_changed = True self.layout.reLayoutEverything() self._after_set_ffmt(cursor, repaint_background, restore_cursor, **after_kwargs) def _doc_set_font_family(self, value: str, cursor: QTextCursor): Loading Loading @@ -822,11 +827,11 @@ class TextBlkItem(QGraphicsTextItem): self.update() def setRelFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): doc = QTextDocument() doc.setDocumentMargin(self.document().documentMargin()) doc.setDefaultFont(self.document().defaultFont()) doc.setHtml(self.document().toHtml()) doc.setDefaultTextOption(self.document().defaultTextOption()) self.is_formatting = True self.block_change_signal = True self.layout.relayout_on_changed = False old_undo_steps = self.document().availableUndoSteps() doc = self.document() cursor = QTextCursor(doc) block = doc.firstBlock() while block.isValid(): Loading @@ -844,14 +849,17 @@ class TextBlkItem(QGraphicsTextItem): cursor.mergeCharFormat(cfmt) it += 1 block = block.next() self.setHtml(doc.toHtml()) br = self.absBoundingRect(qrect=True) br_w, br_h = br.width(), br.height() self.set_size(br_w * value, br_h * value, set_layout_maxsize=True, set_blk_size=True) self.doc_size_changed.emit(self.idx) self.repaint_background() self.old_undo_steps = new_undo_steps = self.document().availableUndoSteps() self.layout.relayout_on_changed = True self.layout.reLayoutEverything() self.squeezeBoundingRect(True) self.repaint_background() new_steps = new_undo_steps - old_undo_steps self.push_undo_stack.emit(new_steps, self.is_formatting) self.is_formatting = False self.block_change_signal = False def setFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): ''' Loading