implemented correct value changing in the CurveView widget
This commit is contained in:
@@ -6,12 +6,12 @@
|
|||||||
#include "common/qtversionabstraction.h"
|
#include "common/qtversionabstraction.h"
|
||||||
|
|
||||||
CurveView::CurveView(QWidget *parent) :
|
CurveView::CurveView(QWidget *parent) :
|
||||||
KeyframeViewBase(parent),
|
KeyframeViewBase(parent)
|
||||||
y_scale_(1.0)
|
|
||||||
{
|
{
|
||||||
setAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
setAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
||||||
setDragMode(RubberBandDrag);
|
setDragMode(RubberBandDrag);
|
||||||
setViewportUpdateMode(FullViewportUpdate);
|
setViewportUpdateMode(FullViewportUpdate);
|
||||||
|
SetYAxisEnabled(true);
|
||||||
|
|
||||||
text_padding_ = QFontMetricsWidth(fontMetrics(), QStringLiteral("i"));
|
text_padding_ = QFontMetricsWidth(fontMetrics(), QStringLiteral("i"));
|
||||||
|
|
||||||
@@ -36,12 +36,6 @@ void CurveView::Clear()
|
|||||||
lines_.clear();
|
lines_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurveView::SetYScale(const double &y_scale)
|
|
||||||
{
|
|
||||||
y_scale_ = y_scale;
|
|
||||||
viewport()->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CurveView::drawBackground(QPainter *painter, const QRectF &rect)
|
void CurveView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||||
{
|
{
|
||||||
if (timebase().isNull()) {
|
if (timebase().isNull()) {
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ public:
|
|||||||
|
|
||||||
virtual void Clear() override;
|
virtual void Clear() override;
|
||||||
|
|
||||||
void SetYScale(const double& y_scale);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void AddKeyframe(NodeKeyframePtr key);
|
void AddKeyframe(NodeKeyframePtr key);
|
||||||
|
|
||||||
@@ -40,8 +38,6 @@ private:
|
|||||||
|
|
||||||
int text_padding_;
|
int text_padding_;
|
||||||
|
|
||||||
double y_scale_;
|
|
||||||
|
|
||||||
int minimum_grid_space_;
|
int minimum_grid_space_;
|
||||||
|
|
||||||
QList<QGraphicsLineItem*> lines_;
|
QList<QGraphicsLineItem*> lines_;
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
KeyframeViewBase::KeyframeViewBase(QWidget *parent) :
|
KeyframeViewBase::KeyframeViewBase(QWidget *parent) :
|
||||||
TimelineViewBase(parent),
|
TimelineViewBase(parent),
|
||||||
dragging_bezier_point_(nullptr)
|
y_scale_(1.0),
|
||||||
|
dragging_bezier_point_(nullptr),
|
||||||
|
y_axis_enabled_(false)
|
||||||
{
|
{
|
||||||
setDragMode(RubberBandDrag);
|
setDragMode(RubberBandDrag);
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
@@ -31,6 +33,12 @@ void KeyframeViewBase::Clear()
|
|||||||
item_map_.clear();
|
item_map_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyframeViewBase::SetYScale(const double &y_scale)
|
||||||
|
{
|
||||||
|
y_scale_ = y_scale;
|
||||||
|
viewport()->update();
|
||||||
|
}
|
||||||
|
|
||||||
void KeyframeViewBase::RemoveKeyframe(NodeKeyframePtr key)
|
void KeyframeViewBase::RemoveKeyframe(NodeKeyframePtr key)
|
||||||
{
|
{
|
||||||
KeyframeAboutToBeRemoved(key.get());
|
KeyframeAboutToBeRemoved(key.get());
|
||||||
@@ -79,7 +87,7 @@ void KeyframeViewBase::mousePressEvent(QMouseEvent *event)
|
|||||||
for (int i=0;i<selected_items.size();i++) {
|
for (int i=0;i<selected_items.size();i++) {
|
||||||
KeyframeViewItem* key = static_cast<KeyframeViewItem*>(selected_items.at(i));
|
KeyframeViewItem* key = static_cast<KeyframeViewItem*>(selected_items.at(i));
|
||||||
|
|
||||||
selected_keys_.replace(i, {key, key->x(), key->key()->time()});
|
selected_keys_.replace(i, {key, key->x(), key->key()->time(), key->key()->value().toDouble()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +116,10 @@ void KeyframeViewBase::mouseMoveEvent(QMouseEvent *event)
|
|||||||
foreach (const KeyframeItemAndTime& keypair, selected_keys_) {
|
foreach (const KeyframeItemAndTime& keypair, selected_keys_) {
|
||||||
// FIXME: Find some way to do single frame updates as the NodeParamViewWidgetBridge does?
|
// FIXME: Find some way to do single frame updates as the NodeParamViewWidgetBridge does?
|
||||||
keypair.key->key()->set_time(CalculateNewTimeFromScreen(keypair.time, mouse_diff_scaled.x()));
|
keypair.key->key()->set_time(CalculateNewTimeFromScreen(keypair.time, mouse_diff_scaled.x()));
|
||||||
|
|
||||||
|
if (y_axis_enabled_) {
|
||||||
|
keypair.key->key()->set_value(keypair.value - mouse_diff_scaled.y());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,6 +160,14 @@ void KeyframeViewBase::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
new_time,
|
new_time,
|
||||||
keypair.time,
|
keypair.time,
|
||||||
command);
|
command);
|
||||||
|
|
||||||
|
// Commit value if we're setting a vaule
|
||||||
|
if (y_axis_enabled_) {
|
||||||
|
new NodeParamSetKeyframeValueCommand(item->key(),
|
||||||
|
keypair.value - mouse_diff_scaled.y(),
|
||||||
|
keypair.value,
|
||||||
|
command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::instance()->undo_stack()->push(command);
|
Core::instance()->undo_stack()->push(command);
|
||||||
@@ -177,6 +197,11 @@ void KeyframeViewBase::KeyframeAboutToBeRemoved(NodeKeyframe *)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyframeViewBase::SetYAxisEnabled(bool e)
|
||||||
|
{
|
||||||
|
y_axis_enabled_ = e;
|
||||||
|
}
|
||||||
|
|
||||||
rational KeyframeViewBase::CalculateNewTimeFromScreen(const rational &old_time, double cursor_diff)
|
rational KeyframeViewBase::CalculateNewTimeFromScreen(const rational &old_time, double cursor_diff)
|
||||||
{
|
{
|
||||||
return rational::fromDouble(old_time.toDouble() + cursor_diff);
|
return rational::fromDouble(old_time.toDouble() + cursor_diff);
|
||||||
@@ -252,8 +277,8 @@ void KeyframeViewBase::ProcessBezierDrag(QPointF mouse_diff_scaled, bool include
|
|||||||
|
|
||||||
QPointF KeyframeViewBase::GetScaledCursorPos(const QPoint &cursor_pos)
|
QPointF KeyframeViewBase::GetScaledCursorPos(const QPoint &cursor_pos)
|
||||||
{
|
{
|
||||||
return QPointF (static_cast<double>(cursor_pos.x()) / scale_,
|
return QPointF(static_cast<double>(cursor_pos.x()) / scale_,
|
||||||
cursor_pos.y());;
|
static_cast<double>(cursor_pos.y()) / y_scale_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyframeViewBase::ShowContextMenu()
|
void KeyframeViewBase::ShowContextMenu()
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public:
|
|||||||
|
|
||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
|
|
||||||
|
void SetYScale(const double& y_scale);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void RemoveKeyframe(NodeKeyframePtr key);
|
void RemoveKeyframe(NodeKeyframePtr key);
|
||||||
|
|
||||||
@@ -31,6 +33,10 @@ protected:
|
|||||||
|
|
||||||
virtual void KeyframeAboutToBeRemoved(NodeKeyframe* key);
|
virtual void KeyframeAboutToBeRemoved(NodeKeyframe* key);
|
||||||
|
|
||||||
|
void SetYAxisEnabled(bool e);
|
||||||
|
|
||||||
|
double y_scale_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rational CalculateNewTimeFromScreen(const rational& old_time, double cursor_diff);
|
rational CalculateNewTimeFromScreen(const rational& old_time, double cursor_diff);
|
||||||
|
|
||||||
@@ -46,6 +52,7 @@ private:
|
|||||||
KeyframeViewItem* key;
|
KeyframeViewItem* key;
|
||||||
qreal item_x;
|
qreal item_x;
|
||||||
rational time;
|
rational time;
|
||||||
|
double value;
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap<NodeKeyframe*, KeyframeViewItem*> item_map_;
|
QMap<NodeKeyframe*, KeyframeViewItem*> item_map_;
|
||||||
@@ -60,6 +67,8 @@ private:
|
|||||||
|
|
||||||
QVector<KeyframeItemAndTime> selected_keys_;
|
QVector<KeyframeItemAndTime> selected_keys_;
|
||||||
|
|
||||||
|
bool y_axis_enabled_;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void ShowContextMenu();
|
void ShowContextMenu();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user