2014-11-18 18:32:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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 Digia. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-12-09 12:12:57 +01:00
|
|
|
#include "timelinerenderstate_p.h"
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2014-12-09 11:01:23 +01:00
|
|
|
namespace Timeline {
|
2014-11-18 18:32:43 +01:00
|
|
|
|
|
|
|
|
TimelineRenderState::TimelineRenderState(qint64 start, qint64 end, qreal scale, int numPasses) :
|
2014-12-09 12:12:57 +01:00
|
|
|
d_ptr(new TimelineRenderStatePrivate)
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
d->expandedRowRoot = new QSGNode;
|
|
|
|
|
d->collapsedRowRoot = new QSGNode;
|
|
|
|
|
d->expandedOverlayRoot = new QSGNode;
|
|
|
|
|
d->collapsedOverlayRoot = new QSGNode;
|
|
|
|
|
d->start = start;
|
|
|
|
|
d->end = end;
|
|
|
|
|
d->scale = scale;
|
|
|
|
|
d->passes.resize(numPasses);
|
|
|
|
|
|
|
|
|
|
d->expandedRowRoot->setFlag(QSGNode::OwnedByParent, false);
|
|
|
|
|
d->collapsedRowRoot->setFlag(QSGNode::OwnedByParent, false);
|
|
|
|
|
d->expandedOverlayRoot->setFlag(QSGNode::OwnedByParent, false);
|
|
|
|
|
d->collapsedOverlayRoot->setFlag(QSGNode::OwnedByParent, false);
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimelineRenderState::~TimelineRenderState()
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
delete d->expandedRowRoot;
|
|
|
|
|
delete d->collapsedRowRoot;
|
|
|
|
|
delete d->expandedOverlayRoot;
|
|
|
|
|
delete d->collapsedOverlayRoot;
|
2014-12-16 15:32:15 +01:00
|
|
|
qDeleteAll(d->passes);
|
2014-12-09 12:12:57 +01:00
|
|
|
delete d;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 TimelineRenderState::start() const
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->start;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 TimelineRenderState::end() const
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->end;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qreal TimelineRenderState::scale() const
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->scale;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 12:12:57 +01:00
|
|
|
const QSGNode *TimelineRenderState::expandedRowRoot() const
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->expandedRowRoot;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 12:12:57 +01:00
|
|
|
const QSGNode *TimelineRenderState::collapsedRowRoot() const
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->collapsedRowRoot;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 12:12:57 +01:00
|
|
|
const QSGNode *TimelineRenderState::expandedOverlayRoot() const
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->expandedOverlayRoot;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 12:12:57 +01:00
|
|
|
const QSGNode *TimelineRenderState::collapsedOverlayRoot() const
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->collapsedOverlayRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGNode *TimelineRenderState::expandedRowRoot()
|
|
|
|
|
{
|
|
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
return d->expandedRowRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGNode *TimelineRenderState::collapsedRowRoot()
|
|
|
|
|
{
|
|
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
return d->collapsedRowRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGNode *TimelineRenderState::expandedOverlayRoot()
|
|
|
|
|
{
|
|
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
return d->expandedOverlayRoot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGNode *TimelineRenderState::collapsedOverlayRoot()
|
|
|
|
|
{
|
|
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
return d->collapsedOverlayRoot;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TimelineRenderState::isEmpty() const
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->collapsedRowRoot->childCount() == 0 && d->expandedRowRoot->childCount() == 0 &&
|
|
|
|
|
d->collapsedOverlayRoot->childCount() == 0 && d->expandedOverlayRoot->childCount() == 0;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 14:18:05 +01:00
|
|
|
void TimelineRenderState::assembleNodeTree(const TimelineModel *model, int defaultRowHeight,
|
|
|
|
|
int defaultRowOffset)
|
|
|
|
|
{
|
|
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
for (int pass = 0; pass < d->passes.length(); ++pass) {
|
|
|
|
|
const TimelineRenderPass::State *passState = d->passes[pass];
|
|
|
|
|
if (!passState)
|
|
|
|
|
continue;
|
|
|
|
|
if (passState->expandedOverlay())
|
|
|
|
|
d->expandedOverlayRoot->appendChildNode(passState->expandedOverlay());
|
|
|
|
|
if (passState->collapsedOverlay())
|
|
|
|
|
d->collapsedOverlayRoot->appendChildNode(passState->collapsedOverlay());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int row = 0;
|
|
|
|
|
for (int i = 0; i < model->expandedRowCount(); ++i) {
|
|
|
|
|
QSGTransformNode *rowNode = new QSGTransformNode;
|
|
|
|
|
for (int pass = 0; pass < d->passes.length(); ++pass) {
|
|
|
|
|
const TimelineRenderPass::State *passState = d->passes[pass];
|
|
|
|
|
if (!passState)
|
|
|
|
|
continue;
|
|
|
|
|
const QVector<QSGNode *> &rows = passState->expandedRows();
|
|
|
|
|
if (rows.length() > row) {
|
|
|
|
|
QSGNode *rowChildNode = rows[row];
|
|
|
|
|
if (rowChildNode)
|
|
|
|
|
rowNode->appendChildNode(rowChildNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d->expandedRowRoot->appendChildNode(rowNode);
|
|
|
|
|
++row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < model->collapsedRowCount(); ++row) {
|
|
|
|
|
QSGTransformNode *rowNode = new QSGTransformNode;
|
|
|
|
|
QMatrix4x4 matrix;
|
|
|
|
|
matrix.translate(0, row * defaultRowOffset, 0);
|
|
|
|
|
matrix.scale(1.0, static_cast<float>(defaultRowHeight) /
|
|
|
|
|
static_cast<float>(TimelineModel::defaultRowHeight()), 1.0);
|
|
|
|
|
rowNode->setMatrix(matrix);
|
|
|
|
|
for (int pass = 0; pass < d->passes.length(); ++pass) {
|
|
|
|
|
const TimelineRenderPass::State *passState = d->passes[pass];
|
|
|
|
|
if (!passState)
|
|
|
|
|
continue;
|
|
|
|
|
const QVector<QSGNode *> &rows = passState->collapsedRows();
|
|
|
|
|
if (rows.length() > row) {
|
|
|
|
|
QSGNode *rowChildNode = rows[row];
|
|
|
|
|
if (rowChildNode)
|
|
|
|
|
rowNode->appendChildNode(rowChildNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d->collapsedRowRoot->appendChildNode(rowNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateExpandedRowHeights(model, defaultRowHeight, defaultRowOffset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimelineRenderState::updateExpandedRowHeights(const TimelineModel *model, int defaultRowHeight,
|
|
|
|
|
int defaultRowOffset)
|
|
|
|
|
{
|
|
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
int row = 0;
|
|
|
|
|
qreal offset = 0;
|
|
|
|
|
for (QSGNode *rowNode = d->expandedRowRoot->firstChild(); rowNode != 0;
|
|
|
|
|
rowNode = rowNode->nextSibling()) {
|
|
|
|
|
qreal rowHeight = model->expandedRowHeight(row++);
|
|
|
|
|
QMatrix4x4 matrix;
|
|
|
|
|
matrix.translate(0, offset, 0);
|
|
|
|
|
matrix.scale(1, rowHeight / defaultRowHeight, 1);
|
|
|
|
|
offset += defaultRowOffset * rowHeight / defaultRowHeight;
|
|
|
|
|
static_cast<QSGTransformNode *>(rowNode)->setMatrix(matrix);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGTransformNode *TimelineRenderState::finalize(QSGNode *oldNode, bool expanded,
|
|
|
|
|
const QMatrix4x4 &transform)
|
|
|
|
|
{
|
|
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
QSGNode *rowNode = expanded ? d->expandedRowRoot : d->collapsedRowRoot;
|
|
|
|
|
QSGNode *overlayNode = expanded ?d->expandedOverlayRoot : d->collapsedOverlayRoot;
|
|
|
|
|
|
|
|
|
|
QSGTransformNode *node = oldNode ? static_cast<QSGTransformNode *>(oldNode) :
|
|
|
|
|
new QSGTransformNode;
|
|
|
|
|
node->setMatrix(transform);
|
|
|
|
|
|
|
|
|
|
if (node->firstChild() != rowNode || node->lastChild() != overlayNode) {
|
|
|
|
|
node->removeAllChildNodes();
|
|
|
|
|
node->appendChildNode(rowNode);
|
|
|
|
|
node->appendChildNode(overlayNode);
|
|
|
|
|
}
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 18:32:43 +01:00
|
|
|
TimelineRenderPass::State *TimelineRenderState::passState(int i)
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
return d->passes[i];
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TimelineRenderPass::State *TimelineRenderState::passState(int i) const
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(const TimelineRenderState);
|
|
|
|
|
return d->passes[i];
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimelineRenderState::setPassState(int i, TimelineRenderPass::State *state)
|
|
|
|
|
{
|
2014-12-09 12:12:57 +01:00
|
|
|
Q_D(TimelineRenderState);
|
|
|
|
|
d->passes[i] = state;
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 11:01:23 +01:00
|
|
|
} // namespace Timeline
|