aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/timeline/timelinezoomcontrol.h
blob: 2236e754f35f8762ff4f6d2b3de3399f35e4cd39 (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
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
****************************************************************************/

#pragma once

#include "timeline_global.h"
#include <QTimer>

namespace Timeline {

class TIMELINE_EXPORT TimelineZoomControl : public QObject {
    Q_OBJECT

    Q_PROPERTY(qint64 traceStart READ traceStart NOTIFY traceChanged)
    Q_PROPERTY(qint64 traceEnd READ traceEnd NOTIFY traceChanged)
    Q_PROPERTY(qint64 traceDuration READ traceDuration NOTIFY traceChanged)

    Q_PROPERTY(qint64 windowStart READ windowStart NOTIFY windowChanged)
    Q_PROPERTY(qint64 windowEnd READ windowEnd NOTIFY windowChanged)
    Q_PROPERTY(qint64 windowDuration READ windowDuration NOTIFY windowChanged)

    Q_PROPERTY(qint64 rangeStart READ rangeStart NOTIFY rangeChanged)
    Q_PROPERTY(qint64 rangeEnd READ rangeEnd NOTIFY rangeChanged)
    Q_PROPERTY(qint64 rangeDuration READ rangeDuration NOTIFY rangeChanged)

    Q_PROPERTY(qint64 selectionStart READ selectionStart NOTIFY selectionChanged)
    Q_PROPERTY(qint64 selectionEnd READ selectionEnd NOTIFY selectionChanged)
    Q_PROPERTY(qint64 selectionDuration READ selectionDuration NOTIFY selectionChanged)

    Q_PROPERTY(bool windowLocked READ windowLocked WRITE setWindowLocked NOTIFY windowLockedChanged)
    Q_PROPERTY(bool windowMoving READ windowMoving NOTIFY windowMovingChanged)

    Q_PROPERTY(qint64 maximumZoomFactor READ maximumZoomFactor CONSTANT)
    Q_PROPERTY(qint64 minimumRangeLength READ minimumRangeLength CONSTANT)

public:
    qint64 maximumZoomFactor() const { return 1 << 10; }
    qint64 minimumRangeLength() const { return 500; }

    TimelineZoomControl(QObject *parent = 0);
    qint64 traceStart() const { return m_traceStart; }
    qint64 traceEnd() const { return m_traceEnd; }
    qint64 traceDuration() const { return m_traceEnd - m_traceStart; }

    qint64 windowStart() const { return m_windowStart; }
    qint64 windowEnd() const { return m_windowEnd; }
    qint64 windowDuration() const { return m_windowEnd - m_windowStart; }

    qint64 rangeStart() const { return m_rangeStart; }
    qint64 rangeEnd() const { return m_rangeEnd; }
    qint64 rangeDuration() const { return m_rangeEnd - m_rangeStart; }

    qint64 selectionStart() const { return m_selectionStart; }
    qint64 selectionEnd() const { return m_selectionEnd; }
    qint64 selectionDuration() const { return m_selectionEnd - m_selectionStart; }

    bool windowLocked() const { return m_windowLocked; }
    bool windowMoving() const { return m_timer.isActive(); }

    virtual void clear();

signals:
    void traceChanged(qint64 start, qint64 end);
    void windowChanged(qint64 start, qint64 end);
    void rangeChanged(qint64 start, qint64 end);
    void selectionChanged(qint64 start, qint64 end);
    void windowLockedChanged(bool windowLocked);
    void windowMovingChanged(bool windowMoving);

public slots:
    void setTrace(qint64 start, qint64 end);
    void setRange(qint64 start, qint64 end);
    void setSelection(qint64 start, qint64 end);
    void setWindowLocked(bool windowLocked);

protected slots:
    void moveWindow();

protected:
    qint64 m_traceStart;
    qint64 m_traceEnd;
    qint64 m_windowStart;
    qint64 m_windowEnd;
    qint64 m_rangeStart;
    qint64 m_rangeEnd;
    qint64 m_selectionStart;
    qint64 m_selectionEnd;

    QTimer m_timer;
    bool m_windowLocked;

    void rebuildWindow();
    void clampRangeToWindow();
};

} // namespace Timeline