Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 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 "qmimedataadapter.h"
23 :
24 : #include <QMimeData>
25 :
26 : #include "log.h"
27 :
28 : using namespace mu;
29 : using namespace muse::draw;
30 : using namespace mu::engraving;
31 :
32 58 : QMimeDataAdapter::QMimeDataAdapter(const QMimeData* d)
33 58 : : m_data(d)
34 : {
35 58 : }
36 :
37 0 : std::vector<std::string> QMimeDataAdapter::formats() const
38 : {
39 0 : std::vector<std::string> ret;
40 0 : QStringList fs = m_data->formats();
41 0 : for (const QString& f : fs) {
42 0 : ret.push_back(f.toStdString());
43 : }
44 0 : return ret;
45 0 : }
46 :
47 117 : bool QMimeDataAdapter::hasFormat(const std::string& mimeType) const
48 : {
49 117 : return m_data->hasFormat(QString::fromStdString(mimeType));
50 : }
51 :
52 61 : muse::ByteArray QMimeDataAdapter::data(const std::string& mimeType) const
53 : {
54 61 : return muse::ByteArray::fromQByteArray(m_data->data(QString::fromStdString(mimeType)));
55 : }
56 :
57 0 : bool QMimeDataAdapter::hasImage() const
58 : {
59 0 : return m_data->hasImage();
60 : }
61 :
62 0 : static std::shared_ptr<Pixmap> pixmapFromQVariant(const QVariant& val)
63 : {
64 : using namespace muse::draw;
65 0 : IF_ASSERT_FAILED(val.canConvert<Pixmap>() || val.canConvert<QImage>()) {
66 : }
67 :
68 0 : if (val.canConvert<Pixmap>()) {
69 0 : return std::make_shared<Pixmap>(val.value<Pixmap>());
70 0 : } else if (val.canConvert<QImage>()) {
71 0 : return std::make_shared<Pixmap>(Pixmap::fromQPixmap(QPixmap::fromImage(val.value<QImage>())));
72 : }
73 0 : return nullptr;
74 : }
75 :
76 0 : std::shared_ptr<Pixmap> QMimeDataAdapter::imageData() const
77 : {
78 0 : return pixmapFromQVariant(m_data->imageData());
79 : }
|