From 428b92583ee2102c7ef16776a9b7785df7ff4e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 15 Jan 2015 13:38:40 +0100 Subject: High-dpi SVG and QQuickImageProvider Images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Scale sourceSize by the target devicePixelRatio before passing it to the providers. Task-number: QTBUG-38127 Task-number: QTBUG-38991 Change-Id: I1746e0859b4e63eb0d28d1a1c8aac610b68a9eb9 Reviewed-by: Jocelyn Turcotte Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Morten Johan Sørvig --- tests/manual/highdpi/ImageProvider/qmldir | 1 + tests/manual/highdpi/heart.svg | 55 ++++++++++++++++ tests/manual/highdpi/highdpi.pro | 13 ++++ tests/manual/highdpi/highdpi.qmlproject | 14 +++++ tests/manual/highdpi/imageprovider.cpp | 101 ++++++++++++++++++++++++++++++ tests/manual/highdpi/imageprovider.qml | 59 +++++++++++++++++ tests/manual/highdpi/svg.qml | 73 +++++++++++++++++++++ 7 files changed, 316 insertions(+) create mode 100644 tests/manual/highdpi/ImageProvider/qmldir create mode 100644 tests/manual/highdpi/heart.svg create mode 100644 tests/manual/highdpi/highdpi.pro create mode 100644 tests/manual/highdpi/highdpi.qmlproject create mode 100644 tests/manual/highdpi/imageprovider.cpp create mode 100644 tests/manual/highdpi/imageprovider.qml create mode 100644 tests/manual/highdpi/svg.qml (limited to 'tests/manual/highdpi') diff --git a/tests/manual/highdpi/ImageProvider/qmldir b/tests/manual/highdpi/ImageProvider/qmldir new file mode 100644 index 0000000000..add39d4ee8 --- /dev/null +++ b/tests/manual/highdpi/ImageProvider/qmldir @@ -0,0 +1 @@ +plugin qmlimageproviderplugin diff --git a/tests/manual/highdpi/heart.svg b/tests/manual/highdpi/heart.svg new file mode 100644 index 0000000000..8c982cd93c --- /dev/null +++ b/tests/manual/highdpi/heart.svg @@ -0,0 +1,55 @@ + + + + + +Heart Left-Highlight +This is a normal valentines day heart. + + +holiday +valentines + +valentine +hash(0x8a091c0) +hash(0x8a0916c) +signs_and_symbols +hash(0x8a091f0) +day + + + + +Jon Phillips + + + + +Jon Phillips + + + + +Jon Phillips + + + +image/svg+xml + + +en + + + + + + + + + + + + + + + diff --git a/tests/manual/highdpi/highdpi.pro b/tests/manual/highdpi/highdpi.pro new file mode 100644 index 0000000000..a434f848ae --- /dev/null +++ b/tests/manual/highdpi/highdpi.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml quick + +DESTDIR = ImageProvider +TARGET = qmlimageproviderplugin + +SOURCES += imageprovider.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/quick/imageprovider/ImageProvider +qml.files = ImageProvider/qmldir +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/imageprovider/ImageProvider +INSTALLS = target qml diff --git a/tests/manual/highdpi/highdpi.qmlproject b/tests/manual/highdpi/highdpi.qmlproject new file mode 100644 index 0000000000..2bb4016996 --- /dev/null +++ b/tests/manual/highdpi/highdpi.qmlproject @@ -0,0 +1,14 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} diff --git a/tests/manual/highdpi/imageprovider.cpp b/tests/manual/highdpi/imageprovider.cpp new file mode 100644 index 0000000000..8488d3c6a7 --- /dev/null +++ b/tests/manual/highdpi/imageprovider.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#include +#include +#include +#include +#include + +class ColorImageProvider : public QQuickImageProvider +{ +public: + ColorImageProvider() + : QQuickImageProvider(QQuickImageProvider::Pixmap) + { + } + + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) + { + int width = 50; + int height = 50; + + QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width, + requestedSize.height() > 0 ? requestedSize.height() : height); + if (size) + *size = QSize(pixmap.width(), pixmap.height()); + pixmap.fill(QColor(id).rgba()); + + // draw lines on even y offsets + QPainter p(&pixmap); + for (int y = 0; y < pixmap.height(); y+=2) { + p.drawLine(0, y, pixmap.width(), y); + } + return pixmap; + } +}; + + +class ImageProviderExtensionPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") +public: + void registerTypes(const char *uri) + { + Q_UNUSED(uri); + } + + void initializeEngine(QQmlEngine *engine, const char *uri) + { + Q_UNUSED(uri); + engine->addImageProvider("colors", new ColorImageProvider); + } + +}; + + +#define QQmlExtensionInterface_iid "org.qt-project.Qt.QQmlExtensionInterface" + + +#include "imageprovider.moc" diff --git a/tests/manual/highdpi/imageprovider.qml b/tests/manual/highdpi/imageprovider.qml new file mode 100644 index 0000000000..8125d774ad --- /dev/null +++ b/tests/manual/highdpi/imageprovider.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "ImageProvider" + +Rectangle { + width: 400 + height: 400 + + Row { + // should render a sharp image on high-dpi displays. sourceSize is in device-independent + // pixels; the image provider will be asked to create a 400x400 device pixel image. + Image { + sourceSize.width: 200 + sourceSize.height: 200 + source: "image://colors/green" + } + + // should NOT render a sharp image on retina displays. sourceSize is omitted and + // the image provider default size will be used (in this case 50x50). + Image { + width : 200 + height : 200 + source : "image://colors/red" + } + + } +} diff --git a/tests/manual/highdpi/svg.qml b/tests/manual/highdpi/svg.qml new file mode 100644 index 0000000000..ed2444d4da --- /dev/null +++ b/tests/manual/highdpi/svg.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + + Row { + Column { + // should render a sharp image on retina displays: (sourceSize is in device-independent pixels) + Image { + sourceSize.width: 100 + sourceSize.height: 100 + source : "heart.svg" + } + + // should render a sharp image on retina displays: if sourceSize is omitted + // the svg viewBox size will be used; in this case 550x500 + Image { + width : 100 + height : 100 + source : "heart.svg" + } + } + + // should render a sharp image on retina displays: (sourceSize is in device-independent pixels) + Image { + sourceSize.width: 700 + sourceSize.height: 700 + source : "heart.svg" + } + + // should NOT render a sharp image on retina displays: if sourceSize is omitted + // the svg viewBox size will be used; in this case 550x500 + Image { + width : 700 + height : 700 + source : "heart.svg" + } + } +} -- cgit v1.2.3