summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Palettes/TimelineGraphicsView/ui/RowTimelinePropertyGraph.cpp
blob: 4c8e075220343a2f8d1f416408f70452e27ce68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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
** 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.
**
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "RowTimelinePropertyGraph.h"
#include "RowTimeline.h"
#include "RowTree.h"
#include "StudioApp.h"
#include "Core.h"
#include "Doc.h"
#include "IDocumentEditor.h"
#include "Qt3DSDMAnimation.h"
#include "Keyframe.h"
#include "Ruler.h"
#include "TimelineGraphicsScene.h"
#include "StudioPreferences.h"
#include "HotKeys.h"
#include "Bindings/ITimelineItemProperty.h"

using namespace qt3dsdm;
using namespace TimelineConstants;

RowTimelinePropertyGraph::RowTimelinePropertyGraph(QObject *parent)
    : QObject(parent)
    , m_rowTimeline(static_cast<RowTimeline *>(parent))
    , m_animCore(g_StudioApp.GetCore()->GetDoc()->GetAnimationCore())
    , m_UpdatableEditor(*g_StudioApp.GetCore()->GetDoc())
{
    m_fitCurveTimer.setInterval(10);

    // smooth animation for when curve height change
    connect(&m_fitCurveTimer, &QTimer::timeout, [this]() {
        fitGraph();
        if (m_rowTimeline->size().height() == m_expandHeight)
            m_fitCurveTimer.stop();
    });
}

void RowTimelinePropertyGraph::paintGraphs(QPainter *painter, const QRectF &rect)
{
    m_propBinding = m_rowTimeline->rowTree()->propBinding();

    if (rect.height() < ROW_H) // rect height = row height - 1
        return;

    painter->setRenderHint(QPainter::Antialiasing);
    painter->setClipRect(rect);

    static const QPointF edgeOffset(RULER_EDGE_OFFSET, 0);

    // draw graph baseline (graph_Y)
    painter->setPen(QPen(CStudioPreferences::studioColor3()));
    painter->drawLine(edgeOffset.x(), m_graphY, rect.right(), m_graphY);

    // draw value ruler
    static const int STEP_MIN = 20;
    static const int STEP_MAX = 40;
    static const QVector<qreal> RULER_VALS {1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000};

    int rulerValIdx = 5; // start at val 100
    qreal step = RULER_VALS[rulerValIdx] * m_valScale;

    while (step < STEP_MIN && rulerValIdx < RULER_VALS.size() - 1)
        step = RULER_VALS[++rulerValIdx] * m_valScale;
    while (step > STEP_MAX && rulerValIdx > 0)
        step = RULER_VALS[--rulerValIdx] * m_valScale;

    qreal dy = rect.bottom() - m_graphY;
    qreal d_start = dy > 0 ? std::fmod(dy, step) : step - std::fmod(-dy, step); // start delta
    qreal start_y = rect.bottom() - d_start;
    painter->setFont(QFont(CStudioPreferences::fontFaceName(), 7));
    for (qreal i = start_y; i > rect.y(); i -= step) {
        // draw ruler line
        painter->setPen(QPen(CStudioPreferences::studioColor2(), 1));
        painter->drawLine(rect.x(), rect.y() + i, rect.right(), rect.y() + i);

        // draw ruler value text
        painter->setPen(QPen(CStudioPreferences::studioColor3(), 1));
        qreal val_i = (m_graphY - i) / m_valScale;
        painter->drawText(rect.x() + edgeOffset.x() + 8, i - 2, QString::number(qRound(val_i)));
    }

    // draw vertical keyframe separator lines
    painter->setPen(QPen(CStudioPreferences::studioColor2(), 1));
    Qt3DSDMTimelineKeyframe::TKeyframeHandleList keyframeHandles;
    m_animCore->GetKeyframes(m_activeChannels[0], keyframeHandles);
    for (size_t i = 0; i < keyframeHandles.size(); ++i) {
        TKeyframe kf = m_animCore->GetKeyframeData(keyframeHandles[i]);
        QPointF centerPos = getKeyframePosition(getKeyframeTime(kf), getKeyframeValue(kf))
                            + edgeOffset;
        painter->drawLine(centerPos.x(), rect.y(), centerPos.x(), rect.height());
    }

    // draw channel curves
    painter->setPen(CStudioPreferences::studioColor3()); // default to locked color
    for (int i = 0; i < m_activeChannels.size(); ++i) {
        QPainterPath path;
        int start_j = qMax(rect.x(), edgeOffset.x());
        for (int j = start_j; j < rect.right(); j += 5) { // 5 = sampling step in pixels
            long time = m_rowTimeline->rowTree()->m_scene->ruler()
                                                         ->distanceToTime(j - edgeOffset.x());
            float value = m_propBinding->GetChannelValueAtTime(m_activeChannelsIndex[i], time);
            adjustColorProperty(value);

            qreal yPos = m_graphY - value * m_valScale;

            if (j == start_j)
                path.moveTo(j, yPos);
            else
                path.lineTo(j, yPos);
        }

        static const QColor chColors[4] {
            CStudioPreferences::xAxisColor(),
            CStudioPreferences::yAxisColor(),
            CStudioPreferences::zAxisColor(),
            CStudioPreferences::wAxisColor()
        };

        if (!m_rowTimeline->rowTree()->locked())
            painter->setPen(chColors[m_activeChannelsIndex[i]]);
        painter->drawPath(path);
    }

    // draw bezier keyframes and their control points
    if (m_rowTimeline->rowTree()->propBinding()->animationType() == EAnimationTypeBezier) {
        for (size_t i = 0; i < m_activeChannels.size(); ++i) {
            // draw bezier control points
            static const QPixmap pixBezierHandle("://images/breadcrumb_component_button.png");

            Qt3DSDMTimelineKeyframe::TKeyframeHandleList keyframeHandles;
            m_animCore->GetKeyframes(m_activeChannels[i], keyframeHandles);

            for (auto &kfHandle : keyframeHandles) {
                SBezierKeyframe kf = get<SBezierKeyframe>(m_animCore->GetKeyframeData(kfHandle));

                QPointF centerPos = getBezierControlPosition(kf) + edgeOffset;
                const QPointF PIX_HALF_W = QPointF(8.0, 8.0);

                bool kfSelected = m_selectedBezierKeyframes.contains(kfHandle)
                                  && !m_rowTimeline->rowTree()->locked();
                if (kfSelected) {
                    // draw tangent-in part
                    painter->setPen(CStudioPreferences::bezierControlColor());
                    if (kfHandle != *keyframeHandles.begin()) {
                        QPointF cInPos = getBezierControlPosition(kf, BezierControlType::In)
                                         + edgeOffset;
                        painter->drawLine(cInPos, centerPos);
                        painter->drawPixmap(cInPos - PIX_HALF_W, pixBezierHandle);
                    }

                    // draw tangent-out part
                    if (kfHandle != *(keyframeHandles.end() - 1)) {
                        QPointF cOutPos = getBezierControlPosition(kf, BezierControlType::Out)
                                          + edgeOffset;
                        painter->drawLine(cOutPos, centerPos);
                        painter->drawPixmap(cOutPos - PIX_HALF_W, pixBezierHandle);
                    }
                } else if (kfHandle == m_hoveredBezierKeyframe) {
                    // a bezier keyframe hovered
                    painter->setPen(QPen(CStudioPreferences::bezierControlColor()));
                    painter->drawRect(centerPos.x() - 4, centerPos.y() - 4, 8, 8);
                }

                // draw center point
                painter->setPen(QPen(m_rowTimeline->rowTree()->locked()
                                     ? CStudioPreferences::studioColor3()
                                     : CStudioPreferences::bezierControlColor(), kfSelected
                                                                                    ? 6 : 3));
                painter->drawPoint(centerPos);
            }
        }
    }
}

/**
 * This method is called when the user mouse-presses the property graph. If the press is on a
 * bezier keyframe handle, it returns the handle type and saves the list of keyframe channels
 * handles to be precessed while the user drags the handle (in updateBezierControlValue())
 *
 * @param pos press position in local coordinate system
 * @param isHover when true this is a hover, else a click
 * @return the pressed handle type, or None if no handle is pressed
 */
TimelineControlType RowTimelinePropertyGraph::getClickedBezierControl(const QPointF &pos,
                                                                      bool isHover)
{
    if (m_rowTimeline->rowTree()->propBinding()->animationType() != EAnimationTypeBezier)
        return TimelineControlType::None;

    bool aKeyframeWasHovered = m_hoveredBezierKeyframe.Valid();

    // reset data
    m_hoveredBezierKeyframe = 0;
    m_pressedKeyframeHandle = 0;

    if (aKeyframeWasHovered)
        m_rowTimeline->update();

    for (int i = 0; i < m_activeChannels.size(); ++i) {
        Qt3DSDMTimelineKeyframe::TKeyframeHandleList keyframeHandles;
        m_animCore->GetKeyframes(m_activeChannels[i], keyframeHandles);
        const double CONTROL_RADIUS = 8;
        for (auto kfHandle : keyframeHandles) {
            SBezierKeyframe kf = get<SBezierKeyframe>(m_animCore->GetKeyframeData(kfHandle));

            QPointF kfPos = getBezierControlPosition(kf);
            if (QLineF(kfPos, pos).length() < CONTROL_RADIUS) { // over a bezier keyframe
                m_pressedKeyframeHandle = kfHandle;
                if (isHover) {
                    m_hoveredBezierKeyframe = kfHandle;
                } else {
                    if (CHotKeys::isCtrlDown()) {
                        if (m_selectedBezierKeyframes.contains(kfHandle))
                            m_selectedBezierKeyframes.remove(kfHandle);
                        else
                            m_selectedBezierKeyframes.insert(kfHandle);
                    } else {
                        if (!m_selectedBezierKeyframes.contains(kfHandle))
                            m_selectedBezierKeyframes.clear();
                        m_selectedBezierKeyframes.insert(kfHandle);
                    }
                }
                m_rowTimeline->update();

                return TimelineControlType::BezierKeyframe;
            }

            if (m_selectedBezierKeyframes.contains(kfHandle)) {
                QPointF cInPos = getBezierControlPosition(kf, BezierControlType::In);
                QPointF cOutPos = getBezierControlPosition(kf, BezierControlType::Out);
                bool clickedInHandle = QLineF(cInPos, pos).length() < CONTROL_RADIUS;
                bool clickedOutHandle = QLineF(cOutPos, pos).length() < CONTROL_RADIUS;
                if (clickedInHandle || clickedOutHandle) {
                    m_pressedKeyframeHandle = kfHandle;

                    return clickedInHandle ? TimelineControlType::BezierInHandle
                                           : TimelineControlType::BezierOutHandle;
                }
            }
        }
    }

    return TimelineControlType::None;
}

QPointF RowTimelinePropertyGraph::getBezierControlPosition(const SBezierKeyframe &kf,
                                                           BezierControlType type) const
{
    long time = 0;
    float value = 0;
    if (type == BezierControlType::None) {
        time = kf.m_time;
        value = kf.m_value;
    } else if (type == BezierControlType::In) {
        time = kf.m_InTangentTime;
        value = kf.m_InTangentValue;
    } else if (type == BezierControlType::Out) {
        time = kf.m_OutTangentTime;
        value = kf.m_OutTangentValue;
    }

    return getKeyframePosition(time, value);
}

QPointF RowTimelinePropertyGraph::getKeyframePosition(long time, float value) const
{
    adjustColorProperty(value);

    return QPointF(m_rowTimeline->rowTree()->m_scene->ruler()->timeToDistance(time),
                   m_graphY - value * m_valScale);
}

/**
 * This method is called when the user drags a bezier control. It updates the bezier control
 * values based on the current position of the handle.
 *
 * @param controlType which handle is being dragged? (BezierInHandle or BezierOutHandle)
 * @param scenePos handle position in timeline scene coordinates
 */
void RowTimelinePropertyGraph::updateBezierControlValue(TimelineControlType controlType,
                                                        const QPointF &scenePos)
{
    QPointF p = m_rowTimeline->mapFromScene(scenePos.x() - RULER_EDGE_OFFSET, scenePos.y());

    // time and value at current mouse position
    float time = float(m_rowTimeline->rowTree()->m_scene->ruler()->distanceToTime(p.x()));
    float value = (m_graphY - p.y()) / m_valScale;
    adjustColorProperty(value, false);

    SBezierKeyframe kf = get<SBezierKeyframe>(m_animCore->GetKeyframeData(m_pressedKeyframeHandle));

     // moving selected keyframes (vertically)
    if (controlType == TimelineControlType::BezierKeyframe) {
        float dVal = value - kf.m_value;

        for (auto kfHandle : qAsConst(m_selectedBezierKeyframes)) {
            SBezierKeyframe kf_i = get<SBezierKeyframe>(m_animCore->GetKeyframeData(kfHandle));
            kf_i.m_value += dVal;
            kf_i.m_InTangentValue += dVal;
            kf_i.m_OutTangentValue += dVal;
            m_UpdatableEditor.EnsureEditor(QObject::tr("Edit Bezier curve"), __FILE__, __LINE__)
                    .setBezierKeyframeValue(kfHandle, kf_i);
        }
        // immediate refresh is needed to update the value in the inspector, this is not needed
        // when moving the control points as they are not shown in the inspector
        m_UpdatableEditor.FireImmediateRefresh(m_rowTimeline->rowTree()->parentRow()->instance());
        m_rowTimeline->update();
        return;
    }

    bool isBezierIn = controlType == TimelineControlType::BezierInHandle;

    // prevent handles from moving to the other side of the keyframe
    if ((isBezierIn && time > kf.m_time)
        || (!isBezierIn && time < kf.m_time)) {
        time = kf.m_time;
    }

    // prevent handles from going beyond prev. and next keyframes
    Qt3DSDMAnimationHandle anim = m_animCore->GetAnimationForKeyframe(m_pressedKeyframeHandle);
    Qt3DSDMTimelineKeyframe::TKeyframeHandleList keyframeHandles;
    m_animCore->GetKeyframes(anim, keyframeHandles);
    for (size_t i = 0; i < keyframeHandles.size(); ++i) {
        if (keyframeHandles[i] == m_pressedKeyframeHandle) {
            float currKfTime = float(getKeyframeTime(m_animCore->GetKeyframeData(
                                                                    keyframeHandles[i])));
            // FLT_MAX is divided by 2 so that it doesn't cause an overflow in the calculations
            // below
            float prevKfTime = i > 0
                    ? float(getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i - 1])))
                    : -FLT_MAX / 2.f;
            float nextKfTime = i < keyframeHandles.size() - 1.f
                    ? float(getKeyframeTime(m_animCore->GetKeyframeData(keyframeHandles[i + 1])))
                    : FLT_MAX / 2.f;

            if (isBezierIn) {
                if (time < prevKfTime)
                    time = prevKfTime;
                if (!CHotKeys::isCtrlDown() && time < currKfTime * 2.f - nextKfTime)
                    time = currKfTime * 2.f - nextKfTime;
            } else { // bezier out
                if (time > nextKfTime)
                    time = nextKfTime;
                if (!CHotKeys::isCtrlDown() && time > currKfTime * 2.f - prevKfTime)
                    time = currKfTime * 2.f - prevKfTime;
            }
            break;
        }
    }

    float &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;
    float &otherHandleValue = isBezierIn ? kf.m_OutTangentValue : kf.m_InTangentValue;

    currHandleTime = time;
    currHandleValue = value;

    if (!CHotKeys::isCtrlDown()) {
        otherHandleTime = kf.m_time + (kf.m_time - time);
        otherHandleValue = kf.m_value + (kf.m_value - currHandleValue);
    }

    m_UpdatableEditor.EnsureEditor(QObject::tr("Edit Bezier curve"), __FILE__, __LINE__)
            .setBezierKeyframeValue(m_pressedKeyframeHandle, kf);
    m_rowTimeline->update();
}

void RowTimelinePropertyGraph::updateChannelFiltering(const QVector<bool> &activeChannels)
{
    m_activeChannels.clear();
    m_activeChannelsIndex.clear();

    const auto animHandles = m_rowTimeline->rowTree()->propBinding()->animationHandles();
    for (int i = 0; i < activeChannels.size(); ++i) {
        if (activeChannels[i]) {
            m_activeChannels.append(animHandles[i]);
            m_activeChannelsIndex.append(i);
        }
    }

    fitGraph();
}

// adjust graph scale and y so that all keyframe and control points are visible
void RowTimelinePropertyGraph::fitGraph()
{
    // get min/max keyframes values in the active channels
    float minVal = FLT_MAX;
    float maxVal = -FLT_MAX;

    auto ruler = m_rowTimeline->rowTree()->m_scene->ruler();
    int startX = qMax(ruler->viewportX() - int(RULER_EDGE_OFFSET), 0);
    int endX   = ruler->viewportX() + m_rowTimeline->rowTree()->m_scene->widgetTimeline()
                                                   ->viewTimelineContent()->width();
    long startTime = ruler->distanceToTime(startX);
    long endTime   = ruler->distanceToTime(endX);

    for (int i = 0; i < m_activeChannels.size(); ++i) {
        auto extrema = m_animCore->getAnimationExtrema(m_activeChannels[i], startTime, endTime);
        if (extrema.second < minVal)
            minVal = extrema.second;
        if (extrema.first > maxVal)
            maxVal = extrema.first;

        // for bezier keyframes check selected tangents in/out also
        for (auto kfHandle : qAsConst(m_selectedBezierKeyframes)) {
            TKeyframe keyframeData = m_animCore->GetKeyframeData(kfHandle);

            if (keyframeData.getType() == qt3dsdm::EAnimationTypeBezier) {
                long timeIn, timeOut;
                float valueIn, valueOut;
                getBezierValues(keyframeData, timeIn, valueIn, timeOut, valueOut);

                if (!m_animCore->IsFirstKeyframe(kfHandle)) { // check tangent-in value
                    if (valueIn < minVal)
                        minVal = valueIn;
                    if (valueIn > maxVal)
                        maxVal = valueIn;
                }

                if (!m_animCore->IsLastKeyframe(kfHandle)) { // check tangent-out value
                    if (valueOut < minVal)
                        minVal = valueOut;
                    if (valueOut > maxVal)
                        maxVal = valueOut;
                }
            }
        }
    }

    adjustColorProperty(maxVal);
    adjustColorProperty(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 = double(marginT + maxVal * m_valScale);

    // if value range is < min scale, center the range
    float rangeH = (maxVal - minVal) * m_valScale;
    if (rangeH < graphH)
        m_graphY += double(graphH - rangeH) / 2.;

    m_rowTimeline->update();
}

// show color properties values in the range 0-255
void RowTimelinePropertyGraph::adjustColorProperty(float &val, bool scaleUp) const
{
    if (m_rowTimeline->isColorProperty())
        scaleUp ? val *= 255.f : val /= 255.f;
}

void RowTimelinePropertyGraph::checkValScaleLimits()
{
    // m_valScale can be NaN if maxVal and minVal are same (i.e. horizontal line curve)
    if (isnan(m_valScale) || m_valScale > 10.f)
        m_valScale = 10.f;
    else if (m_valScale < .01f)
        m_valScale = .01f;
}

void RowTimelinePropertyGraph::selectBezierKeyframesInRange(const QRectF &rect)
{
    QRectF localRect = m_rowTimeline->mapFromScene(rect).boundingRect();
    localRect.translate(-RULER_EDGE_OFFSET, 0);

    for (int i = 0; i < m_activeChannels.size(); ++i) {
        Qt3DSDMTimelineKeyframe::TKeyframeHandleList keyframeHandles;
        m_animCore->GetKeyframes(m_activeChannels[i], keyframeHandles);
        for (auto kfHandle : keyframeHandles) {
            SBezierKeyframe kf = get<SBezierKeyframe>(m_animCore->GetKeyframeData(kfHandle));

            QPointF kfPosition = getKeyframePosition(getKeyframeTime(kf), getKeyframeValue(kf));
            if (localRect.contains(kfPosition))
                m_selectedBezierKeyframes.insert(kfHandle);
            else
                m_selectedBezierKeyframes.remove(kfHandle);
        }
    }
}

void RowTimelinePropertyGraph::deselectAllBezierKeyframes()
{
    if (!m_pressedKeyframeHandle.Valid()) // not currently editing a bezier control
        m_selectedBezierKeyframes.clear();
}

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();
}

void RowTimelinePropertyGraph::startPan()
{
    m_graphYPanInit = m_graphY;
}

void RowTimelinePropertyGraph::pan(qreal dy)
{
    m_graphY = m_graphYPanInit + dy;
    m_rowTimeline->update();
}

void RowTimelinePropertyGraph::commitBezierEdit()
{
    m_UpdatableEditor.CommitEditor();
}

void RowTimelinePropertyGraph::setExpandHeight(int h)
{
    m_expandHeight = h;
    m_fitCurveTimer.start();
}