viewertexteditor: set char format to last used when cleared

This commit is contained in:
itsmattkc
2022-07-23 16:57:09 -07:00
parent 12f9b1acfc
commit b65d445145
3 changed files with 22 additions and 5 deletions
-3
View File
@@ -34,8 +34,6 @@
#include <QScreen>
#include <QTextEdit>
#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 {
+19 -2
View File
@@ -24,11 +24,12 @@
#include <QColorDialog>
#include <QKeyEvent>
#include <QHBoxLayout>
#include <QPainter>
#include <QScrollBar>
#include <QTextBlock>
#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
+3
View File
@@ -165,6 +165,9 @@ private:
bool listen_to_focus_events_;
bool forced_default_;
QTextCharFormat default_fmt_;
private slots:
void FormatChanged(const QTextCharFormat &f);