moveableItem.ipp 3.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/***************************************************************************
 *   Copyright (C) 2017 by Nicolas Carion                                  *
 *   This file is part of Kdenlive. See www.kdenlive.org.                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) version 3 or any later version accepted by the       *
 *   membership of KDE e.V. (or its successor approved  by the membership  *
 *   of KDE e.V.), which shall act as a proxy defined in Section 14 of     *
 *   version 3 of the license.                                             *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

Nicolas Carion's avatar
Nicolas Carion committed
22
#include "macros.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
23
24
#include <utility>

Nicolas Carion's avatar
Nicolas Carion committed
25
26
template <typename Service>
MoveableItem<Service>::MoveableItem(std::weak_ptr<TimelineModel> parent, int id)
Nicolas Carion's avatar
Nicolas Carion committed
27
    : m_parent(std::move(parent))
28
29
30
    , m_id(id == -1 ? TimelineModel::getNextId() : id)
    , m_position(-1)
    , m_currentTrackId(-1)
31
    , m_grabbed(false)
Nicolas Carion's avatar
Nicolas Carion committed
32
    , m_lock(QReadWriteLock::Recursive)
33
34
35
{
}

Nicolas Carion's avatar
Nicolas Carion committed
36
template <typename Service> int MoveableItem<Service>::getId() const
37
{
Nicolas Carion's avatar
Nicolas Carion committed
38
    READ_LOCK();
39
40
41
    return m_id;
}

Nicolas Carion's avatar
Nicolas Carion committed
42
template <typename Service> int MoveableItem<Service>::getCurrentTrackId() const
43
{
Nicolas Carion's avatar
Nicolas Carion committed
44
    READ_LOCK();
45
46
47
    return m_currentTrackId;
}

Nicolas Carion's avatar
Nicolas Carion committed
48
template <typename Service> int MoveableItem<Service>::getPosition() const
49
{
Nicolas Carion's avatar
Nicolas Carion committed
50
    READ_LOCK();
51
52
53
    return m_position;
}

Nicolas Carion's avatar
Nicolas Carion committed
54
template <typename Service> std::pair<int, int> MoveableItem<Service>::getInOut() const
55
{
Nicolas Carion's avatar
Nicolas Carion committed
56
    READ_LOCK();
57
58
59
    return {getIn(), getOut()};
}

Nicolas Carion's avatar
Nicolas Carion committed
60
template <typename Service> int MoveableItem<Service>::getIn() const
61
{
Nicolas Carion's avatar
Nicolas Carion committed
62
    READ_LOCK();
63
64
65
    return service()->get_in();
}

Nicolas Carion's avatar
Nicolas Carion committed
66
template <typename Service> int MoveableItem<Service>::getOut() const
67
{
Nicolas Carion's avatar
Nicolas Carion committed
68
    READ_LOCK();
69
70
71
    return service()->get_out();
}

Nicolas Carion's avatar
Nicolas Carion committed
72
template <typename Service> bool MoveableItem<Service>::isValid()
73
{
Nicolas Carion's avatar
Nicolas Carion committed
74
    READ_LOCK();
75
76
77
    return service()->is_valid();
}

Nicolas Carion's avatar
Nicolas Carion committed
78
template <typename Service> void MoveableItem<Service>::setPosition(int pos)
79
{
Nicolas Carion's avatar
Nicolas Carion committed
80
    QWriteLocker locker(&m_lock);
81
82
83
    m_position = pos;
}

84
template <typename Service> void MoveableItem<Service>::setCurrentTrackId(int tid, bool finalMove)
85
{
86
    Q_UNUSED(finalMove);
Nicolas Carion's avatar
Nicolas Carion committed
87
    QWriteLocker locker(&m_lock);
88
    m_currentTrackId = tid;
89
90
91
    if (tid == -1) {
        selected = false;
    }
92
93
}

Nicolas Carion's avatar
Nicolas Carion committed
94
template <typename Service> void MoveableItem<Service>::setInOut(int in, int out)
95
{
Nicolas Carion's avatar
Nicolas Carion committed
96
    QWriteLocker locker(&m_lock);
97
98
    service()->set_in_and_out(in, out);
}
99
100
101
102
103
104

template <typename Service> bool MoveableItem<Service>::isGrabbed() const
{
    READ_LOCK();
    return m_grabbed;
}