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 "timelinenotesrenderpass.h"
|
|
|
|
|
#include "timelinerenderstate.h"
|
2014-12-10 12:53:49 +01:00
|
|
|
#include "timelinenotesmodel.h"
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2016-07-28 12:30:32 +02:00
|
|
|
#include <utils/theme/theme.h>
|
|
|
|
|
|
2014-12-09 11:01:23 +01:00
|
|
|
namespace Timeline {
|
2014-11-18 18:32:43 +01:00
|
|
|
|
|
|
|
|
struct Point2DWithDistanceFromTop {
|
|
|
|
|
float x, y, d;
|
|
|
|
|
void set(float nx, float ny, float nd);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NotesMaterial : public QSGMaterial
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QSGMaterialType *type() const;
|
|
|
|
|
QSGMaterialShader *createShader() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct NotesGeometry
|
|
|
|
|
{
|
|
|
|
|
static const int maxNotes;
|
|
|
|
|
static const QSGGeometry::AttributeSet &point2DWithDistanceFromTop();
|
|
|
|
|
|
|
|
|
|
static QSGGeometry *createGeometry(QVector<int> &ids, const TimelineModel *model,
|
|
|
|
|
const TimelineRenderState *parentState, bool collapsed);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const int NotesGeometry::maxNotes = 0xffff / 2;
|
|
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
class TimelineNotesRenderPassState : public TimelineRenderPass::State
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2015-04-14 13:23:37 +02:00
|
|
|
public:
|
2014-11-18 18:32:43 +01:00
|
|
|
TimelineNotesRenderPassState(int expandedRows);
|
2015-04-14 13:23:37 +02:00
|
|
|
~TimelineNotesRenderPassState();
|
|
|
|
|
|
|
|
|
|
QSGNode *expandedRow(int row) const { return m_expandedRows[row]; }
|
|
|
|
|
QSGNode *collapsedOverlay() const { return m_collapsedOverlay; }
|
|
|
|
|
const QVector<QSGNode *> &expandedRows() const { return m_expandedRows; }
|
|
|
|
|
|
|
|
|
|
QSGGeometry *nullGeometry() { return &m_nullGeometry; }
|
|
|
|
|
NotesMaterial *material() { return &m_material; }
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
private:
|
2014-11-18 18:32:43 +01:00
|
|
|
QSGGeometryNode *createNode();
|
|
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
NotesMaterial m_material;
|
|
|
|
|
QSGGeometry m_nullGeometry;
|
2014-12-09 12:44:23 +01:00
|
|
|
QSGGeometryNode *m_collapsedOverlay;
|
|
|
|
|
QVector<QSGNode *> m_expandedRows;
|
2014-11-18 18:32:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const QSGGeometry::AttributeSet &NotesGeometry::point2DWithDistanceFromTop()
|
|
|
|
|
{
|
|
|
|
|
static QSGGeometry::Attribute data[] = {
|
|
|
|
|
QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),
|
|
|
|
|
QSGGeometry::Attribute::create(1, 1, GL_FLOAT),
|
|
|
|
|
};
|
|
|
|
|
static QSGGeometry::AttributeSet attrs = {
|
|
|
|
|
2,
|
|
|
|
|
sizeof(Point2DWithDistanceFromTop),
|
|
|
|
|
data
|
|
|
|
|
};
|
|
|
|
|
return attrs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TimelineNotesRenderPass *TimelineNotesRenderPass::instance()
|
|
|
|
|
{
|
|
|
|
|
static const TimelineNotesRenderPass pass;
|
|
|
|
|
return &pass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimelineNotesRenderPass::TimelineNotesRenderPass()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-09 14:18:05 +01:00
|
|
|
TimelineRenderPass::State *TimelineNotesRenderPass::update(const TimelineAbstractRenderer *renderer,
|
2014-11-18 18:32:43 +01:00
|
|
|
const TimelineRenderState *parentState,
|
|
|
|
|
State *oldState, int firstIndex,
|
|
|
|
|
int lastIndex, bool stateChanged,
|
2018-01-11 13:31:58 +01:00
|
|
|
float spacing) const
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(firstIndex)
|
|
|
|
|
Q_UNUSED(lastIndex)
|
|
|
|
|
Q_UNUSED(spacing)
|
2014-11-18 18:32:43 +01:00
|
|
|
|
2014-12-08 16:14:52 +01:00
|
|
|
const TimelineNotesModel *notes = renderer->notes();
|
2014-11-18 18:32:43 +01:00
|
|
|
const TimelineModel *model = renderer->model();
|
|
|
|
|
|
2014-12-10 14:11:09 +01:00
|
|
|
if (!model || !notes)
|
|
|
|
|
return oldState;
|
|
|
|
|
|
2014-11-18 18:32:43 +01:00
|
|
|
TimelineNotesRenderPassState *state;
|
|
|
|
|
if (oldState == 0) {
|
|
|
|
|
state = new TimelineNotesRenderPassState(model->expandedRowCount());
|
|
|
|
|
} else {
|
|
|
|
|
if (!stateChanged && !renderer->notesDirty())
|
|
|
|
|
return oldState;
|
|
|
|
|
state = static_cast<TimelineNotesRenderPassState *>(oldState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<QVector<int> > expanded(model->expandedRowCount());
|
|
|
|
|
QVector<int> collapsed;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < qMin(notes->count(), NotesGeometry::maxNotes); ++i) {
|
|
|
|
|
if (notes->timelineModel(i) != model->modelId())
|
|
|
|
|
continue;
|
|
|
|
|
int timelineIndex = notes->timelineIndex(i);
|
|
|
|
|
if (model->startTime(timelineIndex) > parentState->end() ||
|
|
|
|
|
model->endTime(timelineIndex) < parentState->start())
|
|
|
|
|
continue;
|
|
|
|
|
expanded[model->expandedRow(timelineIndex)] << timelineIndex;
|
|
|
|
|
collapsed << timelineIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
QSGGeometryNode *collapsedNode = static_cast<QSGGeometryNode *>(state->collapsedOverlay());
|
2014-11-18 18:32:43 +01:00
|
|
|
|
|
|
|
|
if (collapsed.count() > 0) {
|
|
|
|
|
collapsedNode->setGeometry(NotesGeometry::createGeometry(collapsed, model, parentState,
|
|
|
|
|
true));
|
|
|
|
|
collapsedNode->setFlag(QSGGeometryNode::OwnsGeometry, true);
|
|
|
|
|
} else {
|
2015-04-14 13:23:37 +02:00
|
|
|
collapsedNode->setGeometry(state->nullGeometry());
|
2014-11-18 18:32:43 +01:00
|
|
|
collapsedNode->setFlag(QSGGeometryNode::OwnsGeometry, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < model->expandedRowCount(); ++row) {
|
2015-04-14 13:23:37 +02:00
|
|
|
QSGGeometryNode *rowNode = static_cast<QSGGeometryNode *>(state->expandedRow(row));
|
2014-11-18 18:32:43 +01:00
|
|
|
if (expanded[row].isEmpty()) {
|
2015-04-14 13:23:37 +02:00
|
|
|
rowNode->setGeometry(state->nullGeometry());
|
2014-11-18 18:32:43 +01:00
|
|
|
rowNode->setFlag(QSGGeometryNode::OwnsGeometry, false);
|
|
|
|
|
} else {
|
|
|
|
|
rowNode->setGeometry(NotesGeometry::createGeometry(expanded[row], model, parentState,
|
|
|
|
|
false));
|
|
|
|
|
collapsedNode->setFlag(QSGGeometryNode::OwnsGeometry, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimelineNotesRenderPassState::TimelineNotesRenderPassState(int numExpandedRows) :
|
2015-04-14 13:23:37 +02:00
|
|
|
m_nullGeometry(NotesGeometry::point2DWithDistanceFromTop(), 0)
|
2014-11-18 18:32:43 +01:00
|
|
|
{
|
2015-04-14 13:23:37 +02:00
|
|
|
m_material.setFlag(QSGMaterial::Blending, true);
|
2014-12-09 12:44:23 +01:00
|
|
|
m_expandedRows.reserve(numExpandedRows);
|
2014-11-18 18:32:43 +01:00
|
|
|
for (int i = 0; i < numExpandedRows; ++i)
|
2014-12-09 12:44:23 +01:00
|
|
|
m_expandedRows << createNode();
|
|
|
|
|
m_collapsedOverlay = createNode();
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-14 13:23:37 +02:00
|
|
|
TimelineNotesRenderPassState::~TimelineNotesRenderPassState()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_expandedRows);
|
|
|
|
|
delete m_collapsedOverlay;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 18:32:43 +01:00
|
|
|
QSGGeometryNode *TimelineNotesRenderPassState::createNode()
|
|
|
|
|
{
|
|
|
|
|
QSGGeometryNode *node = new QSGGeometryNode;
|
2015-04-14 13:23:37 +02:00
|
|
|
node->setGeometry(&m_nullGeometry);
|
|
|
|
|
node->setMaterial(&m_material);
|
|
|
|
|
node->setFlag(QSGNode::OwnedByParent, false);
|
2014-11-18 18:32:43 +01:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGGeometry *NotesGeometry::createGeometry(QVector<int> &ids, const TimelineModel *model,
|
|
|
|
|
const TimelineRenderState *parentState, bool collapsed)
|
|
|
|
|
{
|
|
|
|
|
float rowHeight = TimelineModel::defaultRowHeight();
|
|
|
|
|
QSGGeometry *geometry = new QSGGeometry(point2DWithDistanceFromTop(),
|
|
|
|
|
ids.count() * 2);
|
2016-12-12 13:00:35 +01:00
|
|
|
Q_ASSERT(geometry->vertexData());
|
2014-11-18 18:32:43 +01:00
|
|
|
geometry->setDrawingMode(GL_LINES);
|
|
|
|
|
geometry->setLineWidth(3);
|
|
|
|
|
Point2DWithDistanceFromTop *v =
|
|
|
|
|
static_cast<Point2DWithDistanceFromTop *>(geometry->vertexData());
|
|
|
|
|
for (int i = 0; i < ids.count(); ++i) {
|
|
|
|
|
int timelineIndex = ids[i];
|
|
|
|
|
float horizontalCenter = ((model->startTime(timelineIndex) +
|
|
|
|
|
model->endTime(timelineIndex)) / (qint64)2 -
|
|
|
|
|
parentState->start()) * parentState->scale();
|
|
|
|
|
float verticalStart = (collapsed ? (model->collapsedRow(timelineIndex) + 0.1) : 0.1) *
|
|
|
|
|
rowHeight;
|
|
|
|
|
float verticalEnd = verticalStart + 0.8 * rowHeight;
|
|
|
|
|
v[i * 2].set(horizontalCenter, verticalStart, 0);
|
|
|
|
|
v[i * 2 + 1].set(horizontalCenter, verticalEnd, 1);
|
|
|
|
|
}
|
|
|
|
|
return geometry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class NotesMaterialShader : public QSGMaterialShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
NotesMaterialShader();
|
|
|
|
|
|
2018-06-22 15:08:09 +02:00
|
|
|
void updateState(const RenderState &state, QSGMaterial *newEffect,
|
|
|
|
|
QSGMaterial *oldEffect) override;
|
|
|
|
|
char const *const *attributeNames() const override;
|
2014-11-18 18:32:43 +01:00
|
|
|
|
|
|
|
|
private:
|
2018-06-22 15:08:09 +02:00
|
|
|
void initialize() override;
|
2014-11-18 18:32:43 +01:00
|
|
|
|
|
|
|
|
int m_matrix_id;
|
|
|
|
|
int m_z_range_id;
|
2016-07-28 12:30:32 +02:00
|
|
|
int m_color_id;
|
2014-11-18 18:32:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NotesMaterialShader::NotesMaterialShader()
|
|
|
|
|
: QSGMaterialShader()
|
|
|
|
|
{
|
2018-05-03 09:50:11 +02:00
|
|
|
setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/tracing/notes.vert"));
|
|
|
|
|
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/tracing/notes.frag"));
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotesMaterialShader::updateState(const RenderState &state, QSGMaterial *, QSGMaterial *)
|
|
|
|
|
{
|
|
|
|
|
if (state.isMatrixDirty()) {
|
|
|
|
|
program()->setUniformValue(m_matrix_id, state.combinedMatrix());
|
|
|
|
|
program()->setUniformValue(m_z_range_id, GLfloat(1.0));
|
2016-08-08 10:23:15 +02:00
|
|
|
const QColor notesColor = Utils::creatorTheme()
|
|
|
|
|
? Utils::creatorTheme()->color(Utils::Theme::Timeline_HighlightColor)
|
|
|
|
|
: QColor(255, 165, 0);
|
|
|
|
|
program()->setUniformValue(m_color_id, notesColor);
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char const *const *NotesMaterialShader::attributeNames() const
|
|
|
|
|
{
|
|
|
|
|
static const char *const attr[] = {"vertexCoord", "distanceFromTop", 0};
|
|
|
|
|
return attr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NotesMaterialShader::initialize()
|
|
|
|
|
{
|
|
|
|
|
m_matrix_id = program()->uniformLocation("matrix");
|
|
|
|
|
m_z_range_id = program()->uniformLocation("_qt_zRange");
|
2016-07-28 12:30:32 +02:00
|
|
|
m_color_id = program()->uniformLocation("notesColor");
|
2014-11-18 18:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGMaterialType *NotesMaterial::type() const
|
|
|
|
|
{
|
|
|
|
|
static QSGMaterialType type;
|
|
|
|
|
return &type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSGMaterialShader *NotesMaterial::createShader() const
|
|
|
|
|
{
|
|
|
|
|
return new NotesMaterialShader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Point2DWithDistanceFromTop::set(float nx, float ny, float nd)
|
|
|
|
|
{
|
|
|
|
|
x = nx; y = ny; d = nd;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-09 11:01:23 +01:00
|
|
|
} // namespace Timeline
|