Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2025 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "qmldrag.h"
23 :
24 : using namespace muse::ui;
25 :
26 0 : QmlDrag::QmlDrag(QObject* parent)
27 0 : : QObject(parent), muse::Contextable(muse::iocCtxForQmlObject(this))
28 : {
29 0 : m_data = std::make_shared<DragData>();
30 0 : }
31 :
32 0 : QmlDrag* QmlDrag::qmlAttachedProperties(QObject* object)
33 : {
34 0 : return new QmlDrag(object);
35 : }
36 :
37 0 : QQuickItem* QmlDrag::target() const
38 : {
39 0 : return qobject_cast<QQuickItem*>(parent());
40 : }
41 :
42 0 : void QmlDrag::onActiveDrag()
43 : {
44 0 : controller()->setCurrentData(m_data);
45 0 : }
46 :
47 0 : void QmlDrag::onDeactivateDrag()
48 : {
49 0 : }
50 :
51 0 : bool QmlDrag::active() const
52 : {
53 0 : return m_active;
54 : }
55 :
56 0 : void QmlDrag::setActive(bool newActive)
57 : {
58 0 : if (m_active == newActive) {
59 0 : return;
60 : }
61 0 : m_active = newActive;
62 :
63 0 : if (m_active) {
64 0 : onActiveDrag();
65 : } else {
66 0 : onDeactivateDrag();
67 : }
68 :
69 0 : emit activeChanged();
70 : }
71 :
72 0 : QVariantMap QmlDrag::mimeData() const
73 : {
74 0 : QVariantMap map;
75 0 : for (const QString& f : m_data->mimeData.formats()) {
76 0 : map[f] = m_data->mimeData.data(f);
77 0 : }
78 0 : return map;
79 0 : }
80 :
81 0 : void QmlDrag::setMimeData(const QVariantMap& map)
82 : {
83 0 : for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
84 0 : m_data->mimeData.setData(it.key(), it.value().toByteArray());
85 : }
86 0 : emit mimeDataChanged();
87 0 : }
|