made improvements to legacy text effect
This commit is contained in:
+45
-17
@@ -23,35 +23,56 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
#include <QIcon>
|
||||
|
||||
TextEditDialog::TextEditDialog(QWidget *parent, const QString &s) :
|
||||
QDialog(parent)
|
||||
#include "ui/icons.h"
|
||||
|
||||
TextEditDialog::TextEditDialog(QWidget *parent, const QString &s, bool rich_text) :
|
||||
QDialog(parent),
|
||||
rich_text_(rich_text)
|
||||
{
|
||||
setWindowTitle(tr("Edit Text"));
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
|
||||
QHBoxLayout* toolbar = new QHBoxLayout();
|
||||
if (rich_text) {
|
||||
QHBoxLayout* toolbar = new QHBoxLayout();
|
||||
|
||||
QPushButton* italic_button = new QPushButton("I");
|
||||
italic_button->setCheckable(true);
|
||||
toolbar->addWidget(italic_button);
|
||||
// Italic Button
|
||||
italic_button = new QPushButton();
|
||||
italic_button->setIcon(QIcon(":/icons/italic.svg"));
|
||||
italic_button->setCheckable(true);
|
||||
connect(italic_button, SIGNAL(clicked(bool)), textEdit, SLOT(setFontItalic(bool)));
|
||||
toolbar->addWidget(italic_button);
|
||||
|
||||
QPushButton* underline_button = new QPushButton("U");
|
||||
underline_button->setCheckable(true);
|
||||
toolbar->addWidget(underline_button);
|
||||
// Underline Button
|
||||
underline_button = new QPushButton();
|
||||
underline_button->setIcon(QIcon(":/icons/underline.svg"));
|
||||
underline_button->setCheckable(true);
|
||||
toolbar->addWidget(underline_button);
|
||||
|
||||
toolbar->addStretch();
|
||||
// Font Name
|
||||
font_list = new QFontComboBox();
|
||||
connect(font_list, SIGNAL(setCurrentFont(const QFont&)), textEdit, SLOT(setCurrentFont(const QFont&)));
|
||||
toolbar->addWidget(font_list);
|
||||
|
||||
layout->addLayout(toolbar);
|
||||
|
||||
toolbar->addStretch();
|
||||
|
||||
layout->addLayout(toolbar);
|
||||
}
|
||||
|
||||
// Create central text editor object
|
||||
textEdit = new QTextEdit(this);
|
||||
textEdit->setHtml(s);
|
||||
layout->addWidget(textEdit);
|
||||
textEdit->setUndoRedoEnabled(true);
|
||||
|
||||
// Connect buttons to the text field
|
||||
connect(italic_button, SIGNAL(clicked(bool)), textEdit, SLOT(setFontItalic(bool)));
|
||||
connect(underline_button, SIGNAL(clicked(bool)), textEdit, SLOT(setFontUnderline(bool)));
|
||||
if (rich_text_) {
|
||||
textEdit->setHtml(s);
|
||||
} else {
|
||||
textEdit->setPlainText(s);
|
||||
}
|
||||
|
||||
layout->addWidget(textEdit);
|
||||
|
||||
// Create dialog buttons at the bottom
|
||||
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
||||
@@ -65,10 +86,17 @@ const QString& TextEditDialog::get_string() {
|
||||
}
|
||||
|
||||
void TextEditDialog::save() {
|
||||
result_str = textEdit->toHtml();
|
||||
result_str = rich_text_ ? textEdit->toHtml() : textEdit->toPlainText();
|
||||
accept();
|
||||
}
|
||||
|
||||
void TextEditDialog::cancel() {
|
||||
reject();
|
||||
}
|
||||
|
||||
void TextEditDialog::UpdateUIFromTextCursor()
|
||||
{
|
||||
italic_button->setChecked(textEdit->fontItalic());
|
||||
underline_button->setChecked(textEdit->fontUnderline());
|
||||
font_list->setCurrentText(textEdit->fontFamily());
|
||||
}
|
||||
|
||||
@@ -23,18 +23,27 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QFontComboBox>
|
||||
|
||||
class TextEditDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextEditDialog(QWidget* parent = nullptr, const QString& s = nullptr);
|
||||
TextEditDialog(QWidget* parent = nullptr, const QString& s = nullptr, bool rich_text = true);
|
||||
const QString& get_string();
|
||||
signals:
|
||||
void cursorPositionChanged();
|
||||
private slots:
|
||||
void save();
|
||||
void cancel();
|
||||
void UpdateUIFromTextCursor();
|
||||
private:
|
||||
bool rich_text_;
|
||||
|
||||
QString result_str;
|
||||
QTextEdit* textEdit;
|
||||
QPushButton* italic_button;
|
||||
QPushButton* underline_button;
|
||||
QFontComboBox* font_list;
|
||||
};
|
||||
|
||||
#endif // TEXTEDITDIALOG_H
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "richtexteffect.h"
|
||||
|
||||
RichTextEffect::RichTextEffect(Clip *c, const EffectMeta *em)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RichTextEffect::redraw(double timecode)
|
||||
{
|
||||
QPainter p(&img);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
int width = img.width();
|
||||
int height = img.height();
|
||||
|
||||
img.fill(Qt::transparent);
|
||||
|
||||
QTextDocument td;
|
||||
td.setHtml(text_val->GetStringAt(timecode));
|
||||
td.drawContents(&p);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef RICHTEXTEFFECT_H
|
||||
#define RICHTEXTEFFECT_H
|
||||
|
||||
#include "effects/effect.h"
|
||||
|
||||
class RichTextEffect : public Effect {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RichTextEffect(Clip* c, const EffectMeta *em);
|
||||
void redraw(double timecode);
|
||||
|
||||
StringField* text_val;
|
||||
};
|
||||
|
||||
#endif // RICHTEXTEFFECT_H
|
||||
@@ -80,6 +80,14 @@ TextEffect::TextEffect(Clip* c, const EffectMeta* em) :
|
||||
word_wrap_field = new BoolField(word_wrap_row, "wordwrap");
|
||||
word_wrap_field->SetColumnSpan(2);
|
||||
|
||||
EffectRow* padding_row = new EffectRow(this, tr("Padding"));
|
||||
padding_field = new DoubleField(padding_row, "padding");
|
||||
padding_field->SetColumnSpan(2);
|
||||
|
||||
EffectRow* position_row = new EffectRow(this, tr("Position"));
|
||||
position_x = new DoubleField(position_row, "posx");
|
||||
position_y = new DoubleField(position_row, "posy");
|
||||
|
||||
EffectRow* outline_row = new EffectRow(this, tr("Outline"));
|
||||
outline_bool = new BoolField(outline_row, "outline");
|
||||
outline_bool->SetColumnSpan(2);
|
||||
@@ -217,8 +225,9 @@ void TextEffect::redraw(double timecode) {
|
||||
|
||||
QPainter p(&img);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
int width = img.width();
|
||||
int height = img.height();
|
||||
int padding = qRound(padding_field->GetDoubleAt(timecode));
|
||||
int width = img.width() - padding * 2;
|
||||
int height = img.height() - padding * 2;
|
||||
|
||||
// set font
|
||||
font.setStyleHint(QFont::Helvetica, QFont::PreferAntialias);
|
||||
@@ -307,6 +316,8 @@ void TextEffect::redraw(double timecode) {
|
||||
path.addText(text_x, text_y, font, lines.at(i));
|
||||
}
|
||||
|
||||
path.translate(position_x->GetDoubleAt(timecode) + padding, position_y->GetDoubleAt(timecode) + padding);
|
||||
|
||||
// draw software shadow
|
||||
if (shadow_bool->GetBoolAt(timecode)) {
|
||||
p.setPen(Qt::NoPen);
|
||||
|
||||
@@ -31,6 +31,11 @@ class TextEffect : public Effect {
|
||||
public:
|
||||
TextEffect(Clip* c, const EffectMeta *em);
|
||||
void redraw(double timecode);
|
||||
private slots:
|
||||
void outline_enable(bool);
|
||||
void shadow_enable(bool);
|
||||
private:
|
||||
QFont font;
|
||||
|
||||
StringField* text_val;
|
||||
DoubleField* size_val;
|
||||
@@ -39,6 +44,9 @@ public:
|
||||
ComboField* halign_field;
|
||||
ComboField* valign_field;
|
||||
BoolField* word_wrap_field;
|
||||
DoubleField* padding_field;
|
||||
DoubleField* position_x;
|
||||
DoubleField* position_y;
|
||||
|
||||
BoolField* outline_bool;
|
||||
DoubleField* outline_width;
|
||||
@@ -50,11 +58,7 @@ public:
|
||||
ColorField* shadow_color;
|
||||
DoubleField* shadow_softness;
|
||||
DoubleField* shadow_opacity;
|
||||
private slots:
|
||||
void outline_enable(bool);
|
||||
void shadow_enable(bool);
|
||||
private:
|
||||
QFont font;
|
||||
|
||||
};
|
||||
|
||||
#endif // TEXTEFFECT_H
|
||||
|
||||
@@ -45,5 +45,7 @@
|
||||
<file>videosource.svg</file>
|
||||
<file>zoomin.svg</file>
|
||||
<file>zoomout.svg</file>
|
||||
<file>italic.svg</file>
|
||||
<file>underline.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
|
||||
<path d="M2 0v1h1.63l-.06.13-2 5-.34.88h-1.22v1h5v-1h-1.63l.06-.13 2-5 .34-.88h1.22v-1h-5z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 183 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
|
||||
<path d="M1 0v4c0 1.1 1.12 2 2.5 2h.5c1.1 0 2-.9 2-2v-4h-1v4c0 .55-.45 1-1 1s-1-.45-1-1v-4h-2zm-1 7v1h7v-1h-7z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 203 B |
@@ -172,7 +172,8 @@ SOURCES += \
|
||||
ui/effectui.cpp \
|
||||
effects/transition.cpp \
|
||||
ui/styling.cpp \
|
||||
undo/undostack.cpp
|
||||
undo/undostack.cpp \
|
||||
effects/internal/richtexteffect.cpp
|
||||
|
||||
HEADERS += \
|
||||
ui/mainwindow.h \
|
||||
@@ -298,7 +299,8 @@ HEADERS += \
|
||||
effects/fields/combofield.h \
|
||||
effects/transition.h \
|
||||
ui/styling.h \
|
||||
undo/undostack.h
|
||||
undo/undostack.h \
|
||||
effects/internal/richtexteffect.h
|
||||
|
||||
FORMS +=
|
||||
|
||||
|
||||
+12
-4
@@ -68,7 +68,9 @@ void TextEditEx::updateText() {
|
||||
#include "dialogs/texteditdialog.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
TextEditEx::TextEditEx(QWidget *parent) : QTextEdit(parent)
|
||||
TextEditEx::TextEditEx(QWidget *parent, bool enable_rich_text) :
|
||||
QTextEdit(parent),
|
||||
enable_rich_text_(enable_rich_text)
|
||||
{
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(text_edit_menu()));
|
||||
@@ -85,15 +87,21 @@ void TextEditEx::text_edit_menu() {
|
||||
}
|
||||
|
||||
void TextEditEx::open_text_edit() {
|
||||
TextEditDialog ted(olive::MainWindow, this->toHtml());
|
||||
const QString& current_text = (enable_rich_text_) ? toHtml() : toPlainText();
|
||||
|
||||
TextEditDialog ted(olive::MainWindow, current_text, enable_rich_text_);
|
||||
ted.exec();
|
||||
QString result = ted.get_string();
|
||||
if (!result.isEmpty()) {
|
||||
setHtml(result);
|
||||
if (enable_rich_text_) {
|
||||
setHtml(result);
|
||||
} else {
|
||||
setPlainText(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditEx::queue_text_modified()
|
||||
{
|
||||
emit textModified(toHtml());
|
||||
emit textModified(toPlainText());
|
||||
}
|
||||
|
||||
+3
-1
@@ -26,13 +26,15 @@
|
||||
class TextEditEx : public QTextEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextEditEx(QWidget* parent = nullptr);
|
||||
TextEditEx(QWidget* parent = nullptr, bool enable_rich_text = true);
|
||||
signals:
|
||||
void textModified(const QString& s);
|
||||
private slots:
|
||||
void text_edit_menu();
|
||||
void open_text_edit();
|
||||
void queue_text_modified();
|
||||
private:
|
||||
bool enable_rich_text_;
|
||||
};
|
||||
|
||||
#endif // TEXTEDITEX_H
|
||||
|
||||
Reference in New Issue
Block a user