curvewidget: allow zooming only one axis and allow hiding keyframe tracks
This commit is contained in:
@@ -61,6 +61,16 @@ void CurveView::Clear()
|
||||
void CurveView::SetTrackCount(int count)
|
||||
{
|
||||
track_count_ = count;
|
||||
|
||||
track_visible_.resize(track_count_);
|
||||
track_visible_.fill(true);
|
||||
}
|
||||
|
||||
void CurveView::SetTrackVisible(int track, bool visible)
|
||||
{
|
||||
track_visible_[track] = visible;
|
||||
|
||||
SetKeyframeTrackVisible(track, visible);
|
||||
}
|
||||
|
||||
void CurveView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
@@ -116,6 +126,10 @@ void CurveView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
// Draw keyframe lines
|
||||
|
||||
for (int j=0;j<track_count_;j++) {
|
||||
if (!track_visible_.at(j)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
painter->setPen(QPen(GetKeyframeColor(j), qMax(1, fontMetrics().height() / 4)));
|
||||
QList<NodeKeyframe*> keys = GetKeyframesSortedByTime(j);
|
||||
|
||||
@@ -239,12 +253,33 @@ void CurveView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (WheelEventIsAZoomEvent(event)) {
|
||||
if (!event->angleDelta().isNull()) {
|
||||
bool only_vertical = false;
|
||||
bool only_horizontal = false;
|
||||
|
||||
if (event->modifiers() & Qt::ShiftModifier) {
|
||||
if (event->modifiers() & Qt::AltModifier) {
|
||||
only_horizontal = true;
|
||||
} else {
|
||||
only_vertical = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (event->angleDelta().x() + event->angleDelta().y() > 0) {
|
||||
emit ScaleChanged(GetScale() * 1.1);
|
||||
SetYScale(GetYScale() * 1.1);
|
||||
if (!only_vertical) {
|
||||
emit ScaleChanged(GetScale() * 1.1);
|
||||
}
|
||||
|
||||
if (!only_horizontal) {
|
||||
SetYScale(GetYScale() * 1.1);
|
||||
}
|
||||
} else {
|
||||
emit ScaleChanged(GetScale() * 0.9);
|
||||
SetYScale(GetYScale() * 0.9);
|
||||
if (!only_vertical) {
|
||||
emit ScaleChanged(GetScale() * 0.9);
|
||||
}
|
||||
|
||||
if (!only_horizontal) {
|
||||
SetYScale(GetYScale() *0.9);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -39,6 +39,8 @@ public:
|
||||
|
||||
void SetTrackCount(int count);
|
||||
|
||||
void SetTrackVisible(int track, bool visible);
|
||||
|
||||
public slots:
|
||||
void AddKeyframe(NodeKeyframePtr key);
|
||||
|
||||
@@ -76,6 +78,8 @@ private:
|
||||
|
||||
QList<BezierControlPointItem*> bezier_control_points_;
|
||||
|
||||
QVector<bool> track_visible_;
|
||||
|
||||
int track_count_;
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -117,12 +117,17 @@ void CurveWidget::SetInput(NodeInput *input)
|
||||
{
|
||||
if (bridge_) {
|
||||
foreach (QWidget* bridge_widget, bridge_->widgets()) {
|
||||
delete bridge_widget;
|
||||
bridge_widget->deleteLater();
|
||||
}
|
||||
delete bridge_;
|
||||
bridge_->deleteLater();
|
||||
bridge_ = nullptr;
|
||||
}
|
||||
|
||||
foreach (QCheckBox* box, checkboxes_) {
|
||||
box->deleteLater();
|
||||
}
|
||||
checkboxes_.clear();
|
||||
|
||||
if (input_) {
|
||||
disconnect(input_, &NodeInput::KeyframeAdded, view_, &CurveView::AddKeyframe);
|
||||
disconnect(input_, &NodeInput::KeyframeRemoved, view_, &CurveView::RemoveKeyframe);
|
||||
@@ -142,7 +147,15 @@ void CurveWidget::SetInput(NodeInput *input)
|
||||
|
||||
for (int i=0;i<bridge_->widgets().size();i++) {
|
||||
// Insert between two stretches to center the widget
|
||||
widget_bridge_layout_->insertWidget(2 + i, bridge_->widgets().at(i));
|
||||
QCheckBox* checkbox = new QCheckBox();
|
||||
checkbox->setChecked(true);
|
||||
widget_bridge_layout_->insertWidget(2 + i*2, checkbox);
|
||||
checkboxes_.append(checkbox);
|
||||
connect(checkbox, &QCheckBox::clicked, this, [this](bool e){
|
||||
view_->SetTrackVisible(checkboxes_.indexOf(static_cast<QCheckBox*>(sender())), e);
|
||||
});
|
||||
|
||||
widget_bridge_layout_->insertWidget(2 + i*2 + 1, bridge_->widgets().at(i));
|
||||
}
|
||||
|
||||
connect(input_, &NodeInput::KeyframeAdded, view_, &CurveView::AddKeyframe);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef CURVEWIDGET_H
|
||||
#define CURVEWIDGET_H
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
@@ -87,6 +88,8 @@ private:
|
||||
|
||||
NodeParamViewKeyframeControl* key_control_;
|
||||
|
||||
QList<QCheckBox*> checkboxes_;
|
||||
|
||||
private slots:
|
||||
void SelectionChanged();
|
||||
|
||||
|
||||
@@ -106,6 +106,11 @@ KeyframeViewItem *KeyframeViewBase::AddKeyframeInternal(NodeKeyframePtr key)
|
||||
item->SetScale(GetScale());
|
||||
item_map_.insert(key.get(), item);
|
||||
scene()->addItem(item);
|
||||
|
||||
if (hidden_tracks_.contains(key->track())) {
|
||||
item->setVisible(false);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -306,6 +311,27 @@ void KeyframeViewBase::SetYAxisEnabled(bool e)
|
||||
y_axis_enabled_ = e;
|
||||
}
|
||||
|
||||
void KeyframeViewBase::SetKeyframeTrackVisible(int track, bool visible)
|
||||
{
|
||||
if (!visible == hidden_tracks_.contains(track)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMap<NodeKeyframe*, KeyframeViewItem*>::const_iterator i;
|
||||
|
||||
for (i=item_map_.constBegin(); i!=item_map_.constEnd(); i++) {
|
||||
if (i.key()->track() == track) {
|
||||
i.value()->setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
if (visible) {
|
||||
hidden_tracks_.removeOne(track);
|
||||
} else {
|
||||
hidden_tracks_.append(track);
|
||||
}
|
||||
}
|
||||
|
||||
rational KeyframeViewBase::CalculateNewTimeFromScreen(const rational &old_time, double cursor_diff)
|
||||
{
|
||||
return rational::fromDouble(old_time.toDouble() + cursor_diff);
|
||||
|
||||
@@ -64,6 +64,8 @@ protected:
|
||||
|
||||
void SetYAxisEnabled(bool e);
|
||||
|
||||
void SetKeyframeTrackVisible(int track, bool visible);
|
||||
|
||||
private:
|
||||
rational CalculateNewTimeFromScreen(const rational& old_time, double cursor_diff);
|
||||
|
||||
@@ -100,6 +102,8 @@ private:
|
||||
|
||||
bool currently_autoselecting_;
|
||||
|
||||
QList<int> hidden_tracks_;
|
||||
|
||||
private slots:
|
||||
void ShowContextMenu();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user