more qml/extending/components examples

This commit is contained in:
therecipe 2017-05-30 22:35:39 +02:00
parent 73d9e74dd7
commit 74048e48e8
25 changed files with 582 additions and 0 deletions

View file

@ -80,7 +80,11 @@ func Test(target string, docker bool) {
filepath.Join("extending", "chapter2-methods"),
filepath.Join("extending", "chapter3-bindings"),
filepath.Join("extending", "chapter4-customPropertyTypes"),
filepath.Join("extending", "components", "test_dir"),
filepath.Join("extending", "components", "test_dir_2"),
filepath.Join("extending", "components", "test_go"),
filepath.Join("extending", "components", "test_module"),
filepath.Join("extending", "components", "test_module_2"),
filepath.Join("extending", "components", "test_qml"),
filepath.Join("extending", "components", "test_qml_go"),
"gallery", "material",

View file

@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
//![0]
import QtQuick 2.0
import "SomeComponentDir"
Rectangle {
width: 400; height: 300
color: "green"
TheComponent {
anchors.centerIn: parent
}
}
//![0]

View file

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>app.qml</file>
</qresource>
</RCC>

View file

@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>SomeComponentDir/qmldir</file>
<file>SomeComponentDir/SomeComponent.qml</file>
</qresource>
</RCC>

View file

@ -0,0 +1,18 @@
import Charts 1.0
import QtQuick 2.0
Rectangle {
width: 300; height: 200
color: "blue"
PieChart {
id: aPieChart
anchors.centerIn: parent
width: 100; height: 100
name: "A simple pie chart"
color: "red"
Component.onCompleted: factory.create(aPieChart)
}
}

View file

@ -0,0 +1 @@
TheComponent 1.0 SomeComponent.qml

View file

@ -0,0 +1,42 @@
package component
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
)
func init() {
PieChart_QmlRegisterType2("Charts", 1, 0, "PieChart")
}
type PieChart struct {
quick.QQuickPaintedItem
_ string `property:"name"`
_ *gui.QColor `property:"color"`
}
func (p *PieChart) paint(painter *gui.QPainter) {
pen := gui.NewQPen3(p.Color())
pen.SetWidth(2)
painter.SetPen(pen)
painter.SetRenderHints(gui.QPainter__Antialiasing, true)
painter.DrawPie3(core.NewQRect4(0, 0, int(p.Width()), int(p.Height())).Adjusted(1, 1, -1, -1), 90*16, 290*16)
}
type PieChartFactory struct {
core.QObject
_ func() `constructor:"init"`
_ func(p *PieChart) `slot:"create"`
}
func (p *PieChartFactory) init() {
p.ConnectCreate(p.create)
}
func (p *PieChartFactory) create(pie *PieChart) {
pie.ConnectPaint(pie.paint)
}

View file

@ -0,0 +1,24 @@
package main
import (
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/internal/examples/qml/extending/components/test_dir/component"
)
func main() {
gui.NewQGuiApplication(len(os.Args), os.Args)
view := quick.NewQQuickView(nil)
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
view.RootContext().SetContextProperty("factory", component.NewPieChartFactory(nil))
view.SetSource(core.NewQUrl3("qrc:///app.qml", 0))
view.Show()
gui.QGuiApplication_Exec()
}

View file

@ -0,0 +1,42 @@
package component
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
)
func init() {
PieChart_QmlRegisterType2("Charts", 1, 0, "PieChart")
}
type PieChart struct {
quick.QQuickPaintedItem
_ string `property:"name"`
_ *gui.QColor `property:"color"`
}
func (p *PieChart) paint(painter *gui.QPainter) {
pen := gui.NewQPen3(p.Color())
pen.SetWidth(2)
painter.SetPen(pen)
painter.SetRenderHints(gui.QPainter__Antialiasing, true)
painter.DrawPie3(core.NewQRect4(0, 0, int(p.Width()), int(p.Height())).Adjusted(1, 1, -1, -1), 90*16, 290*16)
}
type PieChartFactory struct {
core.QObject
_ func() `constructor:"init"`
_ func(p *PieChart) `slot:"create"`
}
func (p *PieChartFactory) init() {
p.ConnectCreate(p.create)
}
func (p *PieChartFactory) create(pie *PieChart) {
pie.ConnectPaint(pie.paint)
}

View file

@ -0,0 +1,18 @@
import Charts 1.0
import QtQuick 2.0
Rectangle {
width: 300; height: 200
color: "blue"
PieChart {
id: aPieChart
anchors.centerIn: parent
width: 100; height: 100
name: "A simple pie chart"
color: "red"
Component.onCompleted: factory.create(aPieChart)
}
}

View file

@ -0,0 +1 @@
TheComponent 1.0 SomeComponent.qml

View file

@ -0,0 +1,24 @@
package main
import (
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/internal/examples/qml/extending/components/test_dir_2/component"
)
func main() {
gui.NewQGuiApplication(len(os.Args), os.Args)
view := quick.NewQQuickView(nil)
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
view.RootContext().SetContextProperty("factory", component.NewPieChartFactory(nil))
view.SetSource(core.NewQUrl3("qrc:///qml/app.qml", 0))
view.Show()
gui.QGuiApplication_Exec()
}

View file

@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
//![0]
import QtQuick 2.0
import "SomeComponentDir"
Rectangle {
width: 400; height: 300
color: "green"
TheComponent {
anchors.centerIn: parent
}
}
//![0]

View file

@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
//![0]
import QtQuick 2.0
import SomeComponentModule 1.0
Rectangle {
width: 400; height: 300
color: "green"
TheComponent {
anchors.centerIn: parent
}
}
//![0]

View file

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>app.qml</file>
</qresource>
</RCC>

View file

@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>SomeComponentModule/qmldir</file>
<file>SomeComponentModule/SomeComponent.qml</file>
</qresource>
</RCC>

View file

@ -0,0 +1,18 @@
import Charts 1.0
import QtQuick 2.0
Rectangle {
width: 300; height: 200
color: "blue"
PieChart {
id: aPieChart
anchors.centerIn: parent
width: 100; height: 100
name: "A simple pie chart"
color: "red"
Component.onCompleted: factory.create(aPieChart)
}
}

View file

@ -0,0 +1,2 @@
module SomeComponentModule
TheComponent 1.0 SomeComponent.qml

View file

@ -0,0 +1,42 @@
package component
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
)
func init() {
PieChart_QmlRegisterType2("Charts", 1, 0, "PieChart")
}
type PieChart struct {
quick.QQuickPaintedItem
_ string `property:"name"`
_ *gui.QColor `property:"color"`
}
func (p *PieChart) paint(painter *gui.QPainter) {
pen := gui.NewQPen3(p.Color())
pen.SetWidth(2)
painter.SetPen(pen)
painter.SetRenderHints(gui.QPainter__Antialiasing, true)
painter.DrawPie3(core.NewQRect4(0, 0, int(p.Width()), int(p.Height())).Adjusted(1, 1, -1, -1), 90*16, 290*16)
}
type PieChartFactory struct {
core.QObject
_ func() `constructor:"init"`
_ func(p *PieChart) `slot:"create"`
}
func (p *PieChartFactory) init() {
p.ConnectCreate(p.create)
}
func (p *PieChartFactory) create(pie *PieChart) {
pie.ConnectPaint(pie.paint)
}

View file

@ -0,0 +1,25 @@
package main
import (
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/internal/examples/qml/extending/components/test_module/component"
)
func main() {
gui.NewQGuiApplication(len(os.Args), os.Args)
view := quick.NewQQuickView(nil)
view.Engine().AddImportPath("qrc:///")
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
view.RootContext().SetContextProperty("factory", component.NewPieChartFactory(nil))
view.SetSource(core.NewQUrl3("qrc:///app.qml", 0))
view.Show()
gui.QGuiApplication_Exec()
}

View file

@ -0,0 +1,42 @@
package component
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
)
func init() {
PieChart_QmlRegisterType2("Charts", 1, 0, "PieChart")
}
type PieChart struct {
quick.QQuickPaintedItem
_ string `property:"name"`
_ *gui.QColor `property:"color"`
}
func (p *PieChart) paint(painter *gui.QPainter) {
pen := gui.NewQPen3(p.Color())
pen.SetWidth(2)
painter.SetPen(pen)
painter.SetRenderHints(gui.QPainter__Antialiasing, true)
painter.DrawPie3(core.NewQRect4(0, 0, int(p.Width()), int(p.Height())).Adjusted(1, 1, -1, -1), 90*16, 290*16)
}
type PieChartFactory struct {
core.QObject
_ func() `constructor:"init"`
_ func(p *PieChart) `slot:"create"`
}
func (p *PieChartFactory) init() {
p.ConnectCreate(p.create)
}
func (p *PieChartFactory) create(pie *PieChart) {
pie.ConnectPaint(pie.paint)
}

View file

@ -0,0 +1,18 @@
import Charts 1.0
import QtQuick 2.0
Rectangle {
width: 300; height: 200
color: "blue"
PieChart {
id: aPieChart
anchors.centerIn: parent
width: 100; height: 100
name: "A simple pie chart"
color: "red"
Component.onCompleted: factory.create(aPieChart)
}
}

View file

@ -0,0 +1,2 @@
module SomeComponentModule
TheComponent 1.0 SomeComponent.qml

View file

@ -0,0 +1,25 @@
package main
import (
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/internal/examples/qml/extending/components/test_module_2/component"
)
func main() {
gui.NewQGuiApplication(len(os.Args), os.Args)
view := quick.NewQQuickView(nil)
view.Engine().AddImportPath("qrc:///qml")
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
view.RootContext().SetContextProperty("factory", component.NewPieChartFactory(nil))
view.SetSource(core.NewQUrl3("qrc:///qml/app.qml", 0))
view.Show()
gui.QGuiApplication_Exec()
}

View file

@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
//![0]
import QtQuick 2.0
import SomeComponentModule 1.0
Rectangle {
width: 400; height: 300
color: "green"
TheComponent {
anchors.centerIn: parent
}
}
//![0]