summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Palettes
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2019-08-19 10:54:45 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2019-08-19 18:45:24 +0300
commit53c5ed746a611befd2932a0434619d4c5a17e126 (patch)
tree1d445a6b3c286bb804d3db8fc917716121905279 /src/Authoring/Qt3DStudio/Palettes
parent1475e5b1e770ee6bfbd2f3e3df68116a0c13578d (diff)
Pivot property graph scaling to the mouse position
- adjust scaling so that its pivoted to the current mouse y position - increase the top margin so that bezier keyframe is not hidden under the row keyframe when the curve is fitted - move the ruler text a bit to the right so it is not hidden under the row keyframe when a ruler's line happen to be under a row's keyframe Change-Id: I099d73ee0b93f6028121c428bcbbc94f6b76e083 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring/Qt3DStudio/Palettes')
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp2
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp23
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h3
3 files changed, 18 insertions, 10 deletions
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
index 10e4ba06..1eba78ac 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
@@ -936,7 +936,7 @@ void TimelineGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
if (item && item->type() == TimelineItem::TypeRowTimeline) {
RowTimeline *rowTimeline = static_cast<RowTimeline *>(item);
if (rowTimeline->propertyGraph())
- rowTimeline->propertyGraph()->adjustScale(wheelEvent->delta() > 0);
+ rowTimeline->propertyGraph()->adjustScale(pos, wheelEvent->delta() > 0);
}
}
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
index b12dbea7..14615598 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
@@ -101,7 +101,7 @@ void RowTimelinePropertyGraph::paintGraphs(QPainter *painter, const QRectF &rect
// draw ruler value text
painter->setPen(QPen(CStudioPreferences::studioColor3(), 1));
qreal val_i = (m_graphY - i) / m_valScale;
- painter->drawText(rect.x() + edgeOffset.x() + 3, i - 2, QString::number(qRound(val_i)));
+ painter->drawText(rect.x() + edgeOffset.x() + 8, i - 2, QString::number(qRound(val_i)));
}
// draw vertical keyframe separator lines
@@ -373,9 +373,6 @@ void RowTimelinePropertyGraph::updateChannelFiltering(const QVector<bool> &activ
// adjust graph scale and y so that all keyframe and control points are visible
void RowTimelinePropertyGraph::fitGraph()
{
- const qreal MARGIN_Y = 10; // margin at top & bottom of graph
- m_graphH = m_rowTimeline->size().height() - MARGIN_Y * 2;
-
// get min/max keyframes values in the active channels
float minVal = FLT_MAX;
float maxVal = -FLT_MAX;
@@ -415,10 +412,13 @@ void RowTimelinePropertyGraph::fitGraph()
adjustColorProperty(maxVal);
adjustColorProperty(minVal);
- m_valScale = m_graphH / (maxVal - minVal);
+ const float marginT = 20.f;
+ const float marginB = 10.f;
+ const float graphH = float(m_rowTimeline->size().height()) - (marginT + marginB);
+ m_valScale = graphH / (maxVal - minVal);
checkValScaleLimits();
- m_graphY = (m_rowTimeline->size().height() + (maxVal + minVal) * m_valScale) / 2;
+ m_graphY = marginT + maxVal * m_valScale;
m_rowTimeline->update();
}
@@ -465,11 +465,20 @@ void RowTimelinePropertyGraph::deselectAllBezierKeyframes()
m_selectedBezierKeyframes.clear();
}
-void RowTimelinePropertyGraph::adjustScale(bool isIncrement)
+void RowTimelinePropertyGraph::adjustScale(const QPointF &scenePos, bool isIncrement)
{
+ QPointF p = m_rowTimeline->mapFromScene(scenePos.x() - RULER_EDGE_OFFSET, scenePos.y());
+
+ float oldScale = m_valScale;
float pitch = m_valScale * .3f;
m_valScale += isIncrement ? pitch : -pitch;
checkValScaleLimits();
+
+ float d1 = m_graphY - p.y(); // dY before scale
+ float d2 = d1 * m_valScale / oldScale; // dY after scale
+
+ m_graphY += d2 - d1;
+
m_rowTimeline->update();
}
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h
index dbb28b16..0607b8a2 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h
@@ -56,7 +56,7 @@ public:
TimelineControlType getClickedBezierControl(const QPointF &pos, bool isHover = false);
void paintGraphs(QPainter *painter, const QRectF &rect);
void updateBezierControlValue(TimelineControlType controlType, const QPointF &scenePos);
- void adjustScale(bool isIncrement);
+ void adjustScale(const QPointF &scenePos, bool isIncrement);
void startPan();
void pan(qreal dy);
void fitGraph();
@@ -82,7 +82,6 @@ private:
float m_valScale = .5f;
qreal m_graphY = 0;
qreal m_graphYPanInit = 0; // value of graph_y when panning starts
- qreal m_graphH = 0;
int m_expandHeight = TimelineConstants::ROW_GRAPH_H; // height when expanded
qt3dsdm::Qt3DSDMKeyframeHandle m_hoveredBezierKeyframe;
QSet<qt3dsdm::Qt3DSDMKeyframeHandle> m_selectedBezierKeyframes;