2014-11-18 18:32:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-11-18 18:32:43 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:58:39 +01:00
|
|
|
** 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.
|
2014-11-18 18:32:43 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** 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.
|
2014-11-18 18:32:43 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "timelineselectionrenderpass.h"
|
2015-09-01 17:09:36 +02:00
|
|
|
#include "timelineitemsrenderpass.h"
|
2014-12-12 12:26:14 +01:00
|
|
|
#include <QtMath>
|
2014-11-18 18:32:43 +01:00
|
|
|
#include <QSGSimpleRectNode>
|
|
|
|
|
|
2014-12-09 11:01:23 +01:00
|
|
|
namespace Timeline {
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2015-09-01 17:09:36 +02:00
|
|
|
QSGGeometryNode *createSelectionNode(QSGMaterial *material)
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2015-09-01 17:09:36 +02:00
|
|
|
QSGGeometryNode *selectionNode = new QSGGeometryNode;
|
|
|
|
|
selectionNode->setMaterial(material);
|
|
|
|
|
selectionNode->setFlag(QSGNode::OwnsMaterial, false);
|
|
|
|
|
QSGGeometry *geometry = new QSGGeometry(OpaqueColoredPoint2DWithSize::attributes(), 4);
|
2016-12-12 13:00:35 +01:00
|
|
|
Q_ASSERT(geometry->vertexData());
|
2015-09-01 17:09:36 +02:00
|
|
|
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
|
|
|
|
|
OpaqueColoredPoint2DWithSize *v = OpaqueColoredPoint2DWithSize::fromVertexData(geometry);
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
2016-05-06 16:58:22 +02:00
|
|
|
v[i].set(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
2015-09-01 17:09:36 +02:00
|
|
|
selectionNode->setGeometry(geometry);
|
|
|
|
|
selectionNode->setFlag(QSGNode::OwnsGeometry, true);
|
2015-04-14 13:23:37 +02:00
|
|
|
selectionNode->setFlag(QSGNode::OwnedByParent, false);
|
2014-11-18 18:32:43 +01:00
|
|
|
return selectionNode;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
class TimelineSelectionRenderPassState : public TimelineRenderPass::State {
|
|
|
|
|
public:
|
|
|
|
|
TimelineSelectionRenderPassState();
|
|
|
|
|
~TimelineSelectionRenderPassState();
|
2014-12-09 12:44:23 +01:00
|
|
|
|
2018-01-23 18:04:05 +01:00
|
|
|
QSGNode *expandedOverlay() const override { return m_expandedOverlay; }
|
|
|
|
|
QSGNode *collapsedOverlay() const override { return m_collapsedOverlay; }
|
2015-09-01 17:09:36 +02:00
|
|
|
TimelineItemsMaterial *material() { return &m_material; }
|
|
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
private:
|
2015-09-01 17:09:36 +02:00
|
|
|
QSGNode *m_expandedOverlay;
|
|
|
|
|
QSGNode *m_collapsedOverlay;
|
|
|
|
|
TimelineItemsMaterial m_material;
|
2014-12-09 12:44:23 +01:00
|
|
|
};
|
|
|
|
|
|
2014-12-09 14:18:05 +01:00
|
|
|
TimelineRenderPass::State *TimelineSelectionRenderPass::update(
|
|
|
|
|
const TimelineAbstractRenderer *renderer, const TimelineRenderState *parentState,
|
2018-01-11 13:31:58 +01:00
|
|
|
State *oldState, int firstIndex, int lastIndex, bool stateChanged, float spacing) const
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(stateChanged)
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2014-12-10 14:11:09 +01:00
|
|
|
const TimelineModel *model = renderer->model();
|
2015-04-16 16:20:48 +02:00
|
|
|
if (!model || model->isEmpty())
|
2014-12-10 14:11:09 +01:00
|
|
|
return oldState;
|
|
|
|
|
|
2014-12-09 12:44:23 +01:00
|
|
|
TimelineSelectionRenderPassState *state;
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
if (oldState == 0)
|
2014-12-09 12:44:23 +01:00
|
|
|
state = new TimelineSelectionRenderPassState;
|
2015-04-14 13:23:37 +02:00
|
|
|
else
|
2014-12-09 12:44:23 +01:00
|
|
|
state = static_cast<TimelineSelectionRenderPassState *>(oldState);
|
2014-11-18 18:32:43 +01:00
|
|
|
|
|
|
|
|
int selectedItem = renderer->selectedItem();
|
2015-09-01 17:09:36 +02:00
|
|
|
QSGGeometryNode *node = static_cast<QSGGeometryNode *>(model->expanded() ?
|
|
|
|
|
state->expandedOverlay() :
|
|
|
|
|
state->collapsedOverlay());
|
|
|
|
|
|
2014-11-18 18:32:43 +01:00
|
|
|
if (selectedItem != -1 && selectedItem >= firstIndex && selectedItem < lastIndex) {
|
|
|
|
|
qreal top = 0;
|
|
|
|
|
qreal height = 0;
|
|
|
|
|
if (model->expanded()) {
|
|
|
|
|
int row = model->expandedRow(selectedItem);
|
|
|
|
|
int rowHeight = model->expandedRowHeight(row);
|
|
|
|
|
height = rowHeight * model->relativeHeight(selectedItem);
|
2015-09-08 12:35:18 +02:00
|
|
|
top = (model->expandedRowOffset(row) + rowHeight) - height;
|
2014-11-18 18:32:43 +01:00
|
|
|
} else {
|
|
|
|
|
int row = model->collapsedRow(selectedItem);
|
|
|
|
|
height = TimelineModel::defaultRowHeight() * model->relativeHeight(selectedItem);
|
|
|
|
|
top = TimelineModel::defaultRowHeight() * (row + 1) - height;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 11:37:39 +01:00
|
|
|
qint64 startTime = qBound(parentState->start(), model->startTime(selectedItem),
|
|
|
|
|
parentState->end());
|
|
|
|
|
qint64 endTime = qBound(parentState->start(), model->endTime(selectedItem),
|
|
|
|
|
parentState->end());
|
|
|
|
|
qint64 left = startTime - parentState->start();
|
|
|
|
|
qint64 width = endTime - startTime;
|
2014-11-18 18:32:43 +01:00
|
|
|
|
|
|
|
|
// Construct from upper left and lower right for better precision. When constructing from
|
|
|
|
|
// left and width the error on the left border is inherited by the right border. Like this
|
|
|
|
|
// they're independent.
|
|
|
|
|
|
2015-09-08 12:35:18 +02:00
|
|
|
QRectF position(left * parentState->scale(), top, width * parentState->scale(), height);
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2015-09-01 17:09:36 +02:00
|
|
|
QColor itemColor = model->color(selectedItem);
|
|
|
|
|
uchar red = itemColor.red();
|
|
|
|
|
uchar green = itemColor.green();
|
|
|
|
|
uchar blue = itemColor.blue();
|
|
|
|
|
int selectionId = model->selectionId(selectedItem);
|
|
|
|
|
|
|
|
|
|
OpaqueColoredPoint2DWithSize *v = OpaqueColoredPoint2DWithSize::fromVertexData(
|
|
|
|
|
node->geometry());
|
|
|
|
|
v[0].set(position.left(), position.bottom(), -position.width(), -position.height(),
|
2016-05-06 16:58:22 +02:00
|
|
|
selectionId, red, green, blue, 255);
|
2015-09-01 17:09:36 +02:00
|
|
|
v[1].set(position.right(), position.bottom(), position.width(), -position.height(),
|
2016-05-06 16:58:22 +02:00
|
|
|
selectionId, red, green, blue, 255);
|
2015-09-01 17:09:36 +02:00
|
|
|
v[2].set(position.left(), position.top(), -position.width(), position.height(),
|
2016-05-06 16:58:22 +02:00
|
|
|
selectionId, red, green, blue, 255);
|
2015-09-01 17:09:36 +02:00
|
|
|
v[3].set(position.right(), position.top(), position.width(), position.height(),
|
2016-05-06 16:58:22 +02:00
|
|
|
selectionId, red, green, blue, 255);
|
2015-09-01 17:09:36 +02:00
|
|
|
state->material()->setSelectionColor(renderer->selectionLocked() ? QColor(96,0,255) :
|
|
|
|
|
Qt::blue);
|
|
|
|
|
state->material()->setSelectedItem(selectionId);
|
|
|
|
|
state->material()->setScale(QVector2D(spacing / parentState->scale(), 1));
|
|
|
|
|
node->markDirty(QSGNode::DirtyMaterial | QSGNode::DirtyGeometry);
|
2014-11-18 18:32:43 +01:00
|
|
|
} else {
|
2015-09-01 17:09:36 +02:00
|
|
|
OpaqueColoredPoint2DWithSize *v = OpaqueColoredPoint2DWithSize::fromVertexData(
|
|
|
|
|
node->geometry());
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
2016-05-06 16:58:22 +02:00
|
|
|
v[i].set(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
2015-09-01 17:09:36 +02:00
|
|
|
node->markDirty(QSGNode::DirtyGeometry);
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TimelineSelectionRenderPass *TimelineSelectionRenderPass::instance()
|
|
|
|
|
{
|
|
|
|
|
static const TimelineSelectionRenderPass pass;
|
|
|
|
|
return &pass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimelineSelectionRenderPass::TimelineSelectionRenderPass()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
TimelineSelectionRenderPassState::TimelineSelectionRenderPassState() :
|
2015-09-01 17:09:36 +02:00
|
|
|
m_expandedOverlay(0), m_collapsedOverlay(0)
|
2015-04-14 13:23:37 +02:00
|
|
|
{
|
2015-09-01 17:09:36 +02:00
|
|
|
m_expandedOverlay = createSelectionNode(&m_material);
|
|
|
|
|
m_collapsedOverlay = createSelectionNode(&m_material);
|
2015-04-14 13:23:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimelineSelectionRenderPassState::~TimelineSelectionRenderPassState()
|
|
|
|
|
{
|
|
|
|
|
delete m_collapsedOverlay;
|
|
|
|
|
delete m_expandedOverlay;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-09 11:01:23 +01:00
|
|
|
} // namespace Timeline
|