change: change code style to Linux style except indent.
This commit is contained in:
@@ -23,12 +23,13 @@
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
enum TextVerticalAlign {
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorV1::kTextInput = QStringLiteral("text_in");
|
||||
@@ -42,132 +43,142 @@ const QString TextGeneratorV1::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
|
||||
TextGeneratorV1::TextGeneratorV1()
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
|
||||
AddInput(kHtmlInput, NodeValue::kBoolean, false);
|
||||
AddInput(kHtmlInput, NodeValue::kBoolean, false);
|
||||
|
||||
AddInput(kColorInput, NodeValue::kColor, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
|
||||
AddInput(kColorInput, NodeValue::kColor,
|
||||
QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
|
||||
|
||||
AddInput(kVAlignInput, NodeValue::kCombo, 1);
|
||||
AddInput(kVAlignInput, NodeValue::kCombo, 1);
|
||||
|
||||
AddInput(kFontInput, NodeValue::kFont);
|
||||
AddInput(kFontInput, NodeValue::kFont);
|
||||
|
||||
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
|
||||
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
|
||||
|
||||
SetFlag(kDontShowInCreateMenu);
|
||||
SetFlag(kDontShowInCreateMenu);
|
||||
}
|
||||
|
||||
QString TextGeneratorV1::Name() const
|
||||
{
|
||||
return tr("Text (Legacy)");
|
||||
return tr("Text (Legacy)");
|
||||
}
|
||||
|
||||
QString TextGeneratorV1::id() const
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorV1::Category() const
|
||||
{
|
||||
return {kCategoryGenerator};
|
||||
return { kCategoryGenerator };
|
||||
}
|
||||
|
||||
QString TextGeneratorV1::Description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorV1::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kHtmlInput, tr("Enable HTML"));
|
||||
SetInputName(kFontInput, tr("Font"));
|
||||
SetInputName(kFontSizeInput, tr("Font Size"));
|
||||
SetInputName(kColorInput, tr("Color"));
|
||||
SetInputName(kVAlignInput, tr("Vertical Align"));
|
||||
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kHtmlInput, tr("Enable HTML"));
|
||||
SetInputName(kFontInput, tr("Font"));
|
||||
SetInputName(kFontSizeInput, tr("Font Size"));
|
||||
SetInputName(kColorInput, tr("Color"));
|
||||
SetInputName(kVAlignInput, tr("Vertical Align"));
|
||||
SetComboBoxStrings(kVAlignInput, { tr("Top"), tr("Center"), tr("Bottom") });
|
||||
}
|
||||
|
||||
void TextGeneratorV1::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void TextGeneratorV1::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
if (!value[kTextInput].toString().isEmpty()) {
|
||||
table->Push(NodeValue::kTexture, Texture::Job(globals.vparams(), GenerateJob(value)), this);
|
||||
}
|
||||
if (!value[kTextInput].toString().isEmpty()) {
|
||||
table->Push(NodeValue::kTexture,
|
||||
Texture::Job(globals.vparams(), GenerateJob(value)), this);
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorV1::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
void TextGeneratorV1::GenerateFrame(FramePtr frame,
|
||||
const GenerateJob &job) const
|
||||
{
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
|
||||
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
|
||||
// with correct float RGB.
|
||||
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
|
||||
img.fill(0);
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
|
||||
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
|
||||
// with correct float RGB.
|
||||
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
|
||||
img.fill(0);
|
||||
|
||||
QTextDocument text_doc;
|
||||
QTextDocument text_doc;
|
||||
|
||||
// Set default font
|
||||
QFont default_font;
|
||||
default_font.setFamily(job.Get(kFontInput).toString());
|
||||
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
|
||||
text_doc.setDefaultFont(default_font);
|
||||
// Set default font
|
||||
QFont default_font;
|
||||
default_font.setFamily(job.Get(kFontInput).toString());
|
||||
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
|
||||
text_doc.setDefaultFont(default_font);
|
||||
|
||||
// Center by default
|
||||
text_doc.setDefaultTextOption(QTextOption(Qt::AlignCenter));
|
||||
// Center by default
|
||||
text_doc.setDefaultTextOption(QTextOption(Qt::AlignCenter));
|
||||
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
if (job.Get(kHtmlInput).toBool()) {
|
||||
html.replace('\n', QStringLiteral("<br>"));
|
||||
text_doc.setHtml(html);
|
||||
} else {
|
||||
text_doc.setPlainText(html);
|
||||
}
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
if (job.Get(kHtmlInput).toBool()) {
|
||||
html.replace('\n', QStringLiteral("<br>"));
|
||||
text_doc.setHtml(html);
|
||||
} else {
|
||||
text_doc.setPlainText(html);
|
||||
}
|
||||
|
||||
// Align to 80% width because that's considered the "title safe" area
|
||||
int tenth_of_width = frame->video_params().width() / 10;
|
||||
text_doc.setTextWidth(tenth_of_width * 8);
|
||||
// Align to 80% width because that's considered the "title safe" area
|
||||
int tenth_of_width = frame->video_params().width() / 10;
|
||||
text_doc.setTextWidth(tenth_of_width * 8);
|
||||
|
||||
// Draw rich text onto image
|
||||
QPainter p(&img);
|
||||
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
|
||||
// Draw rich text onto image
|
||||
QPainter p(&img);
|
||||
p.scale(1.0 / frame->video_params().divider(),
|
||||
1.0 / frame->video_params().divider());
|
||||
|
||||
// Push 10% inwards to compensate for title safe area
|
||||
p.translate(tenth_of_width, 0);
|
||||
// Push 10% inwards to compensate for title safe area
|
||||
p.translate(tenth_of_width, 0);
|
||||
|
||||
TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
|
||||
int doc_height = text_doc.size().height();
|
||||
TextVerticalAlign valign =
|
||||
static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
|
||||
int doc_height = text_doc.size().height();
|
||||
|
||||
switch (valign) {
|
||||
case kVerticalAlignTop:
|
||||
// Push 10% inwards for title safe area
|
||||
p.translate(0, frame->video_params().height() / 10);
|
||||
break;
|
||||
case kVerticalAlignCenter:
|
||||
// Center align
|
||||
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
|
||||
break;
|
||||
case kVerticalAlignBottom:
|
||||
// Push 10% inwards for title safe area
|
||||
p.translate(0, frame->video_params().height() - doc_height - frame->video_params().height() / 10);
|
||||
break;
|
||||
}
|
||||
switch (valign) {
|
||||
case kVerticalAlignTop:
|
||||
// Push 10% inwards for title safe area
|
||||
p.translate(0, frame->video_params().height() / 10);
|
||||
break;
|
||||
case kVerticalAlignCenter:
|
||||
// Center align
|
||||
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
|
||||
break;
|
||||
case kVerticalAlignBottom:
|
||||
// Push 10% inwards for title safe area
|
||||
p.translate(0, frame->video_params().height() - doc_height -
|
||||
frame->video_params().height() / 10);
|
||||
break;
|
||||
}
|
||||
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, Qt::white);
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, Qt::white);
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
|
||||
// Transplant alpha channel to frame
|
||||
Color rgb = job.Get(kColorInput).toColor();
|
||||
for (int x=0; x<frame->width(); x++) {
|
||||
for (int y=0; y<frame->height(); y++) {
|
||||
uchar src_alpha = img.bits()[img.bytesPerLine() * y + x];
|
||||
float alpha = float(src_alpha) / 255.0f;
|
||||
// Transplant alpha channel to frame
|
||||
Color rgb = job.Get(kColorInput).toColor();
|
||||
for (int x = 0; x < frame->width(); x++) {
|
||||
for (int y = 0; y < frame->height(); y++) {
|
||||
uchar src_alpha = img.bits()[img.bytesPerLine() * y + x];
|
||||
float alpha = float(src_alpha) / 255.0f;
|
||||
|
||||
frame->set_pixel(x, y, Color(rgb.red() * alpha, rgb.green() * alpha, rgb.blue() * alpha, alpha));
|
||||
}
|
||||
}
|
||||
frame->set_pixel(x, y,
|
||||
Color(rgb.red() * alpha, rgb.green() * alpha,
|
||||
rgb.blue() * alpha, alpha));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,34 +23,35 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TextGeneratorV1 : public Node
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class TextGeneratorV1 : public Node {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextGeneratorV1();
|
||||
TextGeneratorV1();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV1)
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV1)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
|
||||
|
||||
static const QString kTextInput;
|
||||
static const QString kHtmlInput;
|
||||
static const QString kColorInput;
|
||||
static const QString kVAlignInput;
|
||||
static const QString kFontInput;
|
||||
static const QString kFontSizeInput;
|
||||
virtual void GenerateFrame(FramePtr frame,
|
||||
const GenerateJob &job) const override;
|
||||
|
||||
static const QString kTextInput;
|
||||
static const QString kHtmlInput;
|
||||
static const QString kColorInput;
|
||||
static const QString kVAlignInput;
|
||||
static const QString kFontInput;
|
||||
static const QString kFontSizeInput;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+107
-100
@@ -25,14 +25,15 @@
|
||||
#include <QDateTime>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super ShapeNodeBase
|
||||
|
||||
enum TextVerticalAlign {
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorV2::kTextInput = QStringLiteral("text_in");
|
||||
@@ -43,156 +44,162 @@ const QString TextGeneratorV2::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
|
||||
TextGeneratorV2::TextGeneratorV2()
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
|
||||
AddInput(kHtmlInput, NodeValue::kBoolean, false);
|
||||
AddInput(kHtmlInput, NodeValue::kBoolean, false);
|
||||
|
||||
AddInput(kVAlignInput, NodeValue::kCombo, kVerticalAlignTop);
|
||||
AddInput(kVAlignInput, NodeValue::kCombo, kVerticalAlignTop);
|
||||
|
||||
AddInput(kFontInput, NodeValue::kFont);
|
||||
AddInput(kFontInput, NodeValue::kFont);
|
||||
|
||||
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
|
||||
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
|
||||
|
||||
SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
|
||||
SetFlag(kDontShowInCreateMenu);
|
||||
SetFlag(kDontShowInCreateMenu);
|
||||
}
|
||||
|
||||
QString TextGeneratorV2::Name() const
|
||||
{
|
||||
return tr("Text (Legacy)");
|
||||
return tr("Text (Legacy)");
|
||||
}
|
||||
|
||||
QString TextGeneratorV2::id() const
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text2");
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text2");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorV2::Category() const
|
||||
{
|
||||
return {kCategoryGenerator};
|
||||
return { kCategoryGenerator };
|
||||
}
|
||||
|
||||
QString TextGeneratorV2::Description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorV2::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kHtmlInput, tr("Enable HTML"));
|
||||
SetInputName(kFontInput, tr("Font"));
|
||||
SetInputName(kFontSizeInput, tr("Font Size"));
|
||||
SetInputName(kVAlignInput, tr("Vertical Align"));
|
||||
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kHtmlInput, tr("Enable HTML"));
|
||||
SetInputName(kFontInput, tr("Font"));
|
||||
SetInputName(kFontSizeInput, tr("Font Size"));
|
||||
SetInputName(kVAlignInput, tr("Vertical Align"));
|
||||
SetComboBoxStrings(kVAlignInput, { tr("Top"), tr("Center"), tr("Bottom") });
|
||||
}
|
||||
|
||||
void TextGeneratorV2::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void TextGeneratorV2::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
if (!value[kTextInput].toString().isEmpty()) {
|
||||
GenerateJob job(value);
|
||||
auto text_params = globals.vparams();
|
||||
text_params.set_format(PixelFormat::F32);
|
||||
table->Push(NodeValue::kTexture, Texture::Job(text_params, job), this);
|
||||
}
|
||||
if (!value[kTextInput].toString().isEmpty()) {
|
||||
GenerateJob job(value);
|
||||
auto text_params = globals.vparams();
|
||||
text_params.set_format(PixelFormat::F32);
|
||||
table->Push(NodeValue::kTexture, Texture::Job(text_params, job), this);
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorV2::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
void TextGeneratorV2::GenerateFrame(FramePtr frame,
|
||||
const GenerateJob &job) const
|
||||
{
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
|
||||
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
|
||||
// with correct float RGB.
|
||||
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
|
||||
img.fill(Qt::transparent);
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
// QImages only support integer pixels and we use float pixels, so what we do here is draw onto
|
||||
// a single-channel QImage (alpha only) and then transplant that alpha channel to our float buffer
|
||||
// with correct float RGB.
|
||||
QImage img(frame->width(), frame->height(), QImage::Format_Grayscale8);
|
||||
img.fill(Qt::transparent);
|
||||
|
||||
// 72 DPI in DPM (72 / 2.54 * 100)
|
||||
const int dpm = 2835;
|
||||
img.setDotsPerMeterX(dpm);
|
||||
img.setDotsPerMeterY(dpm);
|
||||
// 72 DPI in DPM (72 / 2.54 * 100)
|
||||
const int dpm = 2835;
|
||||
img.setDotsPerMeterX(dpm);
|
||||
img.setDotsPerMeterY(dpm);
|
||||
|
||||
QTextDocument text_doc;
|
||||
text_doc.documentLayout()->setPaintDevice(&img);
|
||||
QTextDocument text_doc;
|
||||
text_doc.documentLayout()->setPaintDevice(&img);
|
||||
|
||||
// Set default font
|
||||
QFont default_font;
|
||||
default_font.setFamily(job.Get(kFontInput).toString());
|
||||
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
|
||||
text_doc.setDefaultFont(default_font);
|
||||
// Set default font
|
||||
QFont default_font;
|
||||
default_font.setFamily(job.Get(kFontInput).toString());
|
||||
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
|
||||
text_doc.setDefaultFont(default_font);
|
||||
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
if (job.Get(kHtmlInput).toBool()) {
|
||||
html.replace('\n', QStringLiteral("<br>"));
|
||||
text_doc.setHtml(html);
|
||||
} else {
|
||||
text_doc.setPlainText(html);
|
||||
}
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
if (job.Get(kHtmlInput).toBool()) {
|
||||
html.replace('\n', QStringLiteral("<br>"));
|
||||
text_doc.setHtml(html);
|
||||
} else {
|
||||
text_doc.setPlainText(html);
|
||||
}
|
||||
|
||||
QVector2D size = job.Get(kSizeInput).toVec2();
|
||||
text_doc.setTextWidth(size.x());
|
||||
QVector2D size = job.Get(kSizeInput).toVec2();
|
||||
text_doc.setTextWidth(size.x());
|
||||
|
||||
// Draw rich text onto image
|
||||
QPainter p(&img);
|
||||
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
|
||||
// Draw rich text onto image
|
||||
QPainter p(&img);
|
||||
p.scale(1.0 / frame->video_params().divider(),
|
||||
1.0 / frame->video_params().divider());
|
||||
|
||||
QVector2D pos = job.Get(kPositionInput).toVec2();
|
||||
p.translate(pos.x() - size.x() / 2, pos.y() - size.y() / 2);
|
||||
p.translate(frame->video_params().width() / 2,
|
||||
frame->video_params().height() / 2);
|
||||
p.setClipRect(0, 0, size.x(), size.y());
|
||||
|
||||
QVector2D pos = job.Get(kPositionInput).toVec2();
|
||||
p.translate(pos.x() - size.x()/2, pos.y() - size.y()/2);
|
||||
p.translate(frame->video_params().width()/2, frame->video_params().height()/2);
|
||||
p.setClipRect(0, 0, size.x(), size.y());
|
||||
TextVerticalAlign valign =
|
||||
static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
|
||||
int doc_height = text_doc.size().height();
|
||||
|
||||
TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
|
||||
int doc_height = text_doc.size().height();
|
||||
switch (valign) {
|
||||
case kVerticalAlignTop:
|
||||
// Do nothing
|
||||
break;
|
||||
case kVerticalAlignCenter:
|
||||
// Center align
|
||||
p.translate(0, size.y() / 2 - doc_height / 2);
|
||||
break;
|
||||
case kVerticalAlignBottom:
|
||||
p.translate(0, size.y() - doc_height);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (valign) {
|
||||
case kVerticalAlignTop:
|
||||
// Do nothing
|
||||
break;
|
||||
case kVerticalAlignCenter:
|
||||
// Center align
|
||||
p.translate(0, size.y() / 2 - doc_height / 2);
|
||||
break;
|
||||
case kVerticalAlignBottom:
|
||||
p.translate(0, size.y() - doc_height);
|
||||
break;
|
||||
}
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, Qt::white);
|
||||
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, Qt::white);
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
|
||||
// Transplant alpha channel to frame
|
||||
Color rgba = job.Get(kColorInput).toColor();
|
||||
// Transplant alpha channel to frame
|
||||
Color rgba = job.Get(kColorInput).toColor();
|
||||
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
|
||||
__m128 sse_color = _mm_loadu_ps(rgba.data());
|
||||
__m128 sse_color = _mm_loadu_ps(rgba.data());
|
||||
#endif
|
||||
|
||||
float *frame_dst = reinterpret_cast<float*>(frame->data());
|
||||
for (int y=0; y<frame->height(); y++) {
|
||||
uchar *src_y = img.bits() + img.bytesPerLine() * y;
|
||||
float *dst_y = frame_dst + y*frame->linesize_pixels()*VideoParams::kRGBAChannelCount;
|
||||
float *frame_dst = reinterpret_cast<float *>(frame->data());
|
||||
for (int y = 0; y < frame->height(); y++) {
|
||||
uchar *src_y = img.bits() + img.bytesPerLine() * y;
|
||||
float *dst_y = frame_dst + y * frame->linesize_pixels() *
|
||||
VideoParams::kRGBAChannelCount;
|
||||
|
||||
for (int x=0; x<frame->width(); x++) {
|
||||
float alpha = float(src_y[x]) / 255.0f;
|
||||
float *dst = dst_y + x*VideoParams::kRGBAChannelCount;
|
||||
for (int x = 0; x < frame->width(); x++) {
|
||||
float alpha = float(src_y[x]) / 255.0f;
|
||||
float *dst = dst_y + x * VideoParams::kRGBAChannelCount;
|
||||
|
||||
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
|
||||
__m128 sse_alpha = _mm_load1_ps(&alpha);
|
||||
__m128 sse_res = _mm_mul_ps(sse_color, sse_alpha);
|
||||
__m128 sse_alpha = _mm_load1_ps(&alpha);
|
||||
__m128 sse_res = _mm_mul_ps(sse_color, sse_alpha);
|
||||
|
||||
_mm_store_ps(dst, sse_res);
|
||||
_mm_store_ps(dst, sse_res);
|
||||
#else
|
||||
for (int i=0; i<VideoParams::kRGBAChannelCount; i++) {
|
||||
dst[i] = rgba.data()[i] * alpha;
|
||||
}
|
||||
for (int i = 0; i < VideoParams::kRGBAChannelCount; i++) {
|
||||
dst[i] = rgba.data()[i] * alpha;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,33 +23,34 @@
|
||||
|
||||
#include "node/generator/shape/shapenodebase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TextGeneratorV2 : public ShapeNodeBase
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class TextGeneratorV2 : public ShapeNodeBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextGeneratorV2();
|
||||
TextGeneratorV2();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV2)
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV2)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
|
||||
|
||||
static const QString kTextInput;
|
||||
static const QString kHtmlInput;
|
||||
static const QString kVAlignInput;
|
||||
static const QString kFontInput;
|
||||
static const QString kFontSizeInput;
|
||||
virtual void GenerateFrame(FramePtr frame,
|
||||
const GenerateJob &job) const override;
|
||||
|
||||
static const QString kTextInput;
|
||||
static const QString kHtmlInput;
|
||||
static const QString kVAlignInput;
|
||||
static const QString kFontInput;
|
||||
static const QString kFontSizeInput;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+182
-154
@@ -29,253 +29,281 @@
|
||||
#include "node/project.h"
|
||||
#include "node/nodeundo.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super ShapeNodeBase
|
||||
|
||||
enum TextVerticalAlign {
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorV3::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV3::kVerticalAlignmentInput = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV3::kVerticalAlignmentInput =
|
||||
QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV3::kUseArgsInput = QStringLiteral("use_args_in");
|
||||
const QString TextGeneratorV3::kArgsInput = QStringLiteral("args_in");
|
||||
|
||||
TextGeneratorV3::TextGeneratorV3() :
|
||||
ShapeNodeBase(false),
|
||||
dont_emit_valign_(false)
|
||||
TextGeneratorV3::TextGeneratorV3()
|
||||
: ShapeNodeBase(false)
|
||||
, dont_emit_valign_(false)
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>").arg(tr("Sample Text")));
|
||||
SetInputProperty(kTextInput, QStringLiteral("vieweronly"), true);
|
||||
AddInput(kTextInput, NodeValue::kText,
|
||||
QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>")
|
||||
.arg(tr("Sample Text")));
|
||||
SetInputProperty(kTextInput, QStringLiteral("vieweronly"), true);
|
||||
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
|
||||
AddInput(kVerticalAlignmentInput, NodeValue::kCombo, InputFlags(kInputFlagHidden | kInputFlagStatic));
|
||||
AddInput(kVerticalAlignmentInput, NodeValue::kCombo,
|
||||
InputFlags(kInputFlagHidden | kInputFlagStatic));
|
||||
|
||||
AddInput(kUseArgsInput, NodeValue::kBoolean, true, InputFlags(kInputFlagHidden | kInputFlagStatic));
|
||||
AddInput(kUseArgsInput, NodeValue::kBoolean, true,
|
||||
InputFlags(kInputFlagHidden | kInputFlagStatic));
|
||||
|
||||
AddInput(kArgsInput, NodeValue::kText, InputFlags(kInputFlagArray));
|
||||
SetInputProperty(kArgsInput, QStringLiteral("arraystart"), 1);
|
||||
AddInput(kArgsInput, NodeValue::kText, InputFlags(kInputFlagArray));
|
||||
SetInputProperty(kArgsInput, QStringLiteral("arraystart"), 1);
|
||||
|
||||
text_gizmo_ = new TextGizmo(this);
|
||||
text_gizmo_->SetInput(NodeInput(this, kTextInput));
|
||||
connect(text_gizmo_, &TextGizmo::Activated, this, &TextGeneratorV3::GizmoActivated);
|
||||
connect(text_gizmo_, &TextGizmo::Deactivated, this, &TextGeneratorV3::GizmoDeactivated);
|
||||
text_gizmo_ = new TextGizmo(this);
|
||||
text_gizmo_->SetInput(NodeInput(this, kTextInput));
|
||||
connect(text_gizmo_, &TextGizmo::Activated, this,
|
||||
&TextGeneratorV3::GizmoActivated);
|
||||
connect(text_gizmo_, &TextGizmo::Deactivated, this,
|
||||
&TextGeneratorV3::GizmoDeactivated);
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::Name() const
|
||||
{
|
||||
return tr("Text");
|
||||
return tr("Text");
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::id() const
|
||||
{
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text3");
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text3");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorV3::Category() const
|
||||
{
|
||||
return {kCategoryGenerator};
|
||||
return { kCategoryGenerator };
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::Description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorV3::Retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::Retranslate();
|
||||
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kVerticalAlignmentInput, tr("Vertical Alignment"));
|
||||
SetComboBoxStrings(kVerticalAlignmentInput, {tr("Top"), tr("Middle"), tr("Bottom")});
|
||||
SetInputName(kArgsInput, tr("Arguments"));
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kVerticalAlignmentInput, tr("Vertical Alignment"));
|
||||
SetComboBoxStrings(kVerticalAlignmentInput,
|
||||
{ tr("Top"), tr("Middle"), tr("Bottom") });
|
||||
SetInputName(kArgsInput, tr("Arguments"));
|
||||
}
|
||||
|
||||
void TextGeneratorV3::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
|
||||
void TextGeneratorV3::Value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
QString text = value[kTextInput].toString();
|
||||
QString text = value[kTextInput].toString();
|
||||
|
||||
if (value[kUseArgsInput].toBool()) {
|
||||
auto args = value[kArgsInput].toArray();
|
||||
if (!args.empty()) {
|
||||
QStringList list;
|
||||
list.reserve(args.size());
|
||||
for (size_t i=0; i<args.size(); i++) {
|
||||
list.append(args[i].toString());
|
||||
}
|
||||
if (value[kUseArgsInput].toBool()) {
|
||||
auto args = value[kArgsInput].toArray();
|
||||
if (!args.empty()) {
|
||||
QStringList list;
|
||||
list.reserve(args.size());
|
||||
for (size_t i = 0; i < args.size(); i++) {
|
||||
list.append(args[i].toString());
|
||||
}
|
||||
|
||||
text = FormatString(text, list);
|
||||
}
|
||||
}
|
||||
text = FormatString(text, list);
|
||||
}
|
||||
}
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
TexturePtr base = value[kTextInput].toTexture();
|
||||
if (!text.isEmpty()) {
|
||||
TexturePtr base = value[kTextInput].toTexture();
|
||||
|
||||
VideoParams text_params = base ? base->params() : globals.vparams();
|
||||
text_params.set_format(PixelFormat::U8);
|
||||
text_params.set_colorspace(project()->color_manager()->GetDefaultInputColorSpace());
|
||||
VideoParams text_params = base ? base->params() : globals.vparams();
|
||||
text_params.set_format(PixelFormat::U8);
|
||||
text_params.set_colorspace(
|
||||
project()->color_manager()->GetDefaultInputColorSpace());
|
||||
|
||||
GenerateJob job(value);
|
||||
job.Insert(kTextInput, NodeValue(NodeValue::kText, text));
|
||||
GenerateJob job(value);
|
||||
job.Insert(kTextInput, NodeValue(NodeValue::kText, text));
|
||||
|
||||
PushMergableJob(value, Texture::Job(text_params, job), table);
|
||||
} else if (value[kBaseInput].toTexture()) {
|
||||
table->Push(value[kBaseInput]);
|
||||
}
|
||||
PushMergableJob(value, Texture::Job(text_params, job), table);
|
||||
} else if (value[kBaseInput].toTexture()) {
|
||||
table->Push(value[kBaseInput]);
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorV3::GenerateFrame(FramePtr frame, const GenerateJob& job) const
|
||||
void TextGeneratorV3::GenerateFrame(FramePtr frame,
|
||||
const GenerateJob &job) const
|
||||
{
|
||||
QImage img(reinterpret_cast<uchar*>(frame->data()), frame->width(), frame->height(), frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
|
||||
img.fill(Qt::transparent);
|
||||
QImage img(reinterpret_cast<uchar *>(frame->data()), frame->width(),
|
||||
frame->height(), frame->linesize_bytes(),
|
||||
QImage::Format_RGBA8888_Premultiplied);
|
||||
img.fill(Qt::transparent);
|
||||
|
||||
// 96 DPI in DPM (96 / 2.54 * 100)
|
||||
const int dpm = 3780;
|
||||
img.setDotsPerMeterX(dpm);
|
||||
img.setDotsPerMeterY(dpm);
|
||||
// 96 DPI in DPM (96 / 2.54 * 100)
|
||||
const int dpm = 3780;
|
||||
img.setDotsPerMeterX(dpm);
|
||||
img.setDotsPerMeterY(dpm);
|
||||
|
||||
QTextDocument text_doc;
|
||||
text_doc.documentLayout()->setPaintDevice(&img);
|
||||
QTextDocument text_doc;
|
||||
text_doc.documentLayout()->setPaintDevice(&img);
|
||||
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
Html::HtmlToDoc(&text_doc, html);
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
Html::HtmlToDoc(&text_doc, html);
|
||||
|
||||
QVector2D size = job.Get(kSizeInput).toVec2();
|
||||
text_doc.setTextWidth(size.x());
|
||||
QVector2D size = job.Get(kSizeInput).toVec2();
|
||||
text_doc.setTextWidth(size.x());
|
||||
|
||||
// Draw rich text onto image
|
||||
QPainter p(&img);
|
||||
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
|
||||
// Draw rich text onto image
|
||||
QPainter p(&img);
|
||||
p.scale(1.0 / frame->video_params().divider(),
|
||||
1.0 / frame->video_params().divider());
|
||||
|
||||
QVector2D pos = job.Get(kPositionInput).toVec2();
|
||||
p.translate(pos.x() - size.x()/2, pos.y() - size.y()/2);
|
||||
p.translate(frame->video_params().width()/2, frame->video_params().height()/2);
|
||||
p.setClipRect(0, 0, size.x(), size.y());
|
||||
QVector2D pos = job.Get(kPositionInput).toVec2();
|
||||
p.translate(pos.x() - size.x() / 2, pos.y() - size.y() / 2);
|
||||
p.translate(frame->video_params().width() / 2,
|
||||
frame->video_params().height() / 2);
|
||||
p.setClipRect(0, 0, size.x(), size.y());
|
||||
|
||||
switch (static_cast<VerticalAlignment>(job.Get(kVerticalAlignmentInput).toInt())) {
|
||||
case kVAlignTop:
|
||||
// Do nothing
|
||||
break;
|
||||
case kVAlignMiddle:
|
||||
p.translate(0, size.y()/2-text_doc.size().height()/2);
|
||||
break;
|
||||
case kVAlignBottom:
|
||||
p.translate(0, size.y()-text_doc.size().height());
|
||||
break;
|
||||
}
|
||||
switch (static_cast<VerticalAlignment>(
|
||||
job.Get(kVerticalAlignmentInput).toInt())) {
|
||||
case kVAlignTop:
|
||||
// Do nothing
|
||||
break;
|
||||
case kVAlignMiddle:
|
||||
p.translate(0, size.y() / 2 - text_doc.size().height() / 2);
|
||||
break;
|
||||
case kVAlignBottom:
|
||||
p.translate(0, size.y() - text_doc.size().height());
|
||||
break;
|
||||
}
|
||||
|
||||
// Ensure default text color is white
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, Qt::white);
|
||||
// Ensure default text color is white
|
||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||
ctx.palette.setColor(QPalette::Text, Qt::white);
|
||||
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
}
|
||||
|
||||
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
|
||||
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
super::UpdateGizmoPositions(row, globals);
|
||||
super::UpdateGizmoPositions(row, globals);
|
||||
|
||||
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
|
||||
text_gizmo_->SetRect(rect);
|
||||
text_gizmo_->SetHtml(row[kTextInput].toString());
|
||||
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
|
||||
text_gizmo_->SetRect(rect);
|
||||
text_gizmo_->SetHtml(row[kTextInput].toString());
|
||||
}
|
||||
|
||||
Qt::Alignment TextGeneratorV3::GetQtAlignmentFromOurs(VerticalAlignment v)
|
||||
{
|
||||
switch (v) {
|
||||
case kVAlignTop:
|
||||
return Qt::AlignTop;
|
||||
case kVAlignMiddle:
|
||||
return Qt::AlignVCenter;
|
||||
case kVAlignBottom:
|
||||
return Qt::AlignBottom;
|
||||
}
|
||||
return Qt::Alignment();
|
||||
switch (v) {
|
||||
case kVAlignTop:
|
||||
return Qt::AlignTop;
|
||||
case kVAlignMiddle:
|
||||
return Qt::AlignVCenter;
|
||||
case kVAlignBottom:
|
||||
return Qt::AlignBottom;
|
||||
}
|
||||
return Qt::Alignment();
|
||||
}
|
||||
|
||||
TextGeneratorV3::VerticalAlignment TextGeneratorV3::GetOurAlignmentFromQts(Qt::Alignment v)
|
||||
TextGeneratorV3::VerticalAlignment
|
||||
TextGeneratorV3::GetOurAlignmentFromQts(Qt::Alignment v)
|
||||
{
|
||||
switch (v) {
|
||||
case Qt::AlignTop:
|
||||
return kVAlignTop;
|
||||
case Qt::AlignVCenter:
|
||||
return kVAlignMiddle;
|
||||
case Qt::AlignBottom:
|
||||
return kVAlignBottom;
|
||||
}
|
||||
switch (v) {
|
||||
case Qt::AlignTop:
|
||||
return kVAlignTop;
|
||||
case Qt::AlignVCenter:
|
||||
return kVAlignMiddle;
|
||||
case Qt::AlignBottom:
|
||||
return kVAlignBottom;
|
||||
}
|
||||
|
||||
return kVAlignTop;
|
||||
return kVAlignTop;
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::FormatString(const QString &input, const QStringList &args)
|
||||
QString TextGeneratorV3::FormatString(const QString &input,
|
||||
const QStringList &args)
|
||||
{
|
||||
QString output;
|
||||
output.reserve(input.size());
|
||||
QString output;
|
||||
output.reserve(input.size());
|
||||
|
||||
for (int i=0; i<input.size(); i++) {
|
||||
const QChar &this_char = input.at(i);
|
||||
for (int i = 0; i < input.size(); i++) {
|
||||
const QChar &this_char = input.at(i);
|
||||
|
||||
if (i < input.size()-1 && this_char == '%') {
|
||||
const QChar &next_char = input.at(i+1);
|
||||
if (next_char == '%') {
|
||||
// Double percent, append a single percent
|
||||
output.append('%');
|
||||
i++;
|
||||
} else if (next_char.isDigit()) {
|
||||
// Find length of number
|
||||
QString num;
|
||||
i++;
|
||||
while (i < input.size() && input.at(i).isDigit()) {
|
||||
num.append(input.at(i));
|
||||
i++;
|
||||
}
|
||||
i--;
|
||||
int index = num.toInt()-1;
|
||||
if (index >= 0 && index < args.size()) {
|
||||
output.append(args.at(index));
|
||||
}
|
||||
} else {
|
||||
output.append(this_char);
|
||||
}
|
||||
} else {
|
||||
output.append(this_char);
|
||||
}
|
||||
}
|
||||
if (i < input.size() - 1 && this_char == '%') {
|
||||
const QChar &next_char = input.at(i + 1);
|
||||
if (next_char == '%') {
|
||||
// Double percent, append a single percent
|
||||
output.append('%');
|
||||
i++;
|
||||
} else if (next_char.isDigit()) {
|
||||
// Find length of number
|
||||
QString num;
|
||||
i++;
|
||||
while (i < input.size() && input.at(i).isDigit()) {
|
||||
num.append(input.at(i));
|
||||
i++;
|
||||
}
|
||||
i--;
|
||||
int index = num.toInt() - 1;
|
||||
if (index >= 0 && index < args.size()) {
|
||||
output.append(args.at(index));
|
||||
}
|
||||
} else {
|
||||
output.append(this_char);
|
||||
}
|
||||
} else {
|
||||
output.append(this_char);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
return output;
|
||||
}
|
||||
|
||||
void TextGeneratorV3::InputValueChangedEvent(const QString &input, int element)
|
||||
{
|
||||
if (input == kVerticalAlignmentInput && !dont_emit_valign_) {
|
||||
text_gizmo_->SetVerticalAlignment(GetQtAlignmentFromOurs(GetVerticalAlignment()));
|
||||
}
|
||||
if (input == kVerticalAlignmentInput && !dont_emit_valign_) {
|
||||
text_gizmo_->SetVerticalAlignment(
|
||||
GetQtAlignmentFromOurs(GetVerticalAlignment()));
|
||||
}
|
||||
|
||||
super::InputValueChangedEvent(input, element);
|
||||
super::InputValueChangedEvent(input, element);
|
||||
}
|
||||
|
||||
void TextGeneratorV3::GizmoActivated()
|
||||
{
|
||||
SetStandardValue(kUseArgsInput, false);
|
||||
connect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this, &TextGeneratorV3::SetVerticalAlignmentUndoable);
|
||||
dont_emit_valign_ = true;
|
||||
SetStandardValue(kUseArgsInput, false);
|
||||
connect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
|
||||
&TextGeneratorV3::SetVerticalAlignmentUndoable);
|
||||
dont_emit_valign_ = true;
|
||||
}
|
||||
|
||||
void TextGeneratorV3::GizmoDeactivated()
|
||||
{
|
||||
SetStandardValue(kUseArgsInput, true);
|
||||
disconnect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this, &TextGeneratorV3::SetVerticalAlignmentUndoable);
|
||||
dont_emit_valign_ = true;
|
||||
SetStandardValue(kUseArgsInput, true);
|
||||
disconnect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
|
||||
&TextGeneratorV3::SetVerticalAlignmentUndoable);
|
||||
dont_emit_valign_ = true;
|
||||
}
|
||||
|
||||
void TextGeneratorV3::SetVerticalAlignmentUndoable(Qt::Alignment a)
|
||||
{
|
||||
Core::instance()->undo_stack()->push(new NodeParamSetStandardValueCommand(NodeInput(this, kVerticalAlignmentInput), GetOurAlignmentFromQts(a)), tr("Set Text Vertical Alignment"));
|
||||
Core::instance()->undo_stack()->push(
|
||||
new NodeParamSetStandardValueCommand(NodeInput(this,
|
||||
kVerticalAlignmentInput),
|
||||
GetOurAlignmentFromQts(a)),
|
||||
tr("Set Text Vertical Alignment"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,64 +24,63 @@
|
||||
#include "node/generator/shape/shapenodebase.h"
|
||||
#include "node/gizmo/text.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TextGeneratorV3 : public ShapeNodeBase
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class TextGeneratorV3 : public ShapeNodeBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextGeneratorV3();
|
||||
TextGeneratorV3();
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV3)
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV3)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
virtual QString Name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
|
||||
virtual void Value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;
|
||||
virtual void GenerateFrame(FramePtr frame,
|
||||
const GenerateJob &job) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
enum VerticalAlignment
|
||||
{
|
||||
kVAlignTop,
|
||||
kVAlignMiddle,
|
||||
kVAlignBottom
|
||||
};
|
||||
enum VerticalAlignment { kVAlignTop, kVAlignMiddle, kVAlignBottom };
|
||||
|
||||
VerticalAlignment GetVerticalAlignment() const
|
||||
{
|
||||
return static_cast<VerticalAlignment>(GetStandardValue(kVerticalAlignmentInput).toInt());
|
||||
}
|
||||
VerticalAlignment GetVerticalAlignment() const
|
||||
{
|
||||
return static_cast<VerticalAlignment>(
|
||||
GetStandardValue(kVerticalAlignmentInput).toInt());
|
||||
}
|
||||
|
||||
static Qt::Alignment GetQtAlignmentFromOurs(VerticalAlignment v);
|
||||
static VerticalAlignment GetOurAlignmentFromQts(Qt::Alignment v);
|
||||
static Qt::Alignment GetQtAlignmentFromOurs(VerticalAlignment v);
|
||||
static VerticalAlignment GetOurAlignmentFromQts(Qt::Alignment v);
|
||||
|
||||
static const QString kTextInput;
|
||||
static const QString kVerticalAlignmentInput;
|
||||
static const QString kUseArgsInput;
|
||||
static const QString kArgsInput;
|
||||
static const QString kTextInput;
|
||||
static const QString kVerticalAlignmentInput;
|
||||
static const QString kUseArgsInput;
|
||||
static const QString kArgsInput;
|
||||
|
||||
static QString FormatString(const QString &input, const QStringList &args);
|
||||
static QString FormatString(const QString &input, const QStringList &args);
|
||||
|
||||
protected:
|
||||
virtual void InputValueChangedEvent(const QString &input, int element) override;
|
||||
virtual void InputValueChangedEvent(const QString &input,
|
||||
int element) override;
|
||||
|
||||
private:
|
||||
TextGizmo *text_gizmo_;
|
||||
TextGizmo *text_gizmo_;
|
||||
|
||||
bool dont_emit_valign_;
|
||||
bool dont_emit_valign_;
|
||||
|
||||
private slots:
|
||||
void GizmoActivated();
|
||||
void GizmoDeactivated();
|
||||
void SetVerticalAlignmentUndoable(Qt::Alignment a);
|
||||
|
||||
void GizmoActivated();
|
||||
void GizmoDeactivated();
|
||||
void SetVerticalAlignmentUndoable(Qt::Alignment a);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user