Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwaylandmimehelper.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qwaylandmimehelper_p.h"
5
#
include
<
QImage
>
6
#
include
<
QColor
>
7
#
include
<
QUrl
>
8
#
include
<
QBuffer
>
9
#
include
<
QImageWriter
>
10
11
QT_BEGIN_NAMESPACE
12
13
QByteArray QWaylandMimeHelper::getByteArray(QMimeData *mimeData,
const
QString &mimeType)
14
{
15
QByteArray content;
16
if
(mimeType == QLatin1String(
"text/plain"
)) {
17
content = mimeData->text().toUtf8();
18
}
else
if
(mimeData->hasImage()
19
&& (mimeType == QLatin1String(
"application/x-qt-image"
)
20
|| mimeType.startsWith(QLatin1String(
"image/"
)))) {
21
QImage image = qvariant_cast<QImage>(mimeData->imageData());
22
if
(!image.isNull()) {
23
QBuffer buf;
24
buf.open(QIODevice::ReadWrite);
25
QByteArray fmt =
"BMP"
;
26
if
(mimeType.startsWith(QLatin1String(
"image/"
))) {
27
QByteArray imgFmt = mimeType.mid(6).toLower().toLatin1();
28
if
(QImageWriter::supportedImageFormats().contains(imgFmt))
29
fmt = imgFmt;
30
}
31
QImageWriter wr(&buf, fmt);
32
wr.write(image);
33
content = buf.buffer();
34
}
35
}
else
if
(mimeType == QLatin1String(
"application/x-color"
)) {
36
content = qvariant_cast<QColor>(mimeData->colorData()).name().toLatin1();
37
}
else
if
(mimeType == QLatin1String(
"text/uri-list"
)) {
38
QList<QUrl> urls = mimeData->urls();
39
for
(
int
i = 0; i < urls.size(); ++i) {
40
content.append(urls.at(i).toEncoded());
41
content.append(
"\r\n"
);
42
}
43
}
else
{
44
content = mimeData->data(mimeType);
45
}
46
return
content;
47
}
48
49
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtwayland
src
shared
qwaylandmimehelper.cpp
Generated on
for Qt by
1.18.0