From beb3dfed07b35d74050fcd40a99f705c033597f7 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 4 Aug 2011 13:01:04 +0300 Subject: Support QImage and others in Wayland clipboard. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jørgen Lind --- .../platforms/wayland/qwaylandclipboard.cpp | 17 ++--- src/plugins/platforms/wayland/qwaylandclipboard.h | 4 +- src/plugins/platforms/wayland/qwaylandmime.cpp | 83 ++++++++++++++++++++++ src/plugins/platforms/wayland/qwaylandmime.h | 55 ++++++++++++++ src/plugins/platforms/wayland/wayland.pro | 6 +- 5 files changed, 153 insertions(+), 12 deletions(-) create mode 100644 src/plugins/platforms/wayland/qwaylandmime.cpp create mode 100644 src/plugins/platforms/wayland/qwaylandmime.h (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wayland/qwaylandclipboard.cpp b/src/plugins/platforms/wayland/qwaylandclipboard.cpp index 1ef063fec1..d20f183efe 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 #include #include @@ -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(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 87294342d7..6b113ae5b0 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 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 0000000000..c218d7ddb8 --- /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 +#include +#include +#include +#include + +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(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(mimeData->colorData()).name().toAscii(); + } else if (mimeType == QLatin1String("text/uri-list")) { + QList 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 0000000000..5f6ed954a1 --- /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 +#include +#include + +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 857a2918ce..1e0bbe6cdd 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 -- cgit v1.2.3 From 7ce8491280990350162933a0716d1b014f65aeb6 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 3 Aug 2011 21:16:10 +0200 Subject: support xcb-icccm 3.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this is a rather crude hack, but whatever. Change-Id: I3fa363572842b207202d4aac8526951c0e16bf5b Reviewed-on: http://codereview.qt.nokia.com/2602 Reviewed-by: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/plugins/platforms/xcb/qxcbwindow.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 0a02c7eff5..20e4187541 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -49,7 +49,17 @@ #include "qdri2context.h" #endif +#define class class_name // Yeah, in 2011 ... #include +#undef class + +// xcb-icccm 3.8 support +#ifdef XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS +#define xcb_wm_hints_t xcb_icccm_wm_hints_t +#define xcb_wm_hints_set_iconic xcb_icccm_wm_hints_set_iconic +#define xcb_wm_hints_set_normal xcb_icccm_wm_hints_set_normal +#define xcb_set_wm_hints xcb_icccm_set_wm_hints +#endif #include #include -- cgit v1.2.3 From e95edf644ee7c66708e878469ed3aec00c90e75c Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Fri, 5 Aug 2011 10:59:34 +0200 Subject: Fix weight parsing in QBasicUnixFontDatabase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First check the usWeightClass in OS/2 font table, then check the weight byte in panose structure because Nokia Pure Text fonts only have that set correctly. Change-Id: Idce2626c8df17ce74ba78b317846cb42c3f1fe84 Reviewed-by: Jørgen Lind Reviewed-on: http://codereview.qt.nokia.com/2682 Reviewed-by: Qt Sanity Bot Reviewed-by: Jiang Jiang --- .../basicunix/qbasicunixfontdatabase.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp b/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp index 001d377ca0..6b844f9df1 100644 --- a/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp +++ b/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp @@ -308,6 +308,33 @@ QStringList QBasicUnixFontDatabase::addTTFile(const QByteArray &fontData, const }; writingSystems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange); + + if (os2->usWeightClass == 0) + ; + else if (os2->usWeightClass < 350) + weight = QFont::Light; + else if (os2->usWeightClass < 450) + weight = QFont::Normal; + else if (os2->usWeightClass < 650) + weight = QFont::DemiBold; + else if (os2->usWeightClass < 750) + weight = QFont::Bold; + else if (os2->usWeightClass < 1000) + weight = QFont::Black; + + if (os2->panose[2] >= 2) { + int w = os2->panose[2]; + if (w <= 3) + weight = QFont::Light; + else if (w <= 5) + weight = QFont::Normal; + else if (w <= 7) + weight = QFont::DemiBold; + else if (w <= 8) + weight = QFont::Bold; + else if (w <= 10) + weight = QFont::Black; + } } QString family = QString::fromAscii(face->family_name); -- cgit v1.2.3 From 6729dfbe0ed52d1fd5e1722d28c584cdcdd64545 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Fri, 5 Aug 2011 15:49:21 +0200 Subject: Fix fallbacksForFamily in QBasicUnixFontDatabase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that this function instead of the one in QPlatformFontDatabase will be called. Change-Id: Ifdb75ada27723c688e42067c7633b08391d66467 Reviewed-on: http://codereview.qt.nokia.com/2696 Reviewed-by: Qt Sanity Bot Reviewed-by: Jørgen Lind --- .../platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp | 2 +- src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp b/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp index 6b844f9df1..d91cce59a9 100644 --- a/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp +++ b/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.cpp @@ -237,7 +237,7 @@ QFontEngine *QBasicUnixFontDatabase::fontEngine(const QFontDef &fontDef, QUnicod return engine; } -QStringList QBasicUnixFontDatabase::fallbacksForFamily(const QString family, const QFont::Style &style, const QUnicodeTables::Script &script) const +QStringList QBasicUnixFontDatabase::fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const { Q_UNUSED(family); Q_UNUSED(style); diff --git a/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.h b/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.h index f7fc0e547b..0e17ed55b6 100644 --- a/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.h +++ b/src/plugins/platforms/fontdatabases/basicunix/qbasicunixfontdatabase.h @@ -57,7 +57,7 @@ class QBasicUnixFontDatabase : public QPlatformFontDatabase public: void populateFontDatabase(); QFontEngine *fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle); - QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QUnicodeTables::Script &script) const; + QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const; QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName); void releaseHandle(void *handle); -- cgit v1.2.3 From 80e7ea928f3b69dec90c0020671c5d7354c37227 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 10 Aug 2011 10:05:03 +0300 Subject: Handle EINTR gracefully in Wayland clipboard. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Idd5082f02eb6708685421492afb8ad5b8546a5d6 Reviewed-on: http://codereview.qt.nokia.com/2810 Reviewed-by: Qt Sanity Bot Reviewed-by: Jørgen Lind --- src/plugins/platforms/wayland/qwaylandclipboard.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wayland/qwaylandclipboard.cpp b/src/plugins/platforms/wayland/qwaylandclipboard.cpp index d20f183efe..45f0abc00a 100644 --- a/src/plugins/platforms/wayland/qwaylandclipboard.cpp +++ b/src/plugins/platforms/wayland/qwaylandclipboard.cpp @@ -50,6 +50,7 @@ #include #include #include +#include // for QT_READ static QWaylandClipboard *clipboard = 0; @@ -219,7 +220,7 @@ QVariant QWaylandClipboard::retrieveData(const QString &mimeType, QVariant::Type char buf[256]; int n; close(pipefd[1]); - while ((n = read(pipefd[0], &buf, sizeof buf)) > 0) + while ((n = QT_READ(pipefd[0], &buf, sizeof buf)) > 0) content.append(buf, n); close(pipefd[0]); return content; -- cgit v1.2.3