reimplemented double and bool widgets separately

This commit is contained in:
itsmattkc
2019-03-13 00:12:15 +11:00
parent 5b03af5e5a
commit e3e45279b9
36 changed files with 327 additions and 312 deletions
+18
View File
@@ -1,5 +1,7 @@
#include "boolfield.h"
#include <QCheckBox>
BoolField::BoolField(EffectRow *parent, const QString &id) :
EffectField(parent, id, EFFECT_FIELD_BOOL)
{}
@@ -9,6 +11,17 @@ bool BoolField::GetBoolAt(double timecode)
return GetValueAt(timecode).toBool();
}
QWidget *BoolField::CreateWidget()
{
QCheckBox* cb = new QCheckBox();
connect(cb, SIGNAL(toggled(bool)), this, SLOT(UpdateFromWidget(bool)));
connect(this, SIGNAL(EnabledChanged(bool)), cb, SLOT(setEnabled(bool)));
connect(cb, SIGNAL(toggled(bool)), this, SIGNAL(Toggled(bool)));
return cb;
}
QVariant BoolField::ConvertStringToValue(const QString &s)
{
return (s == "1");
@@ -18,3 +31,8 @@ QString BoolField::ConvertValueToString(const QVariant &v)
{
return QString::number(v.toBool());
}
void BoolField::UpdateFromWidget(bool b)
{
SetValueAt(Now(), b);
}
+6
View File
@@ -11,8 +11,14 @@ public:
bool GetBoolAt(double timecode);
virtual QWidget* CreateWidget() override;
virtual QVariant ConvertStringToValue(const QString& s) override;
virtual QString ConvertValueToString(const QVariant& v) override;
signals:
void Toggled(bool);
private slots:
void UpdateFromWidget(bool b);
};
#endif // BOOLFIELD_H
+29 -5
View File
@@ -2,8 +2,11 @@
DoubleField::DoubleField(EffectRow* parent, const QString& id) :
EffectField(parent, id, EFFECT_FIELD_DOUBLE),
min_(DBL_MIN),
max_(DBL_MAX),
min_(qSNaN()),
max_(qSNaN()),
default_(0),
display_type_(LabelSlider::LABELSLIDER_NORMAL),
frame_rate_(30),
value_set_(false)
{
connect(this, SIGNAL(Changed()), this, SLOT(ValueHasBeenSet()), Qt::DirectConnection);
@@ -54,12 +57,33 @@ QString DoubleField::ConvertValueToString(const QVariant &v)
return QString::number(v.toDouble());
}
//QWidget *DoubleField::CreateWidget()
//{
QWidget *DoubleField::CreateWidget()
{
LabelSlider* ls = new LabelSlider();
//}
if (!qIsNaN(min_)) {
ls->set_minimum_value(min_);
}
ls->set_default_value(default_);
if (!qIsNaN(max_)) {
ls->set_maximum_value(max_);
}
ls->set_display_type(display_type_);
ls->set_frame_rate(frame_rate_);
connect(ls, SIGNAL(valueChanged(double)), this, SLOT(UpdateFromWidget(double)));
connect(ls, SIGNAL(clicked()), this, SIGNAL(Clicked()));
connect(this, SIGNAL(EnabledChanged(bool)), ls, SLOT(setEnabled(bool)));
return ls;
}
void DoubleField::ValueHasBeenSet()
{
value_set_ = true;
}
void DoubleField::UpdateFromWidget(double d)
{
SetValueAt(Now(), d);
}
+2 -1
View File
@@ -35,7 +35,7 @@ public:
virtual QVariant ConvertStringToValue(const QString& s);
virtual QString ConvertValueToString(const QVariant& v);
//virtual QWidget* CreateWidget() override;
virtual QWidget* CreateWidget() override;
private:
double min_;
double max_;
@@ -47,6 +47,7 @@ private:
bool value_set_;
private slots:
void ValueHasBeenSet();
void UpdateFromWidget(double d);
};
#endif // DOUBLEFIELD_H
+19 -67
View File
@@ -20,6 +20,9 @@
#include "effectfield.h"
#include <QDateTime>
#include <QtMath>
#include "ui/labelslider.h"
#include "ui/colorbutton.h"
#include "ui/texteditex.h"
@@ -28,6 +31,8 @@
#include "ui/fontcombobox.h"
#include "ui/embeddedfilechooser.h"
#include "rendering/renderfunctions.h"
#include "io/config.h"
#include "project/effectrow.h"
@@ -39,9 +44,6 @@
#include "io/math.h"
#include <QDateTime>
#include <QtMath>
#include "debug.h"
EffectField::EffectField(EffectRow* parent, const QString &i, EffectFieldType t) :
@@ -54,74 +56,14 @@ EffectField::EffectField(EffectRow* parent, const QString &i, EffectFieldType t)
Q_ASSERT(parent != nullptr);
Q_ASSERT(!i.isEmpty() || t == EFFECT_FIELD_UI);
// Add this field to the parent row specified
parent->AddField(this);
/*
switch (t) {
case EFFECT_FIELD_DOUBLE:
{
LabelSlider* ls = new LabelSlider();
ui_element = ls;
connect(ls, SIGNAL(valueChanged()), this, SLOT(ui_element_change()));
connect(ls, SIGNAL(clicked()), this, SIGNAL(clicked()));
}
break;
case EFFECT_FIELD_COLOR:
{
ColorButton* cb = new ColorButton();
ui_element = cb;
connect(cb, SIGNAL(color_changed()), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_STRING:
{
TextEditEx* edit = new TextEditEx();
// TODO magic number 2 - It seems to just be +1 for the top and +1 for the bottom, which is sort of sensible but
// feels a little tacky?
edit->setFixedHeight(qCeil(edit->fontMetrics().lineSpacing()*olive::CurrentConfig.effect_textbox_lines
+ edit->document()->documentMargin()
+ edit->document()->documentMargin()
+ 2));
edit->setUndoRedoEnabled(true);
ui_element = edit;
connect(edit, SIGNAL(textChanged()), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_BOOL:
{
CheckboxEx* cb = new CheckboxEx();
ui_element = cb;
connect(cb, SIGNAL(clicked(bool)), this, SLOT(ui_element_change()));
connect(cb, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
}
break;
case EFFECT_FIELD_COMBO:
{
ComboBoxEx* cb = new ComboBoxEx();
ui_element = cb;
connect(cb, SIGNAL(activated(int)), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_FONT:
{
FontCombobox* fcb = new FontCombobox();
ui_element = fcb;
connect(fcb, SIGNAL(activated(int)), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_FILE:
{
EmbeddedFileChooser* efc = new EmbeddedFileChooser();
ui_element = efc;
connect(efc, SIGNAL(changed()), this, SLOT(ui_element_change()));
}
break;
}
*/
// Set a very base default value
SetValueAt(0, 0);
// Connect this field to the effect's changed function
connect(this, SIGNAL(Changed()), parent->GetParentEffect(), SLOT(FieldChanged()));
}
EffectField::~EffectField() {}
@@ -223,6 +165,8 @@ QVariant EffectField::GetValueAt(double timecode)
case EFFECT_FIELD_FONT:
case EFFECT_FIELD_FILE:
return before_data;
default:
break;
}
}
@@ -247,6 +191,12 @@ void EffectField::SetValueAt(double timecode, const QVariant &value)
emit Changed();
}
double EffectField::Now()
{
Clip* c = GetParentRow()->GetParentEffect()->parent_clip;
return playhead_to_clip_seconds(c, c->sequence->playhead);
}
const EffectField::EffectFieldType &EffectField::type()
{
return type_;
@@ -351,6 +301,7 @@ bool EffectField::HasKeyframes() {
return (GetParentRow()->IsKeyframing() && keyframes.size() > 1);
}
/*
void EffectField::ui_element_change() {
// TODO address this
//bool dragging_double = (type_ == EFFECT_FIELD_DOUBLE && static_cast<LabelSlider*>(ui_element)->is_dragging());
@@ -361,6 +312,7 @@ void EffectField::ui_element_change() {
if (!dragging_double) olive::UndoStack.push(ca);
emit Changed();
}
*/
/*
void EffectField::make_key_from_change(ComboAction* ca) {
+2 -2
View File
@@ -55,6 +55,8 @@ public:
QVariant GetValueAt(double timecode);
void SetValueAt(double timecode, const QVariant& value);
double Now();
int GetColumnSpan();
void SetColumnSpan(int i);
@@ -69,8 +71,6 @@ public:
void SetEnabled(bool e);
QVector<EffectKeyframe> keyframes;
public slots:
void ui_element_change();
private:
EffectFieldType type_;
QString id_;