summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Palettes
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2019-08-23 12:15:25 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2019-08-27 10:49:26 +0300
commit317766c96985aa2c772536bed3a0058d2a4534e8 (patch)
tree0b2c34076298f4ae6b1cc1bdec741eb7fa562cba /src/Authoring/Qt3DStudio/Palettes
parent8e9cbd3e2384653ac41404e035b1422bfc8f83a0 (diff)
Unify Editor timeline unit to millisecond
The studio has mixed timing units (seconds and milliseconds). This commit unifies the timings to milliseconds. The values are however kept saved in the UIP file in seconds for backward compatibility and also cause it is more compact (ex: 1 vs 1000). Change-Id: I906214dfbb4e666ee099b4055ef4c9aa98e91745 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Authoring/Qt3DStudio/Palettes')
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h18
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp6
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp36
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h2
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp9
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp6
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp43
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h2
8 files changed, 47 insertions, 75 deletions
diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h
index f6330cc0..44b585b1 100644
--- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h
+++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/PasteKeyframesCommandHelper.h
@@ -48,7 +48,7 @@ public:
~CPasteKeyframeCommandHelper() {}
// inTime should be relative to the earliest keyframe time in this list
- void AddKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, float inKeyframeTime,
+ void AddKeyframeData(qt3dsdm::Qt3DSDMPropertyHandle inProperty, long inKeyframeTime,
qt3dsdm::SGetOrSetKeyframeInfo *inInfos, size_t inInfoCount)
{
m_CopiedKeyframeList.push_back(CCmdDataModelInsertKeyframe::STimeKeyframeData(
@@ -66,23 +66,23 @@ public:
// but that is not an issue in the new data model.
//
// 2. The first pasted keyframe is at current view time and the rest are offset accordingly.
- CCmdDataModelInsertKeyframe *GetCommand(CDoc *inDoc, long inTimeOffsetInMilliseconds,
- qt3dsdm::Qt3DSDMInstanceHandle inTargetInstance)
+ CCmdDataModelInsertKeyframe *GetCommand(CDoc *doc, long timeOffset,
+ qt3dsdm::Qt3DSDMInstanceHandle targetInstance)
{
using namespace qt3dsdm;
CCmdDataModelInsertKeyframe *insertKeyframesCmd = nullptr;
- qt3dsdm::IPropertySystem *propSys = inDoc->GetStudioSystem()->GetPropertySystem();
- CClientDataModelBridge *bridge = inDoc->GetStudioSystem()->GetClientDataModelBridge();
+ qt3dsdm::IPropertySystem *propSys = doc->GetStudioSystem()->GetPropertySystem();
+ CClientDataModelBridge *bridge = doc->GetStudioSystem()->GetClientDataModelBridge();
for (auto &kfData : m_CopiedKeyframeList) {
// check property exists on target
- if (bridge->hasAggregateInstanceProperty(inTargetInstance, kfData.m_Property)) {
+ if (bridge->hasAggregateInstanceProperty(targetInstance, kfData.m_Property)) {
if (!insertKeyframesCmd)
- insertKeyframesCmd = new CCmdDataModelInsertKeyframe(inDoc, inTargetInstance);
+ insertKeyframesCmd = new CCmdDataModelInsertKeyframe(doc, targetInstance);
- // Offset keyframe time by current view time (time in seconds)
- float time = kfData.m_KeyframeTime + inTimeOffsetInMilliseconds / 1000.f;
+ // Offset keyframe time by current view time
+ long time = kfData.m_KeyframeTime + timeOffset;
insertKeyframesCmd->AddKeyframeData(kfData.m_Property, time, kfData.m_Infos,
kfData.m_ValidInfoCount);
}
diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp
index bc9cefe7..a5c49bfa 100644
--- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemProperty.cpp
@@ -285,10 +285,8 @@ float Qt3DSDMTimelineItemProperty::GetChannelValueAtTime(size_t chIndex, long ti
}
IAnimationCore *animCore = m_TransMgr->GetStudioSystem()->GetAnimationCore();
- if (!m_AnimationHandles.empty() && chIndex < m_AnimationHandles.size()) {
- return animCore->EvaluateAnimation(m_AnimationHandles[chIndex],
- Qt3DSDMTimelineKeyframe::GetTimeInSecs(time));
- }
+ if (!m_AnimationHandles.empty() && chIndex < m_AnimationHandles.size())
+ return animCore->EvaluateAnimation(m_AnimationHandles[chIndex], time);
return 0.f;
}
diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp
index d447307c..acfbf4ac 100644
--- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.cpp
@@ -56,58 +56,32 @@ bool Qt3DSDMTimelineKeyframe::IsSelected() const
return m_Selected;
}
-float my_roundf(float r)
-{
- return (r > 0.0f) ? floorf(r + 0.5f) : ceilf(r - 0.5f);
-}
-
long Qt3DSDMTimelineKeyframe::GetTime() const
{
if (!m_KeyframeHandles.empty()) {
IAnimationCore *animaCore = m_Doc->GetStudioSystem()->GetAnimationCore();
Qt3DSDMKeyframeHandle kfHandle = *m_KeyframeHandles.begin();
- if (animaCore->KeyframeValid(kfHandle)) {
- float theTimeinSecs = getKeyframeTime(animaCore->GetKeyframeData(kfHandle));
- // We always convert back and forth between between long and float.
- // This causes especially issues when we do comparisons
- return (long)my_roundf(theTimeinSecs * 1000);
- }
+ if (animaCore->KeyframeValid(kfHandle))
+ return getKeyframeTime(animaCore->GetKeyframeData(kfHandle));
}
- return -1; // keyframe was deleted, and data cannot be retrieved.
-}
-float Qt3DSDMTimelineKeyframe::GetTimeInSecs(long inTime)
-{
- float theTimeinSecs = static_cast<float>(inTime) / 1000.f;
- // round off to 4 decimal place to workaround precision issues
- // TODO: fix this, either all talk float OR long. choose one.
- theTimeinSecs = (float)(((theTimeinSecs + 0.00005) * 10000.0) / 10000.0f);
- return theTimeinSecs;
+ return -1; // keyframe was deleted, and data cannot be retrieved.
}
void Qt3DSDMTimelineKeyframe::SetTime(const long inNewTime)
{
- float theTimeinSecs = GetTimeInSecs(inNewTime);
CCmd *theCmd = nullptr;
if (m_KeyframeHandles.size() == 1) {
- theCmd = new CCmdDataModelSetKeyframeTime(m_Doc, m_KeyframeHandles.front(), theTimeinSecs);
+ theCmd = new CCmdDataModelSetKeyframeTime(m_Doc, m_KeyframeHandles.front(), inNewTime);
} else { // more than 1 channel
CCmdBatch *theBatch = new CCmdBatch(m_Doc);
TKeyframeHandleList::iterator theIter = m_KeyframeHandles.begin();
for (; theIter != m_KeyframeHandles.end(); ++theIter)
- theBatch->AddCommand(new CCmdDataModelSetKeyframeTime(m_Doc, *theIter, theTimeinSecs));
+ theBatch->AddCommand(new CCmdDataModelSetKeyframeTime(m_Doc, *theIter, inNewTime));
theCmd = theBatch;
}
if (theCmd)
m_Doc->GetCore()->ExecuteCommand(theCmd);
-
-#ifdef _DEBUG
- // we have a precision issue from converting from long to float..
- IAnimationCore *theAnimationCore = m_Doc->GetStudioSystem()->GetAnimationCore();
- long theTest = static_cast<long>(
- getKeyframeTime(theAnimationCore->GetKeyframeData(*m_KeyframeHandles.begin())) * 1000);
- Q_ASSERT(inNewTime == theTest);
-#endif
}
inline Qt3DSDMAnimationHandle GetAnimationHandle(qt3dsdm::IAnimationCore *inAnimationCore,
diff --git a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h
index 63944764..3b73a3e7 100644
--- a/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h
+++ b/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/Qt3DSDMTimelineKeyframe.h
@@ -63,8 +63,6 @@ public:
void UpdateKeyframesTime(COffsetKeyframesCommandHelper *inCommandHelper, long inTime);
void GetKeyframeHandles(TKeyframeHandleList &outList) const;
- static float GetTimeInSecs(long inTime);
-
private:
TKeyframeHandleList m_KeyframeHandles; // channels handles of the animated property
CDoc *m_Doc = nullptr;
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp
index dcb1c5eb..4da0d376 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/KeyframeManager.cpp
@@ -334,7 +334,7 @@ void KeyframeManager::copySelectedKeyframes()
break;
}
- float dt = Qt3DSDMTimelineKeyframe::GetTimeInSecs(kf->GetTime() - minTime);
+ long dt = kf->GetTime() - minTime;
qt3dsdm::Qt3DSDMAnimationHandle animation
= animationCore->GetAnimationForKeyframe(theKeyframeHandles[0]);
m_pasteKeyframeCommandHelper->AddKeyframeData(
@@ -361,10 +361,9 @@ void KeyframeManager::pasteKeyframes()
if (m_pasteKeyframeCommandHelper && m_pasteKeyframeCommandHelper->HasCopiedKeyframes()) {
qt3dsdm::Qt3DSDMInstanceHandle theSelectedInstance = theDoc->GetSelectedInstance();
if (theSelectedInstance.Valid()) {
- long theCurrentViewTimeInMilliseconds = theDoc->GetCurrentViewTime();
- CCmdDataModelInsertKeyframe *theInsertKeyframesCommand =
- m_pasteKeyframeCommandHelper->GetCommand(theDoc, theCurrentViewTimeInMilliseconds,
- theSelectedInstance);
+ CCmdDataModelInsertKeyframe *theInsertKeyframesCommand
+ = m_pasteKeyframeCommandHelper->GetCommand(theDoc, theDoc->GetCurrentViewTime(),
+ theSelectedInstance);
if (theInsertKeyframesCommand)
g_StudioApp.GetCore()->ExecuteCommand(theInsertKeyframesCommand);
}
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp
index 8080f004..0078bc15 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp
@@ -270,11 +270,11 @@ void RowTimelineContextMenu::onAnimTypeChange(QAction *action)
QVector<SBezierKeyframe> keyframes;
for (Qt3DSDMKeyframeHandle kfHandle : keyframeHandles) {
TKeyframe kfData = animCore->GetKeyframeData(kfHandle);
- float kfTime = getKeyframeTime(kfData);
+ long kfTime = getKeyframeTime(kfData);
float kfValue = getKeyframeValue(kfData);
keyframes.append(SBezierKeyframe(kfTime, kfValue,
- kfTime - .5f, kfValue,
- kfTime + .5f, kfValue));
+ kfTime - 500, kfValue,
+ kfTime + 500, kfValue));
}
long numFloatsPerKeyframe = sizeof(SBezierKeyframe) / sizeof(float);
long numValues = long(keyframeHandles.size()) * numFloatsPerKeyframe;
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
index cdd38744..fbc92377 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
@@ -266,11 +266,11 @@ TimelineControlType RowTimelinePropertyGraph::getClickedBezierControl(const QPoi
QPointF RowTimelinePropertyGraph::getBezierControlPosition(const SBezierKeyframe &kf,
BezierControlType type) const
{
- float time = 0; // seconds
+ long time = 0;
float value = 0;
if (type == BezierControlType::None) {
- time = kf.m_KeyframeSeconds;
- value = kf.m_KeyframeValue;
+ time = kf.m_time;
+ value = kf.m_value;
} else if (type == BezierControlType::In) {
time = kf.m_InTangentTime;
value = kf.m_InTangentValue;
@@ -282,12 +282,11 @@ QPointF RowTimelinePropertyGraph::getBezierControlPosition(const SBezierKeyframe
return getKeyframePosition(time, value);
}
-// time is in seconds
-QPointF RowTimelinePropertyGraph::getKeyframePosition(float time, float value) const
+QPointF RowTimelinePropertyGraph::getKeyframePosition(long time, float value) const
{
adjustColorProperty(value);
- return QPointF(m_rowTimeline->rowTree()->m_scene->ruler()->timeToDistance(time * 1000),
+ return QPointF(m_rowTimeline->rowTree()->m_scene->ruler()->timeToDistance(time),
m_graphY - value * m_valScale);
}
@@ -304,7 +303,7 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont
QPointF p = m_rowTimeline->mapFromScene(scenePos.x() - RULER_EDGE_OFFSET, scenePos.y());
// time and value at current mouse position
- float time = m_rowTimeline->rowTree()->m_scene->ruler()->distanceToTime(p.x()) / 1000.f; // secs
+ long time = m_rowTimeline->rowTree()->m_scene->ruler()->distanceToTime(p.x());
float value = (m_graphY - p.y()) / m_valScale;
adjustColorProperty(value, false);
@@ -312,9 +311,9 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont
bool isBezierIn = controlType == TimelineControlType::BezierInHandle;
// prevent handles from moving to the other side of the keyframe
- if ((isBezierIn && time > kf.m_KeyframeSeconds)
- || (!isBezierIn && time < kf.m_KeyframeSeconds)) {
- time = kf.m_KeyframeSeconds;
+ if ((isBezierIn && time > kf.m_time)
+ || (!isBezierIn && time < kf.m_time)) {
+ time = kf.m_time;
}
// prevent handles from going beyond prev. and next keyframes
@@ -323,11 +322,14 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont
m_animCore->GetKeyframes(anim, keyframeHandles);
for (size_t i = 0; i < keyframeHandles.size(); ++i) {
if (keyframeHandles[i] == m_currKeyframeData.first) {
- float currKfTime = getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i]));
- float prevKfTime = i > 0
- ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i - 1])) : -FLT_MAX;
- float nextKfTime = i < keyframeHandles.size() - 1
- ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i + 1])) : FLT_MAX;
+ long currKfTime = getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i]));
+ long prevKfTime = i > 0
+ ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i - 1]))
+ : LONG_MIN / 2;
+ long nextKfTime = i < keyframeHandles.size() - 1
+ ? getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i + 1]))
+ : LONG_MAX / 2;
+
if (isBezierIn) {
if (time < prevKfTime)
time = prevKfTime;
@@ -343,17 +345,17 @@ void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType cont
}
}
- float &currHandleTime = isBezierIn ? kf.m_InTangentTime : kf.m_OutTangentTime;
+ long &currHandleTime = isBezierIn ? kf.m_InTangentTime : kf.m_OutTangentTime;
float &currHandleValue = isBezierIn ? kf.m_InTangentValue : kf.m_OutTangentValue;
- float &otherHandleTime = isBezierIn ? kf.m_OutTangentTime : kf.m_InTangentTime;
+ long &otherHandleTime = isBezierIn ? kf.m_OutTangentTime : kf.m_InTangentTime;
float &otherHandleValue = isBezierIn ? kf.m_OutTangentValue : kf.m_InTangentValue;
currHandleTime = time;
currHandleValue = value;
if (!CHotKeys::isCtrlDown()) {
- otherHandleTime = kf.m_KeyframeSeconds + (kf.m_KeyframeSeconds - time);
- otherHandleValue = kf.m_KeyframeValue + (kf.m_KeyframeValue - currHandleValue);
+ otherHandleTime = kf.m_time + (kf.m_time - time);
+ otherHandleValue = kf.m_value + (kf.m_value - currHandleValue);
}
m_animCore->SetKeyframeData(m_currKeyframeData.first, kf);
@@ -394,7 +396,8 @@ void RowTimelinePropertyGraph::fitGraph()
// for bezier keyframes compare tangents in/out also
if (keyframeData.getType() == qt3dsdm::EAnimationTypeBezier) {
- float timeIn, valueIn, timeOut, valueOut;
+ long timeIn, timeOut;
+ float valueIn, valueOut;
getBezierValues(keyframeData, timeIn, valueIn, timeOut, valueOut);
if (!m_animCore->IsFirstKeyframe(kfHandle)) { // check tangent-in value
diff --git a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h
index 0607b8a2..b3ec82b1 100644
--- a/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h
+++ b/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.h
@@ -71,7 +71,7 @@ private:
QPointF getBezierControlPosition(const qt3dsdm::SBezierKeyframe &kf,
BezierControlType type = BezierControlType::None) const;
- QPointF getKeyframePosition(float time, float value) const;
+ QPointF getKeyframePosition(long time, float value) const;
void checkValScaleLimits();
void adjustColorProperty(float &val, bool scaleUp = true) const;