style: unify identifier naming per updated conventions
Automated with clang-tidy readability-identifier-naming (config added to .clang-tidy) plus scripted passes, per the updated rules now documented in CONTRIBUTING.md: - types (class/struct/enum/alias/template params): PascalCase - functions, variables, members: snake_case (incl. rational -> Rational) - private/protected members: trailing underscore; static member variables likewise (instance_, available_themes_) - constants and enum values: snake_case (kLinear -> k_linear, F32P -> f32p); ALL_CAPS reserved for macros - macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG -> OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE, include guards -> OAK_*) - file names: all lowercase (Current/Plugin/OliveHost/OliveClip/ OlivePluginInstance -> current/plugin/olivehost/oliveclip/ oliveplugininstance) - getters share the member name sans underscore, setters set_foo() - Qt and third-party (OpenFX) virtual overrides and framework callbacks keep their original names (exempt in .clang-tidy) Manual follow-ups required where automation could not reach: - string-based QMetaObject/SIGNAL/SLOT references updated to renamed methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...) - macro bodies referencing renamed methods (OLIVE_CONFIG, NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*) - self-shadowing locals renamed where signals/methods became same-named (size_changed, worker_count, selected_items, import param, filters) - third_party OFX member/namespace usages restored (OFX::Host::*, _created, _clipPrefsDirty, createInstance, clearPersistentMessage) - STL protocol aliases restored (const_iterator) with .clang-tidy ignore rules; qHash overloads restored Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
This commit is contained in:
@@ -28,39 +28,39 @@ namespace olive
|
||||
{
|
||||
|
||||
enum TextVerticalAlign {
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
k_vertical_align_top,
|
||||
k_vertical_align_center,
|
||||
k_vertical_align_bottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorV1::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV1::kHtmlInput = QStringLiteral("html_in");
|
||||
const QString TextGeneratorV1::kColorInput = QStringLiteral("color_in");
|
||||
const QString TextGeneratorV1::kVAlignInput = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV1::kFontInput = QStringLiteral("font_in");
|
||||
const QString TextGeneratorV1::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
const QString TextGeneratorV1::k_text_input = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV1::k_html_input = QStringLiteral("html_in");
|
||||
const QString TextGeneratorV1::k_color_input = QStringLiteral("color_in");
|
||||
const QString TextGeneratorV1::k_v_align_input = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV1::k_font_input = QStringLiteral("font_in");
|
||||
const QString TextGeneratorV1::k_font_size_input = QStringLiteral("font_size_in");
|
||||
|
||||
#define super Node
|
||||
|
||||
TextGeneratorV1::TextGeneratorV1()
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
add_input(k_text_input, NodeValue::k_text, tr("Sample Text"));
|
||||
|
||||
AddInput(kHtmlInput, NodeValue::kBoolean, false);
|
||||
add_input(k_html_input, NodeValue::k_boolean, false);
|
||||
|
||||
AddInput(kColorInput, NodeValue::kColor,
|
||||
add_input(k_color_input, NodeValue::k_color,
|
||||
QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
|
||||
|
||||
AddInput(kVAlignInput, NodeValue::kCombo, 1);
|
||||
add_input(k_v_align_input, NodeValue::k_combo, 1);
|
||||
|
||||
AddInput(kFontInput, NodeValue::kFont);
|
||||
add_input(k_font_input, NodeValue::k_font);
|
||||
|
||||
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
|
||||
add_input(k_font_size_input, NodeValue::k_float, 72.0f);
|
||||
|
||||
SetFlag(kDontShowInCreateMenu);
|
||||
set_flag(k_dont_show_in_create_menu);
|
||||
}
|
||||
|
||||
QString TextGeneratorV1::Name() const
|
||||
QString TextGeneratorV1::name() const
|
||||
{
|
||||
return tr("Text (Legacy)");
|
||||
}
|
||||
@@ -70,40 +70,40 @@ QString TextGeneratorV1::id() const
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.textgenerator");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorV1::Category() const
|
||||
QVector<Node::CategoryID> TextGeneratorV1::category() const
|
||||
{
|
||||
return { kCategoryGenerator };
|
||||
return { k_category_generator };
|
||||
}
|
||||
|
||||
QString TextGeneratorV1::Description() const
|
||||
QString TextGeneratorV1::description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorV1::Retranslate()
|
||||
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") });
|
||||
set_input_name(k_text_input, tr("Text"));
|
||||
set_input_name(k_html_input, tr("Enable HTML"));
|
||||
set_input_name(k_font_input, tr("Font"));
|
||||
set_input_name(k_font_size_input, tr("Font Size"));
|
||||
set_input_name(k_color_input, tr("Color"));
|
||||
set_input_name(k_v_align_input, tr("Vertical Align"));
|
||||
set_combo_box_strings(k_v_align_input, { tr("Top"), tr("Center"), tr("Bottom") });
|
||||
}
|
||||
|
||||
void TextGeneratorV1::Value(const NodeValueRow &value,
|
||||
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[k_text_input].to_string().isEmpty()) {
|
||||
table->push(NodeValue::k_texture,
|
||||
Texture::job(globals.vparams(), GenerateJob(value)), this);
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorV1::GenerateFrame(FramePtr frame,
|
||||
void TextGeneratorV1::generate_frame(FramePtr frame,
|
||||
const GenerateJob &job) const
|
||||
{
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
@@ -117,15 +117,15 @@ void TextGeneratorV1::GenerateFrame(FramePtr frame,
|
||||
|
||||
// Set default font
|
||||
QFont default_font;
|
||||
default_font.setFamily(job.Get(kFontInput).toString());
|
||||
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
|
||||
default_font.setFamily(job.get(k_font_input).to_string());
|
||||
default_font.setPointSizeF(job.get(k_font_size_input).to_double());
|
||||
text_doc.setDefaultFont(default_font);
|
||||
|
||||
// Center by default
|
||||
text_doc.setDefaultTextOption(QTextOption(Qt::AlignCenter));
|
||||
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
if (job.Get(kHtmlInput).toBool()) {
|
||||
QString html = job.get(k_text_input).to_string();
|
||||
if (job.get(k_html_input).to_bool()) {
|
||||
html.replace('\n', QStringLiteral("<br>"));
|
||||
text_doc.setHtml(html);
|
||||
} else {
|
||||
@@ -145,19 +145,19 @@ void TextGeneratorV1::GenerateFrame(FramePtr frame,
|
||||
p.translate(tenth_of_width, 0);
|
||||
|
||||
TextVerticalAlign valign =
|
||||
static_cast<TextVerticalAlign>(job.Get(kVAlignInput).toInt());
|
||||
static_cast<TextVerticalAlign>(job.get(k_v_align_input).to_int());
|
||||
int doc_height = text_doc.size().height();
|
||||
|
||||
switch (valign) {
|
||||
case kVerticalAlignTop:
|
||||
case k_vertical_align_top:
|
||||
// Push 10% inwards for title safe area
|
||||
p.translate(0, frame->video_params().height() / 10);
|
||||
break;
|
||||
case kVerticalAlignCenter:
|
||||
case k_vertical_align_center:
|
||||
// Center align
|
||||
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
|
||||
break;
|
||||
case kVerticalAlignBottom:
|
||||
case k_vertical_align_bottom:
|
||||
// Push 10% inwards for title safe area
|
||||
p.translate(0, frame->video_params().height() - doc_height -
|
||||
frame->video_params().height() / 10);
|
||||
@@ -169,7 +169,7 @@ void TextGeneratorV1::GenerateFrame(FramePtr frame,
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
|
||||
// Transplant alpha channel to frame
|
||||
Color rgb = job.Get(kColorInput).toColor();
|
||||
Color rgb = job.get(k_color_input).to_color();
|
||||
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];
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TEXTGENERATORV1_H
|
||||
#define TEXTGENERATORV1_H
|
||||
#ifndef OAK_TEXTGENERATORV1_H
|
||||
#define OAK_TEXTGENERATORV1_H
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
@@ -34,27 +34,27 @@ public:
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV1)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() 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,
|
||||
virtual void value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame,
|
||||
virtual void generate_frame(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;
|
||||
static const QString k_text_input;
|
||||
static const QString k_html_input;
|
||||
static const QString k_color_input;
|
||||
static const QString k_v_align_input;
|
||||
static const QString k_font_input;
|
||||
static const QString k_font_size_input;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TEXTGENERATORV1_H
|
||||
#endif // OAK_TEXTGENERATORV1_H
|
||||
|
||||
@@ -32,36 +32,36 @@ namespace olive
|
||||
#define super ShapeNodeBase
|
||||
|
||||
enum TextVerticalAlign {
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
k_vertical_align_top,
|
||||
k_vertical_align_center,
|
||||
k_vertical_align_bottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorV2::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV2::kHtmlInput = QStringLiteral("html_in");
|
||||
const QString TextGeneratorV2::kVAlignInput = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV2::kFontInput = QStringLiteral("font_in");
|
||||
const QString TextGeneratorV2::kFontSizeInput = QStringLiteral("font_size_in");
|
||||
const QString TextGeneratorV2::k_text_input = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV2::k_html_input = QStringLiteral("html_in");
|
||||
const QString TextGeneratorV2::k_v_align_input = QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV2::k_font_input = QStringLiteral("font_in");
|
||||
const QString TextGeneratorV2::k_font_size_input = QStringLiteral("font_size_in");
|
||||
|
||||
TextGeneratorV2::TextGeneratorV2()
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText, tr("Sample Text"));
|
||||
add_input(k_text_input, NodeValue::k_text, tr("Sample Text"));
|
||||
|
||||
AddInput(kHtmlInput, NodeValue::kBoolean, false);
|
||||
add_input(k_html_input, NodeValue::k_boolean, false);
|
||||
|
||||
AddInput(kVAlignInput, NodeValue::kCombo, kVerticalAlignTop);
|
||||
add_input(k_v_align_input, NodeValue::k_combo, k_vertical_align_top);
|
||||
|
||||
AddInput(kFontInput, NodeValue::kFont);
|
||||
add_input(k_font_input, NodeValue::k_font);
|
||||
|
||||
AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);
|
||||
add_input(k_font_size_input, NodeValue::k_float, 72.0f);
|
||||
|
||||
SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
set_standard_value(k_color_input, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
|
||||
set_standard_value(k_size_input, QVector2D(400, 300));
|
||||
|
||||
SetFlag(kDontShowInCreateMenu);
|
||||
set_flag(k_dont_show_in_create_menu);
|
||||
}
|
||||
|
||||
QString TextGeneratorV2::Name() const
|
||||
QString TextGeneratorV2::name() const
|
||||
{
|
||||
return tr("Text (Legacy)");
|
||||
}
|
||||
@@ -71,41 +71,41 @@ QString TextGeneratorV2::id() const
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text2");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorV2::Category() const
|
||||
QVector<Node::CategoryID> TextGeneratorV2::category() const
|
||||
{
|
||||
return { kCategoryGenerator };
|
||||
return { k_category_generator };
|
||||
}
|
||||
|
||||
QString TextGeneratorV2::Description() const
|
||||
QString TextGeneratorV2::description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorV2::Retranslate()
|
||||
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") });
|
||||
set_input_name(k_text_input, tr("Text"));
|
||||
set_input_name(k_html_input, tr("Enable HTML"));
|
||||
set_input_name(k_font_input, tr("Font"));
|
||||
set_input_name(k_font_size_input, tr("Font Size"));
|
||||
set_input_name(k_v_align_input, tr("Vertical Align"));
|
||||
set_combo_box_strings(k_v_align_input, { tr("Top"), tr("Center"), tr("Bottom") });
|
||||
}
|
||||
|
||||
void TextGeneratorV2::Value(const NodeValueRow &value,
|
||||
void TextGeneratorV2::value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
if (!value[kTextInput].toString().isEmpty()) {
|
||||
if (!value[k_text_input].to_string().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);
|
||||
text_params.set_format(PixelFormat::f32);
|
||||
table->push(NodeValue::k_texture, Texture::job(text_params, job), this);
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorV2::GenerateFrame(FramePtr frame,
|
||||
void TextGeneratorV2::generate_frame(FramePtr frame,
|
||||
const GenerateJob &job) const
|
||||
{
|
||||
// This could probably be more optimized, but for now we use Qt to draw to a QImage.
|
||||
@@ -125,19 +125,19 @@ void TextGeneratorV2::GenerateFrame(FramePtr frame,
|
||||
|
||||
// Set default font
|
||||
QFont default_font;
|
||||
default_font.setFamily(job.Get(kFontInput).toString());
|
||||
default_font.setPointSizeF(job.Get(kFontSizeInput).toDouble());
|
||||
default_font.setFamily(job.get(k_font_input).to_string());
|
||||
default_font.setPointSizeF(job.get(k_font_size_input).to_double());
|
||||
text_doc.setDefaultFont(default_font);
|
||||
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
if (job.Get(kHtmlInput).toBool()) {
|
||||
QString html = job.get(k_text_input).to_string();
|
||||
if (job.get(k_html_input).to_bool()) {
|
||||
html.replace('\n', QStringLiteral("<br>"));
|
||||
text_doc.setHtml(html);
|
||||
} else {
|
||||
text_doc.setPlainText(html);
|
||||
}
|
||||
|
||||
QVector2D size = job.Get(kSizeInput).toVec2();
|
||||
QVector2D size = job.get(k_size_input).to_vec2();
|
||||
text_doc.setTextWidth(size.x());
|
||||
|
||||
// Draw rich text onto image
|
||||
@@ -145,25 +145,25 @@ void TextGeneratorV2::GenerateFrame(FramePtr frame,
|
||||
p.scale(1.0 / frame->video_params().divider(),
|
||||
1.0 / frame->video_params().divider());
|
||||
|
||||
QVector2D pos = job.Get(kPositionInput).toVec2();
|
||||
QVector2D pos = job.get(k_position_input).to_vec2();
|
||||
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());
|
||||
static_cast<TextVerticalAlign>(job.get(k_v_align_input).to_int());
|
||||
int doc_height = text_doc.size().height();
|
||||
|
||||
switch (valign) {
|
||||
case kVerticalAlignTop:
|
||||
case k_vertical_align_top:
|
||||
// Do nothing
|
||||
break;
|
||||
case kVerticalAlignCenter:
|
||||
case k_vertical_align_center:
|
||||
// Center align
|
||||
p.translate(0, size.y() / 2 - doc_height / 2);
|
||||
break;
|
||||
case kVerticalAlignBottom:
|
||||
case k_vertical_align_bottom:
|
||||
p.translate(0, size.y() - doc_height);
|
||||
break;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ void TextGeneratorV2::GenerateFrame(FramePtr frame,
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
|
||||
// Transplant alpha channel to frame
|
||||
Color rgba = job.Get(kColorInput).toColor();
|
||||
Color rgba = job.get(k_color_input).to_color();
|
||||
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
|
||||
__m128 sse_color = _mm_loadu_ps(rgba.data());
|
||||
#endif
|
||||
@@ -183,11 +183,11 @@ void TextGeneratorV2::GenerateFrame(FramePtr frame,
|
||||
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;
|
||||
VideoParams::k_rgba_channel_count;
|
||||
|
||||
for (int x = 0; x < frame->width(); x++) {
|
||||
float alpha = float(src_y[x]) / 255.0f;
|
||||
float *dst = dst_y + x * VideoParams::kRGBAChannelCount;
|
||||
float *dst = dst_y + x * VideoParams::k_rgba_channel_count;
|
||||
|
||||
#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM)
|
||||
__m128 sse_alpha = _mm_load1_ps(&alpha);
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TEXTGENERATORV2_H
|
||||
#define TEXTGENERATORV2_H
|
||||
#ifndef OAK_TEXTGENERATORV2_H
|
||||
#define OAK_TEXTGENERATORV2_H
|
||||
|
||||
#include "node/generator/shape/shapenodebase.h"
|
||||
|
||||
@@ -34,26 +34,26 @@ public:
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV2)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() 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,
|
||||
virtual void value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame,
|
||||
virtual void generate_frame(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;
|
||||
static const QString k_text_input;
|
||||
static const QString k_html_input;
|
||||
static const QString k_v_align_input;
|
||||
static const QString k_font_input;
|
||||
static const QString k_font_size_input;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TEXTGENERATORV2_H
|
||||
#endif // OAK_TEXTGENERATORV2_H
|
||||
|
||||
@@ -36,46 +36,46 @@ namespace olive
|
||||
#define super ShapeNodeBase
|
||||
|
||||
enum TextVerticalAlign {
|
||||
kVerticalAlignTop,
|
||||
kVerticalAlignCenter,
|
||||
kVerticalAlignBottom,
|
||||
k_vertical_align_top,
|
||||
k_vertical_align_center,
|
||||
k_vertical_align_bottom,
|
||||
};
|
||||
|
||||
const QString TextGeneratorV3::kTextInput = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV3::kVerticalAlignmentInput =
|
||||
const QString TextGeneratorV3::k_text_input = QStringLiteral("text_in");
|
||||
const QString TextGeneratorV3::k_vertical_alignment_input =
|
||||
QStringLiteral("valign_in");
|
||||
const QString TextGeneratorV3::kUseArgsInput = QStringLiteral("use_args_in");
|
||||
const QString TextGeneratorV3::kArgsInput = QStringLiteral("args_in");
|
||||
const QString TextGeneratorV3::k_use_args_input = QStringLiteral("use_args_in");
|
||||
const QString TextGeneratorV3::k_args_input = QStringLiteral("args_in");
|
||||
|
||||
TextGeneratorV3::TextGeneratorV3()
|
||||
: ShapeNodeBase(false)
|
||||
, dont_emit_valign_(false)
|
||||
{
|
||||
AddInput(kTextInput, NodeValue::kText,
|
||||
add_input(k_text_input, NodeValue::k_text,
|
||||
QStringLiteral("<p style='font-size: 72pt; color: white;'>%1</p>")
|
||||
.arg(tr("Sample Text")));
|
||||
SetInputProperty(kTextInput, QStringLiteral("vieweronly"), true);
|
||||
set_input_property(k_text_input, QStringLiteral("vieweronly"), true);
|
||||
|
||||
SetStandardValue(kSizeInput, QVector2D(400, 300));
|
||||
set_standard_value(k_size_input, QVector2D(400, 300));
|
||||
|
||||
AddInput(kVerticalAlignmentInput, NodeValue::kCombo,
|
||||
InputFlags(kInputFlagHidden | kInputFlagStatic));
|
||||
add_input(k_vertical_alignment_input, NodeValue::k_combo,
|
||||
InputFlags(k_input_flag_hidden | k_input_flag_static));
|
||||
|
||||
AddInput(kUseArgsInput, NodeValue::kBoolean, true,
|
||||
InputFlags(kInputFlagHidden | kInputFlagStatic));
|
||||
add_input(k_use_args_input, NodeValue::k_boolean, true,
|
||||
InputFlags(k_input_flag_hidden | k_input_flag_static));
|
||||
|
||||
AddInput(kArgsInput, NodeValue::kText, InputFlags(kInputFlagArray));
|
||||
SetInputProperty(kArgsInput, QStringLiteral("arraystart"), 1);
|
||||
add_input(k_args_input, NodeValue::k_text, InputFlags(k_input_flag_array));
|
||||
set_input_property(k_args_input, 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_->set_input(NodeInput(this, k_text_input));
|
||||
connect(text_gizmo_, &TextGizmo::activated, this,
|
||||
&TextGeneratorV3::gizmo_activated);
|
||||
connect(text_gizmo_, &TextGizmo::deactivated, this,
|
||||
&TextGeneratorV3::gizmo_deactivated);
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::Name() const
|
||||
QString TextGeneratorV3::name() const
|
||||
{
|
||||
return tr("Text");
|
||||
}
|
||||
@@ -85,64 +85,64 @@ QString TextGeneratorV3::id() const
|
||||
return QStringLiteral("org.olivevideoeditor.Olive.text3");
|
||||
}
|
||||
|
||||
QVector<Node::CategoryID> TextGeneratorV3::Category() const
|
||||
QVector<Node::CategoryID> TextGeneratorV3::category() const
|
||||
{
|
||||
return { kCategoryGenerator };
|
||||
return { k_category_generator };
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::Description() const
|
||||
QString TextGeneratorV3::description() const
|
||||
{
|
||||
return tr("Generate rich text.");
|
||||
}
|
||||
|
||||
void TextGeneratorV3::Retranslate()
|
||||
void TextGeneratorV3::retranslate()
|
||||
{
|
||||
super::Retranslate();
|
||||
super::retranslate();
|
||||
|
||||
SetInputName(kTextInput, tr("Text"));
|
||||
SetInputName(kVerticalAlignmentInput, tr("Vertical Alignment"));
|
||||
SetComboBoxStrings(kVerticalAlignmentInput,
|
||||
set_input_name(k_text_input, tr("Text"));
|
||||
set_input_name(k_vertical_alignment_input, tr("Vertical Alignment"));
|
||||
set_combo_box_strings(k_vertical_alignment_input,
|
||||
{ tr("Top"), tr("Middle"), tr("Bottom") });
|
||||
SetInputName(kArgsInput, tr("Arguments"));
|
||||
set_input_name(k_args_input, tr("Arguments"));
|
||||
}
|
||||
|
||||
void TextGeneratorV3::Value(const NodeValueRow &value,
|
||||
void TextGeneratorV3::value(const NodeValueRow &value,
|
||||
const NodeGlobals &globals,
|
||||
NodeValueTable *table) const
|
||||
{
|
||||
QString text = value[kTextInput].toString();
|
||||
QString text = value[k_text_input].to_string();
|
||||
|
||||
if (value[kUseArgsInput].toBool()) {
|
||||
auto args = value[kArgsInput].toArray();
|
||||
if (value[k_use_args_input].to_bool()) {
|
||||
auto args = value[k_args_input].to_array();
|
||||
if (!args.empty()) {
|
||||
QStringList list;
|
||||
list.reserve(args.size());
|
||||
for (size_t i = 0; i < args.size(); i++) {
|
||||
list.append(args[i].toString());
|
||||
list.append(args[i].to_string());
|
||||
}
|
||||
|
||||
text = FormatString(text, list);
|
||||
text = format_string(text, list);
|
||||
}
|
||||
}
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
TexturePtr base = value[kTextInput].toTexture();
|
||||
TexturePtr base = value[k_text_input].to_texture();
|
||||
|
||||
VideoParams text_params = base ? base->params() : globals.vparams();
|
||||
text_params.set_format(PixelFormat::U8);
|
||||
text_params.set_format(PixelFormat::u8);
|
||||
text_params.set_colorspace(
|
||||
project()->color_manager()->GetDefaultInputColorSpace());
|
||||
project()->color_manager()->get_default_input_color_space());
|
||||
|
||||
GenerateJob job(value);
|
||||
job.Insert(kTextInput, NodeValue(NodeValue::kText, text));
|
||||
job.insert(k_text_input, NodeValue(NodeValue::k_text, text));
|
||||
|
||||
PushMergableJob(value, Texture::Job(text_params, job), table);
|
||||
} else if (value[kBaseInput].toTexture()) {
|
||||
table->Push(value[kBaseInput]);
|
||||
push_mergable_job(value, Texture::job(text_params, job), table);
|
||||
} else if (value[k_base_input].to_texture()) {
|
||||
table->push(value[k_base_input]);
|
||||
}
|
||||
}
|
||||
|
||||
void TextGeneratorV3::GenerateFrame(FramePtr frame,
|
||||
void TextGeneratorV3::generate_frame(FramePtr frame,
|
||||
const GenerateJob &job) const
|
||||
{
|
||||
QImage img(reinterpret_cast<uchar *>(frame->data()), frame->width(),
|
||||
@@ -158,10 +158,10 @@ void TextGeneratorV3::GenerateFrame(FramePtr frame,
|
||||
QTextDocument text_doc;
|
||||
text_doc.documentLayout()->setPaintDevice(&img);
|
||||
|
||||
QString html = job.Get(kTextInput).toString();
|
||||
Html::HtmlToDoc(&text_doc, html);
|
||||
QString html = job.get(k_text_input).to_string();
|
||||
Html::html_to_doc(&text_doc, html);
|
||||
|
||||
QVector2D size = job.Get(kSizeInput).toVec2();
|
||||
QVector2D size = job.get(k_size_input).to_vec2();
|
||||
text_doc.setTextWidth(size.x());
|
||||
|
||||
// Draw rich text onto image
|
||||
@@ -169,21 +169,21 @@ void TextGeneratorV3::GenerateFrame(FramePtr frame,
|
||||
p.scale(1.0 / frame->video_params().divider(),
|
||||
1.0 / frame->video_params().divider());
|
||||
|
||||
QVector2D pos = job.Get(kPositionInput).toVec2();
|
||||
QVector2D pos = job.get(k_position_input).to_vec2();
|
||||
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:
|
||||
job.get(k_vertical_alignment_input).to_int())) {
|
||||
case k_v_align_top:
|
||||
// Do nothing
|
||||
break;
|
||||
case kVAlignMiddle:
|
||||
case k_v_align_middle:
|
||||
p.translate(0, size.y() / 2 - text_doc.size().height() / 2);
|
||||
break;
|
||||
case kVAlignBottom:
|
||||
case k_v_align_bottom:
|
||||
p.translate(0, size.y() - text_doc.size().height());
|
||||
break;
|
||||
}
|
||||
@@ -195,45 +195,45 @@ void TextGeneratorV3::GenerateFrame(FramePtr frame,
|
||||
text_doc.documentLayout()->draw(&p, ctx);
|
||||
}
|
||||
|
||||
void TextGeneratorV3::UpdateGizmoPositions(const NodeValueRow &row,
|
||||
void TextGeneratorV3::update_gizmo_positions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals)
|
||||
{
|
||||
super::UpdateGizmoPositions(row, globals);
|
||||
super::update_gizmo_positions(row, globals);
|
||||
|
||||
QRectF rect = poly_gizmo()->GetPolygon().boundingRect();
|
||||
text_gizmo_->SetRect(rect);
|
||||
text_gizmo_->SetHtml(row[kTextInput].toString());
|
||||
QRectF rect = poly_gizmo()->get_polygon().boundingRect();
|
||||
text_gizmo_->set_rect(rect);
|
||||
text_gizmo_->set_html(row[k_text_input].to_string());
|
||||
}
|
||||
|
||||
Qt::Alignment TextGeneratorV3::GetQtAlignmentFromOurs(VerticalAlignment v)
|
||||
Qt::Alignment TextGeneratorV3::get_qt_alignment_from_ours(VerticalAlignment v)
|
||||
{
|
||||
switch (v) {
|
||||
case kVAlignTop:
|
||||
case k_v_align_top:
|
||||
return Qt::AlignTop;
|
||||
case kVAlignMiddle:
|
||||
case k_v_align_middle:
|
||||
return Qt::AlignVCenter;
|
||||
case kVAlignBottom:
|
||||
case k_v_align_bottom:
|
||||
return Qt::AlignBottom;
|
||||
}
|
||||
return Qt::Alignment();
|
||||
}
|
||||
|
||||
TextGeneratorV3::VerticalAlignment
|
||||
TextGeneratorV3::GetOurAlignmentFromQts(Qt::Alignment v)
|
||||
TextGeneratorV3::get_our_alignment_from_qts(Qt::Alignment v)
|
||||
{
|
||||
switch (v) {
|
||||
case Qt::AlignTop:
|
||||
return kVAlignTop;
|
||||
return k_v_align_top;
|
||||
case Qt::AlignVCenter:
|
||||
return kVAlignMiddle;
|
||||
return k_v_align_middle;
|
||||
case Qt::AlignBottom:
|
||||
return kVAlignBottom;
|
||||
return k_v_align_bottom;
|
||||
}
|
||||
|
||||
return kVAlignTop;
|
||||
return k_v_align_top;
|
||||
}
|
||||
|
||||
QString TextGeneratorV3::FormatString(const QString &input,
|
||||
QString TextGeneratorV3::format_string(const QString &input,
|
||||
const QStringList &args)
|
||||
{
|
||||
QString output;
|
||||
@@ -274,36 +274,36 @@ QString TextGeneratorV3::FormatString(const QString &input,
|
||||
|
||||
void TextGeneratorV3::InputValueChangedEvent(const QString &input, int element)
|
||||
{
|
||||
if (input == kVerticalAlignmentInput && !dont_emit_valign_) {
|
||||
text_gizmo_->SetVerticalAlignment(
|
||||
GetQtAlignmentFromOurs(GetVerticalAlignment()));
|
||||
if (input == k_vertical_alignment_input && !dont_emit_valign_) {
|
||||
text_gizmo_->set_vertical_alignment(
|
||||
get_qt_alignment_from_ours(get_vertical_alignment()));
|
||||
}
|
||||
|
||||
super::InputValueChangedEvent(input, element);
|
||||
}
|
||||
|
||||
void TextGeneratorV3::GizmoActivated()
|
||||
void TextGeneratorV3::gizmo_activated()
|
||||
{
|
||||
SetStandardValue(kUseArgsInput, false);
|
||||
connect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
|
||||
&TextGeneratorV3::SetVerticalAlignmentUndoable);
|
||||
set_standard_value(k_use_args_input, false);
|
||||
connect(text_gizmo_, &TextGizmo::vertical_alignment_changed, this,
|
||||
&TextGeneratorV3::set_vertical_alignment_undoable);
|
||||
dont_emit_valign_ = true;
|
||||
}
|
||||
|
||||
void TextGeneratorV3::GizmoDeactivated()
|
||||
void TextGeneratorV3::gizmo_deactivated()
|
||||
{
|
||||
SetStandardValue(kUseArgsInput, true);
|
||||
disconnect(text_gizmo_, &TextGizmo::VerticalAlignmentChanged, this,
|
||||
&TextGeneratorV3::SetVerticalAlignmentUndoable);
|
||||
set_standard_value(k_use_args_input, true);
|
||||
disconnect(text_gizmo_, &TextGizmo::vertical_alignment_changed, this,
|
||||
&TextGeneratorV3::set_vertical_alignment_undoable);
|
||||
dont_emit_valign_ = true;
|
||||
}
|
||||
|
||||
void TextGeneratorV3::SetVerticalAlignmentUndoable(Qt::Alignment a)
|
||||
void TextGeneratorV3::set_vertical_alignment_undoable(Qt::Alignment a)
|
||||
{
|
||||
Core::instance()->undo_stack()->push(
|
||||
new NodeParamSetStandardValueCommand(NodeInput(this,
|
||||
kVerticalAlignmentInput),
|
||||
GetOurAlignmentFromQts(a)),
|
||||
k_vertical_alignment_input),
|
||||
get_our_alignment_from_qts(a)),
|
||||
tr("Set Text Vertical Alignment"));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TEXTGENERATORV3_H
|
||||
#define TEXTGENERATORV3_H
|
||||
#ifndef OAK_TEXTGENERATORV3_H
|
||||
#define OAK_TEXTGENERATORV3_H
|
||||
|
||||
#include "node/generator/shape/shapenodebase.h"
|
||||
#include "node/gizmo/text.h"
|
||||
@@ -35,39 +35,39 @@ public:
|
||||
|
||||
NODE_DEFAULT_FUNCTIONS(TextGeneratorV3)
|
||||
|
||||
virtual QString Name() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() 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,
|
||||
virtual void value(const NodeValueRow &value, const NodeGlobals &globals,
|
||||
NodeValueTable *table) const override;
|
||||
|
||||
virtual void GenerateFrame(FramePtr frame,
|
||||
virtual void generate_frame(FramePtr frame,
|
||||
const GenerateJob &job) const override;
|
||||
|
||||
virtual void UpdateGizmoPositions(const NodeValueRow &row,
|
||||
virtual void update_gizmo_positions(const NodeValueRow &row,
|
||||
const NodeGlobals &globals) override;
|
||||
|
||||
enum VerticalAlignment { kVAlignTop, kVAlignMiddle, kVAlignBottom };
|
||||
enum VerticalAlignment { k_v_align_top, k_v_align_middle, k_v_align_bottom };
|
||||
|
||||
VerticalAlignment GetVerticalAlignment() const
|
||||
VerticalAlignment get_vertical_alignment() const
|
||||
{
|
||||
return static_cast<VerticalAlignment>(
|
||||
GetStandardValue(kVerticalAlignmentInput).toInt());
|
||||
get_standard_value(k_vertical_alignment_input).toInt());
|
||||
}
|
||||
|
||||
static Qt::Alignment GetQtAlignmentFromOurs(VerticalAlignment v);
|
||||
static VerticalAlignment GetOurAlignmentFromQts(Qt::Alignment v);
|
||||
static Qt::Alignment get_qt_alignment_from_ours(VerticalAlignment v);
|
||||
static VerticalAlignment get_our_alignment_from_qts(Qt::Alignment v);
|
||||
|
||||
static const QString kTextInput;
|
||||
static const QString kVerticalAlignmentInput;
|
||||
static const QString kUseArgsInput;
|
||||
static const QString kArgsInput;
|
||||
static const QString k_text_input;
|
||||
static const QString k_vertical_alignment_input;
|
||||
static const QString k_use_args_input;
|
||||
static const QString k_args_input;
|
||||
|
||||
static QString FormatString(const QString &input, const QStringList &args);
|
||||
static QString format_string(const QString &input, const QStringList &args);
|
||||
|
||||
protected:
|
||||
virtual void InputValueChangedEvent(const QString &input,
|
||||
@@ -79,11 +79,11 @@ private:
|
||||
bool dont_emit_valign_;
|
||||
|
||||
private slots:
|
||||
void GizmoActivated();
|
||||
void GizmoDeactivated();
|
||||
void SetVerticalAlignmentUndoable(Qt::Alignment a);
|
||||
void gizmo_activated();
|
||||
void gizmo_deactivated();
|
||||
void set_vertical_alignment_undoable(Qt::Alignment a);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TEXTGENERATORV3_H
|
||||
#endif // OAK_TEXTGENERATORV3_H
|
||||
|
||||
Reference in New Issue
Block a user