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"
|
2022-04-05 13:45:30 +02:00
|
|
|
#include "curveeditortoolbar.h"
|
2019-06-18 15:12:21 +02:00
|
|
|
#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>
|
2021-10-25 14:48:07 +02:00
|
|
|
#include <QScrollArea>
|
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
|
|
|
|
2020-10-26 15:26:17 +01:00
|
|
|
namespace QmlDesigner {
|
2018-10-24 15:18:33 +02:00
|
|
|
|
2019-06-18 15:12:21 +02:00
|
|
|
CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
2022-04-05 13:45:30 +02:00
|
|
|
, m_infoText(nullptr)
|
2022-07-01 13:22:32 +02:00
|
|
|
, m_statusLine(nullptr)
|
2022-04-05 13:45:30 +02:00
|
|
|
, m_toolbar(new CurveEditorToolBar(model, this))
|
2019-06-18 15:12:21 +02:00
|
|
|
, m_tree(new TreeView(model, this))
|
2021-10-25 14:48:07 +02:00
|
|
|
, m_view(new GraphicsView(model, this))
|
2018-10-24 15:18:33 +02:00
|
|
|
{
|
2022-04-05 13:45:30 +02:00
|
|
|
const QString labelText = tr(
|
|
|
|
|
"This file does not contain a timeline. <br><br>"
|
|
|
|
|
"To create an animation, add a timeline by clicking the + button in the \"Timeline\" view."
|
|
|
|
|
);
|
|
|
|
|
m_infoText = new QLabel(labelText);
|
|
|
|
|
|
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);
|
|
|
|
|
|
2021-10-25 14:48:07 +02:00
|
|
|
QScrollArea* area = new QScrollArea;
|
|
|
|
|
area->setWidget(splitter);
|
|
|
|
|
area->setWidgetResizable(true);
|
|
|
|
|
|
2022-07-01 13:22:32 +02:00
|
|
|
m_statusLine = new QLabel();
|
|
|
|
|
|
2019-08-13 15:21:12 +02:00
|
|
|
auto *box = new QVBoxLayout;
|
2022-04-05 13:45:30 +02:00
|
|
|
box->addWidget(m_infoText);
|
|
|
|
|
box->addWidget(m_toolbar);
|
2021-10-25 14:48:07 +02:00
|
|
|
box->addWidget(area);
|
2022-07-01 13:22:32 +02:00
|
|
|
box->addWidget(m_statusLine);
|
2019-06-18 15:12:21 +02:00
|
|
|
setLayout(box);
|
|
|
|
|
|
2022-04-05 13:45:30 +02:00
|
|
|
connect(m_toolbar, &CurveEditorToolBar::unifyClicked, [this]() {
|
|
|
|
|
m_view->toggleUnified();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_toolbar, &CurveEditorToolBar::interpolationClicked, [this](Keyframe::Interpolation ipol) {
|
|
|
|
|
m_view->setInterpolation(ipol);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_toolbar, &CurveEditorToolBar::startFrameChanged, [this, model](int frame) {
|
|
|
|
|
model->setMinimumTime(frame);
|
|
|
|
|
m_view->viewport()->update();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_toolbar, &CurveEditorToolBar::endFrameChanged, [this, model](int frame) {
|
|
|
|
|
model->setMaximumTime(frame);
|
|
|
|
|
m_view->viewport()->update();
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-01 13:22:32 +02:00
|
|
|
connect(m_toolbar, &CurveEditorToolBar::currentFrameChanged, [this, model](int frame) {
|
|
|
|
|
model->setCurrentFrame(frame);
|
|
|
|
|
updateStatusLine();
|
|
|
|
|
m_view->viewport()->update();
|
|
|
|
|
});
|
2022-04-05 13:45:30 +02:00
|
|
|
|
2022-08-04 15:59:45 +02:00
|
|
|
connect(m_toolbar, &CurveEditorToolBar::zoomChanged, [this](double zoom) {
|
|
|
|
|
const bool wasBlocked = m_view->blockSignals(true);
|
|
|
|
|
m_view->setZoomX(zoom);
|
|
|
|
|
m_view->blockSignals(wasBlocked);
|
|
|
|
|
m_view->viewport()->update();
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-05 13:45:30 +02:00
|
|
|
connect(
|
|
|
|
|
m_view, &GraphicsView::currentFrameChanged,
|
|
|
|
|
m_toolbar, &CurveEditorToolBar::setCurrentFrame);
|
|
|
|
|
|
2020-10-26 15:26:17 +01:00
|
|
|
connect(m_tree, &TreeView::treeItemLocked, model, &CurveEditorModel::setLocked);
|
|
|
|
|
connect(m_tree, &TreeView::treeItemPinned, model, &CurveEditorModel::setPinned);
|
2020-02-21 15:28:31 +01:00
|
|
|
|
2022-04-05 13:45:30 +02:00
|
|
|
connect(
|
|
|
|
|
m_tree->selectionModel(), &SelectionModel::curvesSelected,
|
|
|
|
|
m_view, &GraphicsView::updateSelection);
|
|
|
|
|
|
2022-08-04 15:59:45 +02:00
|
|
|
connect(m_view, &GraphicsView::zoomChanged, [this](double x, double y) {
|
|
|
|
|
Q_UNUSED(y);
|
|
|
|
|
m_toolbar->setZoom(x);
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-05 13:45:30 +02:00
|
|
|
auto updateTimeline = [this, model](bool validTimeline) {
|
|
|
|
|
if (validTimeline) {
|
2022-07-01 13:22:32 +02:00
|
|
|
updateStatusLine();
|
|
|
|
|
m_view->setCurrentFrame(m_view->model()->currentFrame(), false);
|
2022-04-05 13:45:30 +02:00
|
|
|
m_toolbar->updateBoundsSilent(model->minimumTime(), model->maximumTime());
|
|
|
|
|
m_toolbar->show();
|
|
|
|
|
m_tree->show();
|
|
|
|
|
m_view->show();
|
|
|
|
|
m_infoText->hide();
|
|
|
|
|
} else {
|
|
|
|
|
m_toolbar->hide();
|
|
|
|
|
m_tree->hide();
|
|
|
|
|
m_view->hide();
|
|
|
|
|
m_infoText->show();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
connect(model, &CurveEditorModel::timelineChanged, this, updateTimeline);
|
2022-07-01 13:22:32 +02:00
|
|
|
|
|
|
|
|
connect(model, &CurveEditorModel::setStatusLineMsg, m_statusLine, &QLabel::setText);
|
2018-10-24 15:18:33 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 13:42:32 +02:00
|
|
|
bool CurveEditor::dragging() const
|
|
|
|
|
{
|
|
|
|
|
return m_view->dragging();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-09-28 17:54:31 +02:00
|
|
|
void CurveEditor::showEvent(QShowEvent *event)
|
|
|
|
|
{
|
|
|
|
|
emit viewEnabledChanged(true);
|
|
|
|
|
QWidget::showEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurveEditor::hideEvent(QHideEvent *event)
|
|
|
|
|
{
|
|
|
|
|
emit viewEnabledChanged(false);
|
|
|
|
|
QWidget::hideEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 13:22:32 +02:00
|
|
|
void CurveEditor::updateStatusLine()
|
|
|
|
|
{
|
|
|
|
|
int currentFrame = m_view->model()->currentFrame();
|
|
|
|
|
QString currentText = QString("Playhead frame %1").arg(currentFrame);
|
|
|
|
|
m_statusLine->setText(currentText);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 15:26:17 +01:00
|
|
|
} // End namespace QmlDesigner.
|