diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2015-01-15 13:38:40 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@theqtcompany.com> | 2015-02-13 19:22:39 +0000 |
commit | 428b92583ee2102c7ef16776a9b7785df7ff4e2c (patch) | |
tree | c04e51093d4eb31ea248a035deb52c66d265a576 /tests/manual/highdpi | |
parent | 5b31071e56ef6e241e27b66ff91f4e9222f2cddb (diff) |
High-dpi SVG and QQuickImageProvider Images
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 <jturcotte@woboq.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Diffstat (limited to 'tests/manual/highdpi')
-rw-r--r-- | tests/manual/highdpi/ImageProvider/qmldir | 1 | ||||
-rw-r--r-- | tests/manual/highdpi/heart.svg | 55 | ||||
-rw-r--r-- | tests/manual/highdpi/highdpi.pro | 13 | ||||
-rw-r--r-- | tests/manual/highdpi/highdpi.qmlproject | 14 | ||||
-rw-r--r-- | tests/manual/highdpi/imageprovider.cpp | 101 | ||||
-rw-r--r-- | tests/manual/highdpi/imageprovider.qml | 59 | ||||
-rw-r--r-- | tests/manual/highdpi/svg.qml | 73 |
7 files changed, 316 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --><svg viewBox="100 200 550 500" height="841.88976pt" id="svg1" inkscape:version="0.40+cvs" sodipodi:docbase="C:\Documents and Settings\Jon Phillips\My Documents\projects\clipart-project\submissions" sodipodi:docname="heart-left-highlight.svg" sodipodi:version="0.32" width="595.27559pt" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg"> +<metadata> +<rdf:RDF xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> +<cc:Work rdf:about=""> +<dc:title>Heart Left-Highlight</dc:title> +<dc:description>This is a normal valentines day heart.</dc:description> +<dc:subject> +<rdf:Bag> +<rdf:li>holiday</rdf:li> +<rdf:li>valentines</rdf:li> +<rdf:li></rdf:li> +<rdf:li>valentine</rdf:li> +<rdf:li>hash(0x8a091c0)</rdf:li> +<rdf:li>hash(0x8a0916c)</rdf:li> +<rdf:li>signs_and_symbols</rdf:li> +<rdf:li>hash(0x8a091f0)</rdf:li> +<rdf:li>day</rdf:li> +</rdf:Bag> +</dc:subject> +<dc:publisher> +<cc:Agent rdf:about="http://www.openclipart.org"> +<dc:title>Jon Phillips</dc:title> +</cc:Agent> +</dc:publisher> +<dc:creator> +<cc:Agent> +<dc:title>Jon Phillips</dc:title> +</cc:Agent> +</dc:creator> +<dc:rights> +<cc:Agent> +<dc:title>Jon Phillips</dc:title> +</cc:Agent> +</dc:rights> +<dc:date></dc:date> +<dc:format>image/svg+xml</dc:format> +<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> +<cc:license rdf:resource="http://web.resource.org/cc/PublicDomain"/> +<dc:language>en</dc:language> +</cc:Work> +<cc:License rdf:about="http://web.resource.org/cc/PublicDomain"> +<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/> +<cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/> +<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/> +</cc:License> +</rdf:RDF> +</metadata> +<defs id="defs3"/> +<sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="549.40674" inkscape:cy="596.00159" inkscape:document-units="px" inkscape:guide-bbox="true" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="615" inkscape:window-width="866" inkscape:window-x="88" inkscape:window-y="116" inkscape:zoom="0.35000000" pagecolor="#ffffff" showguides="true"/> +<g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1"> +<path d="M 263.41570,235.14588 C 197.17570,235.14588 143.41575,288.90587 143.41575,355.14588 C 143.41575,489.90139 279.34890,525.23318 371.97820,658.45392 C 459.55244,526.05056 600.54070,485.59932 600.54070,355.14588 C 600.54070,288.90588 546.78080,235.14587 480.54070,235.14588 C 432.49280,235.14588 391.13910,263.51631 371.97820,304.33338 C 352.81740,263.51630 311.46370,235.14587 263.41570,235.14588 z " id="path7" sodipodi:nodetypes="ccccccc" style="fill:#e60000;fill-opacity:1.0000000;stroke:#000000;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/> +<path d="M 265.00000,253.59375 C 207.04033,253.59375 160.00000,300.63407 160.00000,358.59375 C 160.00000,476.50415 278.91857,507.43251 359.96875,624.00000 C 366.52868,614.08205 220.00000,478.47309 220.00000,378.59375 C 220.00000,320.63407 267.04033,273.59375 325.00000,273.59375 C 325.50453,273.59375 325.99718,273.64912 326.50000,273.65625 C 309.22436,261.07286 288.00557,253.59374 265.00000,253.59375 z " id="path220" sodipodi:nodetypes="ccccccc" style="fill:#e6e6e6;fill-opacity:0.64556962;stroke:none;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/> +</g> +</svg> 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 <qqmlextensionplugin.h> + +#include <qqmlengine.h> +#include <qquickimageprovider.h> +#include <QImage> +#include <QPainter> +#include <qDebug.h> + +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" + } + } +} |