diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2022-12-14 10:48:27 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-01-31 15:20:05 +0000 |
commit | 90d4fb5e04a43e6acf4bb59e9ef4cefdf68946f0 (patch) | |
tree | 0968ae052361e7bd5a394441437a24884a713fbd | |
parent | 8e88754e2d059535bacdb6dc1feb2795cd247f76 (diff) |
Doc: improve grabToImage snippets
- Change the code that is quoted so that the indenting looks sane
- Make it possible to copy and run the first snippet without
modification
- Make it easier to copy and run the second snippet without
modification
- Move itemGrab.qml to item sub-directory
- Generally tidy up
Change-Id: I608b7a6025b9866c14b84420ae64827965a7519f
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
(cherry picked from commit f0f9bacca8d44e20bd0e21da819737aed0ff62b8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick/doc/snippets/qml/item/itemGrab.qml | 39 | ||||
-rw-r--r-- | src/quick/doc/snippets/qml/itemGrab.qml | 50 | ||||
-rw-r--r-- | src/quick/items/qquickitemgrabresult.cpp | 12 |
3 files changed, 44 insertions, 57 deletions
diff --git a/src/quick/doc/snippets/qml/item/itemGrab.qml b/src/quick/doc/snippets/qml/item/itemGrab.qml new file mode 100644 index 0000000000..ef4430175a --- /dev/null +++ b/src/quick/doc/snippets/qml/item/itemGrab.qml @@ -0,0 +1,39 @@ +// Copyright (C) 2014 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick 2.4 + +Item { + width: 320 + height: 480 + +//! [grab-to-file] +Rectangle { + id: sourceRectangle + width: 100 + height: 100 + gradient: Gradient { + GradientStop { position: 0; color: "steelblue" } + GradientStop { position: 1; color: "black" } + } + + Component.onCompleted: { + sourceRectangle.grabToImage(function(result) { + result.saveToFile("something.png") + }) + } +} +//! [grab-to-file] + +//! [grab-to-image] +Image { + id: image +} + +Component.onCompleted: { + sourceRectangle.grabToImage(function(result) { + image.source = result.url + }, Qt.size(50, 50)) +} +//! [grab-to-image] +} diff --git a/src/quick/doc/snippets/qml/itemGrab.qml b/src/quick/doc/snippets/qml/itemGrab.qml deleted file mode 100644 index dd02661894..0000000000 --- a/src/quick/doc/snippets/qml/itemGrab.qml +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2014 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick 2.4 - -Item { - width: 320 - height: 480 - -//! [grab-source] -Rectangle { - id: source - width: 100 - height: 100 - gradient: Gradient { - GradientStop { position: 0; color: "steelblue" } - GradientStop { position: 1; color: "black" } - } -} -//! [grab-source] - -//! [grab-image-target] -Image { - id: image -} -//! [grab-image-target] - Timer { - repeat: false - running: true - interval: 1000 - onTriggered: { -//! [grab-to-file] - - // ... - source.grabToImage(function(result) { - result.saveToFile("something.png"); - }); -//! [grab-to-file] - -//! [grab-to-cache] - - // ... - source.grabToImage(function(result) { - image.source = result.url; - }, - Qt.size(50, 50)); -//! [grab-to-cache] - } - } -} diff --git a/src/quick/items/qquickitemgrabresult.cpp b/src/quick/items/qquickitemgrabresult.cpp index 01b64a7732..bcd1afc19d 100644 --- a/src/quick/items/qquickitemgrabresult.cpp +++ b/src/quick/items/qquickitemgrabresult.cpp @@ -345,17 +345,15 @@ QSharedPointer<QQuickItemGrabResult> QQuickItem::grabToImage(const QSize &target * * If the grab could not be initiated, the function returns \c false. * - * The following snippet shows how to grab an item and store the results to - * a file. + * The following snippet shows how to grab an item and store the results in + * a file: * - * \snippet qml/itemGrab.qml grab-source - * \snippet qml/itemGrab.qml grab-to-file + * \snippet qml/item/itemGrab.qml grab-to-file * * The following snippet shows how to grab an item and use the results in - * another image element. + * another image element: * - * \snippet qml/itemGrab.qml grab-image-target - * \snippet qml/itemGrab.qml grab-to-cache + * \snippet qml/item/itemGrab.qml grab-to-image * * \note This function will render the item to an offscreen surface and * copy that surface from the GPU's memory into the CPU's memory, which can |