diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-08-04 13:01:04 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-04 12:10:53 +0200 |
commit | a1049ff899fa621ef41266e5af419bddbf0f8cdb (patch) | |
tree | 5cd1a30970e77bef876578d8301f933d51100f3b /src | |
parent | fc9e419cabc67c33907661dfbfa5595a5896afdb (diff) |
Support QImage and others in Wayland clipboard.
The wayland plugin's clipboard implementation lacked support for data
set via QMimeData::setImageData, QClipboard::setPixmap, etc. because
everything was treated as a QByteArray. A variant having an image
cannot however be converted to a byte array. Therefore, to make these
convenience functions to work, the image is now encoded via
QImageWriter before sending it. On the receiving side QMimeData is
capable of decoding images from byte arrays, so no problem there.
The patch also renames an internal QWaylandMimeData class to a more
suitable clipboard-specific name as the functionality is clipboard
specific.
Change-Id: I77e7df903b8dbe9731613fdbb9693b2a37b05d18
Reviewed-on: http://codereview.qt.nokia.com/2616
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/wayland/qwaylandclipboard.cpp | 17 | ||||
-rw-r--r-- | src/plugins/platforms/wayland/qwaylandclipboard.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/wayland/qwaylandmime.cpp | 83 | ||||
-rw-r--r-- | src/plugins/platforms/wayland/qwaylandmime.h | 55 | ||||
-rw-r--r-- | src/plugins/platforms/wayland/wayland.pro | 6 |
5 files changed, 153 insertions, 12 deletions
diff --git a/src/plugins/platforms/wayland/qwaylandclipboard.cpp b/src/plugins/platforms/wayland/qwaylandclipboard.cpp index 1ef063f..d20f183 100644 --- a/src/plugins/platforms/wayland/qwaylandclipboard.cpp +++ b/src/plugins/platforms/wayland/qwaylandclipboard.cpp @@ -42,6 +42,7 @@ #include "qwaylandclipboard.h" #include "qwaylanddisplay.h" #include "qwaylandinputdevice.h" +#include "qwaylandmime.h" #include <QtGui/QPlatformNativeInterface> #include <QtGui/QApplication> #include <QtCore/QMimeData> @@ -52,7 +53,7 @@ static QWaylandClipboard *clipboard = 0; -class QWaylandMimeData : public QInternalMimeData +class QWaylandClipboardMimeData : public QInternalMimeData { public: void clearAll(); @@ -64,28 +65,28 @@ private: QStringList mFormatList; }; -void QWaylandMimeData::clearAll() +void QWaylandClipboardMimeData::clearAll() { clear(); mFormatList.clear(); } -void QWaylandMimeData::setFormats(const QStringList &formatList) +void QWaylandClipboardMimeData::setFormats(const QStringList &formatList) { mFormatList = formatList; } -bool QWaylandMimeData::hasFormat_sys(const QString &mimeType) const +bool QWaylandClipboardMimeData::hasFormat_sys(const QString &mimeType) const { return formats().contains(mimeType); } -QStringList QWaylandMimeData::formats_sys() const +QStringList QWaylandClipboardMimeData::formats_sys() const { return mFormatList; } -QVariant QWaylandMimeData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const +QVariant QWaylandClipboardMimeData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const { return clipboard->retrieveData(mimeType, type); } @@ -147,7 +148,7 @@ void QWaylandSelection::send(void *data, Q_UNUSED(selection); QWaylandSelection *self = static_cast<QWaylandSelection *>(data); QString mimeType = QString::fromLatin1(mime_type); - QByteArray content = self->mMimeData->data(mimeType); + QByteArray content = QWaylandMimeHelper::getByteArray(self->mMimeData, mimeType); if (!content.isEmpty()) { QFile f; if (f.open(fd, QIODevice::WriteOnly)) @@ -230,7 +231,7 @@ QMimeData *QWaylandClipboard::mimeData(QClipboard::Mode mode) if (!mSelections.isEmpty()) return mSelections.last()->mMimeData; if (!mMimeDataIn) - mMimeDataIn = new QWaylandMimeData; + mMimeDataIn = new QWaylandClipboardMimeData; mMimeDataIn->clearAll(); if (!mOfferedMimeTypes.isEmpty() && mOffer) mMimeDataIn->setFormats(mOfferedMimeTypes); diff --git a/src/plugins/platforms/wayland/qwaylandclipboard.h b/src/plugins/platforms/wayland/qwaylandclipboard.h index 8729434..6b113ae 100644 --- a/src/plugins/platforms/wayland/qwaylandclipboard.h +++ b/src/plugins/platforms/wayland/qwaylandclipboard.h @@ -48,7 +48,7 @@ class QWaylandDisplay; class QWaylandSelection; -class QWaylandMimeData; +class QWaylandClipboardMimeData; struct wl_selection_offer; class QWaylandClipboardSignalEmitter : public QObject @@ -90,7 +90,7 @@ private: static void forceRoundtrip(struct wl_display *display); QWaylandDisplay *mDisplay; - QWaylandMimeData *mMimeDataIn; + QWaylandClipboardMimeData *mMimeDataIn; QList<QWaylandSelection *> mSelections; QStringList mOfferedMimeTypes; struct wl_selection_offer *mOffer; diff --git a/src/plugins/platforms/wayland/qwaylandmime.cpp b/src/plugins/platforms/wayland/qwaylandmime.cpp new file mode 100644 index 0000000..c218d7d --- /dev/null +++ b/src/plugins/platforms/wayland/qwaylandmime.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandmime.h" +#include <QImage> +#include <QColor> +#include <QUrl> +#include <QBuffer> +#include <QImageWriter> + +QByteArray QWaylandMimeHelper::getByteArray(QMimeData *mimeData, const QString &mimeType) +{ + QByteArray content; + if (mimeType == QLatin1String("text/plain")) { + content = mimeData->text().toUtf8(); + } else if (mimeData->hasImage() + && (mimeType == QLatin1String("application/x-qt-image") + || mimeType.startsWith("image/"))) { + QImage image = qvariant_cast<QImage>(mimeData->imageData()); + if (!image.isNull()) { + QBuffer buf; + buf.open(QIODevice::ReadWrite); + QByteArray fmt = "BMP"; + if (mimeType.startsWith("image/")) { + QByteArray imgFmt = mimeType.mid(6).toUpper().toAscii(); + if (QImageWriter::supportedImageFormats().contains(imgFmt)) + fmt = imgFmt; + } + QImageWriter wr(&buf, fmt); + wr.write(image); + content = buf.buffer(); + } + } else if (mimeType == QLatin1String("application/x-color")) { + content = qvariant_cast<QColor>(mimeData->colorData()).name().toAscii(); + } else if (mimeType == QLatin1String("text/uri-list")) { + QList<QUrl> urls = mimeData->urls(); + for (int i = 0; i < urls.count(); ++i) { + content.append(urls.at(i).toEncoded()); + content.append('\n'); + } + } else { + content = mimeData->data(mimeType); + } + return content; +} diff --git a/src/plugins/platforms/wayland/qwaylandmime.h b/src/plugins/platforms/wayland/qwaylandmime.h new file mode 100644 index 0000000..5f6ed95 --- /dev/null +++ b/src/plugins/platforms/wayland/qwaylandmime.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDMIME_H +#define QWAYLANDMIME_H + +#include <QString> +#include <QByteArray> +#include <QMimeData> + +class QWaylandMimeHelper +{ +public: + static QByteArray getByteArray(QMimeData *mimeData, const QString &mimeType); +}; + +#endif diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index 857a291..1e0bbe6 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -20,7 +20,8 @@ SOURCES = main.cpp \ qwaylandwindow.cpp \ qwaylandscreen.cpp \ qwaylandshmwindow.cpp \ - qwaylandclipboard.cpp + qwaylandclipboard.cpp \ + qwaylandmime.cpp HEADERS = qwaylandintegration.h \ qwaylandnativeinterface.h \ @@ -31,7 +32,8 @@ HEADERS = qwaylandintegration.h \ qwaylandshmsurface.h \ qwaylandbuffer.h \ qwaylandshmwindow.h \ - qwaylandclipboard.h + qwaylandclipboard.h \ + qwaylandmime.h INCLUDEPATH += $$QMAKE_INCDIR_WAYLAND LIBS += $$QMAKE_LIBS_WAYLAND |