use QObject property system now that i know how to signal them

This commit is contained in:
itsmattkc
2020-11-27 10:10:24 +11:00
parent 1deb95b804
commit 8a869d0393
14 changed files with 87 additions and 135 deletions
+3 -3
View File
@@ -28,9 +28,9 @@ PanNode::PanNode()
AddInput(samples_input_);
panning_input_ = new NodeInput("panning_in", NodeParam::kFloat, 0.0);
panning_input_->set_property("min", -1.0);
panning_input_->set_property("max", 1.0);
panning_input_->set_property("view", "percent");
panning_input_->setProperty("min", -1.0);
panning_input_->setProperty("max", 1.0);
panning_input_->setProperty("view", QStringLiteral("percent"));
AddInput(panning_input_);
}
+4 -4
View File
@@ -24,13 +24,13 @@ namespace olive {
VolumeNode::VolumeNode()
{
samples_input_ = new NodeInput("samples_in", NodeParam::kSamples);
samples_input_ = new NodeInput(QStringLiteral("samples_in"), NodeParam::kSamples);
samples_input_->set_is_keyframable(false);
AddInput(samples_input_);
volume_input_ = new NodeInput("volume_in", NodeParam::kFloat, 1.0);
volume_input_->set_property("min", 0.0);
volume_input_->set_property("view", "db");
volume_input_ = new NodeInput(QStringLiteral("volume_in"), NodeParam::kFloat, 1.0);
volume_input_->setProperty("min", 0.0);
volume_input_->setProperty("view", QStringLiteral("db"));
AddInput(volume_input_);
}
+1 -1
View File
@@ -51,7 +51,7 @@ Block::Block() :
speed_input_ = new NodeInput("speed_in", NodeParam::kFloat);
speed_input_->set_standard_value(1.0);
speed_input_->set_property(QStringLiteral("view"), QStringLiteral("percent"));
speed_input_->setProperty("view", QStringLiteral("percent"));
AddInput(speed_input_);
// A block's length must be greater than 0
+13 -13
View File
@@ -30,31 +30,31 @@ CropDistortNode::CropDistortNode()
AddInput(texture_input_);
left_input_ = new NodeInput(QStringLiteral("left_in"), NodeParam::kFloat, 0.0);
left_input_->set_property(QStringLiteral("min"), 0.0);
left_input_->set_property(QStringLiteral("max"), 1.0);
left_input_->set_property(QStringLiteral("view"), QStringLiteral("percent"));
left_input_->setProperty("min", 0.0);
left_input_->setProperty("max", 1.0);
left_input_->setProperty("view", QStringLiteral("percent"));
AddInput(left_input_);
top_input_ = new NodeInput(QStringLiteral("top_in"), NodeParam::kFloat, 0.0);
top_input_->set_property(QStringLiteral("min"), 0.0);
top_input_->set_property(QStringLiteral("max"), 1.0);
top_input_->set_property(QStringLiteral("view"), QStringLiteral("percent"));
top_input_->setProperty("min", 0.0);
top_input_->setProperty("max", 1.0);
top_input_->setProperty("view", QStringLiteral("percent"));
AddInput(top_input_);
right_input_ = new NodeInput(QStringLiteral("right_in"), NodeParam::kFloat, 0.0);
right_input_->set_property(QStringLiteral("min"), 0.0);
right_input_->set_property(QStringLiteral("max"), 1.0);
right_input_->set_property(QStringLiteral("view"), QStringLiteral("percent"));
right_input_->setProperty("min", 0.0);
right_input_->setProperty("max", 1.0);
right_input_->setProperty("view", QStringLiteral("percent"));
AddInput(right_input_);
bottom_input_ = new NodeInput(QStringLiteral("bottom_in"), NodeParam::kFloat, 0.0);
bottom_input_->set_property(QStringLiteral("min"), 0.0);
bottom_input_->set_property(QStringLiteral("max"), 1.0);
bottom_input_->set_property(QStringLiteral("view"), QStringLiteral("percent"));
bottom_input_->setProperty("min", 0.0);
bottom_input_->setProperty("max", 1.0);
bottom_input_->setProperty("view", QStringLiteral("percent"));
AddInput(bottom_input_);
feather_input_ = new NodeInput(QStringLiteral("feather_in"), NodeParam::kFloat, 0.0);
feather_input_->set_property(QStringLiteral("min"), 0.0);
feather_input_->setProperty("min", 0.0);
AddInput(feather_input_);
}
@@ -437,8 +437,8 @@ void TransformDistortNode::DrawGizmos(NodeValueDatabase &db, QPainter *p)
// Use offsets to make the appearance of values that start in the top left, even though we
// really anchor around the center
position_input()->set_property(QStringLiteral("offset"), sequence_res * 0.5);
anchor_input()->set_property(QStringLiteral("offset"), tex_sz * 0.5);
position_input()->setProperty("offset", sequence_res * 0.5);
anchor_input()->setProperty("offset", tex_sz * 0.5);
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ BlurFilterNode::BlurFilterNode()
AddInput(method_input_);
radius_input_ = new NodeInput("radius_in", NodeParam::kFloat, 10.0f);
radius_input_->set_property(QStringLiteral("min"), 0.0f);
radius_input_->setProperty("min", 0.0f);
AddInput(radius_input_);
horiz_input_ = new NodeInput("horiz_in", NodeParam::kBoolean, true);
+4 -4
View File
@@ -27,12 +27,12 @@ MosaicFilterNode::MosaicFilterNode()
tex_input_ = new NodeInput(QStringLiteral("tex_in"), NodeParam::kTexture);
AddInput(tex_input_);
horiz_input_ = new NodeInput(QStringLiteral("horiz_in"), NodeParam::kFloat);
horiz_input_->set_property(QStringLiteral("min"), 1.0);
horiz_input_ = new NodeInput(QStringLiteral("horiz_in"), NodeParam::kFloat, 32.0);
horiz_input_->setProperty("min", 1.0);
AddInput(horiz_input_);
vert_input_ = new NodeInput(QStringLiteral("vert_in"), NodeParam::kFloat);
vert_input_->set_property(QStringLiteral("min"), 1.0);
vert_input_ = new NodeInput(QStringLiteral("vert_in"), NodeParam::kFloat, 18.0);
vert_input_->setProperty("min", 1.0);
AddInput(vert_input_);
}
+4 -4
View File
@@ -35,13 +35,13 @@ StrokeFilterNode::StrokeFilterNode()
AddInput(color_input_);
radius_input_ = new NodeInput("radius_in", NodeParam::kFloat, 10.0f);
radius_input_->set_property("min", 0.0f);
radius_input_->setProperty("min", 0.0f);
AddInput(radius_input_);
opacity_input_ = new NodeInput("opacity_in", NodeParam::kFloat, 1.0f);
opacity_input_->set_property("view", "percent");
opacity_input_->set_property("min", 0.0f);
opacity_input_->set_property("max", 1.0f);
opacity_input_->setProperty("view", QStringLiteral("percent"));
opacity_input_->setProperty("min", 0.0f);
opacity_input_->setProperty("max", 1.0f);
AddInput(opacity_input_);
inner_input_ = new NodeInput("inner_in", NodeParam::kBoolean, false);
+4 -4
View File
@@ -34,9 +34,9 @@ MatrixGenerator::MatrixGenerator()
AddInput(rotation_input_);
scale_input_ = new NodeInput("scale_in", NodeParam::kVec2, QVector2D(1.0f, 1.0f));
scale_input_->set_property("min", QVector2D(0, 0));
scale_input_->set_property("view", "percent");
scale_input_->set_property("disabley", true);
scale_input_->setProperty("min", QVector2D(0, 0));
scale_input_->setProperty("view", QStringLiteral("percent"));
scale_input_->setProperty("disabley", true);
AddInput(scale_input_);
uniform_scale_input_ = new NodeInput("uniform_scale_in", NodeParam::kBoolean, true);
@@ -183,7 +183,7 @@ QMatrix4x4 MatrixGenerator::GenerateMatrix(const QVector2D& pos,
void MatrixGenerator::UniformScaleChanged()
{
scale_input_->set_property("disabley", uniform_scale_input_->get_standard_value().toBool());
scale_input_->setProperty("disabley", uniform_scale_input_->get_standard_value().toBool());
}
}
+21 -31
View File
@@ -192,13 +192,13 @@ void NodeInput::Load(QXmlStreamReader *reader, XMLNodeData &xml_node_data, const
}
}
} else if (reader->name() == QStringLiteral("csinput")) {
set_property(QStringLiteral("col_input"), reader->readElementText());
setProperty("col_input", reader->readElementText());
} else if (reader->name() == QStringLiteral("csdisplay")) {
set_property(QStringLiteral("col_display"), reader->readElementText());
setProperty("col_display", reader->readElementText());
} else if (reader->name() == QStringLiteral("csview")) {
set_property(QStringLiteral("col_view"), reader->readElementText());
setProperty("col_view", reader->readElementText());
} else if (reader->name() == QStringLiteral("cslook")) {
set_property(QStringLiteral("col_look"), reader->readElementText());
setProperty("col_look", reader->readElementText());
} else if (reader->name() == QStringLiteral("custom")) {
LoadInternal(reader, xml_node_data, cancelled);
} else {
@@ -250,10 +250,10 @@ void NodeInput::Save(QXmlStreamWriter *writer) const
if (data_type_ == NodeParam::kColor) {
// Save color management information
writer->writeTextElement(QStringLiteral("csinput"), get_property(QStringLiteral("col_input")).toString());
writer->writeTextElement(QStringLiteral("csdisplay"), get_property(QStringLiteral("col_display")).toString());
writer->writeTextElement(QStringLiteral("csview"), get_property(QStringLiteral("col_view")).toString());
writer->writeTextElement(QStringLiteral("cslook"), get_property(QStringLiteral("col_look")).toString());
writer->writeTextElement(QStringLiteral("csinput"), property("col_input").toString());
writer->writeTextElement(QStringLiteral("csdisplay"), property("col_display").toString());
writer->writeTextElement(QStringLiteral("csview"), property("col_view").toString());
writer->writeTextElement(QStringLiteral("cslook"), property("col_look").toString());
}
SaveConnections(writer);
@@ -289,6 +289,17 @@ void NodeInput::SaveInternal(QXmlStreamWriter*) const
{
}
bool NodeInput::event(QEvent *e)
{
if (e->type() == QEvent::DynamicPropertyChange) {
QByteArray key = static_cast<QDynamicPropertyChangeEvent*>(e)->propertyName();
emit PropertyChanged(key, property(key));
return true;
}
return QObject::event(e);
}
void NodeInput::Init(DataType type)
{
keyframable_ = true;
@@ -1106,27 +1117,6 @@ void NodeInput::CopyValues(NodeInput *source, NodeInput *dest, bool include_conn
emit dest->ValueChanged(TimeRange(RATIONAL_MIN, RATIONAL_MAX));
}
void NodeInput::set_property(const QString &key, const QVariant &value)
{
properties_.insert(key, value);
emit PropertyChanged(key, value);
}
QVariant NodeInput::get_property(const QString &key) const
{
return properties_.value(key);
}
bool NodeInput::has_property(const QString &key) const
{
return properties_.contains(key);
}
const QHash<QString, QVariant> &NodeInput::properties() const
{
return properties_;
}
QVector<QVariant> NodeInput::split_normal_value_into_track_values(const QVariant &value) const
{
QVector<QVariant> vals(get_number_of_keyframe_tracks());
@@ -1207,12 +1197,12 @@ QVariant NodeInput::combine_track_values_into_normal_value(const QVector<QVarian
QStringList NodeInput::get_combobox_strings() const
{
return get_property(QStringLiteral("combo_str")).toStringList();
return property("combo_str").toStringList();
}
void NodeInput::set_combobox_strings(const QStringList &strings)
{
set_property(QStringLiteral("combo_str"), strings);
setProperty("combo_str", strings);
}
}
+2 -38
View File
@@ -237,39 +237,6 @@ public:
*/
static void CopyValues(NodeInput* source, NodeInput* dest, bool include_connections = true, bool traverse_arrays = true);
/**
* @brief Set an arbitrary property on this input to influence a UI representation's behavior
*
* NodeInputs also utilize QObject's property key/value system for arbitrary properties that can influence the UI
* representation's behavior.
*
* Currently supported properties:
*
* - `min` - For any numeral type represented with a slider, prevents values going BELOW this number
* - `max` - For any numeral type represented with a slider, prevents values going ABOVE this number
* - `view` - For any numeral type represented with a slider, shows number either as `db`, `percent`, or `normal`
* - `disablex` - For kVec2, kVec3, kVec4 and kColor types, disables the first/X/R UI widget
* - `disabley` - For kVec2, kVec3, kVec4 and kColor types, disables the second/Y/G UI widget
* - `disablez` - For kVec3, kVec4 and kColor types, disables the third/Z/B UI widget
* - `disablew` - For kVec4 and kColor types, disables the fourth/W/A UI widget
*/
void set_property(const QString& key, const QVariant& value);
/**
* @brief Retrieve a property (or an empty QVariant if it hasn't been set)
*/
QVariant get_property(const QString& key) const;
/**
* @brief Return whether a certain property has been set or not
*/
bool has_property(const QString& key) const;
/**
* @brief Get properties hashmap (useful for iterating)
*/
const QHash<QString, QVariant>& properties() const;
QVector<QVariant> split_normal_value_into_track_values(const QVariant &value) const;
QVariant combine_track_values_into_normal_value(const QVector<QVariant>& split) const;
@@ -310,6 +277,8 @@ protected:
virtual void SaveInternal(QXmlStreamWriter* writer) const;
virtual bool event(QEvent* e) override;
private:
void Init(NodeParam::DataType type);
@@ -398,11 +367,6 @@ private:
*/
bool keyframing_;
/**
* @brief Internal properties variable
*/
QHash<QString, QVariant> properties_;
private slots:
/**
* @brief Slot when a keyframe's time changes to keep the keyframes correctly sorted by time
+4 -4
View File
@@ -74,17 +74,17 @@ void NodeInputDragger::Drag(QVariant value)
{
Q_ASSERT(input_);
if (!input_->get_property(QStringLiteral("min")).isNull()) {
if (input_->property("min").isValid()) {
// Assumes the value is a double of some kind
double min = input_->get_property(QStringLiteral("min")).toDouble();
double min = input_->property("min").toDouble();
double v = value.toDouble();
if (v < min) {
value = min;
}
}
if (!input_->get_property(QStringLiteral("max")).isNull()) {
double max = input_->get_property(QStringLiteral("max")).toDouble();
if (input_->property("max").isValid()) {
double max = input_->property("max").toDouble();
double v = value.toDouble();
if (v > max) {
value = max;
+4 -4
View File
@@ -30,13 +30,13 @@ MathNode::MathNode()
AddInput(method_in_);
param_a_in_ = new NodeInput(QStringLiteral("param_a_in"), NodeParam::kFloat, 0.0);
param_a_in_->set_property(QStringLiteral("decimalplaces"), 8);
param_a_in_->set_property(QStringLiteral("autotrim"), true);
param_a_in_->setProperty("decimalplaces", 8);
param_a_in_->setProperty("autotrim", true);
AddInput(param_a_in_);
param_b_in_ = new NodeInput(QStringLiteral("param_b_in"), NodeParam::kFloat, 0.0);
param_b_in_->set_property(QStringLiteral("decimalplaces"), 8);
param_b_in_->set_property(QStringLiteral("autotrim"), true);
param_b_in_->setProperty("decimalplaces", 8);
param_b_in_->setProperty("autotrim", true);
AddInput(param_b_in_);
}
@@ -180,10 +180,8 @@ void NodeParamViewWidgetBridge::CreateWidgets()
}
// Check all properties
QHash<QString, QVariant>::const_iterator iterator;
for (iterator=input_->properties().begin();iterator!=input_->properties().end();iterator++) {
PropertyChanged(iterator.key(), iterator.value());
foreach (const QByteArray& key, input_->dynamicPropertyNames()) {
PropertyChanged(key, input_->property(key));
}
UpdateWidgetValues();
@@ -281,7 +279,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
// Widget is a IntegerSlider
IntegerSlider* slider = static_cast<IntegerSlider*>(sender());
int64_t offset = input_->get_property(QStringLiteral("offset")).toLongLong();
int64_t offset = input_->property("offset").toLongLong();
ProcessSlider(slider, QVariant::fromValue(slider->GetValue() - offset));
break;
@@ -291,7 +289,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
// Widget is a FloatSlider
FloatSlider* slider = static_cast<FloatSlider*>(sender());
double offset = input_->get_property(QStringLiteral("offset")).toDouble();
double offset = input_->property("offset").toDouble();
ProcessSlider(slider, slider->GetValue() - offset);
break;
@@ -301,7 +299,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
// Widget is a FloatSlider
FloatSlider* slider = static_cast<FloatSlider*>(sender());
QVector2D offset = input_->get_property(QStringLiteral("offset")).value<QVector2D>();
QVector2D offset = input_->property("offset").value<QVector2D>();
ProcessSlider(slider, slider->GetValue() - offset[widgets_.indexOf(slider)]);
break;
@@ -311,7 +309,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
// Widget is a FloatSlider
FloatSlider* slider = static_cast<FloatSlider*>(sender());
QVector3D offset = input_->get_property(QStringLiteral("offset")).value<QVector3D>();
QVector3D offset = input_->property("offset").value<QVector3D>();
ProcessSlider(slider, slider->GetValue() - offset[widgets_.indexOf(slider)]);
break;
@@ -321,7 +319,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
// Widget is a FloatSlider
FloatSlider* slider = static_cast<FloatSlider*>(sender());
QVector4D offset = input_->get_property(QStringLiteral("offset")).value<QVector4D>();
QVector4D offset = input_->property("offset").value<QVector4D>();
ProcessSlider(slider, slider->GetValue() - offset[widgets_.indexOf(slider)]);
break;
@@ -342,10 +340,10 @@ void NodeParamViewWidgetBridge::WidgetCallback()
SetInputValueInternal(c.alpha(), 3, command);
input_->blockSignals(true);
input_->set_property(QStringLiteral("col_input"), c.color_input());
input_->set_property(QStringLiteral("col_display"), c.color_output().display());
input_->set_property(QStringLiteral("col_view"), c.color_output().view());
input_->set_property(QStringLiteral("col_look"), c.color_output().look());
input_->setProperty("col_input", c.color_input());
input_->setProperty("col_display", c.color_output().display());
input_->setProperty("col_view", c.color_output().view());
input_->setProperty("col_look", c.color_output().look());
input_->blockSignals(false);
Core::instance()->undo_stack()->pushIfHasChildren(command);
@@ -433,14 +431,14 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues()
break;
case NodeParam::kInt:
{
int64_t offset = input_->get_property(QStringLiteral("offset")).toLongLong();
int64_t offset = input_->property("offset").toLongLong();
static_cast<IntegerSlider*>(widgets_.first())->SetValue(input_->get_value_at_time(node_time).toLongLong() + offset);
break;
}
case NodeParam::kFloat:
{
double offset = input_->get_property(QStringLiteral("offset")).toDouble();
double offset = input_->property("offset").toDouble();
static_cast<FloatSlider*>(widgets_.first())->SetValue(input_->get_value_at_time(node_time).toDouble() + offset);
break;
@@ -448,7 +446,7 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues()
case NodeParam::kVec2:
{
QVector2D vec2 = input_->get_value_at_time(node_time).value<QVector2D>();
QVector2D offset = input_->get_property(QStringLiteral("offset")).value<QVector2D>();
QVector2D offset = input_->property("offset").value<QVector2D>();
static_cast<FloatSlider*>(widgets_.at(0))->SetValue(static_cast<double>(vec2.x() + offset.x()));
static_cast<FloatSlider*>(widgets_.at(1))->SetValue(static_cast<double>(vec2.y() + offset.y()));
@@ -457,7 +455,7 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues()
case NodeParam::kVec3:
{
QVector3D vec3 = input_->get_value_at_time(node_time).value<QVector3D>();
QVector3D offset = input_->get_property(QStringLiteral("offset")).value<QVector3D>();
QVector3D offset = input_->property("offset").value<QVector3D>();
static_cast<FloatSlider*>(widgets_.at(0))->SetValue(static_cast<double>(vec3.x() + offset.x()));
static_cast<FloatSlider*>(widgets_.at(1))->SetValue(static_cast<double>(vec3.y() + offset.y()));
@@ -467,7 +465,7 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues()
case NodeParam::kVec4:
{
QVector4D vec4 = input_->get_value_at_time(node_time).value<QVector4D>();
QVector4D offset = input_->get_property(QStringLiteral("offset")).value<QVector4D>();
QVector4D offset = input_->property("offset").value<QVector4D>();
static_cast<FloatSlider*>(widgets_.at(0))->SetValue(static_cast<double>(vec4.x() + offset.x()));
static_cast<FloatSlider*>(widgets_.at(1))->SetValue(static_cast<double>(vec4.y() + offset.y()));
@@ -482,11 +480,11 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues()
{
ManagedColor mc = input_->get_value_at_time(node_time).value<Color>();
mc.set_color_input(input_->get_property(QStringLiteral("col_input")).toString());
mc.set_color_input(input_->property("col_input").toString());
QString d = input_->get_property(QStringLiteral("col_display")).toString();
QString v = input_->get_property(QStringLiteral("col_view")).toString();
QString l = input_->get_property(QStringLiteral("col_look")).toString();
QString d = input_->property("col_display").toString();
QString v = input_->property("col_view").toString();
QString l = input_->property("col_look").toString();
mc.set_color_output(ColorTransform(d, v, l));