viewertexteditor: improved UI

This commit is contained in:
itsmattkc
2022-03-30 10:13:45 -07:00
parent a4e86bac72
commit 102b782215
3 changed files with 26 additions and 10 deletions
+21 -9
View File
@@ -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)