Commit 73d9982d authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Show keyframe value in tooltip when editing in timeline

Fixes #1032
parent 263d2657
......@@ -924,6 +924,10 @@ QVariant KeyframeModel::getNormalizedValue(double newVal) const
min = ptr->data(m_index, AssetParameterModel::MinRole).toDouble();
max = ptr->data(m_index, AssetParameterModel::MaxRole).toDouble();
}
if (qFuzzyIsNull(min) && qFuzzyIsNull(max)) {
min = 0.;
max = 1.;
}
double factor = ptr->data(m_index, AssetParameterModel::FactorRole).toDouble();
double norm = ptr->data(m_index, AssetParameterModel::DefaultRole).toDouble();
int logRole = ptr->data(m_index, AssetParameterModel::ScaleRole).toInt();
......@@ -1041,6 +1045,33 @@ void KeyframeModel::sendModification()
}
}
QString KeyframeModel::realValue(double normalizedValue) const
{
double value = getNormalizedValue(normalizedValue).toDouble();
if (auto ptr = m_model.lock()) {
int decimals = ptr->data(m_index, AssetParameterModel::DecimalsRole).toInt();
value *= ptr->data(m_index, AssetParameterModel::FactorRole).toDouble();
QString result;
if (decimals == 0) {
if (ptr->getAssetId() == QLatin1String("qtblend")) {
value = qRound(value * 100.);
}
// Fix rounding erros in double > int conversion
if (value > 0.) {
value += 0.001;
} else {
value -= 0.001;
}
result = QString::number(int(value));
} else {
result = QString::number(value, 'f', decimals);
}
result.append(ptr->data(m_index, AssetParameterModel::SuffixRole).toString());
return result;
}
return QString::number(value);
}
void KeyframeModel::refresh()
{
Q_ASSERT(m_index.isValid());
......
......@@ -149,6 +149,7 @@ public:
*/
Q_INVOKABLE bool hasKeyframe(int frame) const;
Q_INVOKABLE bool hasKeyframe(const GenTime &pos) const;
Q_INVOKABLE QString realValue(double normalizedValue) const;
/** @brief Read the value from the model and update itself accordingly */
void refresh();
......
......@@ -379,6 +379,14 @@ KeyframeModel *KeyframeModelList::getKeyModel()
}
if (auto ptr = m_model.lock()) {
for (const auto &param : m_parameters) {
auto tp = ptr->data(param.first, AssetParameterModel::TypeRole).value<ParamType>();
if (tp == ParamType::AnimatedRect) {
// Check if we have an opacity
if (ptr->data(param.first, AssetParameterModel::OpacityRole).toBool() == false) {
// Rect with no opacity, don't show timeline keyframes
continue;
}
}
if (ptr->data(param.first, AssetParameterModel::ShowInTimelineRole) == true) {
m_inTimelineIndex = param.first;
return param.second.get();
......
......@@ -20,7 +20,7 @@
***************************************************************************/
import QtQuick 2.11
import QtQuick.Controls 1.4
import QtQuick.Controls 2.4
import QtQml.Models 2.11
Rectangle
......@@ -98,6 +98,7 @@ Rectangle
id: keyframe
property int frame : model.frame
property int frameType : model.type
property string realValue: model.value
x: (model.frame - inPoint) * timeScale
height: parent.height
property int value: parent.height * model.normalizedValue
......@@ -111,6 +112,9 @@ Rectangle
onValueChanged: {
keyframecanvas.requestPaint()
}
onRealValueChanged: {
kf1MouseArea.movingVal = kfrModel.realValue(model.normalizedValue)
}
width: Math.max(1, timeScale)
color: kfMouseArea.containsMouse ? 'darkred' : 'transparent'
MouseArea {
......@@ -174,6 +178,9 @@ Rectangle
cursorShape: Qt.PointingHandCursor
drag.target: parent
drag.smoothed: false
drag.threshold: 1
property string movingVal: kfrModel.realValue(model.normalizedValue)
property double newVal: NaN
onPressed: {
drag.axis = (mouse.modifiers & Qt.ShiftModifier) ? Drag.YAxis : Drag.XAndYAxis
}
......@@ -183,6 +190,9 @@ Rectangle
keyframeContainer.focus = true
}
onReleased: {
if (isNaN(newVal)) {
return
}
root.autoScrolling = timeline.autoScroll
var newPos = frame == inPoint ? inPoint : Math.round((keyframe.x + parent.x + root.baseUnit / 2) / timeScale) + inPoint
if (newPos === frame && keyframe.value == keyframe.height - parent.y - root.baseUnit / 2) {
......@@ -192,7 +202,6 @@ Rectangle
}
return
}
var newVal = (keyframeContainer.height - (parent.y + mouse.y)) / keyframeContainer.height
if (newVal > 1.5 || newVal < -0.5) {
if (frame != inPoint) {
timeline.removeEffectKeyframe(masterObject.clipId, frame);
......@@ -231,11 +240,15 @@ Rectangle
}
}
keyframecanvas.requestPaint()
newVal = (keyframeContainer.height - (parent.y + mouse.y)) / keyframeContainer.height
movingVal = kfrModel.realValue(Math.min(Math.max(newVal, 0), 1))
}
}
onDoubleClicked: {
timeline.removeEffectKeyframe(masterObject.clipId, frame);
}
ToolTip.visible: (containsMouse || pressed) && movingVal != ""
ToolTip.text: movingVal
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment