From 102b782215f2d9cabbdbd8266e334264bbda7d2a Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed, 30 Mar 2022 10:13:45 -0700 Subject: [PATCH] viewertexteditor: improved UI --- app/widget/viewer/viewerdisplay.cpp | 2 +- app/widget/viewer/viewertexteditor.cpp | 30 ++++++++++++++++++-------- app/widget/viewer/viewertexteditor.h | 4 ++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/widget/viewer/viewerdisplay.cpp b/app/widget/viewer/viewerdisplay.cpp index a0087bc8c..0721ca4bb 100644 --- a/app/widget/viewer/viewerdisplay.cpp +++ b/app/widget/viewer/viewerdisplay.cpp @@ -344,7 +344,7 @@ void ViewerDisplayWidget::mouseDoubleClickEvent(QMouseEvent *event) text_edit->setGeometry(transformed_geom.toRect()); ViewerTextEditorToolBar *toolbar = new ViewerTextEditorToolBar(this); - toolbar->setWindowFlags(Qt::FramelessWindowHint | Qt::Window | Qt::WindowStaysOnTopHint); + toolbar->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); toolbar->resize(toolbar->sizeHint()); QPoint pos = mapToGlobal(QPoint(transformed_geom.x(), transformed_geom.y() - toolbar->height())); diff --git a/app/widget/viewer/viewertexteditor.cpp b/app/widget/viewer/viewertexteditor.cpp index 74fd53116..48d253d7d 100644 --- a/app/widget/viewer/viewertexteditor.cpp +++ b/app/widget/viewer/viewertexteditor.cpp @@ -36,7 +36,8 @@ namespace olive { ViewerTextEditor::ViewerTextEditor(double scale, QWidget *parent) : super(parent), - transparent_clone_(nullptr) + transparent_clone_(nullptr), + block_update_toolbar_signal_(false) { // Ensure default text color is white QPalette p = palette(); @@ -198,8 +199,10 @@ void ViewerTextEditor::FocusChanged(QWidget *old, QWidget *now) void ViewerTextEditor::FormatChanged(const QTextCharFormat &f) { - foreach (ViewerTextEditorToolBar *toolbar, toolbars_) { - UpdateToolBar(toolbar, f, textCursor().blockFormat(), this->alignment()); + if (!block_update_toolbar_signal_) { + foreach (ViewerTextEditorToolBar *toolbar, toolbars_) { + UpdateToolBar(toolbar, f, textCursor().blockFormat(), this->alignment()); + } } } @@ -210,42 +213,51 @@ void ViewerTextEditor::SetFamily(const QString &s) #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) f.setFontFamilies({s}); #endif - mergeCurrentCharFormat(f); + MergeCharFormat(f); } void ViewerTextEditor::SetStyle(const QString &s) { QTextCharFormat f; f.setFontStyleName(s); - mergeCurrentCharFormat(f); + MergeCharFormat(f); } void ViewerTextEditor::SetFontStrikethrough(bool e) { QTextCharFormat f; f.setFontStrikeOut(e); - mergeCurrentCharFormat(f); + MergeCharFormat(f); } void ViewerTextEditor::SetSmallCaps(bool e) { QTextCharFormat f; f.setFontCapitalization(e ? QFont::SmallCaps : QFont::MixedCase); - mergeCurrentCharFormat(f); + MergeCharFormat(f); } void ViewerTextEditor::SetFontStretch(int i) { QTextCharFormat f; f.setFontStretch(i); - mergeCurrentCharFormat(f); + MergeCharFormat(f); } void ViewerTextEditor::SetFontKerning(qreal i) { QTextCharFormat f; f.setFontLetterSpacing(i); - mergeCurrentCharFormat(f); + MergeCharFormat(f); +} + +void ViewerTextEditor::MergeCharFormat(const QTextCharFormat &fmt) +{ + // mergeCurrentCharFormat throws a currentCharFormatChanged signal that updates the toolbar, + // this can be undesirable if the user is currently typing a font + block_update_toolbar_signal_ = true; + mergeCurrentCharFormat(fmt); + block_update_toolbar_signal_ = false; } void ViewerTextEditor::SetLineHeight(qreal i) diff --git a/app/widget/viewer/viewertexteditor.h b/app/widget/viewer/viewertexteditor.h index 12a2e3ee2..e01ced6fa 100644 --- a/app/widget/viewer/viewertexteditor.h +++ b/app/widget/viewer/viewertexteditor.h @@ -142,12 +142,16 @@ protected: private: static void UpdateToolBar(ViewerTextEditorToolBar *toolbar, const QTextCharFormat &f, const QTextBlockFormat &b, Qt::Alignment alignment); + void MergeCharFormat(const QTextCharFormat &fmt); + QVector toolbars_; QImage dpi_force_; QTextDocument *transparent_clone_; + bool block_update_toolbar_signal_; + private slots: void FocusChanged(QWidget *old, QWidget *now);