curve/timeline: improved user interface behavior

* Implements "auto-fit" setting for curve view and sets it on open.
* Improves scroll zooming on all TimelineViewBase derivatives.
* Improves code sharing for better maintenance.
This commit is contained in:
itsmattkc
2020-06-23 05:25:34 +10:00
parent e681b87988
commit 8bf653925f
11 changed files with 198 additions and 82 deletions
+13 -31
View File
@@ -35,8 +35,6 @@ OLIVE_NAMESPACE_ENTER
KeyframeViewBase::KeyframeViewBase(QWidget *parent) :
TimelineViewBase(parent),
dragging_bezier_point_(nullptr),
y_axis_enabled_(false),
y_scale_(1.0),
currently_autoselecting_(false)
{
SetDefaultDragMode(RubberBandDrag);
@@ -57,22 +55,6 @@ void KeyframeViewBase::Clear()
item_map_.clear();
}
const double &KeyframeViewBase::GetYScale() const
{
return y_scale_;
}
void KeyframeViewBase::SetYScale(const double &y_scale)
{
y_scale_ = y_scale;
if (y_axis_enabled_) {
VerticalScaleChangedEvent(y_scale_);
viewport()->update();
}
}
void KeyframeViewBase::DeleteSelected()
{
QUndoCommand* command = new QUndoCommand();
@@ -194,7 +176,7 @@ void KeyframeViewBase::mouseMoveEvent(QMouseEvent *event)
keypair.key->key()->set_time(node_time);
if (y_axis_enabled_) {
if (IsYAxisEnabled()) {
keypair.key->key()->set_value(keypair.value - mouse_diff_scaled.y());
}
@@ -257,7 +239,7 @@ void KeyframeViewBase::mouseReleaseEvent(QMouseEvent *event)
command);
// Commit value if we're setting a value
if (y_axis_enabled_) {
if (IsYAxisEnabled()) {
item->key()->set_value(keypair.value);
new NodeParamSetKeyframeValueCommand(item->key(),
keypair.value - mouse_diff_scaled.y(),
@@ -288,10 +270,6 @@ void KeyframeViewBase::ScaleChangedEvent(const double &scale)
}
}
void KeyframeViewBase::VerticalScaleChangedEvent(double)
{
}
const QMap<NodeKeyframe *, KeyframeViewItem *> &KeyframeViewBase::item_map() const
{
return item_map_;
@@ -310,11 +288,6 @@ void KeyframeViewBase::TimeTargetChangedEvent(Node *target)
}
}
void KeyframeViewBase::SetYAxisEnabled(bool e)
{
y_axis_enabled_ = e;
}
void KeyframeViewBase::SetKeyframeTrackVisible(int track, bool visible)
{
if (!visible == hidden_tracks_.contains(track)) {
@@ -336,6 +309,11 @@ void KeyframeViewBase::SetKeyframeTrackVisible(int track, bool visible)
}
}
void KeyframeViewBase::ContextMenuEvent(Menu& m)
{
Q_UNUSED(m)
}
rational KeyframeViewBase::CalculateNewTimeFromScreen(const rational &old_time, double cursor_diff)
{
return rational::fromDouble(old_time.toDouble() + cursor_diff);
@@ -433,7 +411,7 @@ void KeyframeViewBase::ProcessBezierDrag(QPointF mouse_diff_scaled, bool include
QPointF KeyframeViewBase::GetScaledCursorPos(const QPoint &cursor_pos)
{
return QPointF(static_cast<double>(cursor_pos.x()) / GetScale(),
static_cast<double>(cursor_pos.y()) / y_scale_);
static_cast<double>(cursor_pos.y()) / GetYScale());
}
void KeyframeViewBase::ShowContextMenu()
@@ -480,7 +458,11 @@ void KeyframeViewBase::ShowContextMenu()
break;
}
}
}
ContextMenuEvent(m);
if (!items.isEmpty()) {
m.addSeparator();
QAction* properties_action = m.addAction(tr("P&roperties"));
@@ -532,7 +514,7 @@ void KeyframeViewBase::ShowKeyframePropertiesDialog()
void KeyframeViewBase::AutoSelectKeyTimeNeighbors()
{
if (currently_autoselecting_ || y_axis_enabled_) {
if (currently_autoselecting_ || IsYAxisEnabled()) {
return;
}
+4 -12
View File
@@ -23,9 +23,10 @@
#include "keyframeviewitem.h"
#include "node/keyframe.h"
#include "widget/timetarget/timetarget.h"
#include "widget/curvewidget/beziercontrolpointitem.h"
#include "widget/menu/menu.h"
#include "widget/timelinewidget/view/timelineviewbase.h"
#include "widget/timetarget/timetarget.h"
OLIVE_NAMESPACE_ENTER
@@ -37,9 +38,6 @@ public:
virtual void Clear();
const double& GetYScale() const;
void SetYScale(const double& y_scale);
void DeleteSelected();
public slots:
@@ -54,18 +52,16 @@ protected:
virtual void ScaleChangedEvent(const double& scale) override;
virtual void VerticalScaleChangedEvent(double scale);
const QMap<NodeKeyframe*, KeyframeViewItem*>& item_map() const;
virtual void KeyframeAboutToBeRemoved(NodeKeyframe* key);
virtual void TimeTargetChangedEvent(Node*) override;
void SetYAxisEnabled(bool e);
void SetKeyframeTrackVisible(int track, bool visible);
virtual void ContextMenuEvent(Menu &m);
private:
rational CalculateNewTimeFromScreen(const rational& old_time, double cursor_diff);
@@ -96,10 +92,6 @@ private:
QVector<KeyframeItemAndTime> selected_keys_;
bool y_axis_enabled_;
double y_scale_;
bool currently_autoselecting_;
QList<int> hidden_tracks_;