Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app/node/generator/text/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "text.h"

#include "common/clamp.h"
#include "widget/slider/floatslider.h"
#include <QAbstractTextDocumentLayout>
#include <QDateTime>
#include <QTextDocument>
Expand Down Expand Up @@ -47,6 +49,7 @@ const QString TextGenerator::kHtmlInput = QStringLiteral("html_in");
const QString TextGenerator::kVAlignInput = QStringLiteral("valign_in");
const QString TextGenerator::kFontInput = QStringLiteral("font_in");
const QString TextGenerator::kFontSizeInput = QStringLiteral("font_size_in");
const QString TextGenerator::kTextTypewriterInput = QStringLiteral("text_typewriter_in");

TextGenerator::TextGenerator()
{
Expand All @@ -60,6 +63,12 @@ TextGenerator::TextGenerator()

AddInput(kFontSizeInput, NodeValue::kFloat, 72.0f);

AddInput(kTextTypewriterInput, NodeValue::kFloat, 100);
SetInputProperty(kTextTypewriterInput, QStringLiteral("min"), 0.0f);
SetInputProperty(kTextTypewriterInput, QStringLiteral("max"), GetStandardValue(kTextInput).toString().length());
SetInputProperty(kTextTypewriterInput, QStringLiteral("view"), FloatSlider::kNormal);
SetInputProperty(kTextTypewriterInput, QStringLiteral("decimalplaces"), 0);

SetStandardValue(kColorInput, QVariant::fromValue(Color(1.0f, 1.0f, 1.0)));
SetStandardValue(kSizeInput, QVector2D(400, 300));
}
Expand Down Expand Up @@ -94,6 +103,7 @@ void TextGenerator::Retranslate()
SetInputName(kFontSizeInput, tr("Font Size"));
SetInputName(kVAlignInput, tr("Vertical Align"));
SetComboBoxStrings(kVAlignInput, {tr("Top"), tr("Center"), tr("Bottom")});
SetInputName(kTextTypewriterInput, tr("Text typewriter progress"));
}

void TextGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
Expand Down Expand Up @@ -136,7 +146,9 @@ void TextGenerator::GenerateFrame(FramePtr frame, const GenerateJob& job) const
html.replace('\n', QStringLiteral("<br>"));
text_doc.setHtml(html);
} else {
text_doc.setPlainText(html);
int length = clamp(job.GetValue(kTextTypewriterInput).data().toInt(), 0, html.length());
QString trimmed_text = html.mid(0, length);
text_doc.setPlainText(trimmed_text);
}

QVector2D size = job.GetValue(kSizeInput).data().value<QVector2D>();
Expand Down Expand Up @@ -202,4 +214,16 @@ void TextGenerator::GenerateFrame(FramePtr frame, const GenerateJob& job) const
}
}

void TextGenerator::InputValueChangedEvent(const QString &input, int element)
{
Q_UNUSED(element)

if (input == kTextInput) {
SetInputProperty(kTextTypewriterInput, QStringLiteral("max"), GetStandardValue(kTextInput).toString().length());
} else if (input == kHtmlInput) {
SetInputProperty(kTextTypewriterInput, QStringLiteral("enabled"), ! GetStandardValue(kHtmlInput).toBool());
}
}


}
3 changes: 3 additions & 0 deletions app/node/generator/text/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ class TextGenerator : public ShapeNodeBase

virtual void GenerateFrame(FramePtr frame, const GenerateJob &job) const override;

virtual void InputValueChangedEvent(const QString &input, int element);

static const QString kTextInput;
static const QString kHtmlInput;
static const QString kVAlignInput;
static const QString kFontInput;
static const QString kFontSizeInput;
static const QString kTextTypewriterInput;

};

Expand Down