From b65d4451457735af46aae94594506c59350c08a6 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sat, 23 Jul 2022 16:57:09 -0700 Subject: [PATCH] viewertexteditor: set char format to last used when cleared --- app/widget/viewer/viewerdisplay.cpp | 3 --- app/widget/viewer/viewertexteditor.cpp | 21 +++++++++++++++++++-- app/widget/viewer/viewertexteditor.h | 3 +++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/widget/viewer/viewerdisplay.cpp b/app/widget/viewer/viewerdisplay.cpp index 8c0b42334..92f9bd119 100644 --- a/app/widget/viewer/viewerdisplay.cpp +++ b/app/widget/viewer/viewerdisplay.cpp @@ -34,8 +34,6 @@ #include #include -#include "common/define.h" -#include "common/functiontimer.h" #include "common/html.h" #include "common/qtutils.h" #include "config/config.h" @@ -46,7 +44,6 @@ #include "node/gizmo/polygon.h" #include "node/gizmo/screen.h" #include "viewertexteditor.h" -#include "window/mainwindow/mainwindow.h" namespace olive { diff --git a/app/widget/viewer/viewertexteditor.cpp b/app/widget/viewer/viewertexteditor.cpp index 6a6c3227a..c7cc4efb6 100644 --- a/app/widget/viewer/viewertexteditor.cpp +++ b/app/widget/viewer/viewertexteditor.cpp @@ -24,11 +24,12 @@ #include #include #include +#include #include +#include #include "common/qtutils.h" #include "ui/icons/icons.h" -#include "widget/colorbutton/colorbutton.h" namespace olive { @@ -38,7 +39,8 @@ ViewerTextEditor::ViewerTextEditor(double scale, QWidget *parent) : super(parent), transparent_clone_(nullptr), block_update_toolbar_signal_(false), - listen_to_focus_events_(false) + listen_to_focus_events_(false), + forced_default_(false) { // Ensure default text color is white QPalette p = palette(); @@ -173,6 +175,10 @@ void ViewerTextEditor::FormatChanged(const QTextCharFormat &f) UpdateToolBar(toolbar, f, textCursor().blockFormat(), this->alignment()); } } + + if (!(document()->blockCount() == 1 && document()->firstBlock().text().isEmpty())) { + default_fmt_ = f; + } } void ViewerTextEditor::SetFamily(const QString &s) @@ -235,6 +241,7 @@ void ViewerTextEditor::MergeCharFormat(const QTextCharFormat &fmt) // this can be undesirable if the user is currently typing a font block_update_toolbar_signal_ = true; mergeCurrentCharFormat(fmt); + //default_fmt_ = this->currentCharFormat(); block_update_toolbar_signal_ = false; } @@ -263,6 +270,16 @@ void ViewerTextEditor::LockScrollBarMaximumToZero() void ViewerTextEditor::DocumentChanged() { + if (document()->blockCount() == 1 && document()->firstBlock().text().isEmpty()) { + if (!forced_default_) { + QTextCursor c(document()->firstBlock()); + c.setBlockCharFormat(default_fmt_); + forced_default_ = true; + } + } else { + forced_default_ = false; + } + // HACK: We want to show the text cursor and selections without necessarily rendering the text, // because the text is already being rendered underneath the gizmo (and rendering twice will // alter the overall look of the text while editing). This is something that Qt does not diff --git a/app/widget/viewer/viewertexteditor.h b/app/widget/viewer/viewertexteditor.h index 2731cb710..33b640b76 100644 --- a/app/widget/viewer/viewertexteditor.h +++ b/app/widget/viewer/viewertexteditor.h @@ -165,6 +165,9 @@ private: bool listen_to_focus_events_; + bool forced_default_; + QTextCharFormat default_fmt_; + private slots: void FormatChanged(const QTextCharFormat &f);