implemented correct value changing in the CurveView widget
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
#include "common/qtversionabstraction.h"
|
||||
|
||||
CurveView::CurveView(QWidget *parent) :
|
||||
KeyframeViewBase(parent),
|
||||
y_scale_(1.0)
|
||||
KeyframeViewBase(parent)
|
||||
{
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
||||
setDragMode(RubberBandDrag);
|
||||
setViewportUpdateMode(FullViewportUpdate);
|
||||
SetYAxisEnabled(true);
|
||||
|
||||
text_padding_ = QFontMetricsWidth(fontMetrics(), QStringLiteral("i"));
|
||||
|
||||
@@ -36,12 +36,6 @@ void CurveView::Clear()
|
||||
lines_.clear();
|
||||
}
|
||||
|
||||
void CurveView::SetYScale(const double &y_scale)
|
||||
{
|
||||
y_scale_ = y_scale;
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void CurveView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if (timebase().isNull()) {
|
||||
|
||||
@@ -15,8 +15,6 @@ public:
|
||||
|
||||
virtual void Clear() override;
|
||||
|
||||
void SetYScale(const double& y_scale);
|
||||
|
||||
public slots:
|
||||
void AddKeyframe(NodeKeyframePtr key);
|
||||
|
||||
@@ -40,8 +38,6 @@ private:
|
||||
|
||||
int text_padding_;
|
||||
|
||||
double y_scale_;
|
||||
|
||||
int minimum_grid_space_;
|
||||
|
||||
QList<QGraphicsLineItem*> lines_;
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
|
||||
KeyframeViewBase::KeyframeViewBase(QWidget *parent) :
|
||||
TimelineViewBase(parent),
|
||||
dragging_bezier_point_(nullptr)
|
||||
y_scale_(1.0),
|
||||
dragging_bezier_point_(nullptr),
|
||||
y_axis_enabled_(false)
|
||||
{
|
||||
setDragMode(RubberBandDrag);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
@@ -31,6 +33,12 @@ void KeyframeViewBase::Clear()
|
||||
item_map_.clear();
|
||||
}
|
||||
|
||||
void KeyframeViewBase::SetYScale(const double &y_scale)
|
||||
{
|
||||
y_scale_ = y_scale;
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void KeyframeViewBase::RemoveKeyframe(NodeKeyframePtr key)
|
||||
{
|
||||
KeyframeAboutToBeRemoved(key.get());
|
||||
@@ -79,7 +87,7 @@ void KeyframeViewBase::mousePressEvent(QMouseEvent *event)
|
||||
for (int i=0;i<selected_items.size();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_) {
|
||||
// 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()));
|
||||
|
||||
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,
|
||||
keypair.time,
|
||||
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);
|
||||
@@ -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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return QPointF (static_cast<double>(cursor_pos.x()) / scale_,
|
||||
cursor_pos.y());;
|
||||
return QPointF(static_cast<double>(cursor_pos.x()) / scale_,
|
||||
static_cast<double>(cursor_pos.y()) / y_scale_);
|
||||
}
|
||||
|
||||
void KeyframeViewBase::ShowContextMenu()
|
||||
|
||||
@@ -15,6 +15,8 @@ public:
|
||||
|
||||
virtual void Clear();
|
||||
|
||||
void SetYScale(const double& y_scale);
|
||||
|
||||
public slots:
|
||||
void RemoveKeyframe(NodeKeyframePtr key);
|
||||
|
||||
@@ -31,6 +33,10 @@ protected:
|
||||
|
||||
virtual void KeyframeAboutToBeRemoved(NodeKeyframe* key);
|
||||
|
||||
void SetYAxisEnabled(bool e);
|
||||
|
||||
double y_scale_;
|
||||
|
||||
private:
|
||||
rational CalculateNewTimeFromScreen(const rational& old_time, double cursor_diff);
|
||||
|
||||
@@ -46,6 +52,7 @@ private:
|
||||
KeyframeViewItem* key;
|
||||
qreal item_x;
|
||||
rational time;
|
||||
double value;
|
||||
};
|
||||
|
||||
QMap<NodeKeyframe*, KeyframeViewItem*> item_map_;
|
||||
@@ -60,6 +67,8 @@ private:
|
||||
|
||||
QVector<KeyframeItemAndTime> selected_keys_;
|
||||
|
||||
bool y_axis_enabled_;
|
||||
|
||||
private slots:
|
||||
void ShowContextMenu();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user