2018-10-24 15:18:33 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2019-06-18 15:12:21 +02:00
|
|
|
** Copyright (C) 2019 The Qt Company Ltd.
|
2018-10-24 15:18:33 +02:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
2019-06-18 15:12:21 +02:00
|
|
|
** This file is part of the Qt Design Tooling
|
2018-10-24 15:18:33 +02:00
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2019-06-18 15:12:21 +02:00
|
|
|
#include "curveeditor.h"
|
|
|
|
|
#include "curveeditormodel.h"
|
|
|
|
|
#include "detail/curveitem.h"
|
|
|
|
|
#include "detail/graphicsview.h"
|
|
|
|
|
#include "detail/treeview.h"
|
2018-10-24 15:18:33 +02:00
|
|
|
|
2019-06-28 10:45:28 +02:00
|
|
|
#include <QDoubleSpinBox>
|
2019-06-18 15:12:21 +02:00
|
|
|
#include <QHBoxLayout>
|
2019-06-28 10:45:28 +02:00
|
|
|
#include <QLabel>
|
2019-06-18 15:12:21 +02:00
|
|
|
#include <QSplitter>
|
2019-06-28 10:45:28 +02:00
|
|
|
#include <QVBoxLayout>
|
2018-10-24 15:18:33 +02:00
|
|
|
|
2019-06-18 15:12:21 +02:00
|
|
|
namespace DesignTools {
|
2018-10-24 15:18:33 +02:00
|
|
|
|
2019-06-18 15:12:21 +02:00
|
|
|
CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, m_tree(new TreeView(model, this))
|
|
|
|
|
, m_view(new GraphicsView(model))
|
2018-10-24 15:18:33 +02:00
|
|
|
{
|
2019-08-13 15:21:12 +02:00
|
|
|
auto *splitter = new QSplitter;
|
2019-06-18 15:12:21 +02:00
|
|
|
splitter->addWidget(m_tree);
|
|
|
|
|
splitter->addWidget(m_view);
|
|
|
|
|
splitter->setStretchFactor(1, 2);
|
|
|
|
|
|
2019-08-13 15:21:12 +02:00
|
|
|
auto *box = new QVBoxLayout;
|
2020-02-21 15:28:31 +01:00
|
|
|
box->addWidget(createToolBar(model));
|
2019-06-18 15:12:21 +02:00
|
|
|
box->addWidget(splitter);
|
|
|
|
|
setLayout(box);
|
|
|
|
|
|
2020-02-10 16:21:23 +01:00
|
|
|
connect(m_tree, &TreeView::treeItemLocked, model, &CurveEditorModel::curveChanged);
|
|
|
|
|
connect(m_tree, &TreeView::treeItemPinned, model, &CurveEditorModel::curveChanged);
|
2020-02-21 15:28:31 +01:00
|
|
|
|
|
|
|
|
connect(m_tree, &TreeView::treeItemLocked, m_view, &GraphicsView::setLocked);
|
|
|
|
|
connect(m_tree->selectionModel(),
|
|
|
|
|
&SelectionModel::curvesSelected,
|
|
|
|
|
m_view,
|
|
|
|
|
&GraphicsView::updateSelection);
|
2018-10-24 15:18:33 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-18 15:12:21 +02:00
|
|
|
void CurveEditor::zoomX(double zoom)
|
2018-10-24 15:18:33 +02:00
|
|
|
{
|
2019-06-18 15:12:21 +02:00
|
|
|
m_view->setZoomX(zoom);
|
2018-10-24 15:18:33 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-18 15:12:21 +02:00
|
|
|
void CurveEditor::zoomY(double zoom)
|
2018-10-24 15:18:33 +02:00
|
|
|
{
|
2019-06-18 15:12:21 +02:00
|
|
|
m_view->setZoomY(zoom);
|
2018-10-24 15:18:33 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-28 10:45:28 +02:00
|
|
|
void CurveEditor::clearCanvas()
|
|
|
|
|
{
|
2019-11-29 16:12:16 +01:00
|
|
|
m_view->reset({});
|
2019-06-28 10:45:28 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-21 15:28:31 +01:00
|
|
|
QToolBar *CurveEditor::createToolBar(CurveEditorModel *model)
|
2019-06-28 10:45:28 +02:00
|
|
|
{
|
2019-08-13 15:21:12 +02:00
|
|
|
auto *bar = new QToolBar;
|
2019-06-28 10:45:28 +02:00
|
|
|
bar->setFloatable(false);
|
|
|
|
|
|
2019-08-13 15:21:12 +02:00
|
|
|
QAction *tangentLinearAction = bar->addAction(QIcon(":/curveeditor/images/tangetToolsLinearIcon.png"), "Linear");
|
|
|
|
|
QAction *tangentStepAction = bar->addAction(QIcon(":/curveeditor/images/tangetToolsStepIcon.png"), "Step");
|
|
|
|
|
QAction *tangentSplineAction = bar->addAction(QIcon(":/curveeditor/images/tangetToolsSplineIcon.png"), "Spline");
|
2019-06-28 10:45:28 +02:00
|
|
|
QAction *tangentDefaultAction = bar->addAction("Set Default");
|
2020-03-24 15:05:28 +01:00
|
|
|
QAction *tangentUnifyAction = bar->addAction("Unify");
|
2019-06-28 10:45:28 +02:00
|
|
|
|
|
|
|
|
auto setLinearInterpolation = [this]() {
|
|
|
|
|
m_view->setInterpolation(Keyframe::Interpolation::Linear);
|
|
|
|
|
};
|
|
|
|
|
auto setStepInterpolation = [this]() {
|
|
|
|
|
m_view->setInterpolation(Keyframe::Interpolation::Step);
|
|
|
|
|
};
|
|
|
|
|
auto setSplineInterpolation = [this]() {
|
|
|
|
|
m_view->setInterpolation(Keyframe::Interpolation::Bezier);
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-24 15:05:28 +01:00
|
|
|
auto toggleUnifyKeyframe = [this]() { m_view->toggleUnified(); };
|
|
|
|
|
|
2019-06-28 10:45:28 +02:00
|
|
|
connect(tangentLinearAction, &QAction::triggered, setLinearInterpolation);
|
|
|
|
|
connect(tangentStepAction, &QAction::triggered, setStepInterpolation);
|
|
|
|
|
connect(tangentSplineAction, &QAction::triggered, setSplineInterpolation);
|
2020-03-24 15:05:28 +01:00
|
|
|
connect(tangentUnifyAction, &QAction::triggered, toggleUnifyKeyframe);
|
2019-06-28 10:45:28 +02:00
|
|
|
|
|
|
|
|
Q_UNUSED(tangentLinearAction);
|
|
|
|
|
Q_UNUSED(tangentSplineAction);
|
|
|
|
|
Q_UNUSED(tangentStepAction);
|
|
|
|
|
Q_UNUSED(tangentDefaultAction);
|
|
|
|
|
|
|
|
|
|
auto *durationBox = new QHBoxLayout;
|
2020-02-21 15:28:31 +01:00
|
|
|
auto *startSpin = new QSpinBox;
|
|
|
|
|
auto *endSpin = new QSpinBox;
|
|
|
|
|
|
|
|
|
|
startSpin->setRange(std::numeric_limits<int>::lowest(), std::numeric_limits<int>::max());
|
|
|
|
|
startSpin->setValue(model->minimumTime());
|
|
|
|
|
|
|
|
|
|
auto updateStartFrame = [this, model](int frame) {
|
|
|
|
|
model->setMinimumTime(frame, false);
|
|
|
|
|
m_view->viewport()->update();
|
|
|
|
|
};
|
|
|
|
|
connect(startSpin, QOverload<int>::of(&QSpinBox::valueChanged), updateStartFrame);
|
|
|
|
|
|
|
|
|
|
endSpin->setRange(std::numeric_limits<int>::lowest(), std::numeric_limits<int>::max());
|
|
|
|
|
endSpin->setValue(model->maximumTime());
|
|
|
|
|
|
|
|
|
|
auto updateEndFrame = [this, model](int frame) {
|
|
|
|
|
model->setMaximumTime(frame, false);
|
|
|
|
|
m_view->viewport()->update();
|
|
|
|
|
};
|
|
|
|
|
connect(endSpin, QOverload<int>::of(&QSpinBox::valueChanged), updateEndFrame);
|
|
|
|
|
|
|
|
|
|
auto setStartSlot = [startSpin](int frame) { startSpin->setValue(frame); };
|
|
|
|
|
connect(model, &CurveEditorModel::updateStartFrame, setStartSlot);
|
|
|
|
|
|
|
|
|
|
auto setEndSlot = [endSpin](int frame) { endSpin->setValue(frame); };
|
|
|
|
|
connect(model, &CurveEditorModel::updateEndFrame, setEndSlot);
|
|
|
|
|
|
|
|
|
|
durationBox->addWidget(new QLabel(tr("Start Frame")));
|
|
|
|
|
durationBox->addWidget(startSpin);
|
|
|
|
|
durationBox->addWidget(new QLabel(tr("End Frame")));
|
|
|
|
|
durationBox->addWidget(endSpin);
|
|
|
|
|
|
2019-06-28 10:45:28 +02:00
|
|
|
auto *durationWidget = new QWidget;
|
|
|
|
|
durationWidget->setLayout(durationBox);
|
|
|
|
|
bar->addWidget(durationWidget);
|
|
|
|
|
|
2019-10-24 17:09:22 +02:00
|
|
|
auto *cfspin = new QSpinBox;
|
|
|
|
|
cfspin->setMinimum(0);
|
|
|
|
|
cfspin->setMaximum(std::numeric_limits<int>::max());
|
|
|
|
|
|
|
|
|
|
auto intSignal = static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged);
|
|
|
|
|
connect(cfspin, intSignal, [this](int val) { m_view->setCurrentFrame(val, false); });
|
|
|
|
|
connect(m_view, &GraphicsView::notifyFrameChanged, [cfspin](int val) {
|
|
|
|
|
QSignalBlocker blocker(cfspin);
|
|
|
|
|
cfspin->setValue(val);
|
|
|
|
|
});
|
|
|
|
|
|
2019-06-28 10:45:28 +02:00
|
|
|
auto *positionBox = new QHBoxLayout;
|
|
|
|
|
positionBox->addWidget(new QLabel(tr("Current Frame")));
|
2019-10-24 17:09:22 +02:00
|
|
|
positionBox->addWidget(cfspin);
|
2019-06-28 10:45:28 +02:00
|
|
|
auto *positionWidget = new QWidget;
|
|
|
|
|
positionWidget->setLayout(positionBox);
|
|
|
|
|
bar->addWidget(positionWidget);
|
|
|
|
|
|
|
|
|
|
return bar;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-18 15:12:21 +02:00
|
|
|
} // End namespace DesignTools.
|