From 5f828705bd694e71f6971f9e441cd6107ecb8130 Mon Sep 17 00:00:00 2001 From: Kavindra Palaraja Date: Fri, 6 Jan 2017 23:29:43 +0100 Subject: Remove documentation references to internal functions QSGOpacityNode::combinedOpacity() and QSGTransformNode::combinedMatrix() are intended to be internal. Task-number: QTBUG-53897 Change-Id: Icc73476eb8af5cdc673f7ce9bacd25ecc75202b5 Reviewed-by: Robin Burchell Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/coreapi/qsgnode.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/coreapi/qsgnode.cpp b/src/quick/scenegraph/coreapi/qsgnode.cpp index a1e1ef8c27..7ef75d4b4c 100644 --- a/src/quick/scenegraph/coreapi/qsgnode.cpp +++ b/src/quick/scenegraph/coreapi/qsgnode.cpp @@ -337,13 +337,6 @@ QSGNode::~QSGNode() to the scene graph and will cause the preprocess() function to be called for every frame the node is rendered. - The preprocess function is called before the update pass that propagates - opacity and transformations through the scene graph. That means that - functions like QSGOpacityNode::combinedOpacity() and - QSGTransformNode::combinedMatrix() will not contain up-to-date values. - If such values are changed during the preprocess, these changes will be - propagated through the scene graph before it is rendered. - \warning Beware of deleting nodes while they are being preprocessed. It is possible, with a small performance hit, to delete a single node during its own preprocess call. Deleting a subtree which has nodes that also use -- cgit v1.2.3 From ec5f3fa6b7ddf0ed80801f70add90444f3714593 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Fri, 13 Jan 2017 17:41:34 +0900 Subject: Fix build without feature.shortcut Change-Id: Id0ea0037db4cc3878ae2f75109aa3a7daa120189 Reviewed-by: Lars Knoll --- src/quick/items/qquickevents_p_p.h | 2 ++ src/quick/util/qquickutilmodule.cpp | 9 ++++++++- src/quick/util/util.pri | 9 +++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h index 7b281623fe..cf6f83e5b1 100644 --- a/src/quick/items/qquickevents_p_p.h +++ b/src/quick/items/qquickevents_p_p.h @@ -108,7 +108,9 @@ public: bool isAccepted() { return event.isAccepted(); } void setAccepted(bool accepted) { event.setAccepted(accepted); } +#if QT_CONFIG(shortcut) Q_REVISION(2) Q_INVOKABLE bool matches(QKeySequence::StandardKey key) const { return event.matches(key); } +#endif private: QKeyEvent event; diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp index c1bc3d60b8..5728ad608e 100644 --- a/src/quick/util/qquickutilmodule.cpp +++ b/src/quick/util/qquickutilmodule.cpp @@ -54,7 +54,9 @@ #include "qquicktextmetrics_p.h" #include "qquicktransition_p.h" #include "qquickanimator_p.h" +#if QT_CONFIG(shortcut) #include "qquickshortcut_p.h" +#endif #include "qquickvalidator_p.h" #include #include @@ -63,7 +65,9 @@ #include #include +#if QT_CONFIG(shortcut) Q_DECLARE_METATYPE(QKeySequence::StandardKey) +#endif void QQuickUtilModule::defineModule() { @@ -114,13 +118,16 @@ void QQuickUtilModule::defineModule() qmlRegisterCustomType("QtQuick",2,0,"PropertyChanges", new QQuickPropertyChangesParser); +#if QT_CONFIG(shortcut) qRegisterMetaType(); qmlRegisterUncreatableType("QtQuick", 2, 2, "StandardKey", QStringLiteral("Cannot create an instance of StandardKey.")); +#endif qmlRegisterType("QtQuick", 2, 4, "FontMetrics"); qmlRegisterType("QtQuick", 2, 4, "TextMetrics"); +#if QT_CONFIG(shortcut) qmlRegisterType("QtQuick", 2, 5, "Shortcut"); - qmlRegisterType("QtQuick", 2, 6, "Shortcut"); +#endif } diff --git a/src/quick/util/util.pri b/src/quick/util/util.pri index 1ef1018a31..b53b132cce 100644 --- a/src/quick/util/util.pri +++ b/src/quick/util/util.pri @@ -26,7 +26,6 @@ SOURCES += \ $$PWD/qquickanimatorcontroller.cpp \ $$PWD/qquickfontmetrics.cpp \ $$PWD/qquicktextmetrics.cpp \ - $$PWD/qquickshortcut.cpp \ $$PWD/qquickvalidator.cpp !contains(QT_CONFIG, no-qml-debug): SOURCES += $$PWD/qquickprofiler.cpp @@ -63,9 +62,15 @@ HEADERS += \ $$PWD/qquickprofiler_p.h \ $$PWD/qquickfontmetrics_p.h \ $$PWD/qquicktextmetrics_p.h \ - $$PWD/qquickshortcut_p.h \ $$PWD/qquickvalidator_p.h +qtConfig(shortcut) { + SOURCES += \ + $$PWD/qquickshortcut.cpp + HEADERS += \ + $$PWD/qquickshortcut_p.h +} + qtConfig(quick-path) { SOURCES += \ $$PWD/qquickpath.cpp \ -- cgit v1.2.3 From 5ef3265cd46de6579399562429e26961d6f13885 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Sun, 22 Jan 2017 20:22:14 +0100 Subject: Add anisotropic filtering support to QSGTexture This patch adds support to switch on anisotropic filtering on QSGTexture and to QSGDefaultImageNode. Not adding this support to QSGImageNode since it became public in 5.8, and it does not allow additional virtual methods anymore. Change-Id: Ibf1744845df2297f9129b1b5ce6a69d0a3b31c7c Reviewed-by: Andy Nichols Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/util/qsgdefaultimagenode.cpp | 15 +++++++ src/quick/scenegraph/util/qsgdefaultimagenode_p.h | 4 ++ src/quick/scenegraph/util/qsgimagenode.h | 2 + src/quick/scenegraph/util/qsgtexture.cpp | 53 +++++++++++++++++++++++ src/quick/scenegraph/util/qsgtexture.h | 11 +++++ src/quick/scenegraph/util/qsgtexture_p.h | 2 + src/quick/scenegraph/util/qsgtexturematerial.cpp | 2 + src/quick/scenegraph/util/qsgtexturematerial.h | 7 ++- 8 files changed, 94 insertions(+), 2 deletions(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp index 63773887a0..7186ee4265 100644 --- a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp +++ b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp @@ -94,6 +94,21 @@ QSGTexture::Filtering QSGDefaultImageNode::mipmapFiltering() const return m_material.mipmapFiltering(); } +void QSGDefaultImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel level) +{ + if (m_material.anisotropyLevel() == level) + return; + + m_material.setAnisotropyLevel(level); + m_opaque_material.setAnisotropyLevel(level); + markDirty(DirtyMaterial); +} + +QSGTexture::AnisotropyLevel QSGDefaultImageNode::anisotropyLevel() const +{ + return m_material.anisotropyLevel(); +} + void QSGDefaultImageNode::setRect(const QRectF &r) { if (m_rect == r) diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h index bb9ebec885..cb23e759d3 100644 --- a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h +++ b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h @@ -85,6 +85,10 @@ public: void setOwnsTexture(bool owns) override; bool ownsTexture() const override; + // QSGImageNode now being a public class does not allow any additional virtual methods. Placing these here, non-virtual. + void setAnisotropyLevel(QSGTexture::AnisotropyLevel level); + QSGTexture::AnisotropyLevel anisotropyLevel() const; + private: QSGGeometry m_geometry; QSGOpaqueTextureMaterial m_opaque_material; diff --git a/src/quick/scenegraph/util/qsgimagenode.h b/src/quick/scenegraph/util/qsgimagenode.h index d25e732e4b..0e053c307f 100644 --- a/src/quick/scenegraph/util/qsgimagenode.h +++ b/src/quick/scenegraph/util/qsgimagenode.h @@ -67,6 +67,8 @@ public: virtual void setMipmapFiltering(QSGTexture::Filtering filtering) = 0; virtual QSGTexture::Filtering mipmapFiltering() const = 0; + // ### Qt6: Add anisotropy support here, and possibly a virtual hook or another mean to extend this class. + enum TextureCoordinatesTransformFlag { NoTransform = 0x00, MirrorHorizontally = 0x01, diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp index 47248f2f37..bc59c49162 100644 --- a/src/quick/scenegraph/util/qsgtexture.cpp +++ b/src/quick/scenegraph/util/qsgtexture.cpp @@ -83,6 +83,9 @@ static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK" #define GL_BGRA 0x80E1 #endif +#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#endif QT_BEGIN_NAMESPACE @@ -97,10 +100,12 @@ inline static bool isPowerOfTwo(int x) QSGTexturePrivate::QSGTexturePrivate() : wrapChanged(false) , filteringChanged(false) + , anisotropyChanged(false) , horizontalWrap(QSGTexture::ClampToEdge) , verticalWrap(QSGTexture::ClampToEdge) , mipmapMode(QSGTexture::None) , filterMode(QSGTexture::Nearest) + , anisotropyLevel(QSGTexture::AnisotropyNone) { } @@ -273,6 +278,23 @@ static void qt_debug_remove_texture(QSGTexture* texture) neighboring texels. */ +/*! + \enum QSGTexture::AnisotropyLevel + + Specifies the anisotropic filtering level to be used when + the texture is not screen aligned. + + \value AnisotropyNone No anisotropic filtering. + + \value Anisotropy2x 2x anisotropic filtering. + + \value Anisotropy4x 4x anisotropic filtering. + + \value Anisotropy8x 8x anisotropic filtering. + + \value Anisotropy16x 16x anisotropic filtering. +*/ + /*! \fn QSGTexture::QSGTexture(QSGTexturePrivate &dd) \internal @@ -472,6 +494,31 @@ QSGTexture::Filtering QSGTexture::filtering() const return (QSGTexture::Filtering) d_func()->filterMode; } +/*! + Sets the level of anisotropic filtering to be used for the upcoming bind() call to \a level. + The default value is QSGTexture::AnisotropyNone, which means no anisotropic filtering is enabled. + + \since 5.9 + */ +void QSGTexture::setAnisotropyLevel(AnisotropyLevel level) +{ + Q_D(QSGTexture); + if (d->anisotropyLevel != (uint) level) { + d->anisotropyLevel = level; + d->anisotropyChanged = true; + } +} + +/*! + Returns the anisotropy level in use for filtering this texture. + + \since 5.9 + */ +QSGTexture::AnisotropyLevel QSGTexture::anisotropyLevel() const +{ + return (QSGTexture::AnisotropyLevel) d_func()->anisotropyLevel; +} + /*! @@ -548,6 +595,12 @@ void QSGTexture::updateBindOptions(bool force) d->filteringChanged = false; } + if (force || d->anisotropyChanged) { + d->anisotropyChanged = false; + if (QOpenGLContext::currentContext()->hasExtension(QByteArrayLiteral("GL_EXT_texture_filter_anisotropic"))) + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, float(1 << (d->anisotropyLevel))); + } + if (force || d->wrapChanged) { #ifndef QT_NO_DEBUG if (d->horizontalWrap == Repeat || d->verticalWrap == Repeat) { diff --git a/src/quick/scenegraph/util/qsgtexture.h b/src/quick/scenegraph/util/qsgtexture.h index f0509b58ae..035acc02b1 100644 --- a/src/quick/scenegraph/util/qsgtexture.h +++ b/src/quick/scenegraph/util/qsgtexture.h @@ -67,6 +67,14 @@ public: Linear }; + enum AnisotropyLevel { + AnisotropyNone, + Anisotropy2x, + Anisotropy4x, + Anisotropy8x, + Anisotropy16x + }; + virtual int textureId() const = 0; virtual QSize textureSize() const = 0; virtual bool hasAlphaChannel() const = 0; @@ -87,6 +95,9 @@ public: void setFiltering(Filtering filter); QSGTexture::Filtering filtering() const; + void setAnisotropyLevel(AnisotropyLevel level); + QSGTexture::AnisotropyLevel anisotropyLevel() const; + void setHorizontalWrapMode(WrapMode hwrap); QSGTexture::WrapMode horizontalWrapMode() const; diff --git a/src/quick/scenegraph/util/qsgtexture_p.h b/src/quick/scenegraph/util/qsgtexture_p.h index b6fcfc31c4..36f9b802ba 100644 --- a/src/quick/scenegraph/util/qsgtexture_p.h +++ b/src/quick/scenegraph/util/qsgtexture_p.h @@ -69,11 +69,13 @@ public: uint wrapChanged : 1; uint filteringChanged : 1; + uint anisotropyChanged : 1; uint horizontalWrap : 1; uint verticalWrap : 1; uint mipmapMode : 2; uint filterMode : 2; + uint anisotropyLevel: 3; }; class Q_QUICK_PRIVATE_EXPORT QSGPlainTexture : public QSGTexture diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp index 9326ea640d..c536445e82 100644 --- a/src/quick/scenegraph/util/qsgtexturematerial.cpp +++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp @@ -110,6 +110,7 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa Q_UNUSED(state) #endif t->setMipmapFiltering(tx->mipmapFiltering()); + t->setAnisotropyLevel(tx->anisotropyLevel()); if (oldTx == 0 || oldTx->texture()->textureId() != t->textureId()) t->bind(); @@ -173,6 +174,7 @@ QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial() , m_mipmap_filtering(QSGTexture::None) , m_horizontal_wrap(QSGTexture::ClampToEdge) , m_vertical_wrap(QSGTexture::ClampToEdge) + , m_anisotropy_level(QSGTexture::AnisotropyNone) { } diff --git a/src/quick/scenegraph/util/qsgtexturematerial.h b/src/quick/scenegraph/util/qsgtexturematerial.h index dc87131773..87d8e5fd49 100644 --- a/src/quick/scenegraph/util/qsgtexturematerial.h +++ b/src/quick/scenegraph/util/qsgtexturematerial.h @@ -69,6 +69,9 @@ public: void setVerticalWrapMode(QSGTexture::WrapMode mode) { m_vertical_wrap = mode; } QSGTexture::WrapMode verticalWrapMode() const { return QSGTexture::WrapMode(m_vertical_wrap); } + void setAnisotropyLevel(QSGTexture::AnisotropyLevel level) { m_anisotropy_level = level; } + QSGTexture::AnisotropyLevel anisotropyLevel() const { return QSGTexture::AnisotropyLevel(m_anisotropy_level); } + protected: QSGTexture *m_texture; @@ -76,8 +79,8 @@ protected: uint m_mipmap_filtering: 2; uint m_horizontal_wrap : 1; uint m_vertical_wrap: 1; - - uint m_reserved : 26; + uint m_anisotropy_level : 3; + uint m_reserved : 23; }; -- cgit v1.2.3 From 2c2e7f27426cb4381f2dcaa36affe55719619753 Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Mon, 14 Nov 2016 19:53:24 +0100 Subject: Use independent buffer for indices WebGL does not support using the same buffer for vertices and indices. Change-Id: I362e1cb8e10dc2b4b99f6ce7161c4e3ce8a6f707 Reviewed-by: Laszlo Agocs --- src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h | 9 +-------- src/quick/scenegraph/scenegraph.pri | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 322192944b..2c0f8667e8 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -440,9 +440,7 @@ struct Batch mutable uint uploadedThisFrame : 1; // solely for debugging purposes Buffer vbo; -#ifdef QSG_SEPARATE_INDEX_BUFFER Buffer ibo; -#endif QDataBuffer drawSets; }; @@ -744,9 +742,7 @@ private: ClipType m_currentClipType; QDataBuffer m_vertexUploadPool; -#ifdef QSG_SEPARATE_INDEX_BUFFER QDataBuffer m_indexUploadPool; -#endif // For minimal OpenGL core profile support QOpenGLVertexArrayObject *m_vao; @@ -766,10 +762,7 @@ Batch *Renderer::newBatch() m_batchPool.resize(size - 1); } else { b = new Batch(); - memset(&b->vbo, 0, sizeof(Buffer)); -#ifdef QSG_SEPARATE_INDEX_BUFFER - memset(&b->ibo, 0, sizeof(Buffer)); -#endif + memset(&b->vbo, 0, sizeof(Buffer) * 2); // Clear VBO & IBO } b->init(); return b; diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri index edf4aa08c5..38c3b8dd85 100644 --- a/src/quick/scenegraph/scenegraph.pri +++ b/src/quick/scenegraph/scenegraph.pri @@ -1,4 +1,4 @@ -# DEFINES += QSG_SEPARATE_INDEX_BUFFER +DEFINES += QSG_SEPARATE_INDEX_BUFFER # DEFINES += QSG_DISTANCEFIELD_CACHE_DEBUG # Core API -- cgit v1.2.3 From d0649a1b457f321cfafee1aaf443543fd11a7112 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 9 Jan 2017 15:22:22 +0100 Subject: Make Item::grabToImage work in more cases, and improve test coverage This fixes a regression caused by 9c50216c7bbbdb2bb51d4485286bf09e12fb5b62 when the Image specified fillMode: aspectRatioCrop/Fit. [ChangeLog][QtQuick][Image] Item::grabToImage on an Image element will now work regardless of the Image's sourceSize or cache properties. Change-Id: I225854c48f0c35a3cb2ef0dd56bf51bd88c31779 Reviewed-by: Robin Burchell --- src/quick/items/qquickitemgrabresult.cpp | 2 +- src/quick/util/qquickpixmapcache.cpp | 12 ++++++++++-- src/quick/util/qquickpixmapcache_p.h | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickitemgrabresult.cpp b/src/quick/items/qquickitemgrabresult.cpp index 07c2cb607c..12bcd43076 100644 --- a/src/quick/items/qquickitemgrabresult.cpp +++ b/src/quick/items/qquickitemgrabresult.cpp @@ -75,7 +75,7 @@ public: void ensureImageInCache() const { if (url.isEmpty() && !image.isNull()) { - url.setScheme(QStringLiteral("ItemGrabber")); + url.setScheme(QQuickPixmap::itemGrabberScheme); url.setPath(QVariant::fromValue(item.data()).toString()); static uint counter = 0; url.setFragment(QString::number(++counter)); diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 1c6b2afb54..be6d4d18bd 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -84,6 +84,7 @@ QT_BEGIN_NAMESPACE +const QLatin1String QQuickPixmap::itemGrabberScheme = QLatin1String("itemgrabber"); #ifndef QT_NO_DEBUG static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK"); @@ -1462,8 +1463,15 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques QHash::Iterator iter = store->m_cache.end(); // If Cache is disabled, the pixmap will always be loaded, even if there is an existing - // cached version. - if (options & QQuickPixmap::Cache) + // cached version. Unless it's an itemgrabber url, since the cache is used to pass + // the result between QQuickItemGrabResult and QQuickImage. + if (url.scheme() == itemGrabberScheme) { + QSize dummy; + if (requestSize != dummy) + qWarning() << "Ignoring sourceSize request for image url that came from grabToImage. Use the targetSize parameter of the grabToImage() function instead."; + const QQuickPixmapKey grabberKey = { &url, &dummy, QQuickImageProviderOptions() }; + iter = store->m_cache.find(grabberKey); + } else if (options & QQuickPixmap::Cache) iter = store->m_cache.find(key); if (iter == store->m_cache.end()) { diff --git a/src/quick/util/qquickpixmapcache_p.h b/src/quick/util/qquickpixmapcache_p.h index f7cdfa7d07..a867771755 100644 --- a/src/quick/util/qquickpixmapcache_p.h +++ b/src/quick/util/qquickpixmapcache_p.h @@ -177,6 +177,8 @@ public: static void purgeCache(); static bool isCached(const QUrl &url, const QSize &requestSize); + static const QLatin1String itemGrabberScheme; + private: Q_DISABLE_COPY(QQuickPixmap) QQuickPixmapData *d; -- cgit v1.2.3 From 7900e74edd42bdd7ee3ecf78be656dd8d3211607 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 26 Jan 2017 11:37:44 +0100 Subject: QQuickWindow FBO: fix dpr and rect when there is an actual window QQuickWidget is the primary example of a third case of rendering with QQuickWindow: here the content goes to an FBO via the rendercontrol, but there is still a window associated (the top-level widget's window) in a way, and therefore the devicePixelRatio must be taken into account. This amends ab54d0cab57121055914ff9a750f5ad975fe7525 Task-number: QTBUG-58442 Change-Id: Ic90147646aa9bd9c1fc6a3492ae8c3087a12832b Reviewed-by: Friedemann Kleint Reviewed-by: Alessandro Portale Reviewed-by: Gunnar Sletta --- src/quick/items/qquickwindow.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 660c5f8067..0e7c50ffcf 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -453,8 +453,13 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size) fboId = renderTargetId; renderer->setDeviceRect(rect); renderer->setViewportRect(rect); - renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), rect.size())); - renderer->setDevicePixelRatio(1); + if (QQuickRenderControl::renderWindowFor(q)) { + renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size)); + renderer->setDevicePixelRatio(devicePixelRatio); + } else { + renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), rect.size())); + renderer->setDevicePixelRatio(1); + } } else { QRect rect(QPoint(0, 0), devicePixelRatio * size); renderer->setDeviceRect(rect); -- cgit v1.2.3 From 659d5202f915b84bd22b618b0696bbe68ab4b6b0 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 30 Jan 2017 20:09:23 +0100 Subject: Add fontInfo property to Text This provides a way to determine which font will actually be used to presenting the text, which can be especially useful when not using a fixed size font (the font info will then expose the actual font size used by the Text element.) [ChangeLog][QtQuick][Text] Added fontInfo property to Text type, providing a way to query properties of the actual font used for presenting the text. Task-number: QTBUG-51133 Change-Id: I5860fb1bd25ac5734713f49c8482428f2d531d22 Reviewed-by: Simon Hausmann Reviewed-by: Robin Burchell --- src/quick/items/qquicktext.cpp | 89 +++++++++++++++++++++++++++++++++++++++- src/quick/items/qquicktext_p.h | 5 +++ src/quick/items/qquicktext_p_p.h | 1 + 3 files changed, 94 insertions(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 965fb0102f..1720377046 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -74,7 +74,7 @@ Q_DECLARE_LOGGING_CATEGORY(DBG_HOVER_TRACE) const QChar QQuickTextPrivate::elideChar = QChar(0x2026); QQuickTextPrivate::QQuickTextPrivate() - : elideLayout(0), textLine(0), lineWidth(0) + : fontInfo(font), elideLayout(0), textLine(0), lineWidth(0) , color(0xFF000000), linkColor(0xFF0000FF), styleColor(0xFF000000) , lineCount(1), multilengthEos(-1) , elideMode(QQuickText::ElideNone), hAlign(QQuickText::AlignLeft), vAlign(QQuickText::AlignTop) @@ -1018,6 +1018,17 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) implicitWidthValid = true; implicitHeightValid = true; + QFontInfo scaledFontInfo(scaledFont); + if (fontInfo.weight() != scaledFontInfo.weight() + || fontInfo.pixelSize() != scaledFontInfo.pixelSize() + || fontInfo.italic() != scaledFontInfo.italic() + || !qFuzzyCompare(fontInfo.pointSizeF(), scaledFontInfo.pointSizeF()) + || fontInfo.family() != scaledFontInfo.family() + || fontInfo.styleName() != scaledFontInfo.styleName()) { + fontInfo = scaledFontInfo; + emit q->fontInfoChanged(); + } + if (eos != multilengthEos) truncated = true; @@ -2974,4 +2985,80 @@ void QQuickText::resetBottomPadding() d->setBottomPadding(0, true); } +/*! + \qmlproperty string QtQuick::Text::fontInfo.family + \since 5.9 + + The family name of the font that has been resolved for the current font + and fontSizeMode. +*/ + +/*! + \qmlproperty string QtQuick::Text::fontInfo.styleName + \since 5.9 + + The style name of the font info that has been resolved for the current font + and fontSizeMode. +*/ + +/*! + \qmlproperty bool QtQuick::Text::fontInfo.bold + \since 5.9 + + The bold state of the font info that has been resolved for the current font + and fontSizeMode. This is true if the weight of the resolved font is bold or higher. +*/ + +/*! + \qmlproperty int QtQuick::Text::fontInfo.weight + \since 5.9 + + The weight of the font info that has been resolved for the current font + and fontSizeMode. +*/ + +/*! + \qmlproperty bool QtQuick::Text::fontInfo.italic + \since 5.9 + + The italic state of the font info that has been resolved for the current font + and fontSizeMode. +*/ + +/*! + \qmlproperty real QtQuick::Text::fontInfo.pointSize + \since 5.9 + + The pointSize of the font info that has been resolved for the current font + and fontSizeMode. +*/ + +/*! + \qmlproperty string QtQuick::Text::fontInfo.pixelSize + \since 5.9 + + The pixel size of the font info that has been resolved for the current font + and fontSizeMode. +*/ +QJSValue QQuickText::fontInfo() const +{ + Q_D(const QQuickText); + + QJSEngine *engine = qjsEngine(this); + if (!engine) { + qmlWarning(this) << "fontInfo: item has no JS engine"; + return QJSValue(); + } + + QJSValue value = engine->newObject(); + value.setProperty(QStringLiteral("family"), d->fontInfo.family()); + value.setProperty(QStringLiteral("styleName"), d->fontInfo.styleName()); + value.setProperty(QStringLiteral("bold"), d->fontInfo.bold()); + value.setProperty(QStringLiteral("weight"), d->fontInfo.weight()); + value.setProperty(QStringLiteral("italic"), d->fontInfo.italic()); + value.setProperty(QStringLiteral("pointSize"), d->fontInfo.pointSizeF()); + value.setProperty(QStringLiteral("pixelSize"), d->fontInfo.pixelSize()); + return value; +} + QT_END_NAMESPACE diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h index c3d3906e7e..b190738cfb 100644 --- a/src/quick/items/qquicktext_p.h +++ b/src/quick/items/qquicktext_p.h @@ -98,6 +98,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION 6) Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION 6) + Q_PROPERTY(QJSValue fontInfo READ fontInfo NOTIFY fontInfoChanged REVISION 9) + public: QQuickText(QQuickItem *parent=0); ~QQuickText(); @@ -248,6 +250,8 @@ public: void setBottomPadding(qreal padding); void resetBottomPadding(); + QJSValue fontInfo() const; + Q_SIGNALS: void textChanged(const QString &text); void linkActivated(const QString &link); @@ -280,6 +284,7 @@ Q_SIGNALS: Q_REVISION(6) void leftPaddingChanged(); Q_REVISION(6) void rightPaddingChanged(); Q_REVISION(6) void bottomPaddingChanged(); + Q_REVISION(9) void fontInfoChanged(); protected: QQuickText(QQuickTextPrivate &dd, QQuickItem *parent = 0); diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h index 0669bcf115..6456750359 100644 --- a/src/quick/items/qquicktext_p_p.h +++ b/src/quick/items/qquicktext_p_p.h @@ -122,6 +122,7 @@ public: QString text; QFont font; QFont sourceFont; + QFontInfo fontInfo; QTextLayout layout; QTextLayout *elideLayout; -- cgit v1.2.3 From a92950743f6589ccdce02ec65c0d6e626ccee211 Mon Sep 17 00:00:00 2001 From: Kimmo Ollila Date: Thu, 26 Jan 2017 12:46:16 +0200 Subject: Add fixes for INTEGRITY Full definitions of types are needed in static_casts. Change-Id: I028ffc40a76cdb16cb297a181b3d9dfe9d09c945 Reviewed-by: Simon Hausmann --- src/quick/scenegraph/qsgcontext_p.h | 98 ++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h index 6b9db105e7..2f5d5790ee 100644 --- a/src/quick/scenegraph/qsgcontext_p.h +++ b/src/quick/scenegraph/qsgcontext_p.h @@ -88,6 +88,7 @@ class QSGRectangleNode; class QSGImageNode; class QSGNinePatchNode; class QSGSpriteNode; +class QSGRenderContext; Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERLOOP) Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_COMPILATION) @@ -98,6 +99,54 @@ Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERER) Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_INFO) Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_RENDERLOOP) +class Q_QUICK_PRIVATE_EXPORT QSGContext : public QObject +{ + Q_OBJECT + +public: + enum AntialiasingMethod { + UndecidedAntialiasing, + VertexAntialiasing, + MsaaAntialiasing + }; + + explicit QSGContext(QObject *parent = 0); + virtual ~QSGContext(); + + virtual void renderContextInitialized(QSGRenderContext *renderContext); + virtual void renderContextInvalidated(QSGRenderContext *renderContext); + virtual QSGRenderContext *createRenderContext() = 0; + + QSGInternalRectangleNode *createInternalRectangleNode(const QRectF &rect, const QColor &c); + virtual QSGInternalRectangleNode *createInternalRectangleNode() = 0; + virtual QSGInternalImageNode *createInternalImageNode() = 0; + virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item) = 0; + virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) = 0; + virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0; + virtual QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager(); + virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext, + QSGGuiThreadShaderEffectManager *mgr); +#if QT_CONFIG(quick_sprite) + virtual QSGSpriteNode *createSpriteNode() = 0; +#endif + virtual QAnimationDriver *createAnimationDriver(QObject *parent); + + virtual QSize minimumFBOSize() const; + virtual QSurfaceFormat defaultSurfaceFormat() const = 0; + + virtual QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext); + + virtual QSGRectangleNode *createRectangleNode() = 0; + virtual QSGImageNode *createImageNode() = 0; + virtual QSGNinePatchNode *createNinePatchNode() = 0; + + static QSGContext *createDefaultContext(); + static QQuickTextureFactory *createTextureFactoryFromImage(const QImage &image); + static QSGRenderLoop *createWindowManager(); + + static void setBackend(const QString &backend); +}; + class Q_QUICK_PRIVATE_EXPORT QSGRenderContext : public QObject { Q_OBJECT @@ -150,55 +199,6 @@ protected: QSet m_fontEnginesToClean; }; - -class Q_QUICK_PRIVATE_EXPORT QSGContext : public QObject -{ - Q_OBJECT - -public: - enum AntialiasingMethod { - UndecidedAntialiasing, - VertexAntialiasing, - MsaaAntialiasing - }; - - explicit QSGContext(QObject *parent = 0); - virtual ~QSGContext(); - - virtual void renderContextInitialized(QSGRenderContext *renderContext); - virtual void renderContextInvalidated(QSGRenderContext *renderContext); - virtual QSGRenderContext *createRenderContext() = 0; - - QSGInternalRectangleNode *createInternalRectangleNode(const QRectF &rect, const QColor &c); - virtual QSGInternalRectangleNode *createInternalRectangleNode() = 0; - virtual QSGInternalImageNode *createInternalImageNode() = 0; - virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item) = 0; - virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) = 0; - virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0; - virtual QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager(); - virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext, - QSGGuiThreadShaderEffectManager *mgr); -#if QT_CONFIG(quick_sprite) - virtual QSGSpriteNode *createSpriteNode() = 0; -#endif - virtual QAnimationDriver *createAnimationDriver(QObject *parent); - - virtual QSize minimumFBOSize() const; - virtual QSurfaceFormat defaultSurfaceFormat() const = 0; - - virtual QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext); - - virtual QSGRectangleNode *createRectangleNode() = 0; - virtual QSGImageNode *createImageNode() = 0; - virtual QSGNinePatchNode *createNinePatchNode() = 0; - - static QSGContext *createDefaultContext(); - static QQuickTextureFactory *createTextureFactoryFromImage(const QImage &image); - static QSGRenderLoop *createWindowManager(); - - static void setBackend(const QString &backend); -}; - QT_END_NAMESPACE #endif // QSGCONTEXT_H -- cgit v1.2.3 From b0ced704bcaeb6dc71622c9ce87b78f3b5bd827c Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Thu, 2 Feb 2017 14:22:08 +0100 Subject: Canvas Item: Prevent polish loop when calling requestAnimationFrame Currently if you call requestAnimationFrame within the callback given by requestAnimationFrame there is a polish loop. This is however the common way when using Canvas2D in the browser to get screen refresh rate animations. This patch makes sure that polish won't be called when processing polish items by calling polish indirectly. Task-number: QTBUG-55778 Change-Id: Ib96e39f7ca3cecc33609976e9049cc309768f9f7 Reviewed-by: Laszlo Agocs --- src/quick/items/context2d/qquickcanvasitem.cpp | 20 +++++++++++++++++++- src/quick/items/context2d/qquickcanvasitem_p.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp index b772ed97d2..1167f408f5 100644 --- a/src/quick/items/context2d/qquickcanvasitem.cpp +++ b/src/quick/items/context2d/qquickcanvasitem.cpp @@ -640,6 +640,17 @@ void QQuickCanvasItem::releaseResources() } } +bool QQuickCanvasItem::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::PolishRequest: + polish(); + return true; + default: + return QQuickItem::event(event); + } +} + void QQuickCanvasItem::invalidateSceneGraph() { Q_D(QQuickCanvasItem); @@ -651,6 +662,12 @@ void QQuickCanvasItem::invalidateSceneGraph() d->textureProvider = 0; } +void QQuickCanvasItem::schedulePolish() +{ + auto polishRequestEvent = new QEvent(QEvent::PolishRequest); + QCoreApplication::postEvent(this, polishRequestEvent); +} + void QQuickCanvasItem::componentComplete() { QQuickItem::componentComplete(); @@ -892,8 +909,9 @@ void QQuickCanvasItem::requestAnimationFrame(QQmlV4Function *args) d->animationCallbacks.insert(++id, QV4::PersistentValue(scope.engine, f->asReturnedValue())); + // QTBUG-55778: Calling polish directly here can lead to a polish loop if (isVisible()) - polish(); + schedulePolish(); args->setReturnValue(QV4::Encode(id)); } diff --git a/src/quick/items/context2d/qquickcanvasitem_p.h b/src/quick/items/context2d/qquickcanvasitem_p.h index 8af84d0e7c..217ae9bb69 100644 --- a/src/quick/items/context2d/qquickcanvasitem_p.h +++ b/src/quick/items/context2d/qquickcanvasitem_p.h @@ -182,6 +182,7 @@ private Q_SLOTS: void sceneGraphInitialized(); void checkAnimationCallbacks(); void invalidateSceneGraph(); + void schedulePolish(); protected: void componentComplete() Q_DECL_OVERRIDE; @@ -190,6 +191,7 @@ protected: QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; void releaseResources() Q_DECL_OVERRIDE; + bool event(QEvent *event) Q_DECL_OVERRIDE; private: Q_DECLARE_PRIVATE(QQuickCanvasItem) Q_INVOKABLE void delayedCreate(); -- cgit v1.2.3 From ecd4c83ef764f086f2e101b4201484f3d828c0e3 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 3 Feb 2017 10:10:52 +0100 Subject: Allow to pass all the relevant info to QQuickPixmap::isCached If we don't allow to pass the QQuickImageProviderOptions to the isCached we are missing one of the three components that identify if the pixmap is actually cached. Old code is ok for the QQuickAnimatedImagePrivate use case since it always creates QQuickPixmap with the default QQuickImageProviderOptions options, but if someone else wants to use QQuickPixmap::isCached they will need to be able to pass the options part of the cache key. Change-Id: I3153ad9ed30e7332b5cb4896dcebd408f2bd9afe Reviewed-by: Robin Burchell --- src/quick/items/qquickanimatedimage.cpp | 2 +- src/quick/util/qquickpixmapcache.cpp | 4 ++-- src/quick/util/qquickpixmapcache_p.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp index a1833081c8..22ea4774be 100644 --- a/src/quick/items/qquickanimatedimage.cpp +++ b/src/quick/items/qquickanimatedimage.cpp @@ -67,7 +67,7 @@ QQuickPixmap* QQuickAnimatedImagePrivate::infoForCurrentFrame(QQmlEngine *engine .arg(current)); } if (!requestedUrl.isEmpty()) { - if (QQuickPixmap::isCached(requestedUrl, QSize())) + if (QQuickPixmap::isCached(requestedUrl, QSize(), QQuickImageProviderOptions())) pixmap = new QQuickPixmap(engine, requestedUrl); else pixmap = new QQuickPixmap(requestedUrl, _movie->currentImage()); diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index be6d4d18bd..be27cba989 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -1541,9 +1541,9 @@ void QQuickPixmap::clear(QObject *obj) } } -bool QQuickPixmap::isCached(const QUrl &url, const QSize &requestSize) +bool QQuickPixmap::isCached(const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &options) { - QQuickPixmapKey key = { &url, &requestSize, QQuickImageProviderOptions() }; + QQuickPixmapKey key = { &url, &requestSize, options }; QQuickPixmapStore *store = pixmapStore(); return store->m_cache.contains(key); diff --git a/src/quick/util/qquickpixmapcache_p.h b/src/quick/util/qquickpixmapcache_p.h index a867771755..93d5a1cf56 100644 --- a/src/quick/util/qquickpixmapcache_p.h +++ b/src/quick/util/qquickpixmapcache_p.h @@ -175,7 +175,7 @@ public: bool connectDownloadProgress(QObject *, int); static void purgeCache(); - static bool isCached(const QUrl &url, const QSize &requestSize); + static bool isCached(const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &options); static const QLatin1String itemGrabberScheme; -- cgit v1.2.3 From 790cfb2bb26990c8345c860d6a23e4116df92f48 Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Mon, 30 Jan 2017 13:29:09 +0100 Subject: Doc: added doc for parameter window Undocumented parameter 'window' in QSGRendererInterface::getResource() Change-Id: I13cd520ad0b06abe1ad76be7aec83eae5c3e4d7c Reviewed-by: Martin Smith --- src/quick/scenegraph/coreapi/qsgrendererinterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp index 3b0b2faf97..0f49e615e4 100644 --- a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp +++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp @@ -127,7 +127,7 @@ QSGRendererInterface::~QSGRendererInterface() */ /*! - Queries a graphics \a resource. Returns null when the resource in question is + Queries a graphics \a resource in \a window. Returns null when the resource in question is not supported or not available. When successful, the returned pointer is either a direct pointer to an -- cgit v1.2.3 From 7af9656e789f4fa5073798581b858ae867585d79 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 3 Feb 2017 15:30:55 +0100 Subject: Privately expose QQuickImagePrivate The new private type QQuickIconImage in Controls 2 needs to derive from QQuickImage. Task-number: QTBUG-49820 Change-Id: Idb6f755eca8db52ab9211b0cd332ed3cf425d68c Reviewed-by: J-P Nurmi Reviewed-by: Shawn Rutledge --- src/quick/items/qquickimage_p_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickimage_p_p.h b/src/quick/items/qquickimage_p_p.h index 522dbca803..afc33def0f 100644 --- a/src/quick/items/qquickimage_p_p.h +++ b/src/quick/items/qquickimage_p_p.h @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE class QQuickImageTextureProvider; -class QQuickImagePrivate : public QQuickImageBasePrivate +class Q_QUICK_PRIVATE_EXPORT QQuickImagePrivate : public QQuickImageBasePrivate { Q_DECLARE_PUBLIC(QQuickImage) -- cgit v1.2.3 From eea43b5cc5aa6fab0d7523f92a83a5f75849782d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 7 Feb 2017 13:37:44 +0100 Subject: Fix a crash in canvas2d when calling some methods This fixes a regression introduced in change 4d23faf34192cef372f846dcf02fd8cc398b14c0, where some return values from functions weren't properly encoded as QV4::Value. Task-number: QTBUG-58683 Change-Id: I9dc5f1eb8f5779c58f8b062b9ae3d02284ab2678 Reviewed-by: Simon Hausmann Reviewed-by: J-P Nurmi --- src/quick/items/context2d/qquickcontext2d.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index b0c1d50907..e25cc5ccbe 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -1879,7 +1879,7 @@ void QQuickJSContext2D::method_get_lineWidth(const QV4::BuiltinFunction *, QV4:: QV4::Scoped r(scope, callData->thisObject); CHECK_CONTEXT(r) - RETURN_RESULT(r->d()->context->state.lineWidth); + RETURN_RESULT(QV4::Encode(r->d()->context->state.lineWidth)); } void QQuickJSContext2D::method_set_lineWidth(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) @@ -1906,7 +1906,7 @@ void QQuickJSContext2D::method_get_miterLimit(const QV4::BuiltinFunction *, QV4: QV4::Scoped r(scope, callData->thisObject); CHECK_CONTEXT(r) - RETURN_RESULT(r->d()->context->state.miterLimit); + RETURN_RESULT(QV4::Encode(r->d()->context->state.miterLimit)); } void QQuickJSContext2D::method_set_miterLimit(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) @@ -1933,7 +1933,7 @@ void QQuickJSContext2D::method_get_shadowBlur(const QV4::BuiltinFunction *, QV4: QV4::Scoped r(scope, callData->thisObject); CHECK_CONTEXT(r) - RETURN_RESULT(r->d()->context->state.shadowBlur); + RETURN_RESULT(QV4::Encode(r->d()->context->state.shadowBlur)); } void QQuickJSContext2D::method_set_shadowBlur(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) @@ -1990,7 +1990,7 @@ void QQuickJSContext2D::method_get_shadowOffsetX(const QV4::BuiltinFunction *, Q QV4::Scoped r(scope, callData->thisObject); CHECK_CONTEXT(r) - RETURN_RESULT(r->d()->context->state.shadowOffsetX); + RETURN_RESULT(QV4::Encode(r->d()->context->state.shadowOffsetX)); } void QQuickJSContext2D::method_set_shadowOffsetX(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) @@ -2016,7 +2016,7 @@ void QQuickJSContext2D::method_get_shadowOffsetY(const QV4::BuiltinFunction *, Q QV4::Scoped r(scope, callData->thisObject); CHECK_CONTEXT(r) - RETURN_RESULT(r->d()->context->state.shadowOffsetY); + RETURN_RESULT(QV4::Encode(r->d()->context->state.shadowOffsetY)); } void QQuickJSContext2D::method_set_shadowOffsetY(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) @@ -3043,7 +3043,7 @@ void QQuickJSContext2DPixelData::proto_get_length(const QV4::BuiltinFunction *, if (!r || r->d()->image->isNull()) RETURN_UNDEFINED(); - RETURN_RESULT(r->d()->image->width() * r->d()->image->height() * 4); + RETURN_RESULT(QV4::Encode(r->d()->image->width() * r->d()->image->height() * 4)); } QV4::ReturnedValue QQuickJSContext2DPixelData::getIndexed(const QV4::Managed *m, uint index, bool *hasProperty) -- cgit v1.2.3 From 5f83e6dfe698d65a0c145ccfd09c9f00609311ca Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Wed, 8 Feb 2017 22:57:11 +0100 Subject: Object: Allow put and putIndexed to return success or failure Some parts of the ES6 (and even ES5!) spec specifically require handling of a property write failure. This will be introduced in followup changes, as it's going to be rather more involved than this. Change-Id: Ie482493fcf4780df0e23619650a856421d20bd55 Reviewed-by: Simon Hausmann --- src/quick/items/context2d/qquickcontext2d.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index b0c1d50907..95fa0c530e 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -901,7 +901,7 @@ struct QQuickJSContext2DPixelData : public QV4::Object V4_NEEDS_DESTROY static QV4::ReturnedValue getIndexed(const QV4::Managed *m, uint index, bool *hasProperty); - static void putIndexed(QV4::Managed *m, uint index, const QV4::Value &value); + static bool putIndexed(QV4::Managed *m, uint index, const QV4::Value &value); static void proto_get_length(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); }; @@ -3077,13 +3077,13 @@ QV4::ReturnedValue QQuickJSContext2DPixelData::getIndexed(const QV4::Managed *m, return QV4::Encode::undefined(); } -void QQuickJSContext2DPixelData::putIndexed(QV4::Managed *m, uint index, const QV4::Value &value) +bool QQuickJSContext2DPixelData::putIndexed(QV4::Managed *m, uint index, const QV4::Value &value) { Q_ASSERT(m->as()); QV4::ExecutionEngine *v4 = static_cast(m)->engine(); QV4::Scope scope(v4); if (scope.hasException()) - return; + return false; QV4::Scoped r(scope, static_cast(m)); @@ -3109,7 +3109,10 @@ void QQuickJSContext2DPixelData::putIndexed(QV4::Managed *m, uint index, const Q *pixel = qRgba(qRed(*pixel), qGreen(*pixel), qBlue(*pixel), v); break; } + return true; } + + return false; } /*! \qmlmethod CanvasImageData QtQuick::Context2D::createImageData(real sw, real sh) -- cgit v1.2.3 From f145f33d529c2b59ace7a3cdfd5463e68787f40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 8 Feb 2017 16:25:12 +0100 Subject: Rename Window.targetScreen to screen, and pick up changes to the screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The screen property can be used for both setting the initital screen, and for reading out the current screen, so 'targetScreen' was not an ideal name for this property. Change-Id: I1b617085b1e8e0e437355740be5d3cee9379c47f Reviewed-by: Laszlo Agocs Reviewed-by: Shawn Rutledge Reviewed-by: Tor Arne Vestbø --- src/quick/items/qquickscreen.cpp | 6 +++--- src/quick/items/qquickscreen_p.h | 2 +- src/quick/items/qquickwindow.cpp | 26 +++++++++++++------------- src/quick/items/qquickwindowmodule.cpp | 22 ++++++---------------- src/quick/items/qquickwindowmodule_p.h | 8 ++++---- 5 files changed, 27 insertions(+), 37 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index 9347b55c70..20c6973ee1 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -207,9 +207,9 @@ QT_BEGIN_NAMESPACE By default it is set to the value of the QScreen that the window uses. */ -QQuickScreenInfo::QQuickScreenInfo(QObject *parent) - : QObject(parent), - m_screen(nullptr) +QQuickScreenInfo::QQuickScreenInfo(QObject *parent, QScreen *wrappedScreen) + : QObject(parent) + , m_screen(wrappedScreen) { } diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index 06efb3ab45..99e1466631 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -84,7 +84,7 @@ class Q_AUTOTEST_EXPORT QQuickScreenInfo : public QObject Q_PROPERTY(int virtualY READ virtualY NOTIFY virtualYChanged REVISION 1) public: - QQuickScreenInfo(QObject *parent = nullptr); + QQuickScreenInfo(QObject *parent = nullptr, QScreen *wrappedScreen = nullptr); QString name() const; int width() const; diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 0e7c50ffcf..0ebd644d69 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -4172,25 +4172,25 @@ void QQuickWindow::resetOpenGLState() */ /*! - \qmlproperty variant Window::targetScreen + \qmlproperty variant Window::screen - Specifies the screen the window should be placed on. Equivalent to - QWindow::setScreen(). + The screen with which the window is associated. - The value must be an element from the Qt.application.screens array. + If specified before showing a window, will result in the window being shown + on that screen, unless an explicit window position has been set. The value + must be an element from the Qt.application.screens array. - By default the value is null which leads to using the primary screen. - - \note To ensure that the window is associated with the desired screen right - upon the underlying native window's initial creation, make sure this - property is set as early as possible and that the setting of its value is - not deferred. This can be particularly important on embedded platforms - without a windowing system, where only one window per screen is allowed at a - time. + \note To ensure that the window is associated with the desired screen when + the underlying native window is created, make sure this property is set as + early as possible and that the setting of its value is not deferred. This + can be particularly important on embedded platforms without a windowing system, + where only one window per screen is allowed at a time. Setting the screen after + a window has been created does not move the window if the new screen is part of + the same virtual desktop as the old screen. \since 5.9 - \sa QWindow::setScreen(), QScreen, Qt.application + \sa QWindow::setScreen(), QWindow::screen(), QScreen, Qt.application */ /*! diff --git a/src/quick/items/qquickwindowmodule.cpp b/src/quick/items/qquickwindowmodule.cpp index 42313e4584..6211b7802f 100644 --- a/src/quick/items/qquickwindowmodule.cpp +++ b/src/quick/items/qquickwindowmodule.cpp @@ -59,7 +59,6 @@ public: : complete(false) , visible(false) , visibility(QQuickWindow::AutomaticVisibility) - , targetScreen(nullptr) { } @@ -67,7 +66,6 @@ public: bool visible; QQuickWindow::Visibility visibility; QV4::PersistentValue rootItemMarker; - QObject *targetScreen; }; QQuickWindowQmlImpl::QQuickWindowQmlImpl(QWindow *parent) @@ -75,6 +73,7 @@ QQuickWindowQmlImpl::QQuickWindowQmlImpl(QWindow *parent) { connect(this, &QWindow::visibleChanged, this, &QQuickWindowQmlImpl::visibleChanged); connect(this, &QWindow::visibilityChanged, this, &QQuickWindowQmlImpl::visibilityChanged); + connect(this, &QWindow::screenChanged, this, &QQuickWindowQmlImpl::screenChanged); } void QQuickWindowQmlImpl::setVisible(bool visible) @@ -175,24 +174,15 @@ void QQuickWindowQmlImpl::setWindowVisibility() } } -QObject *QQuickWindowQmlImpl::targetScreen() const +QObject *QQuickWindowQmlImpl::screen() const { - Q_D(const QQuickWindowQmlImpl); - return d->targetScreen; + return new QQuickScreenInfo(const_cast(this), QWindow::screen()); } -void QQuickWindowQmlImpl::setTargetScreen(QObject *screen) +void QQuickWindowQmlImpl::setScreen(QObject *screen) { - Q_D(QQuickWindowQmlImpl); - if (d->targetScreen != screen) { - d->targetScreen = screen; - emit targetScreenChanged(); - QQuickScreenInfo *screenWrapper = qobject_cast(screen); - if (screenWrapper) - setScreen(screenWrapper->wrappedScreen()); - else - setScreen(nullptr); - } + QQuickScreenInfo *screenWrapper = qobject_cast(screen); + QWindow::setScreen(screenWrapper ? screenWrapper->wrappedScreen() : nullptr); } void QQuickWindowModule::defineModule() diff --git a/src/quick/items/qquickwindowmodule_p.h b/src/quick/items/qquickwindowmodule_p.h index 7ca29880ea..16130bc8a0 100644 --- a/src/quick/items/qquickwindowmodule_p.h +++ b/src/quick/items/qquickwindowmodule_p.h @@ -67,7 +67,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickWindowQmlImpl : public QQuickWindow, public Q Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged) - Q_PROPERTY(QObject *targetScreen READ targetScreen WRITE setTargetScreen NOTIFY targetScreenChanged REVISION 2) + Q_PROPERTY(QObject *screen READ screen WRITE setScreen NOTIFY screenChanged REVISION 2) public: QQuickWindowQmlImpl(QWindow *parent = Q_NULLPTR); @@ -75,15 +75,15 @@ public: void setVisible(bool visible); void setVisibility(Visibility visibility); - QObject *targetScreen() const; - void setTargetScreen(QObject *screen); + QObject *screen() const; + void setScreen(QObject *screen); static QQuickWindowAttached *qmlAttachedProperties(QObject *object); Q_SIGNALS: void visibleChanged(bool arg); void visibilityChanged(QWindow::Visibility visibility); - Q_REVISION(2) void targetScreenChanged(); + Q_REVISION(2) void screenChanged(); protected: void classBegin() Q_DECL_OVERRIDE; -- cgit v1.2.3 From 569b3e6f2b651bc899e31fd4a522aa4d6aeae968 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 9 Feb 2017 09:24:52 +0100 Subject: Replace usage of QSignalMapper by lambda QSignalMapper ought to be deprecated soon. It simplifies the code, too. There is still one use in QQuickGenericShaderEffect which is a bit complicated to get rid of. A very similar use of QSignalMapper was in use in QQuickOpenGLShaderEffectCommon but was removed in commit 8c745d80, the same should be done for QQuickGenericShaderEffect. (Note the QueuedConnection in qquickparticlesystem is there because the QSignalMapper used to be in the main thread, meaning a round-trip via the event loop) Change-Id: I331b787becbad37f717035bf119bafd7a7214630 Reviewed-by: Frederik Gladhorn --- src/quick/items/qquickopenglshadereffect_p.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickopenglshadereffect_p.h b/src/quick/items/qquickopenglshadereffect_p.h index 64e79a9343..bc2e2975ee 100644 --- a/src/quick/items/qquickopenglshadereffect_p.h +++ b/src/quick/items/qquickopenglshadereffect_p.h @@ -70,7 +70,6 @@ QT_REQUIRE_CONFIG(quick_shadereffect); QT_BEGIN_NAMESPACE class QSGContext; -class QSignalMapper; class QFileSelector; class QQuickOpenGLCustomMaterialShader; -- cgit v1.2.3 From f64fb98a28fde0e4b2d488d78145c0aa958bbc9c Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 17 Jan 2017 18:56:42 +0100 Subject: dynamic_cast -> qobject_cast for QObjectDerived* We cannot use dynamic_cast in Qt. Change-Id: Ia6aeeb2439ca8c24239dce7cff55a0c18860e43e Reviewed-by: Laszlo Agocs Reviewed-by: Andy Nichols --- .../scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp | 8 ++++---- .../scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp index 1fa5234377..d754089ce4 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp @@ -98,10 +98,10 @@ void QSGSoftwareImageNode::paint(QPainter *painter) if (!m_cachedPixmap.isNull()) { painter->drawPixmap(m_rect, m_cachedPixmap, m_sourceRect); - } else if (QSGSoftwarePixmapTexture *pt = dynamic_cast(m_texture)) { + } else if (QSGSoftwarePixmapTexture *pt = qobject_cast(m_texture)) { const QPixmap &pm = pt->pixmap(); painter->drawPixmap(m_rect, pm, m_sourceRect); - } else if (QSGPlainTexture *pt = dynamic_cast(m_texture)) { + } else if (QSGPlainTexture *pt = qobject_cast(m_texture)) { const QImage &im = pt->image(); painter->drawImage(m_rect, im, m_sourceRect); } @@ -113,14 +113,14 @@ void QSGSoftwareImageNode::updateCachedMirroredPixmap() m_cachedPixmap = QPixmap(); } else { - if (QSGSoftwarePixmapTexture *pt = dynamic_cast(m_texture)) { + if (QSGSoftwarePixmapTexture *pt = qobject_cast(m_texture)) { QTransform mirrorTransform; if (m_transformMode.testFlag(MirrorVertically)) mirrorTransform = mirrorTransform.scale(1, -1); if (m_transformMode.testFlag(MirrorHorizontally)) mirrorTransform = mirrorTransform.scale(-1, 1); m_cachedPixmap = pt->pixmap().transformed(mirrorTransform); - } else if (QSGPlainTexture *pt = dynamic_cast(m_texture)) { + } else if (QSGPlainTexture *pt = qobject_cast(m_texture)) { m_cachedPixmap = QPixmap::fromImage(pt->image().mirrored(m_transformMode.testFlag(MirrorHorizontally), m_transformMode.testFlag(MirrorVertically))); } else { m_cachedPixmap = QPixmap(); diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp index 59c47db0c4..52984a4310 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp @@ -293,10 +293,10 @@ QRegion QSGSoftwareRenderableNode::renderNode(QPainter *painter, bool forceOpaqu case QSGSoftwareRenderableNode::SimpleTexture: { QSGTexture *texture = m_handle.simpleTextureNode->texture(); - if (QSGSoftwarePixmapTexture *pt = dynamic_cast(texture)) { + if (QSGSoftwarePixmapTexture *pt = qobject_cast(texture)) { const QPixmap &pm = pt->pixmap(); painter->drawPixmap(m_handle.simpleTextureNode->rect(), pm, m_handle.simpleTextureNode->sourceRect()); - } else if (QSGPlainTexture *pt = dynamic_cast(texture)) { + } else if (QSGPlainTexture *pt = qobject_cast(texture)) { const QImage &im = pt->image(); painter->drawImage(m_handle.simpleTextureNode->rect(), im, m_handle.simpleTextureNode->sourceRect()); } -- cgit v1.2.3 From 52470e2d6ff707762c38b81d4dedcdc55b898323 Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Thu, 16 Feb 2017 11:04:44 -0800 Subject: QQuickWindowPrivate::deliverWheelEvent: fix global position of the event [ChangeLog][QtQuick] QWheelEvent in QQuickItem::wheelEvent now keeps correct global position. Task-number: QTBUG-58845 Change-Id: I7f88d5152927a157e2bd07ee4d5f2208be884eec Reviewed-by: Friedemann Kleint Reviewed-by: Shawn Rutledge --- src/quick/items/qquickwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 0ebd644d69..57810e4ec9 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1803,7 +1803,7 @@ bool QQuickWindowPrivate::deliverWheelEvent(QQuickItem *item, QWheelEvent *event QPointF p = item->mapFromScene(event->posF()); if (item->contains(p)) { - QWheelEvent wheel(p, p, event->pixelDelta(), event->angleDelta(), event->delta(), + QWheelEvent wheel(p, event->globalPosF(), event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted()); wheel.setTimestamp(event->timestamp()); wheel.accept(); -- cgit v1.2.3 From 48c31733383d14447d1c383cefca9ca40daa6a87 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 17 Feb 2017 09:47:49 +0100 Subject: Add samples property for Item.layer and ShaderEffectSource [ChangeLog][Qt Quick] Added the properties ShaderEffectSource.samples and Item.layer.samples to allow requesting MSAA rendering of an item subtree, without enabling multisampling for the entire scene. Task-number: QTBUG-58945 Change-Id: I9102cfabba10d4dc1e7ad2aa0b258ada6d9a5a47 Reviewed-by: Andy Nichols --- src/quick/items/qquickitem.cpp | 40 ++++++++++++++++++++++ src/quick/items/qquickitem_p.h | 7 ++++ src/quick/items/qquickitemsmodule.cpp | 4 +++ src/quick/items/qquickshadereffectsource.cpp | 40 ++++++++++++++++++++++ src/quick/items/qquickshadereffectsource_p.h | 6 ++++ .../adaptations/software/qsgsoftwarelayer_p.h | 1 + src/quick/scenegraph/qsgadaptationlayer_p.h | 1 + src/quick/scenegraph/qsgdefaultlayer.cpp | 20 ++++++++--- src/quick/scenegraph/qsgdefaultlayer_p.h | 4 +++ 9 files changed, 118 insertions(+), 5 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index f7b9a58329..22ee3f39e4 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -7865,6 +7865,7 @@ QQuickItemLayer::QQuickItemLayer(QQuickItem *item) , m_effect(0) , m_effectSource(0) , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically) + , m_samples(0) { } @@ -7939,6 +7940,7 @@ void QQuickItemLayer::activate() m_effectSource->setWrapMode(m_wrapMode); m_effectSource->setFormat(m_format); m_effectSource->setTextureMirroring(m_textureMirroring); + m_effectSource->setSamples(m_samples); if (m_effectComponent) activateEffect(); @@ -8231,6 +8233,44 @@ void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirro emit textureMirroringChanged(mirroring); } +/*! + \qmlproperty enumeration QtQuick::Item::layer.samples + \since 5.10 + + This property allows requesting multisampled rendering in the layer. + + By default multisampling is enabled whenever multisampling is + enabled for the entire window, assuming the scenegraph renderer in + use and the underlying graphics API supports this. + + By setting the value to 2, 4, etc. multisampled rendering can be requested + for a part of the scene without enabling multisampling for the entire + scene. This way multisampling is applied only to a given subtree, which can + lead to significant performance gains since multisampling is not applied to + other parts of the scene. + + \note Enabling multisampling can be potentially expensive regardless of the + layer's size, as it incurs a hardware and driver dependent performance and + memory cost. + + \note This property is only functional when support for multisample + renderbuffers and framebuffer blits is available. Otherwise the value is + silently ignored. + */ + +void QQuickItemLayer::setSamples(int count) +{ + if (m_samples == count) + return; + + m_samples = count; + + if (m_effectSource) + m_effectSource->setSamples(m_samples); + + emit samplesChanged(count); +} + /*! \qmlproperty string QtQuick::Item::layer.samplerName diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h index c0c9bd46bd..797ba42781 100644 --- a/src/quick/items/qquickitem_p.h +++ b/src/quick/items/qquickitem_p.h @@ -152,6 +152,8 @@ class QQuickItemLayer : public QObject, public QQuickItemChangeListener Q_PROPERTY(QByteArray samplerName READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QQmlComponent *effect READ effect WRITE setEffect NOTIFY effectChanged) Q_PROPERTY(QQuickShaderEffectSource::TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged) + Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged) + public: QQuickItemLayer(QQuickItem *item); ~QQuickItemLayer(); @@ -189,6 +191,9 @@ public: QQuickShaderEffectSource::TextureMirroring textureMirroring() const { return m_textureMirroring; } void setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring); + int samples() const { return m_samples; } + void setSamples(int count); + QQuickShaderEffectSource *effectSource() const { return m_effectSource; } void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) Q_DECL_OVERRIDE; @@ -213,6 +218,7 @@ Q_SIGNALS: void formatChanged(QQuickShaderEffectSource::Format format); void sourceRectChanged(const QRectF &sourceRect); void textureMirroringChanged(QQuickShaderEffectSource::TextureMirroring mirroring); + void samplesChanged(int count); private: friend class QQuickTransformAnimatorJob; @@ -237,6 +243,7 @@ private: QQuickItem *m_effect; QQuickShaderEffectSource *m_effectSource; QQuickShaderEffectSource::TextureMirroring m_textureMirroring; + int m_samples; }; #endif diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index a8824de9c8..eeffe1ee48 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -385,6 +385,10 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterUncreatableType(uri, 2, 9, "Positioner", QStringLiteral("Positioner is an abstract type that is only available as an attached property.")); #endif + +#if QT_CONFIG(quick_shadereffect) + qmlRegisterType(uri, 2, 9, "ShaderEffectSource"); +#endif } static void initResources() diff --git a/src/quick/items/qquickshadereffectsource.cpp b/src/quick/items/qquickshadereffectsource.cpp index 1b37a746d3..c782ddb5f7 100644 --- a/src/quick/items/qquickshadereffectsource.cpp +++ b/src/quick/items/qquickshadereffectsource.cpp @@ -189,6 +189,7 @@ QQuickShaderEffectSource::QQuickShaderEffectSource(QQuickItem *parent) , m_sourceItem(0) , m_textureSize(0, 0) , m_format(RGBA) + , m_samples(0) , m_live(true) , m_hideSource(false) , m_mipmap(false) @@ -581,6 +582,44 @@ void QQuickShaderEffectSource::setTextureMirroring(TextureMirroring mirroring) emit textureMirroringChanged(); } +/*! + \qmlproperty int QtQuick::ShaderEffectSource::samples + \since 5.10 + + This property allows requesting multisampled rendering. + + By default multisampling is enabled whenever multisampling is enabled for + the entire window, assuming the scenegraph renderer in use and the + underlying graphics API supports this. + + By setting the value to 2, 4, etc. multisampled rendering can be requested + for a part of the scene without enabling multisampling for the entire + scene. This way multisampling is applied only to a given subtree, which can + lead to significant performance gains since multisampling is not applied to + other parts of the scene. + + \note Enabling multisampling can be potentially expensive regardless of the + layer's size, as it incurs a hardware and driver dependent performance and + memory cost. + + \note This property is only functional when support for multisample + renderbuffers and framebuffer blits is available. Otherwise the value is + silently ignored. + */ +int QQuickShaderEffectSource::samples() const +{ + return m_samples; +} + +void QQuickShaderEffectSource::setSamples(int count) +{ + if (count == m_samples) + return; + m_samples = count; + update(); + emit samplesChanged(); +} + /*! \qmlmethod QtQuick::ShaderEffectSource::scheduleUpdate() @@ -683,6 +722,7 @@ QSGNode *QQuickShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaint m_texture->setHasMipmaps(m_mipmap); m_texture->setMirrorHorizontal(m_textureMirroring & MirrorHorizontally); m_texture->setMirrorVertical(m_textureMirroring & MirrorVertically); + m_texture->setSamples(m_samples); if (m_grab) m_texture->scheduleUpdate(); diff --git a/src/quick/items/qquickshadereffectsource_p.h b/src/quick/items/qquickshadereffectsource_p.h index 5e7e354feb..d9f9079a3d 100644 --- a/src/quick/items/qquickshadereffectsource_p.h +++ b/src/quick/items/qquickshadereffectsource_p.h @@ -88,6 +88,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectSource : public QQuickItem, publi Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged) Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged) Q_PROPERTY(TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged REVISION 1) + Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged REVISION 2) public: enum WrapMode { @@ -150,6 +151,9 @@ public: Q_INVOKABLE void scheduleUpdate(); + int samples() const; + void setSamples(int count); + Q_SIGNALS: void wrapModeChanged(); void sourceItemChanged(); @@ -161,6 +165,7 @@ Q_SIGNALS: void mipmapChanged(); void recursiveChanged(); void textureMirroringChanged(); + void samplesChanged(); void scheduledUpdateCompleted(); @@ -185,6 +190,7 @@ private: QRectF m_sourceRect; QSize m_textureSize; Format m_format; + int m_samples; uint m_live : 1; uint m_hideSource : 1; uint m_mipmap : 1; diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h index d3f13e40b1..9f5a22e66f 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h @@ -93,6 +93,7 @@ public: void setDevicePixelRatio(qreal ratio) override; void setMirrorHorizontal(bool mirror) override; void setMirrorVertical(bool mirror) override; + void setSamples(int) override { } public slots: void markDirtyTexture() override; diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h index 03a1f7f281..a8e35b1ac1 100644 --- a/src/quick/scenegraph/qsgadaptationlayer_p.h +++ b/src/quick/scenegraph/qsgadaptationlayer_p.h @@ -209,6 +209,7 @@ public: virtual void setDevicePixelRatio(qreal ratio) = 0; virtual void setMirrorHorizontal(bool mirror) = 0; virtual void setMirrorVertical(bool mirror) = 0; + virtual void setSamples(int samples) = 0; Q_SLOT virtual void markDirtyTexture() = 0; Q_SLOT virtual void invalidated() = 0; diff --git a/src/quick/scenegraph/qsgdefaultlayer.cpp b/src/quick/scenegraph/qsgdefaultlayer.cpp index ad5b57ff83..fc8040e67b 100644 --- a/src/quick/scenegraph/qsgdefaultlayer.cpp +++ b/src/quick/scenegraph/qsgdefaultlayer.cpp @@ -99,6 +99,7 @@ QSGDefaultLayer::QSGDefaultLayer(QSGRenderContext *context) #ifdef QSG_DEBUG_FBO_OVERLAY , m_debugOverlay(0) #endif + , m_samples(0) , m_mipmap(false) , m_live(true) , m_recursive(false) @@ -313,11 +314,20 @@ void QSGDefaultLayer::grab() QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); bool deleteFboLater = false; - if (!m_fbo || m_fbo->size() != m_size || m_fbo->format().internalTextureFormat() != m_format - || (!m_fbo->format().mipmap() && m_mipmap)) - { + + int effectiveSamples = m_samples; + // By default m_samples is 0. Fall back to the context's setting in this case. + if (effectiveSamples == 0) + effectiveSamples = m_context->openglContext()->format().samples(); + + const bool needsNewFbo = !m_fbo || m_fbo->size() != m_size || m_fbo->format().internalTextureFormat() != m_format; + const bool mipmapGotEnabled = m_fbo && !m_fbo->format().mipmap() && m_mipmap; + const bool msaaGotEnabled = effectiveSamples > 1 && (!m_secondaryFbo || m_secondaryFbo->format().samples() != effectiveSamples); + const bool msaaGotDisabled = effectiveSamples <= 1 && m_secondaryFbo; + + if (needsNewFbo || mipmapGotEnabled || msaaGotEnabled || msaaGotDisabled) { if (!m_multisamplingChecked) { - if (m_context->openglContext()->format().samples() <= 1) { + if (effectiveSamples <= 1) { m_multisampling = false; } else { const QSet extensions = m_context->openglContext()->extensions(); @@ -333,7 +343,7 @@ void QSGDefaultLayer::grab() QOpenGLFramebufferObjectFormat format; format.setInternalTextureFormat(m_format); - format.setSamples(m_context->openglContext()->format().samples()); + format.setSamples(effectiveSamples); m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format); m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo); } else { diff --git a/src/quick/scenegraph/qsgdefaultlayer_p.h b/src/quick/scenegraph/qsgdefaultlayer_p.h index ae39994096..7b09293095 100644 --- a/src/quick/scenegraph/qsgdefaultlayer_p.h +++ b/src/quick/scenegraph/qsgdefaultlayer_p.h @@ -113,6 +113,9 @@ public: QRectF normalizedTextureSubRect() const Q_DECL_OVERRIDE; + int samples() const { return m_samples; } + void setSamples(int samples) Q_DECL_OVERRIDE { m_samples = samples; } + public Q_SLOTS: void markDirtyTexture() Q_DECL_OVERRIDE; void invalidated() Q_DECL_OVERRIDE; @@ -138,6 +141,7 @@ private: #endif QSGDefaultRenderContext *m_context; + int m_samples; uint m_mipmap : 1; uint m_live : 1; -- cgit v1.2.3 From 3681514f80a2f6a568b0508a58b5e486cee00b0f Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 23 Feb 2017 12:59:05 +0100 Subject: Positioners: remove unused header includes Change-Id: I1d2a57d5a5392986460e2427b4ee2a1b2b17dbaa Reviewed-by: J-P Nurmi Reviewed-by: Robin Burchell --- src/quick/items/qquickpositioners.cpp | 3 --- src/quick/items/qquickpositioners_p.h | 1 - src/quick/items/qquickpositioners_p_p.h | 3 --- 3 files changed, 7 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickpositioners.cpp b/src/quick/items/qquickpositioners.cpp index 05d3ae0191..51eafd9217 100644 --- a/src/quick/items/qquickpositioners.cpp +++ b/src/quick/items/qquickpositioners.cpp @@ -44,9 +44,6 @@ #include #include -#include -#include -#include #include QT_BEGIN_NAMESPACE diff --git a/src/quick/items/qquickpositioners_p.h b/src/quick/items/qquickpositioners_p.h index ae6e795794..9ae7029d69 100644 --- a/src/quick/items/qquickpositioners_p.h +++ b/src/quick/items/qquickpositioners_p.h @@ -58,7 +58,6 @@ QT_REQUIRE_CONFIG(quick_positioners); #include "qquickimplicitsizeitem_p.h" #include "qquickitemviewtransition_p.h" -#include #include #include diff --git a/src/quick/items/qquickpositioners_p_p.h b/src/quick/items/qquickpositioners_p_p.h index 6dd84e6098..0be4c56df6 100644 --- a/src/quick/items/qquickpositioners_p_p.h +++ b/src/quick/items/qquickpositioners_p_p.h @@ -58,9 +58,6 @@ QT_REQUIRE_CONFIG(quick_positioners); #include "qquickpositioners_p.h" #include "qquickimplicitsizeitem_p_p.h" -#include -#include -#include #include #include -- cgit v1.2.3 From 2556bfdab42dc0aefb34bb7cf304063c7db0ff00 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 7 Feb 2017 13:54:29 +0100 Subject: Positioners: allow distinguishing between implicit/explicit child size In Qt Quick Controls 2, we plan on using positioners to layout an icon next to text in a button, for example. Consider the following example: AbstractButton { id: button text: "Button" contentItem: Row { Text { text: button.text width: parent.width } } background: Rectangle { radius: 5 color: "lightsteelblue" opacity: button.pressed ? 1.0 : 0.8 } } In Qt Quick Controls 2, implicit size propagates "up" from the delegates/building blocks to the control, whereas explicit size propagates "down" from the control to the delegates/building blocks. Providing a reasonable implicit size is important to make controls behave well in layouts, etc., and the internal building blocks must follow the size of the control to retain sensible looks when a control is resized. In the example above, contentItem needs to have a "natural" (implicit) size representing the ideal fit of the content, but it needs to respect the explicitly provided size from the control too. With the current behavior, as the explicit width of the Row is 0, the Text item (via the width binding) sets explicit width to 0, and Row uses that explicit width rather than the implicit width, thus, Row here will have an implicit width of 0, which is not what the control wants. This patch: - Allows subclasses of positioners to set QQuickBasePositionerPrivate::useImplicitSize to true in order to tell positioners to use implicit size rather than explicit size. This is not exposed as public API, as this behavior is typically not something desirable in the positioners themselves. For example, Row { Rectangle { width: 100; height: 100 } } would have an implicit size of 0, as Rectangle has no implicit size. - Adds QQuickImplicitRow and QQuickImplicitGrid, which are private subclasses of their respective positioners that simply set useImplicitSize to true in their constructors. - Exports the wrappers privately so that they can be registered by other modules as QML types. Change-Id: Ie68aabd7fbf6c76375badf6e338f2f238f3fc392 Reviewed-by: J-P Nurmi Reviewed-by: Robin Burchell --- src/quick/items/qquickpositioners.cpp | 100 ++++++++++++++++++++++---------- src/quick/items/qquickpositioners_p.h | 33 +++++++++-- src/quick/items/qquickpositioners_p_p.h | 41 +++++++++++-- 3 files changed, 133 insertions(+), 41 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickpositioners.cpp b/src/quick/items/qquickpositioners.cpp index 51eafd9217..be92bb0954 100644 --- a/src/quick/items/qquickpositioners.cpp +++ b/src/quick/items/qquickpositioners.cpp @@ -48,8 +48,19 @@ QT_BEGIN_NAMESPACE -static const QQuickItemPrivate::ChangeTypes watchedChanges - = QQuickItemPrivate::Geometry +// The default item change types that positioners are interested in. +static const QQuickItemPrivate::ChangeTypes explicitSizeItemChangeTypes = + QQuickItemPrivate::Geometry + | QQuickItemPrivate::SiblingOrder + | QQuickItemPrivate::Visibility + | QQuickItemPrivate::Destroyed; + +// The item change types for positioners that are only interested in the implicit +// size of the items they manage. These are used if useImplicitSize is true. +// useImplicitSize should be set in the constructor, before any items are added. +static const QQuickItemPrivate::ChangeTypes implicitSizeItemChangeTypes = + QQuickItemPrivate::ImplicitWidth + | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::Visibility | QQuickItemPrivate::Destroyed; @@ -57,13 +68,15 @@ static const QQuickItemPrivate::ChangeTypes watchedChanges void QQuickBasePositionerPrivate::watchChanges(QQuickItem *other) { QQuickItemPrivate *otherPrivate = QQuickItemPrivate::get(other); - otherPrivate->addItemChangeListener(this, watchedChanges); + otherPrivate->addItemChangeListener(this, useImplicitSize + ? implicitSizeItemChangeTypes : explicitSizeItemChangeTypes); } void QQuickBasePositionerPrivate::unwatchChanges(QQuickItem* other) { QQuickItemPrivate *otherPrivate = QQuickItemPrivate::get(other); - otherPrivate->removeItemChangeListener(this, watchedChanges); + otherPrivate->removeItemChangeListener(this, useImplicitSize + ? implicitSizeItemChangeTypes : explicitSizeItemChangeTypes); } @@ -323,7 +336,7 @@ void QQuickBasePositioner::prePositioning() if (wIdx < 0) { d->watchChanges(child); posItem.isNew = true; - if (!childPrivate->explicitVisible || !child->width() || !child->height()) { + if (!childPrivate->explicitVisible || !d->itemWidth(child) || !d->itemHeight(child)) { posItem.isVisible = false; posItem.index = -1; unpositionedItems.append(posItem); @@ -345,7 +358,7 @@ void QQuickBasePositioner::prePositioning() PositionedItem *item = &oldItems[wIdx]; // Items are only omitted from positioning if they are explicitly hidden // i.e. their positioning is not affected if an ancestor is hidden. - if (!childPrivate->explicitVisible || !child->width() || !child->height()) { + if (!childPrivate->explicitVisible || !d->itemWidth(child) || !d->itemHeight(child)) { item->isVisible = false; item->index = -1; unpositionedItems.append(*item); @@ -944,6 +957,7 @@ QQuickColumn::QQuickColumn(QQuickItem *parent) void QQuickColumn::doPositioning(QSizeF *contentSize) { //Precondition: All items in the positioned list have a valid item pointer and should be positioned + QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); qreal voffset = topPadding(); const qreal padding = leftPadding() + rightPadding(); contentSize->setWidth(qMax(contentSize->width(), padding)); @@ -952,9 +966,9 @@ void QQuickColumn::doPositioning(QSizeF *contentSize) PositionedItem &child = positionedItems[ii]; positionItem(child.itemX() + leftPadding() - child.leftPadding, voffset, &child); child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); - contentSize->setWidth(qMax(contentSize->width(), child.item->width() + padding)); + contentSize->setWidth(qMax(contentSize->width(), d->itemWidth(child.item) + padding)); - voffset += child.item->height(); + voffset += d->itemHeight(child.item); voffset += spacing(); } @@ -1222,9 +1236,9 @@ void QQuickRow::doPositioning(QSizeF *contentSize) hoffsets << hoffset; } - contentSize->setHeight(qMax(contentSize->height(), child.item->height() + padding)); + contentSize->setHeight(qMax(contentSize->height(), d->itemHeight(child.item) + padding)); - hoffset += child.item->width(); + hoffset += d->itemWidth(child.item); hoffset += spacing(); } @@ -1245,7 +1259,7 @@ void QQuickRow::doPositioning(QSizeF *contentSize) int acc = 0; for (int ii = 0; ii < positionedItems.count(); ++ii) { PositionedItem &child = positionedItems[ii]; - hoffset = end - hoffsets[acc++] - child.item->width(); + hoffset = end - hoffsets[acc++] - d->itemWidth(child.item); positionItem(hoffset, child.itemY() + topPadding() - child.topPadding, &child); child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); } @@ -1746,10 +1760,12 @@ void QQuickGrid::doPositioning(QSizeF *contentSize) break; const PositionedItem &child = positionedItems.at(childIndex++); - if (child.item->width() > maxColWidth[j]) - maxColWidth[j] = child.item->width(); - if (child.item->height() > maxRowHeight[i]) - maxRowHeight[i] = child.item->height(); + const qreal childWidth = d->itemWidth(child.item); + const qreal childHeight = d->itemHeight(child.item); + if (childWidth > maxColWidth[j]) + maxColWidth[j] = childWidth; + if (childHeight > maxRowHeight[i]) + maxRowHeight[i] = childHeight; } } } else { @@ -1764,10 +1780,12 @@ void QQuickGrid::doPositioning(QSizeF *contentSize) break; const PositionedItem &child = positionedItems.at(childIndex++); - if (child.item->width() > maxColWidth[j]) - maxColWidth[j] = child.item->width(); - if (child.item->height() > maxRowHeight[i]) - maxRowHeight[i] = child.item->height(); + const qreal childWidth = d->itemWidth(child.item); + const qreal childHeight = d->itemHeight(child.item); + if (childWidth > maxColWidth[j]) + maxColWidth[j] = childWidth; + if (childHeight > maxRowHeight[i]) + maxRowHeight[i] = childHeight; } } } @@ -1809,20 +1827,22 @@ void QQuickGrid::doPositioning(QSizeF *contentSize) for (int i = 0; i < positionedItems.count(); ++i) { PositionedItem &child = positionedItems[i]; qreal childXOffset = xoffset; + const qreal childWidth = d->itemWidth(child.item); + const qreal childHeight = d->itemHeight(child.item); if (effectiveHAlign() == AlignRight) - childXOffset += maxColWidth[curCol] - child.item->width(); + childXOffset += maxColWidth[curCol] - childWidth; else if (hItemAlign() == AlignHCenter) - childXOffset += (maxColWidth[curCol] - child.item->width())/2.0; + childXOffset += (maxColWidth[curCol] - childWidth)/2.0; if (!d->isLeftToRight()) childXOffset -= maxColWidth[curCol]; qreal alignYOffset = yoffset; if (m_vItemAlign == AlignVCenter) - alignYOffset += (maxRowHeight[curRow] - child.item->height())/2.0; + alignYOffset += (maxRowHeight[curRow] - childHeight)/2.0; else if (m_vItemAlign == AlignBottom) - alignYOffset += maxRowHeight[curRow] - child.item->height(); + alignYOffset += maxRowHeight[curRow] - childHeight; positionItem(childXOffset, alignYOffset, &child); child.updatePadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); @@ -2140,15 +2160,17 @@ void QQuickFlow::doPositioning(QSizeF *contentSize) for (int i = 0; i < positionedItems.count(); ++i) { PositionedItem &child = positionedItems[i]; + const qreal childWidth = d->itemWidth(child.item); + const qreal childHeight = d->itemHeight(child.item); if (d->flow == LeftToRight) { - if (widthValid() && hoffset != hoffset1 && hoffset + child.item->width() + hoffset2 > width()) { + if (widthValid() && hoffset != hoffset1 && hoffset + childWidth + hoffset2 > width()) { hoffset = hoffset1; voffset += linemax + spacing(); linemax = 0; } } else { - if (heightValid() && voffset != voffset1 && voffset + child.item->height() + bottomPadding() > height()) { + if (heightValid() && voffset != voffset1 && voffset + childHeight + bottomPadding() > height()) { voffset = voffset1; hoffset += linemax + spacing(); linemax = 0; @@ -2165,17 +2187,17 @@ void QQuickFlow::doPositioning(QSizeF *contentSize) child.bottomPadding = bottomPadding(); } - contentSize->setWidth(qMax(contentSize->width(), hoffset + child.item->width() + hoffset2)); - contentSize->setHeight(qMax(contentSize->height(), voffset + child.item->height() + bottomPadding())); + contentSize->setWidth(qMax(contentSize->width(), hoffset + childWidth + hoffset2)); + contentSize->setHeight(qMax(contentSize->height(), voffset + childHeight + bottomPadding())); if (d->flow == LeftToRight) { - hoffset += child.item->width(); + hoffset += childWidth; hoffset += spacing(); - linemax = qMax(linemax, child.item->height()); + linemax = qMax(linemax, childHeight); } else { - voffset += child.item->height(); + voffset += childHeight; voffset += spacing(); - linemax = qMax(linemax, child.item->width()); + linemax = qMax(linemax, childWidth); } } @@ -2190,7 +2212,7 @@ void QQuickFlow::doPositioning(QSizeF *contentSize) int acc = 0; for (int i = 0; i < positionedItems.count(); ++i) { PositionedItem &child = positionedItems[i]; - hoffset = end - hoffsets[acc++] - child.item->width(); + hoffset = end - hoffsets[acc++] - d->itemWidth(child.item); positionItemX(hoffset, &child); child.leftPadding = leftPadding(); child.rightPadding = rightPadding(); @@ -2214,4 +2236,18 @@ void QQuickFlow::reportConflictingAnchors() qmlWarning(this) << "Cannot specify anchors for items inside Flow." << " Flow will not function."; } +QQuickImplicitRow::QQuickImplicitRow(QQuickItem *parent) + : QQuickRow(parent) +{ + QQuickBasePositionerPrivate *d = QQuickBasePositioner::get(this); + d->useImplicitSize = true; +} + +QQuickImplicitGrid::QQuickImplicitGrid(QQuickItem *parent) + : QQuickGrid(parent) +{ + QQuickBasePositionerPrivate *d = QQuickBasePositioner::get(this); + d->useImplicitSize = true; +} + QT_END_NAMESPACE diff --git a/src/quick/items/qquickpositioners_p.h b/src/quick/items/qquickpositioners_p.h index 9ae7029d69..8dc0d90a2f 100644 --- a/src/quick/items/qquickpositioners_p.h +++ b/src/quick/items/qquickpositioners_p.h @@ -132,6 +132,11 @@ public: static QQuickPositionerAttached *qmlAttachedProperties(QObject *obj); + static QQuickBasePositionerPrivate* get(QQuickBasePositioner *positioner) + { + return positioner->d_func(); + } + void updateAttachedProperties(QQuickPositionerAttached *specificProperty = 0, QQuickItem *specificPropertyOwner = 0) const; qreal padding() const; @@ -182,7 +187,7 @@ protected: virtual void doPositioning(QSizeF *contentSize)=0; virtual void reportConflictingAnchors()=0; - class PositionedItem + class Q_QUICK_PRIVATE_EXPORT PositionedItem { public : PositionedItem(QQuickItem *i); @@ -227,7 +232,7 @@ private: Q_DECLARE_PRIVATE(QQuickBasePositioner) }; -class Q_AUTOTEST_EXPORT QQuickColumn : public QQuickBasePositioner +class Q_QUICK_PRIVATE_EXPORT QQuickColumn : public QQuickBasePositioner { Q_OBJECT public: @@ -241,7 +246,7 @@ private: }; class QQuickRowPrivate; -class Q_AUTOTEST_EXPORT QQuickRow: public QQuickBasePositioner +class Q_QUICK_PRIVATE_EXPORT QQuickRow: public QQuickBasePositioner { Q_OBJECT Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) @@ -266,7 +271,7 @@ private: }; class QQuickGridPrivate; -class Q_AUTOTEST_EXPORT QQuickGrid : public QQuickBasePositioner +class Q_QUICK_PRIVATE_EXPORT QQuickGrid : public QQuickBasePositioner { Q_OBJECT Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) @@ -353,7 +358,7 @@ private: }; class QQuickFlowPrivate; -class Q_AUTOTEST_EXPORT QQuickFlow: public QQuickBasePositioner +class Q_QUICK_PRIVATE_EXPORT QQuickFlow: public QQuickBasePositioner { Q_OBJECT Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) @@ -386,6 +391,22 @@ private: Q_DECLARE_PRIVATE(QQuickFlow) }; +class Q_QUICK_PRIVATE_EXPORT QQuickImplicitRow : public QQuickRow +{ + Q_OBJECT + +public: + QQuickImplicitRow(QQuickItem *parent = nullptr); +}; + +class Q_QUICK_PRIVATE_EXPORT QQuickImplicitGrid : public QQuickGrid +{ + Q_OBJECT + +public: + QQuickImplicitGrid(QQuickItem *parent = nullptr); +}; + QT_END_NAMESPACE @@ -393,6 +414,8 @@ QML_DECLARE_TYPE(QQuickColumn) QML_DECLARE_TYPE(QQuickRow) QML_DECLARE_TYPE(QQuickGrid) QML_DECLARE_TYPE(QQuickFlow) +QML_DECLARE_TYPE(QQuickImplicitRow) +QML_DECLARE_TYPE(QQuickImplicitGrid) QML_DECLARE_TYPE(QQuickBasePositioner) QML_DECLARE_TYPEINFO(QQuickBasePositioner, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/quick/items/qquickpositioners_p_p.h b/src/quick/items/qquickpositioners_p_p.h index 0be4c56df6..1a7051615c 100644 --- a/src/quick/items/qquickpositioners_p_p.h +++ b/src/quick/items/qquickpositioners_p_p.h @@ -89,10 +89,14 @@ public: QLazilyAllocated extra; QQuickBasePositionerPrivate() - : spacing(0), type(QQuickBasePositioner::None) - , transitioner(0), positioningDirty(false) - , doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight) - + : spacing(0) + , type(QQuickBasePositioner::None) + , transitioner(0) + , positioningDirty(false) + , doingPositioning(false) + , anchorConflict(false) + , useImplicitSize(false) + , layoutDirection(Qt::LeftToRight) { } @@ -119,6 +123,7 @@ public: bool positioningDirty : 1; bool doingPositioning : 1; bool anchorConflict : 1; + bool useImplicitSize : 1; Qt::LayoutDirection layoutDirection; @@ -174,6 +179,34 @@ public: { } + void itemImplicitWidthChanged(QQuickItem *) override + { + Q_ASSERT(useImplicitSize); + setPositioningDirty(); + } + + void itemImplicitHeightChanged(QQuickItem *) override + { + Q_ASSERT(useImplicitSize); + setPositioningDirty(); + } + + qreal itemWidth(QQuickItem *item) const + { + if (Q_LIKELY(!useImplicitSize)) + return item->width(); + + return item->implicitWidth(); + } + + qreal itemHeight(QQuickItem *item) const + { + if (Q_LIKELY(!useImplicitSize)) + return item->height(); + + return item->implicitHeight(); + } + inline qreal padding() const { return extra.isAllocated() ? extra->padding : 0.0; } void setTopPadding(qreal value, bool reset = false); void setLeftPadding(qreal value, bool reset = false); -- cgit v1.2.3 From febb1f721f720bb9f32bb60c711f709faadb366a Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 8 Dec 2016 01:53:14 +0300 Subject: sources: Add missing override and remove redundant virtual Change-Id: I48e26b1491024d41ebf75d40f0d1a7e9a1b20f22 Reviewed-by: Anton Kudryavtsev Reviewed-by: Marc Mutz Reviewed-by: Shawn Rutledge --- src/quick/items/qquickpositioners.cpp | 6 ++--- .../software/qsgsoftwarepixmaprenderer.cpp | 2 +- .../adaptations/software/qsgsoftwarerenderer.cpp | 2 +- .../software/qsgsoftwarethreadedrenderloop.cpp | 4 ++-- src/quick/scenegraph/coreapi/qsgrenderer.cpp | 2 +- src/quick/scenegraph/qsgdefaultcontext.cpp | 4 ++-- src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 20 ++++++++--------- .../scenegraph/qsgdefaultinternalimagenode.cpp | 6 ++--- .../scenegraph/qsgdefaultinternalrectanglenode.cpp | 6 ++--- .../scenegraph/qsgdistancefieldglyphnode_p.cpp | 26 +++++++++++----------- src/quick/scenegraph/qsgrenderloop.cpp | 24 ++++++++++---------- src/quick/scenegraph/qsgthreadedrenderloop.cpp | 4 ++-- src/quick/scenegraph/util/qsgflatcolormaterial.cpp | 6 ++--- .../scenegraph/util/qsgvertexcolormaterial.cpp | 6 ++--- src/quick/util/qquickglobal.cpp | 26 +++++++++++----------- src/quick/util/qquickpixmapcache.cpp | 4 ++-- 16 files changed, 74 insertions(+), 74 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickpositioners.cpp b/src/quick/items/qquickpositioners.cpp index be92bb0954..70fc5fa65f 100644 --- a/src/quick/items/qquickpositioners.cpp +++ b/src/quick/items/qquickpositioners.cpp @@ -1148,7 +1148,7 @@ public: : QQuickBasePositionerPrivate() {} - void effectiveLayoutDirectionChange() + void effectiveLayoutDirectionChange() override { Q_Q(QQuickRow); // For RTL layout the positioning changes when the width changes. @@ -1447,7 +1447,7 @@ public: : QQuickBasePositionerPrivate() {} - void effectiveLayoutDirectionChange() + void effectiveLayoutDirectionChange() override { Q_Q(QQuickGrid); // For RTL layout the positioning changes when the width changes. @@ -2040,7 +2040,7 @@ public: : QQuickBasePositionerPrivate(), flow(QQuickFlow::LeftToRight) {} - void effectiveLayoutDirectionChange() + void effectiveLayoutDirectionChange() override { Q_Q(QQuickFlow); // Don't postpone, as it might be the only trigger for visible changes. diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaprenderer.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaprenderer.cpp index f8c1a3d90b..ad6cf39425 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaprenderer.cpp +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaprenderer.cpp @@ -64,7 +64,7 @@ void QSGSoftwarePixmapRenderer::renderScene(uint) class B : public QSGBindable { public: - void bind() const { } + void bind() const override { } } bindable; QSGRenderer::renderScene(bindable); } diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderer.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderer.cpp index cad826fb27..85d04fe136 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderer.cpp +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderer.cpp @@ -90,7 +90,7 @@ void QSGSoftwareRenderer::renderScene(uint) class B : public QSGBindable { public: - void bind() const { } + void bind() const override { } } bindable; QSGRenderer::renderScene(bindable); } diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp index 8abbefdd48..682f89721e 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp @@ -188,8 +188,8 @@ public: delete rc; } - bool event(QEvent *e); - void run(); + bool event(QEvent *e) override; + void run() override; void syncAndRender(); void sync(bool inExpose); diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp index e5d464930c..9207fdbc55 100644 --- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp @@ -189,7 +189,7 @@ void QSGRenderer::renderScene(uint fboId) class B : public QSGBindable { public: - void bind() const { QOpenGLFramebufferObject::bindDefault(); } + void bind() const override { QOpenGLFramebufferObject::bindDefault(); } } bindable; renderScene(bindable); } diff --git a/src/quick/scenegraph/qsgdefaultcontext.cpp b/src/quick/scenegraph/qsgdefaultcontext.cpp index 405f1d86a4..d31a7025e5 100644 --- a/src/quick/scenegraph/qsgdefaultcontext.cpp +++ b/src/quick/scenegraph/qsgdefaultcontext.cpp @@ -68,13 +68,13 @@ QT_BEGIN_NAMESPACE namespace QSGMultisampleAntialiasing { class ImageNode : public QSGDefaultInternalImageNode { public: - void setAntialiasing(bool) { } + void setAntialiasing(bool) override { } }; class RectangleNode : public QSGDefaultInternalRectangleNode { public: - void setAntialiasing(bool) { } + void setAntialiasing(bool) override { } }; } diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index b001899915..edb6e92a0d 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -91,11 +91,11 @@ class QSGTextMaskShader : public QSGMaterialShader public: QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual char const *const *attributeNames() const; + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; + char const *const *attributeNames() const override; protected: - virtual void initialize(); + void initialize() override; int m_matrix_id; int m_color_id; @@ -181,7 +181,7 @@ public: setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/8bittextmask.frag")); } - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; }; void QSG8BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) @@ -206,10 +206,10 @@ public: setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/24bittextmask.frag")); } - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual void initialize(); - void activate(); - void deactivate(); + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; + void initialize() override; + void activate() override; + void deactivate() override; bool useSRGB() const; uint m_useSRGB : 1; @@ -326,10 +326,10 @@ public: setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/styledtext.frag")); } - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; private: - virtual void initialize(); + void initialize() override; int m_shift_id; int m_styleColor_id; diff --git a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp index 1d54628acd..a5a6da06a7 100644 --- a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp +++ b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp @@ -50,11 +50,11 @@ class SmoothTextureMaterialShader : public QSGTextureMaterialShader public: SmoothTextureMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual char const *const *attributeNames() const; + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; + char const *const *attributeNames() const override; protected: - virtual void initialize(); + void initialize() override; int m_pixelSizeLoc; }; diff --git a/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp b/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp index 94414444ba..e52dcaad52 100644 --- a/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp +++ b/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp @@ -55,11 +55,11 @@ class SmoothColorMaterialShader : public QSGMaterialShader public: SmoothColorMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual char const *const *attributeNames() const; + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; + char const *const *attributeNames() const override; private: - virtual void initialize(); + void initialize() override; int m_matrixLoc; int m_opacityLoc; diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp index ca91e5d85f..fc66f2f2cc 100644 --- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp @@ -52,11 +52,11 @@ class QSGDistanceFieldTextMaterialShader : public QSGMaterialShader public: QSGDistanceFieldTextMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual char const *const *attributeNames() const; + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; + char const *const *attributeNames() const override; protected: - virtual void initialize(); + void initialize() override; void updateAlphaRange(ThresholdFunc thresholdFunc, AntialiasingSpreadFunc spreadFunc); void updateColor(const QVector4D &c); @@ -261,10 +261,10 @@ class DistanceFieldStyledTextMaterialShader : public QSGDistanceFieldTextMateria public: DistanceFieldStyledTextMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; protected: - virtual void initialize(); + void initialize() override; int m_styleColor_id; }; @@ -329,10 +329,10 @@ class DistanceFieldOutlineTextMaterialShader : public DistanceFieldStyledTextMat public: DistanceFieldOutlineTextMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; protected: - virtual void initialize(); + void initialize() override; void updateOutlineAlphaRange(ThresholdFunc thresholdFunc, AntialiasingSpreadFunc spreadFunc, int dfRadius); @@ -413,10 +413,10 @@ class DistanceFieldShiftedStyleTextMaterialShader : public DistanceFieldStyledTe public: DistanceFieldShiftedStyleTextMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; protected: - virtual void initialize(); + void initialize() override; void updateShift(qreal fontScale, const QPointF& shift); @@ -492,10 +492,10 @@ class QSGHiQSubPixelDistanceFieldTextMaterialShader : public QSGDistanceFieldTex public: QSGHiQSubPixelDistanceFieldTextMaterialShader(); - virtual void initialize(); - virtual void activate(); - virtual void deactivate(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); + void initialize() override; + void activate() override; + void deactivate() override; + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; private: int m_fontScale_id; diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp index 48288bfc62..bb581c5e36 100644 --- a/src/quick/scenegraph/qsgrenderloop.cpp +++ b/src/quick/scenegraph/qsgrenderloop.cpp @@ -139,25 +139,25 @@ public: QSGGuiThreadRenderLoop(); ~QSGGuiThreadRenderLoop(); - void show(QQuickWindow *window); - void hide(QQuickWindow *window); + void show(QQuickWindow *window) override; + void hide(QQuickWindow *window) override; - void windowDestroyed(QQuickWindow *window); + void windowDestroyed(QQuickWindow *window) override; void renderWindow(QQuickWindow *window); - void exposureChanged(QQuickWindow *window); - QImage grab(QQuickWindow *window); + void exposureChanged(QQuickWindow *window) override; + QImage grab(QQuickWindow *window) override; - void maybeUpdate(QQuickWindow *window); - void update(QQuickWindow *window) { maybeUpdate(window); } // identical for this implementation. - void handleUpdateRequest(QQuickWindow *); + void maybeUpdate(QQuickWindow *window) override; + void update(QQuickWindow *window) override { maybeUpdate(window); } // identical for this implementation. + void handleUpdateRequest(QQuickWindow *) override; - void releaseResources(QQuickWindow *) { } + void releaseResources(QQuickWindow *) override { } - QAnimationDriver *animationDriver() const { return 0; } + QAnimationDriver *animationDriver() const override { return 0; } - QSGContext *sceneGraphContext() const; - QSGRenderContext *createRenderContext(QSGContext *) const { return rc; } + QSGContext *sceneGraphContext() const override; + QSGRenderContext *createRenderContext(QSGContext *) const override { return rc; } struct WindowData { bool updatePending : 1; diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp index 5fa74027c1..17a2c62a4e 100644 --- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -295,8 +295,8 @@ public: void invalidateOpenGL(QQuickWindow *window, bool inDestructor, QOffscreenSurface *backupSurface); void initializeOpenGL(); - bool event(QEvent *); - void run(); + bool event(QEvent *) override; + void run() override; void syncAndRender(); void sync(bool inExpose); diff --git a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp index 8ab7669891..a0c71b5340 100644 --- a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp +++ b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp @@ -50,13 +50,13 @@ class FlatColorMaterialShader : public QSGMaterialShader public: FlatColorMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual char const *const *attributeNames() const; + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; + char const *const *attributeNames() const override; static QSGMaterialType type; private: - virtual void initialize(); + void initialize() override; #if QT_CONFIG(opengl) int m_matrix_id; int m_color_id; diff --git a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp index 8c305d7fd4..42c589b14a 100644 --- a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp +++ b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp @@ -48,13 +48,13 @@ class QSGVertexColorMaterialShader : public QSGMaterialShader public: QSGVertexColorMaterialShader(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual char const *const *attributeNames() const; + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; + char const *const *attributeNames() const override; static QSGMaterialType type; private: - virtual void initialize(); + void initialize() override; #if QT_CONFIG(opengl) int m_matrix_id; int m_opacity_id; diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 5a723e4432..20bb23338d 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE class QQuickColorProvider : public QQmlColorProvider { public: - QVariant colorFromString(const QString &s, bool *ok) + QVariant colorFromString(const QString &s, bool *ok) override { QColor c(s); if (c.isValid()) { @@ -73,7 +73,7 @@ public: return QVariant(); } - unsigned rgbaFromString(const QString &s, bool *ok) + unsigned rgbaFromString(const QString &s, bool *ok) override { QColor c(s); if (c.isValid()) { @@ -95,36 +95,36 @@ public: return QString(); } - QVariant fromRgbF(double r, double g, double b, double a) + QVariant fromRgbF(double r, double g, double b, double a) override { return QVariant(QColor::fromRgbF(r, g, b, a)); } - QVariant fromHslF(double h, double s, double l, double a) + QVariant fromHslF(double h, double s, double l, double a) override { return QVariant(QColor::fromHslF(h, s, l, a)); } - QVariant fromHsvF(double h, double s, double v, double a) + QVariant fromHsvF(double h, double s, double v, double a) override { return QVariant(QColor::fromHsvF(h, s, v, a)); } - QVariant lighter(const QVariant &var, qreal factor) + QVariant lighter(const QVariant &var, qreal factor) override { QColor color = var.value(); color = color.lighter(int(qRound(factor*100.))); return QVariant::fromValue(color); } - QVariant darker(const QVariant &var, qreal factor) + QVariant darker(const QVariant &var, qreal factor) override { QColor color = var.value(); color = color.darker(int(qRound(factor*100.))); return QVariant::fromValue(color); } - QVariant tint(const QVariant &baseVar, const QVariant &tintVar) + QVariant tint(const QVariant &baseVar, const QVariant &tintVar) override { QColor tintColor = tintVar.value(); @@ -778,13 +778,13 @@ public: class QQuickGuiProvider : public QQmlGuiProvider { public: - QQuickApplication *application(QObject *parent) + QQuickApplication *application(QObject *parent) override { return new QQuickApplication(parent); } #if QT_CONFIG(im) - QInputMethod *inputMethod() + QInputMethod *inputMethod() override { QInputMethod *im = qGuiApp->inputMethod(); QQmlEngine::setObjectOwnership(im, QQmlEngine::CppOwnership); @@ -792,20 +792,20 @@ public: } #endif - QStyleHints *styleHints() + QStyleHints *styleHints() override { QStyleHints *sh = qGuiApp->styleHints(); QQmlEngine::setObjectOwnership(sh, QQmlEngine::CppOwnership); return sh; } - QStringList fontFamilies() + QStringList fontFamilies() override { QFontDatabase database; return database.families(); } - bool openUrlExternally(QUrl &url) + bool openUrlExternally(QUrl &url) override { #ifndef QT_NO_DESKTOPSERVICES return QDesktopServices::openUrl(url); diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index be27cba989..395b89c784 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -161,7 +161,7 @@ Q_SIGNALS: void downloadProgress(qint64, qint64); protected: - bool event(QEvent *event); + bool event(QEvent *event) override; private: Q_DISABLE_COPY(QQuickPixmapReply) @@ -199,7 +199,7 @@ public: static QQuickPixmapReader *existingInstance(QQmlEngine *engine); protected: - void run(); + void run() override; private: friend class QQuickPixmapReaderThreadObject; -- cgit v1.2.3 From dca1f953264a373cbbe42adccb93fea84b96af51 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 16 Feb 2017 12:38:51 +0100 Subject: QQuickImageBase: allow derived classes to affect devicePixelRatio usage QQuickImageBase currently sets its d->devicePixelRatio member in three scenarios: - The URL uses the image: scheme (an image provider) - The URL is an svg/svgz - The URL contains the "@2x" syntax In all other cases, it sets d->devicePixelRatio to 1.0. QQuickIconImage derives from QQuickImageBase, and can display theme icons in addition to regular images. Theme icons have their own directory structure that determines what is and is not a high DPI image: https://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html In particular, they use e.g. a 22x22@2 directory to indicate that the icons contained within it are high DPI images, as opposed to storing that information in the file name. To account for these images, QQuickIconImage must be able to affect the decision making progress that determines whether or not an image is loaded at a higher DPI. This patch adds a virtual function to QQuickImageBasePrivate that allows subclasses to have some control over this. Change-Id: Id45e0580c8e2ea9a96a41c54ef5fa765ce5922cf Reviewed-by: J-P Nurmi Reviewed-by: Robin Burchell --- src/quick/items/qquickimagebase.cpp | 47 +++++++++++++++++++++-------------- src/quick/items/qquickimagebase_p_p.h | 4 ++- 2 files changed, 31 insertions(+), 20 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp index 22d631e917..33d69f5032 100644 --- a/src/quick/items/qquickimagebase.cpp +++ b/src/quick/items/qquickimagebase.cpp @@ -49,6 +49,30 @@ QT_BEGIN_NAMESPACE +// This function gives derived classes the chance set the devicePixelRatio +// if they're not happy with our implementation of it. +bool QQuickImageBasePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio) +{ + // QQuickImageProvider and SVG can generate a high resolution image when + // sourceSize is set (this function is only called if it's set). + // If sourceSize is not set then the provider default size will be used, as usual. + bool setDevicePixelRatio = false; + if (url.scheme() == QLatin1String("image")) { + setDevicePixelRatio = true; + } else { + QString stringUrl = url.path(QUrl::PrettyDecoded); + if (stringUrl.endsWith(QLatin1String("svg")) || + stringUrl.endsWith(QLatin1String("svgz"))) { + setDevicePixelRatio = true; + } + } + + if (setDevicePixelRatio) + devicePixelRatio = targetDevicePixelRatio; + + return setDevicePixelRatio; +} + QQuickImageBase::QQuickImageBase(QQuickItem *parent) : QQuickImplicitSizeItem(*(new QQuickImageBasePrivate), parent) { @@ -221,26 +245,11 @@ void QQuickImageBase::load() QUrl loadUrl = d->url; - // QQuickImageProvider and SVG can generate a high resolution image when - // sourceSize is set. If sourceSize is not set then the provider default size - // will be used, as usual. - bool setDevicePixelRatio = false; - if (d->sourcesize.isValid()) { - if (loadUrl.scheme() == QLatin1String("image")) { - setDevicePixelRatio = true; - } else { - QString stringUrl = loadUrl.path(QUrl::PrettyDecoded); - if (stringUrl.endsWith(QLatin1String("svg")) || - stringUrl.endsWith(QLatin1String("svgz"))) { - setDevicePixelRatio = true; - } - } - - if (setDevicePixelRatio) - d->devicePixelRatio = targetDevicePixelRatio; - } + bool updatedDevicePixelRatio = false; + if (d->sourcesize.isValid()) + updatedDevicePixelRatio = d->updateDevicePixelRatio(targetDevicePixelRatio); - if (!setDevicePixelRatio) { + if (!updatedDevicePixelRatio) { // (possible) local file: loadUrl and d->devicePixelRatio will be modified if // an "@2x" file is found. resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); diff --git a/src/quick/items/qquickimagebase_p_p.h b/src/quick/items/qquickimagebase_p_p.h index d9b609c7fe..1b771166a2 100644 --- a/src/quick/items/qquickimagebase_p_p.h +++ b/src/quick/items/qquickimagebase_p_p.h @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE class QNetworkReply; -class QQuickImageBasePrivate : public QQuickImplicitSizeItemPrivate +class Q_QUICK_PRIVATE_EXPORT QQuickImageBasePrivate : public QQuickImplicitSizeItemPrivate { Q_DECLARE_PUBLIC(QQuickImageBase) @@ -75,6 +75,8 @@ public: { } + virtual bool updateDevicePixelRatio(qreal targetDevicePixelRatio); + QQuickPixmap pix; QQuickImageBase::Status status; QUrl url; -- cgit v1.2.3 From bb1acc24587ebdecc4051ef4b573ef32cfb8a8c5 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 16 Feb 2017 13:32:01 +0100 Subject: QQuickImage: take DPI into account for implicit and painted sizes As an example, an @2x image will report an implicit size that is twice as large as it should be when its fillMode is set to PreserveAspectFit. This commit adds code that was likely missed in 63fb30eb. Change-Id: I38cfdf3a429726639209c88dfb38eebb0b9ff162 Reviewed-by: Robin Burchell Reviewed-by: J-P Nurmi --- src/quick/items/qquickimage.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp index f71a2fbdbd..f3d7dc4b56 100644 --- a/src/quick/items/qquickimage.cpp +++ b/src/quick/items/qquickimage.cpp @@ -514,37 +514,41 @@ void QQuickImage::updatePaintedGeometry() setImplicitSize(0, 0); return; } - qreal w = widthValid() ? width() : d->pix.width(); - qreal widthScale = w / qreal(d->pix.width()); - qreal h = heightValid() ? height() : d->pix.height(); - qreal heightScale = h / qreal(d->pix.height()); + const qreal pixWidth = d->pix.width() / d->devicePixelRatio; + const qreal pixHeight = d->pix.height() / d->devicePixelRatio; + const qreal w = widthValid() ? width() : pixWidth; + const qreal widthScale = w / pixWidth; + const qreal h = heightValid() ? height() : pixHeight; + const qreal heightScale = h / pixHeight; if (widthScale <= heightScale) { d->paintedWidth = w; - d->paintedHeight = widthScale * qreal(d->pix.height()); + d->paintedHeight = widthScale * pixHeight; } else if (heightScale < widthScale) { - d->paintedWidth = heightScale * qreal(d->pix.width()); + d->paintedWidth = heightScale * pixWidth; d->paintedHeight = h; } - qreal iHeight = (widthValid() && !heightValid()) ? d->paintedHeight : d->pix.height(); - qreal iWidth = (heightValid() && !widthValid()) ? d->paintedWidth : d->pix.width(); + const qreal iHeight = (widthValid() && !heightValid()) ? d->paintedHeight : pixHeight; + const qreal iWidth = (heightValid() && !widthValid()) ? d->paintedWidth : pixWidth; setImplicitSize(iWidth, iHeight); } else if (d->fillMode == PreserveAspectCrop) { if (!d->pix.width() || !d->pix.height()) return; - qreal widthScale = width() / qreal(d->pix.width()); - qreal heightScale = height() / qreal(d->pix.height()); + const qreal pixWidth = d->pix.width() / d->devicePixelRatio; + const qreal pixHeight = d->pix.height() / d->devicePixelRatio; + qreal widthScale = width() / pixWidth; + qreal heightScale = height() / pixHeight; if (widthScale < heightScale) { widthScale = heightScale; } else if (heightScale < widthScale) { heightScale = widthScale; } - d->paintedHeight = heightScale * qreal(d->pix.height()); - d->paintedWidth = widthScale * qreal(d->pix.width()); + d->paintedHeight = heightScale * pixHeight; + d->paintedWidth = widthScale * pixWidth; } else if (d->fillMode == Pad) { - d->paintedWidth = d->pix.width(); - d->paintedHeight = d->pix.height(); + d->paintedWidth = d->pix.width() / d->devicePixelRatio; + d->paintedHeight = d->pix.height() / d->devicePixelRatio; } else { d->paintedWidth = width(); d->paintedHeight = height(); -- cgit v1.2.3