mirror of
https://github.com/bluszcz/cutego.git
synced 2024-09-29 05:35:16 +03:00
new qml/extending examples
This commit is contained in:
parent
dc62b1d5ff
commit
f5eecc2711
17 changed files with 389 additions and 0 deletions
62
internal/examples/qml/extending/components/test_go/app.qml
Executable file
62
internal/examples/qml/extending/components/test_go/app.qml
Executable file
|
@ -0,0 +1,62 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** 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 Charts 1.0
|
||||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
width: 300; height: 200
|
||||
|
||||
PieChart {
|
||||
id: aPieChart
|
||||
anchors.centerIn: parent
|
||||
width: 100; height: 100
|
||||
name: "A simple pie chart"
|
||||
color: "red"
|
||||
|
||||
Component.onCompleted: factory.create(aPieChart)
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
|
||||
text: aPieChart.name
|
||||
}
|
||||
}
|
||||
//![0]
|
5
internal/examples/qml/extending/components/test_go/app.qrc
Executable file
5
internal/examples/qml/extending/components/test_go/app.qrc
Executable file
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>app.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -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)
|
||||
}
|
23
internal/examples/qml/extending/components/test_go/main.go
Normal file
23
internal/examples/qml/extending/components/test_go/main.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
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_go/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()
|
||||
}
|
52
internal/examples/qml/extending/components/test_qml/app.qml
Executable file
52
internal/examples/qml/extending/components/test_qml/app.qml
Executable file
|
@ -0,0 +1,52 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** 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
|
||||
|
||||
Rectangle {
|
||||
width: 400; height: 300
|
||||
|
||||
color: "green"
|
||||
|
||||
SomeComponent {
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
//![0]
|
5
internal/examples/qml/extending/components/test_qml/app.qrc
Executable file
5
internal/examples/qml/extending/components/test_qml/app.qrc
Executable file
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>app.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -0,0 +1,7 @@
|
|||
import QtQuick 2.0
|
||||
|
||||
Rectangle {
|
||||
width: 300; height: 200
|
||||
|
||||
color: "blue"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>SomeComponent.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
22
internal/examples/qml/extending/components/test_qml/main.go
Normal file
22
internal/examples/qml/extending/components/test_qml/main.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
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_qml/component"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gui.NewQGuiApplication(len(os.Args), os.Args)
|
||||
|
||||
view := quick.NewQQuickView(nil)
|
||||
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
|
||||
view.SetSource(core.NewQUrl3("qrc:///app.qml", 0))
|
||||
view.Show()
|
||||
|
||||
gui.QGuiApplication_Exec()
|
||||
}
|
10
internal/examples/qml/extending/components/test_qml/make.sh
Executable file
10
internal/examples/qml/extending/components/test_qml/make.sh
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
set -ev
|
||||
|
||||
qtrcc
|
||||
cd ./component
|
||||
qtrcc
|
||||
sed -i '' -e 's/main/component/' ./rcc_cgo_darwin_darwin_amd64.go
|
||||
$QT_DIR/5.8/clang_64/bin/rcc -name SomeComponent -o rcc.cpp SomeComponent.qrc
|
||||
cd ..
|
||||
go build -o test_qml && ./test_qml
|
52
internal/examples/qml/extending/components/test_qml_go/app.qml
Executable file
52
internal/examples/qml/extending/components/test_qml_go/app.qml
Executable file
|
@ -0,0 +1,52 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** 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
|
||||
|
||||
Rectangle {
|
||||
width: 400; height: 300
|
||||
|
||||
color: "green"
|
||||
|
||||
SomeComponent {
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
//![0]
|
5
internal/examples/qml/extending/components/test_qml_go/app.qrc
Executable file
5
internal/examples/qml/extending/components/test_qml_go/app.qrc
Executable file
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>app.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>SomeComponent.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
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_qml_go/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()
|
||||
}
|
11
internal/examples/qml/extending/components/test_qml_go/make.sh
Executable file
11
internal/examples/qml/extending/components/test_qml_go/make.sh
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
set -ev
|
||||
|
||||
qtrcc
|
||||
cd ./component
|
||||
qtmoc
|
||||
qtrcc
|
||||
sed -i '' -e 's/main/component/' ./rcc_cgo_darwin_darwin_amd64.go
|
||||
$QT_DIR/5.8/clang_64/bin/rcc -name SomeComponent -o rcc.cpp SomeComponent.qrc
|
||||
cd ..
|
||||
go build -o test_qml_go && ./test_qml_go
|
Loading…
Reference in a new issue