Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5#include <QImage>
6#include <QColor>
7#include <QUrl>
8#include <QBuffer>
9#include <QImageWriter>
10
12
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()) {
25 QByteArray fmt = "BMP";
26 if (mimeType.startsWith(QLatin1String("image/"))) {
27 QByteArray imgFmt = mimeType.mid(6).toLower().toLatin1();
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
\inmodule QtCore \reentrant
Definition qbuffer.h:16
\inmodule QtCore
Definition qbytearray.h:57
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QImageWriter class provides a format independent interface for writing images to files or other d...
static QList< QByteArray > supportedImageFormats()
Returns the list of image formats supported by QImageWriter.
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore
Definition qmimedata.h:16
QVariant colorData() const
Returns a color if the data stored in the object represents a color (MIME type application/x-color); ...
QVariant imageData() const
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null varia...
bool hasImage() const
Returns true if the object can return an image; otherwise returns false.
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType.
QString text() const
Returns a plain text (MIME type text/plain) representation of the data.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QByteArray toUtf8() const &
Definition qstring.h:634
static QByteArray getByteArray(QMimeData *mimeData, const QString &mimeType)
Combined button and popup list for selecting options.
Definition image.cpp:4
const char * mimeType
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLenum GLuint GLenum GLsizei const GLchar * buf
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
QVideoFrameFormat::PixelFormat fmt
QMimeData * mimeData