further progress on rich text effect

This commit is contained in:
itsmattkc
2019-03-14 22:56:23 +11:00
parent c0d3e038eb
commit 9fc542e688
14 changed files with 232 additions and 15 deletions
+142 -11
View File
@@ -24,6 +24,7 @@
#include <QDialogButtonBox>
#include <QPushButton>
#include <QIcon>
#include <QDebug>
#include "ui/icons.h"
@@ -35,9 +36,23 @@ TextEditDialog::TextEditDialog(QWidget *parent, const QString &s, bool rich_text
QVBoxLayout* layout = new QVBoxLayout(this);
// Create central text editor object
textEdit = new QTextEdit(this);
textEdit->setUndoRedoEnabled(true);
// Upper toolbar
if (rich_text) {
QHBoxLayout* toolbar = new QHBoxLayout();
// Bold Button
/*
bold_button = new QPushButton();
bold_button->setIcon(QIcon(":/icons/bold.svg"));
bold_button->setCheckable(true);
connect(bold_button, SIGNAL(clicked(bool)), this, SLOT(SetBold(bool)));
toolbar->addWidget(bold_button);
*/
// Italic Button
italic_button = new QPushButton();
italic_button->setIcon(QIcon(":/icons/italic.svg"));
@@ -49,36 +64,109 @@ TextEditDialog::TextEditDialog(QWidget *parent, const QString &s, bool rich_text
underline_button = new QPushButton();
underline_button->setIcon(QIcon(":/icons/underline.svg"));
underline_button->setCheckable(true);
connect(underline_button, SIGNAL(clicked(bool)), textEdit, SLOT(setFontUnderline(bool)));
toolbar->addWidget(underline_button);
// Font Name
font_list = new QFontComboBox();
connect(font_list, SIGNAL(setCurrentFont(const QFont&)), textEdit, SLOT(setCurrentFont(const QFont&)));
connect(font_list, SIGNAL(currentIndexChanged(const QString&)), textEdit, SLOT(setFontFamily(const QString&)));
toolbar->addWidget(font_list);
// Font Weight
font_weight = new QComboBox();
font_weight->addItem(tr("Thin"), QFont::Thin);
font_weight->addItem(tr("Extra Light"), QFont::ExtraLight);
font_weight->addItem(tr("Light"), QFont::Light);
font_weight->addItem(tr("Normal"), QFont::Normal);
font_weight->addItem(tr("Medium"), QFont::Medium);
font_weight->addItem(tr("Demi Bold"), QFont::DemiBold);
font_weight->addItem(tr("Bold"), QFont::Bold);
font_weight->addItem(tr("Extra Bold"), QFont::ExtraBold);
font_weight->addItem(tr("Black"), QFont::Black);
connect(font_weight, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFontWeight(int)));
toolbar->addWidget(font_weight);
// Font Size
font_size = new LabelSlider();
connect(font_size, SIGNAL(valueChanged(double)), textEdit, SLOT(setFontPointSize(qreal)));
toolbar->addWidget(font_size);
// Font Color
font_color = new ColorButton();
connect(font_color, SIGNAL(color_changed(const QColor&)), textEdit, SLOT(setTextColor(const QColor &)));
toolbar->addWidget(font_color);
toolbar->addStretch();
// Left Align
left_align_button = new QPushButton();
left_align_button->setIcon(QIcon(":/icons/align-left.svg"));
left_align_button->setCheckable(true);
left_align_button->setProperty("a", Qt::AlignLeft);
connect(left_align_button, SIGNAL(clicked(bool)), this, SLOT(SetAlignmentFromProperty()));
toolbar->addWidget(left_align_button);
// Center Align
center_align_button = new QPushButton();
center_align_button->setIcon(QIcon(":/icons/align-center.svg"));
center_align_button->setCheckable(true);
center_align_button->setProperty("a", Qt::AlignCenter);
connect(center_align_button, SIGNAL(clicked(bool)), this, SLOT(SetAlignmentFromProperty()));
toolbar->addWidget(center_align_button);
// Right Align
right_align_button = new QPushButton();
right_align_button->setIcon(QIcon(":/icons/align-right.svg"));
right_align_button->setCheckable(true);
right_align_button->setProperty("a", Qt::AlignRight);
connect(right_align_button, SIGNAL(clicked(bool)), this, SLOT(SetAlignmentFromProperty()));
toolbar->addWidget(right_align_button);
// Justify Align
justify_align_button = new QPushButton();
justify_align_button->setIcon(QIcon(":/icons/justify-center.svg"));
justify_align_button->setCheckable(true);
justify_align_button->setProperty("a", Qt::AlignJustify);
connect(justify_align_button, SIGNAL(clicked(bool)), this, SLOT(SetAlignmentFromProperty()));
toolbar->addWidget(justify_align_button);
layout->addLayout(toolbar);
}
// Create central text editor object
textEdit = new QTextEdit(this);
textEdit->setUndoRedoEnabled(true);
layout->addWidget(textEdit);
// Lower toolbar
/*
if (rich_text) {
QHBoxLayout* lower_toolbar = new QHBoxLayout();
lower_toolbar->addWidget(new QLabel(tr("Letter Spacing:")));
letter_spacing = new LabelSlider();
connect(letter_spacing, SIGNAL(valueChanged(double)), this, SLOT(SetLetterSpacing(qreal)));
lower_toolbar->addWidget(letter_spacing);
lower_toolbar->addStretch();
layout->addLayout(lower_toolbar);
}
*/
// Create dialog buttons at the bottom
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
buttons->setCenterButtons(true);
layout->addWidget(buttons);
connect(buttons, SIGNAL(accepted()), this, SLOT(save()));
connect(buttons, SIGNAL(rejected()), this, SLOT(cancel()));
connect(textEdit, SIGNAL(cursorPositionChanged()), this, SLOT(UpdateUIFromTextCursor()));
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);
layout->addWidget(buttons);
connect(buttons, SIGNAL(accepted()), this, SLOT(save()));
connect(buttons, SIGNAL(rejected()), this, SLOT(cancel()));
UpdateUIFromTextCursor();
}
const QString& TextEditDialog::get_string() {
@@ -94,9 +182,52 @@ void TextEditDialog::cancel() {
reject();
}
void TextEditDialog::SetBold(bool bold)
{
QFont f = textEdit->currentFont();
f.setBold(bold);
textEdit->setCurrentFont(f);
UpdateUIFromTextCursor();
}
void TextEditDialog::SetFontWeight(int i)
{
textEdit->setFontWeight(font_weight->itemData(i).toInt());
}
void TextEditDialog::SetLetterSpacing(qreal spacing)
{
QFont f = textEdit->currentFont();
f.setLetterSpacing(f.letterSpacingType(), spacing);
textEdit->setCurrentFont(f);
}
void TextEditDialog::SetAlignmentFromProperty()
{
textEdit->setAlignment(static_cast<Qt::Alignment>(sender()->property("a").toInt()));
UpdateUIFromTextCursor();
}
void TextEditDialog::UpdateUIFromTextCursor()
{
italic_button->setChecked(textEdit->fontItalic());
underline_button->setChecked(textEdit->fontUnderline());
font_list->setCurrentText(textEdit->fontFamily());
font_size->SetValue(textEdit->fontPointSize());
font_color->set_color(textEdit->textColor());
for (int i=0;i<font_weight->count();i++) {
if (font_weight->itemData(i).toInt() == textEdit->fontWeight()) {
font_weight->blockSignals(true);
font_weight->setCurrentIndex(i);
font_weight->blockSignals(false);
break;
}
}
Qt::Alignment align = textEdit->alignment();
left_align_button->setChecked(align == Qt::AlignLeft);
center_align_button->setChecked(align == Qt::AlignCenter);
right_align_button->setChecked(align == Qt::AlignRight);
justify_align_button->setChecked(align == Qt::AlignJustify);
}
+15
View File
@@ -25,6 +25,9 @@
#include <QPlainTextEdit>
#include <QFontComboBox>
#include "ui/labelslider.h"
#include "ui/colorbutton.h"
class TextEditDialog : public QDialog {
Q_OBJECT
public:
@@ -35,6 +38,11 @@ signals:
private slots:
void save();
void cancel();
void SetBold(bool bold);
void SetFontWeight(int i);
void SetLetterSpacing(qreal spacing);
void SetAlignmentFromProperty();
void UpdateUIFromTextCursor();
private:
bool rich_text_;
@@ -44,6 +52,13 @@ private:
QPushButton* italic_button;
QPushButton* underline_button;
QFontComboBox* font_list;
QComboBox* font_weight;
LabelSlider* font_size;
ColorButton* font_color;
QPushButton* left_align_button;
QPushButton* center_align_button;
QPushButton* right_align_button;
QPushButton* justify_align_button;
};
#endif // TEXTEDITDIALOG_H
+46 -1
View File
@@ -5,8 +5,32 @@
RichTextEffect::RichTextEffect(Clip *c, const EffectMeta *em) :
Effect(c, em)
{
SetFlags(Effect::SuperimposeFlag);
EffectRow* text_row = new EffectRow(this, tr("Text"));
text_val = new StringField(text_row, "text");
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* vertical_align_row = new EffectRow(this, tr("Vertical Align:"));
vertical_align = new ComboField(vertical_align_row, "valign");
vertical_align->AddItem(tr("Top"), Qt::AlignTop);
vertical_align->AddItem(tr("Center"), Qt::AlignCenter);
vertical_align->AddItem(tr("Bottom"), Qt::AlignBottom);
vertical_align->SetValueAt(0, Qt::AlignCenter);
// Create default text
text_val->SetValueAt(0, "<html>"
"<body style=\"color: #ffffff; font-size: 36pt;\">"
"<center>Sample Text</center>"
"</body>"
"</html>");
}
void RichTextEffect::redraw(double timecode)
@@ -18,7 +42,28 @@ void RichTextEffect::redraw(double timecode)
img.fill(Qt::transparent);
int padding = qRound(padding_field->GetDoubleAt(timecode));
width -= 2 * padding;
height -= 2 * padding;
QTextDocument td;
td.setHtml(text_val->GetStringAt(timecode));
td.drawContents(&p);
td.setTextWidth(width);
int translate_x = qRound(position_x->GetDoubleAt(timecode) + padding);
int translate_y = qRound(position_y->GetDoubleAt(timecode) + padding);
if (vertical_align->GetValueAt(timecode).toInt() == Qt::AlignCenter) {
translate_y += height / 2 - td.size().height() / 2;
} else if (vertical_align->GetValueAt(timecode).toInt() == Qt::AlignBottom) {
translate_y += height - td.size().height();
}
QRect clip_rect = img.rect();
clip_rect.translate(-translate_x, -translate_y);
p.translate(translate_x, translate_y);
td.drawContents(&p, clip_rect);
}
+4
View File
@@ -10,6 +10,10 @@ public:
void redraw(double timecode);
private:
StringField* text_val;
DoubleField* padding_field;
DoubleField* position_x;
DoubleField* position_y;
ComboField* vertical_align;
};
#endif // RICHTEXTEFFECT_H
+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
<path style="fill: #ffffff;" d="M0 0v1h8v-1h-8zm1 2v1h6v-1h-6zm-1 2v1h8v-1h-8zm1 2v1h6v-1h-6z" />
</svg>

After

Width:  |  Height:  |  Size: 186 B

+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
<path style="fill: #ffffff;" d="M0 0v1h8v-1h-8zm0 2v1h6v-1h-6zm0 2v1h8v-1h-8zm0 2v1h6v-1h-6z" />
</svg>

After

Width:  |  Height:  |  Size: 185 B

+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
<path style="fill: #ffffff;" d="M0 0v1h8v-1h-8zm2 2v1h6v-1h-6zm-2 2v1h8v-1h-8zm2 2v1h6v-1h-6z" />
</svg>

After

Width:  |  Height:  |  Size: 186 B

+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
<path style="fill: #ffffff;"d="M0 0v1c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1v1h5.5c1.38 0 2.5-1.12 2.5-2.5 0-1-.59-1.85-1.44-2.25.27-.34.44-.78.44-1.25 0-1.1-.89-2-2-2h-5zm3 1h1c.55 0 1 .45 1 1s-.45 1-1 1h-1v-2zm0 3h1.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-1.5v-3z" />
</svg>

After

Width:  |  Height:  |  Size: 354 B

+5
View File
@@ -47,5 +47,10 @@
<file>zoomout.svg</file>
<file>italic.svg</file>
<file>underline.svg</file>
<file>align-center.svg</file>
<file>align-left.svg</file>
<file>align-right.svg</file>
<file>justify-center.svg</file>
<file>bold.svg</file>
</qresource>
</RCC>
+1 -1
View File
@@ -1,3 +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" />
<path style="fill: #ffffff;" 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>

Before

Width:  |  Height:  |  Size: 183 B

After

Width:  |  Height:  |  Size: 206 B

+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 8 8">
<path style="fill: #ffffff;" d="M0 0v1h8v-1h-8zm0 2v1h8v-1h-8zm0 2v1h8v-1h-8zm1 2v1h6v-1h-6z" />
</svg>

After

Width:  |  Height:  |  Size: 185 B

+1 -1
View File
@@ -1,3 +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" />
<path style="fill: #ffffff;" 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>

Before

Width:  |  Height:  |  Size: 203 B

After

Width:  |  Height:  |  Size: 226 B

+2
View File
@@ -29,6 +29,8 @@
#include "ui/icons.h"
KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget(parent) {
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
key_controls = new QHBoxLayout(this);
key_controls->setSpacing(0);
key_controls->setMargin(0);
+1 -1
View File
@@ -103,5 +103,5 @@ void TextEditEx::open_text_edit() {
void TextEditEx::queue_text_modified()
{
emit textModified(toPlainText());
emit textModified(enable_rich_text_ ? toHtml() : toPlainText());
}