2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-09-15 04:28:46 +00:00
|
|
|
|
2021-02-04 10:46:07 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import "../"
|
2013-02-24 14:47:38 +00:00
|
|
|
|
canvas item refactors
1.Supports tiled canvas with canvasSize, tileSize and canvasWindow
2.Supports different rendering targets: Canvas.Image and
Canvas.FrameBufferObject by renderTarget property
3.Supports thread rendering when possible by threadRendering property.
4.Refactors QSGContext2D code, move some logic to
QSGContext2DCommandBuffer,QSGContext2DTexture,QSGContext2DTile, etc
5.Updates/adds some canvas examples
6.Some improvements for context2d API
6.1 drawImage() now loads image asynchoronously and draw images
automatically when they are ready
6.2 adds fillRule supports
6.3 add svg path supports
6.4 Pixel operations (getImageData/putImageData/createImageData)
now have better performance by using V8 indexed array accessors
6.5 Uses QTransform instead of QMatrix
6.6 Gradients/patterns now are V8 values, not QObjects
6.7 Supports measureText and TextMetrics interface
6.8 Gives not support warnings for unimplemented functions
(drawFocusRing,setCaretSelectionRect,caretBlinkRate)
6.9 Better error handling, throw standard DOM exceptions according
to the HTML5 context2d spec.
6.10 Adds shear, resetTransform to matrix operations
6.11 Adds roundedRect, ellipse, text to path operations
6.12 Adds new features to CanvasImageData interface
1) adds mirror() function
2) adds filter() function, include the following filters:
Threshold
GrayScale
Brightness
Invert
Blur
Blend
Opaque
Convolute
7. Adds documentations
Change-Id: Id19224260d6a3fdc589d1f9681c34a88a7e7b3e5
Reviewed-on: http://codereview.qt-project.org/3621
Reviewed-by: Charles Yin <charles.yin@nokia.com>
2011-08-09 06:44:38 +00:00
|
|
|
Item {
|
2023-02-20 17:01:12 +00:00
|
|
|
id: root
|
2013-02-24 14:47:38 +00:00
|
|
|
width: 320
|
|
|
|
height: 480
|
canvas item refactors
1.Supports tiled canvas with canvasSize, tileSize and canvasWindow
2.Supports different rendering targets: Canvas.Image and
Canvas.FrameBufferObject by renderTarget property
3.Supports thread rendering when possible by threadRendering property.
4.Refactors QSGContext2D code, move some logic to
QSGContext2DCommandBuffer,QSGContext2DTexture,QSGContext2DTile, etc
5.Updates/adds some canvas examples
6.Some improvements for context2d API
6.1 drawImage() now loads image asynchoronously and draw images
automatically when they are ready
6.2 adds fillRule supports
6.3 add svg path supports
6.4 Pixel operations (getImageData/putImageData/createImageData)
now have better performance by using V8 indexed array accessors
6.5 Uses QTransform instead of QMatrix
6.6 Gradients/patterns now are V8 values, not QObjects
6.7 Supports measureText and TextMetrics interface
6.8 Gives not support warnings for unimplemented functions
(drawFocusRing,setCaretSelectionRect,caretBlinkRate)
6.9 Better error handling, throw standard DOM exceptions according
to the HTML5 context2d spec.
6.10 Adds shear, resetTransform to matrix operations
6.11 Adds roundedRect, ellipse, text to path operations
6.12 Adds new features to CanvasImageData interface
1) adds mirror() function
2) adds filter() function, include the following filters:
Threshold
GrayScale
Brightness
Invert
Blur
Blend
Opaque
Convolute
7. Adds documentations
Change-Id: Id19224260d6a3fdc589d1f9681c34a88a7e7b3e5
Reviewed-on: http://codereview.qt-project.org/3621
Reviewed-by: Charles Yin <charles.yin@nokia.com>
2011-08-09 06:44:38 +00:00
|
|
|
|
2013-02-24 14:47:38 +00:00
|
|
|
Column {
|
|
|
|
spacing: 6
|
2023-02-20 17:01:12 +00:00
|
|
|
anchors {
|
|
|
|
fill: parent
|
|
|
|
topMargin: 12
|
|
|
|
}
|
2021-02-04 10:46:07 +00:00
|
|
|
|
|
|
|
Label {
|
2013-02-24 14:47:38 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2023-02-20 17:01:12 +00:00
|
|
|
text: qsTr("Rounded rectangle")
|
|
|
|
color: Qt.lighter(palette.text)
|
|
|
|
font {
|
|
|
|
pointSize: 24
|
|
|
|
bold: true
|
|
|
|
}
|
2013-02-24 14:47:38 +00:00
|
|
|
}
|
|
|
|
Canvas {
|
|
|
|
id: canvas
|
canvas item refactors
1.Supports tiled canvas with canvasSize, tileSize and canvasWindow
2.Supports different rendering targets: Canvas.Image and
Canvas.FrameBufferObject by renderTarget property
3.Supports thread rendering when possible by threadRendering property.
4.Refactors QSGContext2D code, move some logic to
QSGContext2DCommandBuffer,QSGContext2DTexture,QSGContext2DTile, etc
5.Updates/adds some canvas examples
6.Some improvements for context2d API
6.1 drawImage() now loads image asynchoronously and draw images
automatically when they are ready
6.2 adds fillRule supports
6.3 add svg path supports
6.4 Pixel operations (getImageData/putImageData/createImageData)
now have better performance by using V8 indexed array accessors
6.5 Uses QTransform instead of QMatrix
6.6 Gradients/patterns now are V8 values, not QObjects
6.7 Supports measureText and TextMetrics interface
6.8 Gives not support warnings for unimplemented functions
(drawFocusRing,setCaretSelectionRect,caretBlinkRate)
6.9 Better error handling, throw standard DOM exceptions according
to the HTML5 context2d spec.
6.10 Adds shear, resetTransform to matrix operations
6.11 Adds roundedRect, ellipse, text to path operations
6.12 Adds new features to CanvasImageData interface
1) adds mirror() function
2) adds filter() function, include the following filters:
Threshold
GrayScale
Brightness
Invert
Blur
Blend
Opaque
Convolute
7. Adds documentations
Change-Id: Id19224260d6a3fdc589d1f9681c34a88a7e7b3e5
Reviewed-on: http://codereview.qt-project.org/3621
Reviewed-by: Charles Yin <charles.yin@nokia.com>
2011-08-09 06:44:38 +00:00
|
|
|
|
2023-02-20 17:01:12 +00:00
|
|
|
readonly property alias radius: rCtrl.value
|
|
|
|
readonly property int rectx: 60
|
|
|
|
readonly property int recty: 60
|
|
|
|
readonly property int rectWidth: width - 2 * rectx
|
|
|
|
readonly property int rectHeight: height - 2 * recty
|
|
|
|
readonly property color strokeStyle: Qt.darker(fillStyle, 1.4)
|
|
|
|
readonly property color fillStyle: "#ae32a0" // purple
|
|
|
|
readonly property alias lineWidth: lineWidthCtrl.value
|
|
|
|
readonly property alias fill: toggleFillCheckBox.checked
|
|
|
|
readonly property alias stroke: toggleStrokeCheckBox.checked
|
|
|
|
readonly property real alpha: 1.0
|
canvas item refactors
1.Supports tiled canvas with canvasSize, tileSize and canvasWindow
2.Supports different rendering targets: Canvas.Image and
Canvas.FrameBufferObject by renderTarget property
3.Supports thread rendering when possible by threadRendering property.
4.Refactors QSGContext2D code, move some logic to
QSGContext2DCommandBuffer,QSGContext2DTexture,QSGContext2DTile, etc
5.Updates/adds some canvas examples
6.Some improvements for context2d API
6.1 drawImage() now loads image asynchoronously and draw images
automatically when they are ready
6.2 adds fillRule supports
6.3 add svg path supports
6.4 Pixel operations (getImageData/putImageData/createImageData)
now have better performance by using V8 indexed array accessors
6.5 Uses QTransform instead of QMatrix
6.6 Gradients/patterns now are V8 values, not QObjects
6.7 Supports measureText and TextMetrics interface
6.8 Gives not support warnings for unimplemented functions
(drawFocusRing,setCaretSelectionRect,caretBlinkRate)
6.9 Better error handling, throw standard DOM exceptions according
to the HTML5 context2d spec.
6.10 Adds shear, resetTransform to matrix operations
6.11 Adds roundedRect, ellipse, text to path operations
6.12 Adds new features to CanvasImageData interface
1) adds mirror() function
2) adds filter() function, include the following filters:
Threshold
GrayScale
Brightness
Invert
Blur
Blend
Opaque
Convolute
7. Adds documentations
Change-Id: Id19224260d6a3fdc589d1f9681c34a88a7e7b3e5
Reviewed-on: http://codereview.qt-project.org/3621
Reviewed-by: Charles Yin <charles.yin@nokia.com>
2011-08-09 06:44:38 +00:00
|
|
|
|
2023-02-20 17:01:12 +00:00
|
|
|
width: root.width
|
|
|
|
height: parent.height - controls.height
|
|
|
|
antialiasing: true
|
|
|
|
|
|
|
|
onLineWidthChanged: requestPaint()
|
|
|
|
onFillChanged: requestPaint()
|
|
|
|
onStrokeChanged: requestPaint()
|
|
|
|
onRadiusChanged: requestPaint()
|
canvas item refactors
1.Supports tiled canvas with canvasSize, tileSize and canvasWindow
2.Supports different rendering targets: Canvas.Image and
Canvas.FrameBufferObject by renderTarget property
3.Supports thread rendering when possible by threadRendering property.
4.Refactors QSGContext2D code, move some logic to
QSGContext2DCommandBuffer,QSGContext2DTexture,QSGContext2DTile, etc
5.Updates/adds some canvas examples
6.Some improvements for context2d API
6.1 drawImage() now loads image asynchoronously and draw images
automatically when they are ready
6.2 adds fillRule supports
6.3 add svg path supports
6.4 Pixel operations (getImageData/putImageData/createImageData)
now have better performance by using V8 indexed array accessors
6.5 Uses QTransform instead of QMatrix
6.6 Gradients/patterns now are V8 values, not QObjects
6.7 Supports measureText and TextMetrics interface
6.8 Gives not support warnings for unimplemented functions
(drawFocusRing,setCaretSelectionRect,caretBlinkRate)
6.9 Better error handling, throw standard DOM exceptions according
to the HTML5 context2d spec.
6.10 Adds shear, resetTransform to matrix operations
6.11 Adds roundedRect, ellipse, text to path operations
6.12 Adds new features to CanvasImageData interface
1) adds mirror() function
2) adds filter() function, include the following filters:
Threshold
GrayScale
Brightness
Invert
Blur
Blend
Opaque
Convolute
7. Adds documentations
Change-Id: Id19224260d6a3fdc589d1f9681c34a88a7e7b3e5
Reviewed-on: http://codereview.qt-project.org/3621
Reviewed-by: Charles Yin <charles.yin@nokia.com>
2011-08-09 06:44:38 +00:00
|
|
|
|
2023-02-20 17:01:12 +00:00
|
|
|
onPaint: function() {
|
|
|
|
var ctx = getContext("2d")
|
|
|
|
ctx.save()
|
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
|
|
ctx.strokeStyle = canvas.strokeStyle
|
2013-02-24 14:47:38 +00:00
|
|
|
ctx.lineWidth = canvas.lineWidth
|
|
|
|
ctx.fillStyle = canvas.fillStyle
|
|
|
|
ctx.globalAlpha = canvas.alpha
|
2023-02-20 17:01:12 +00:00
|
|
|
ctx.beginPath()
|
|
|
|
ctx.moveTo(rectx + radius, recty) // top side
|
|
|
|
ctx.lineTo(rectx + rectWidth - radius, recty)
|
2013-02-24 14:47:38 +00:00
|
|
|
// draw top right corner
|
2023-02-20 17:01:12 +00:00
|
|
|
ctx.arcTo(rectx + rectWidth, recty, rectx + rectWidth, recty + radius, radius)
|
|
|
|
ctx.lineTo(rectx + rectWidth, recty + rectHeight - radius) // right side
|
2013-02-24 14:47:38 +00:00
|
|
|
// draw bottom right corner
|
2023-02-20 17:01:12 +00:00
|
|
|
ctx.arcTo(rectx + rectWidth, recty + rectHeight, rectx + rectWidth - radius, recty + rectHeight, radius)
|
|
|
|
ctx.lineTo(rectx + radius, recty + rectHeight) // bottom side
|
2013-02-24 14:47:38 +00:00
|
|
|
// draw bottom left corner
|
2023-02-20 17:01:12 +00:00
|
|
|
ctx.arcTo(rectx, recty + rectHeight, rectx, recty + rectHeight - radius, radius)
|
|
|
|
ctx.lineTo(rectx, recty + radius) // left side
|
2013-02-24 14:47:38 +00:00
|
|
|
// draw top left corner
|
2023-02-20 17:01:12 +00:00
|
|
|
ctx.arcTo(rectx, recty, rectx + radius, recty, radius)
|
|
|
|
ctx.closePath()
|
2013-02-24 14:47:38 +00:00
|
|
|
if (canvas.fill)
|
2023-02-20 17:01:12 +00:00
|
|
|
ctx.fill()
|
2013-02-24 14:47:38 +00:00
|
|
|
if (canvas.stroke)
|
2023-02-20 17:01:12 +00:00
|
|
|
ctx.stroke()
|
|
|
|
ctx.restore()
|
2013-02-24 14:47:38 +00:00
|
|
|
}
|
canvas item refactors
1.Supports tiled canvas with canvasSize, tileSize and canvasWindow
2.Supports different rendering targets: Canvas.Image and
Canvas.FrameBufferObject by renderTarget property
3.Supports thread rendering when possible by threadRendering property.
4.Refactors QSGContext2D code, move some logic to
QSGContext2DCommandBuffer,QSGContext2DTexture,QSGContext2DTile, etc
5.Updates/adds some canvas examples
6.Some improvements for context2d API
6.1 drawImage() now loads image asynchoronously and draw images
automatically when they are ready
6.2 adds fillRule supports
6.3 add svg path supports
6.4 Pixel operations (getImageData/putImageData/createImageData)
now have better performance by using V8 indexed array accessors
6.5 Uses QTransform instead of QMatrix
6.6 Gradients/patterns now are V8 values, not QObjects
6.7 Supports measureText and TextMetrics interface
6.8 Gives not support warnings for unimplemented functions
(drawFocusRing,setCaretSelectionRect,caretBlinkRate)
6.9 Better error handling, throw standard DOM exceptions according
to the HTML5 context2d spec.
6.10 Adds shear, resetTransform to matrix operations
6.11 Adds roundedRect, ellipse, text to path operations
6.12 Adds new features to CanvasImageData interface
1) adds mirror() function
2) adds filter() function, include the following filters:
Threshold
GrayScale
Brightness
Invert
Blur
Blend
Opaque
Convolute
7. Adds documentations
Change-Id: Id19224260d6a3fdc589d1f9681c34a88a7e7b3e5
Reviewed-on: http://codereview.qt-project.org/3621
Reviewed-by: Charles Yin <charles.yin@nokia.com>
2011-08-09 06:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-24 14:47:38 +00:00
|
|
|
Column {
|
2023-02-20 17:01:12 +00:00
|
|
|
id: controls
|
|
|
|
anchors {
|
|
|
|
bottom: parent.bottom
|
|
|
|
bottomMargin: 12
|
|
|
|
}
|
2021-02-04 10:46:07 +00:00
|
|
|
|
2023-02-20 17:01:12 +00:00
|
|
|
LabeledSlider {
|
|
|
|
id: lineWidthCtrl
|
|
|
|
name: qsTr("Outline")
|
|
|
|
width: root.width
|
|
|
|
min: 1
|
|
|
|
max: 10
|
|
|
|
value: 2
|
|
|
|
}
|
|
|
|
LabeledSlider {
|
|
|
|
id: rCtrl
|
|
|
|
name: qsTr("Radius")
|
|
|
|
width: root.width
|
|
|
|
min: 10
|
|
|
|
max: 80
|
|
|
|
value: 40
|
|
|
|
}
|
|
|
|
Row {
|
|
|
|
CheckBox {
|
|
|
|
id: toggleFillCheckBox
|
|
|
|
checked: true
|
|
|
|
text: qsTr("Toggle fill")
|
|
|
|
}
|
|
|
|
CheckBox {
|
|
|
|
id: toggleStrokeCheckBox
|
|
|
|
checked: true
|
|
|
|
text: qsTr("Toggle stroke")
|
|
|
|
}
|
|
|
|
}
|
canvas item refactors
1.Supports tiled canvas with canvasSize, tileSize and canvasWindow
2.Supports different rendering targets: Canvas.Image and
Canvas.FrameBufferObject by renderTarget property
3.Supports thread rendering when possible by threadRendering property.
4.Refactors QSGContext2D code, move some logic to
QSGContext2DCommandBuffer,QSGContext2DTexture,QSGContext2DTile, etc
5.Updates/adds some canvas examples
6.Some improvements for context2d API
6.1 drawImage() now loads image asynchoronously and draw images
automatically when they are ready
6.2 adds fillRule supports
6.3 add svg path supports
6.4 Pixel operations (getImageData/putImageData/createImageData)
now have better performance by using V8 indexed array accessors
6.5 Uses QTransform instead of QMatrix
6.6 Gradients/patterns now are V8 values, not QObjects
6.7 Supports measureText and TextMetrics interface
6.8 Gives not support warnings for unimplemented functions
(drawFocusRing,setCaretSelectionRect,caretBlinkRate)
6.9 Better error handling, throw standard DOM exceptions according
to the HTML5 context2d spec.
6.10 Adds shear, resetTransform to matrix operations
6.11 Adds roundedRect, ellipse, text to path operations
6.12 Adds new features to CanvasImageData interface
1) adds mirror() function
2) adds filter() function, include the following filters:
Threshold
GrayScale
Brightness
Invert
Blur
Blend
Opaque
Convolute
7. Adds documentations
Change-Id: Id19224260d6a3fdc589d1f9681c34a88a7e7b3e5
Reviewed-on: http://codereview.qt-project.org/3621
Reviewed-by: Charles Yin <charles.yin@nokia.com>
2011-08-09 06:44:38 +00:00
|
|
|
}
|
2012-02-09 05:48:40 +00:00
|
|
|
}
|