From 74048e48e8ea47fa30713c82082c34f86dad811a Mon Sep 17 00:00:00 2001 From: therecipe Date: Tue, 30 May 2017 22:35:39 +0200 Subject: [PATCH] more qml/extending/components examples --- internal/cmd/setup/test.go | 4 ++ .../qml/extending/components/test_dir/app.qml | 53 +++++++++++++++++++ .../qml/extending/components/test_dir/app.qrc | 5 ++ .../test_dir/component/SomeComponentDir.qrc | 6 +++ .../SomeComponentDir/SomeComponent.qml | 18 +++++++ .../component/SomeComponentDir/qmldir | 1 + .../components/test_dir/component/piechart.go | 42 +++++++++++++++ .../qml/extending/components/test_dir/main.go | 24 +++++++++ .../test_dir_2/component/piechart.go | 42 +++++++++++++++ .../qml/SomeComponentDir/SomeComponent.qml | 18 +++++++ .../component/qml/SomeComponentDir/qmldir | 1 + .../extending/components/test_dir_2/main.go | 24 +++++++++ .../components/test_dir_2/qml/app.qml | 53 +++++++++++++++++++ .../extending/components/test_module/app.qml | 53 +++++++++++++++++++ .../extending/components/test_module/app.qrc | 5 ++ .../component/SomeComponentModule.qrc | 6 +++ .../SomeComponentModule/SomeComponent.qml | 18 +++++++ .../component/SomeComponentModule/qmldir | 2 + .../test_module/component/piechart.go | 42 +++++++++++++++ .../extending/components/test_module/main.go | 25 +++++++++ .../test_module_2/component/piechart.go | 42 +++++++++++++++ .../qml/SomeComponentModule/SomeComponent.qml | 18 +++++++ .../component/qml/SomeComponentModule/qmldir | 2 + .../components/test_module_2/main.go | 25 +++++++++ .../components/test_module_2/qml/app.qml | 53 +++++++++++++++++++ 25 files changed, 582 insertions(+) create mode 100755 internal/examples/qml/extending/components/test_dir/app.qml create mode 100755 internal/examples/qml/extending/components/test_dir/app.qrc create mode 100644 internal/examples/qml/extending/components/test_dir/component/SomeComponentDir.qrc create mode 100755 internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/SomeComponent.qml create mode 100644 internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/qmldir create mode 100644 internal/examples/qml/extending/components/test_dir/component/piechart.go create mode 100644 internal/examples/qml/extending/components/test_dir/main.go create mode 100644 internal/examples/qml/extending/components/test_dir_2/component/piechart.go create mode 100755 internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/SomeComponent.qml create mode 100644 internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/qmldir create mode 100644 internal/examples/qml/extending/components/test_dir_2/main.go create mode 100755 internal/examples/qml/extending/components/test_dir_2/qml/app.qml create mode 100755 internal/examples/qml/extending/components/test_module/app.qml create mode 100755 internal/examples/qml/extending/components/test_module/app.qrc create mode 100644 internal/examples/qml/extending/components/test_module/component/SomeComponentModule.qrc create mode 100755 internal/examples/qml/extending/components/test_module/component/SomeComponentModule/SomeComponent.qml create mode 100644 internal/examples/qml/extending/components/test_module/component/SomeComponentModule/qmldir create mode 100644 internal/examples/qml/extending/components/test_module/component/piechart.go create mode 100644 internal/examples/qml/extending/components/test_module/main.go create mode 100644 internal/examples/qml/extending/components/test_module_2/component/piechart.go create mode 100755 internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/SomeComponent.qml create mode 100644 internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/qmldir create mode 100644 internal/examples/qml/extending/components/test_module_2/main.go create mode 100755 internal/examples/qml/extending/components/test_module_2/qml/app.qml diff --git a/internal/cmd/setup/test.go b/internal/cmd/setup/test.go index e4031645..e2b29862 100644 --- a/internal/cmd/setup/test.go +++ b/internal/cmd/setup/test.go @@ -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", diff --git a/internal/examples/qml/extending/components/test_dir/app.qml b/internal/examples/qml/extending/components/test_dir/app.qml new file mode 100755 index 00000000..f463a4fe --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir/app.qml @@ -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] diff --git a/internal/examples/qml/extending/components/test_dir/app.qrc b/internal/examples/qml/extending/components/test_dir/app.qrc new file mode 100755 index 00000000..2acbfd5b --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir/app.qrc @@ -0,0 +1,5 @@ + + + app.qml + + diff --git a/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir.qrc b/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir.qrc new file mode 100644 index 00000000..0e9d60bb --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir.qrc @@ -0,0 +1,6 @@ + + +SomeComponentDir/qmldir +SomeComponentDir/SomeComponent.qml + + diff --git a/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/SomeComponent.qml b/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/SomeComponent.qml new file mode 100755 index 00000000..f279d3cb --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/SomeComponent.qml @@ -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) + } +} diff --git a/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/qmldir b/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/qmldir new file mode 100644 index 00000000..8378130b --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir/component/SomeComponentDir/qmldir @@ -0,0 +1 @@ +TheComponent 1.0 SomeComponent.qml diff --git a/internal/examples/qml/extending/components/test_dir/component/piechart.go b/internal/examples/qml/extending/components/test_dir/component/piechart.go new file mode 100644 index 00000000..2b5b91ec --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir/component/piechart.go @@ -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) +} diff --git a/internal/examples/qml/extending/components/test_dir/main.go b/internal/examples/qml/extending/components/test_dir/main.go new file mode 100644 index 00000000..9d624828 --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir/main.go @@ -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() +} diff --git a/internal/examples/qml/extending/components/test_dir_2/component/piechart.go b/internal/examples/qml/extending/components/test_dir_2/component/piechart.go new file mode 100644 index 00000000..2b5b91ec --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir_2/component/piechart.go @@ -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) +} diff --git a/internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/SomeComponent.qml b/internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/SomeComponent.qml new file mode 100755 index 00000000..f279d3cb --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/SomeComponent.qml @@ -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) + } +} diff --git a/internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/qmldir b/internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/qmldir new file mode 100644 index 00000000..8378130b --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir_2/component/qml/SomeComponentDir/qmldir @@ -0,0 +1 @@ +TheComponent 1.0 SomeComponent.qml diff --git a/internal/examples/qml/extending/components/test_dir_2/main.go b/internal/examples/qml/extending/components/test_dir_2/main.go new file mode 100644 index 00000000..606185b1 --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir_2/main.go @@ -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() +} diff --git a/internal/examples/qml/extending/components/test_dir_2/qml/app.qml b/internal/examples/qml/extending/components/test_dir_2/qml/app.qml new file mode 100755 index 00000000..f463a4fe --- /dev/null +++ b/internal/examples/qml/extending/components/test_dir_2/qml/app.qml @@ -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] diff --git a/internal/examples/qml/extending/components/test_module/app.qml b/internal/examples/qml/extending/components/test_module/app.qml new file mode 100755 index 00000000..c8bfdb31 --- /dev/null +++ b/internal/examples/qml/extending/components/test_module/app.qml @@ -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] diff --git a/internal/examples/qml/extending/components/test_module/app.qrc b/internal/examples/qml/extending/components/test_module/app.qrc new file mode 100755 index 00000000..2acbfd5b --- /dev/null +++ b/internal/examples/qml/extending/components/test_module/app.qrc @@ -0,0 +1,5 @@ + + + app.qml + + diff --git a/internal/examples/qml/extending/components/test_module/component/SomeComponentModule.qrc b/internal/examples/qml/extending/components/test_module/component/SomeComponentModule.qrc new file mode 100644 index 00000000..c9453e65 --- /dev/null +++ b/internal/examples/qml/extending/components/test_module/component/SomeComponentModule.qrc @@ -0,0 +1,6 @@ + + +SomeComponentModule/qmldir +SomeComponentModule/SomeComponent.qml + + diff --git a/internal/examples/qml/extending/components/test_module/component/SomeComponentModule/SomeComponent.qml b/internal/examples/qml/extending/components/test_module/component/SomeComponentModule/SomeComponent.qml new file mode 100755 index 00000000..f279d3cb --- /dev/null +++ b/internal/examples/qml/extending/components/test_module/component/SomeComponentModule/SomeComponent.qml @@ -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) + } +} diff --git a/internal/examples/qml/extending/components/test_module/component/SomeComponentModule/qmldir b/internal/examples/qml/extending/components/test_module/component/SomeComponentModule/qmldir new file mode 100644 index 00000000..c3d3ddeb --- /dev/null +++ b/internal/examples/qml/extending/components/test_module/component/SomeComponentModule/qmldir @@ -0,0 +1,2 @@ +module SomeComponentModule +TheComponent 1.0 SomeComponent.qml diff --git a/internal/examples/qml/extending/components/test_module/component/piechart.go b/internal/examples/qml/extending/components/test_module/component/piechart.go new file mode 100644 index 00000000..2b5b91ec --- /dev/null +++ b/internal/examples/qml/extending/components/test_module/component/piechart.go @@ -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) +} diff --git a/internal/examples/qml/extending/components/test_module/main.go b/internal/examples/qml/extending/components/test_module/main.go new file mode 100644 index 00000000..ad5fcc92 --- /dev/null +++ b/internal/examples/qml/extending/components/test_module/main.go @@ -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() +} diff --git a/internal/examples/qml/extending/components/test_module_2/component/piechart.go b/internal/examples/qml/extending/components/test_module_2/component/piechart.go new file mode 100644 index 00000000..2b5b91ec --- /dev/null +++ b/internal/examples/qml/extending/components/test_module_2/component/piechart.go @@ -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) +} diff --git a/internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/SomeComponent.qml b/internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/SomeComponent.qml new file mode 100755 index 00000000..f279d3cb --- /dev/null +++ b/internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/SomeComponent.qml @@ -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) + } +} diff --git a/internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/qmldir b/internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/qmldir new file mode 100644 index 00000000..c3d3ddeb --- /dev/null +++ b/internal/examples/qml/extending/components/test_module_2/component/qml/SomeComponentModule/qmldir @@ -0,0 +1,2 @@ +module SomeComponentModule +TheComponent 1.0 SomeComponent.qml diff --git a/internal/examples/qml/extending/components/test_module_2/main.go b/internal/examples/qml/extending/components/test_module_2/main.go new file mode 100644 index 00000000..47018b22 --- /dev/null +++ b/internal/examples/qml/extending/components/test_module_2/main.go @@ -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() +} diff --git a/internal/examples/qml/extending/components/test_module_2/qml/app.qml b/internal/examples/qml/extending/components/test_module_2/qml/app.qml new file mode 100755 index 00000000..c8bfdb31 --- /dev/null +++ b/internal/examples/qml/extending/components/test_module_2/qml/app.qml @@ -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]