viewertexteditor: improved UI
This commit is contained in:
@@ -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()));
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<ViewerTextEditorToolBar *> toolbars_;
|
||||
|
||||
QImage dpi_force_;
|
||||
|
||||
QTextDocument *transparent_clone_;
|
||||
|
||||
bool block_update_toolbar_signal_;
|
||||
|
||||
private slots:
|
||||
void FocusChanged(QWidget *old, QWidget *now);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user