change to qrc

change to listview
This commit is contained in:
lordwelch 2016-05-10 09:43:49 -07:00
parent 7fe593a4ef
commit 7e741afd9f
11 changed files with 801 additions and 261 deletions

View File

@ -1,14 +1,14 @@
// PresentationApp project main.go // PresentationApp project main.go
//go:generate genqrc qml
package main package main
import ( import (
"fmt" "fmt"
"image/color" "image/color"
"os" "os"
"path/filepath"
"github.com/go-gl/glfw/v3.1/glfw" "github.com/go-gl/glfw/v3.1/glfw"
"github.com/kardianos/osext"
"github.com/lordwelch/qml" "github.com/lordwelch/qml"
"gopkg.in/gographics/imagick.v2/imagick" "gopkg.in/gographics/imagick.v2/imagick"
) )
@ -41,6 +41,7 @@ type cell struct {
outline Bool outline Bool
} }
} }
type slide []*cell type slide []*cell
var ( var (
@ -69,9 +70,7 @@ func run() error {
engine.Context().SetVar("go", QML) engine.Context().SetVar("go", QML)
findfonts() findfonts()
engine.AddImageProvider("images", imgProvider) engine.AddImageProvider("images", imgProvider)
//path for qml files TODO: change to somewhere else path = "qrc:///qml"
path, err = osext.ExecutableFolder()
path = filepath.Clean(path + "/../src/github.com/lordwelch/PresentationApp/")
mainQml, err = engine.LoadFile(path + "/main.qml") mainQml, err = engine.LoadFile(path + "/main.qml")
if err != nil { if err != nil {

253
main.qml
View File

@ -1,253 +0,0 @@
import QtQuick 2.4
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.3
import QtQuick.Window 2.0
import "qml"
import QtQuick.Layouts 1.0
ApplicationWindow {
id: applicationWindow1
title: "Presentation App"
visible: true
objectName: "applicationWindow1"
minimumWidth: 500
minimumHeight: 500
width: 1000
height: 600
property bool cls: false
/*function getFileDialogUrl() {
return
}*/
onClosing: if (!cls) {
close.accepted = false
}
FileDialog {
id: imgpicker
// @disable-check M16
title: "Choose an image for this slide"
// @disable-check M16
objectName: "imgpicker"
}
AboutDialog {
id: aboutDialog
}
Action {
id: aboutAction
text: "About"
onTriggered: aboutDialog.open()
}
menuBar: MenuBar {
Menu {
title: "&File"
MenuItem {
text: "Close"
shortcut: StandardKey.Quit
}
}
Menu {
title: "&Edit"
MenuItem {
text: "quick edit"
objectName: "mnuEdit"
}
}
Menu {
title: "Window"
MenuItem {
text: "Display"
objectName: "mnuDisplay"
}
}
Menu {
title: "&Help"
MenuItem {
action: aboutAction
}
}
}
Menu {
objectName: "mnuCtx"
title: "new image..."
MenuItem {
objectName: "mnuImgPick"
text: "new Image..."
onTriggered: imgpicker.open()
}
}
SplitView {
id: mainSlider
objectName: "mainSlider"
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.top: parent.top
anchors.left: parent.left
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
orientation: Qt.Horizontal
onResizingChanged: col1.width = gridData.width / 2
Rectangle {
id: gridRect
objectName: "gridRect"
width: 300
color: "#00000000"
border.width: 4
anchors.left: parent.left
anchors.leftMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
property int count: 0
ScrollView {
id: scview
anchors.fill: parent
anchors.margins: 4
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn
SplitView {
id: gridData
objectName: "gridData"
width: scview.width - 1
height: gridRect.count * 101
Rectangle {
id: col1
objectName: "col1"
width: gridData.width / 2
color: "#00000000"
transformOrigin: Item.TopLeft
border.width: 0
Rectangle {
id: textEdit
property int cell
x: 232
y: 622
objectName: "textEdit"
width: 200
height: 200
color: "#ffffff"
visible: false
property bool txt: true
Keys.onPressed: {
if ((event.key == Qt.Key_Return)
&& (event.modifiers & Qt.ControlModifier)) {
txt = true
x = -100
y = -100
visible = false
focus = true
enabled = false
opacity = 0
textEdit1.focus = false
event.accepted = true
}
if (event.key == Qt.Key_Escape) {
txt = false
x = -100
y = -100
visible = false
focus = true
enabled = false
opacity = 0
textEdit1.focus = false
event.accepted = true
}
}
TextArea {
id: textEdit1
objectName: "textEdit1"
anchors.fill: parent
clip: true
textFormat: Text.AutoText
visible: true
font.pixelSize: 12
z: 99
}
}
Column {
id: data1
objectName: "data1"
spacing: 1
anchors.fill: parent
}
}
Rectangle {
id: col2
objectName: "col2"
color: "#00000000"
border.width: 0
Column {
id: data2
spacing: 1
objectName: "data2"
anchors.fill: parent
}
}
}
}
}
Rectangle {
id: mainView
border.width: 0
objectName: "mainView"
anchors.right: parent.right
anchors.rightMargin: 0
anchors.leftMargin: 0
anchors.left: gridRect.right
anchors.bottom: parent.bottom
anchors.top: parent.top
z: 1
clip: false
visible: true
Button {
id: button1
objectName: "btnAdd"
x: 8
y: 8
text: qsTr("Button")
}
Button {
id: button2
x: 8
y: 39
text: qsTr("Button")
objectName: "btnRem"
}
Button {
id: button3
x: 8
y: 70
text: qsTr("Button")
objectName: "btnMem"
}
}
}
}

4
qml.go
View File

@ -13,7 +13,7 @@ import (
) )
var ( var (
selCell int //the focused and selCell int //the focused cell
rhtClkCell int //the cell that was last right clicked rhtClkCell int //the cell that was last right clicked
qimg qml.Object //file for the image object qimg qml.Object //file for the image object
cellQml qml.Object //file for the cell object cellQml qml.Object //file for the cell object
@ -193,10 +193,8 @@ func imgProvider(id string, width, height int) image.Image {
//just gives a new source so that the cache isn't used //just gives a new source so that the cache isn't used
func (cl *cell) clearcache() { func (cl *cell) clearcache() {
str := cl.qmlimg.String("source") str := cl.qmlimg.String("source")
//fmt.Println("source (click): ", str)
i := strings.Index(str, `;`) i := strings.Index(str, `;`)
str1 := str[:i] str1 := str[:i]
//fmt.Println("ext (click): ", str1)
i1, _ := strconv.Atoi(str[i+1:]) i1, _ := strconv.Atoi(str[i+1:])
str = str1 + `;` + strconv.Itoa(i1+1) str = str1 + `;` + strconv.Itoa(i1+1)
//fmt.Println("new source (click): ", str) //fmt.Println("new source (click): ", str)

601
qml/main.qml Normal file
View File

@ -0,0 +1,601 @@
import QtQuick 2.4
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.3
import QtQuick.Window 2.0
import "qml"
import QtQuick.Layouts 1.0
ApplicationWindow {
id: applicationWindow1
title: "Presentation App"
visible: true
objectName: "applicationWindow1"
minimumWidth: 500
minimumHeight: 500
width: 1000
height: 600
property bool cls: false
/*function getFileDialogUrl() {
return
}*/
/*onClosing: if (!cls) {
close.accepted = false
}*/
FileDialog {
id: imgpicker
// @disable-check M16
title: "Choose an image for this slide"
// @disable-check M16
objectName: "imgpicker"
}
AboutDialog {
id: aboutDialog
}
Action {
id: aboutAction
text: "About"
onTriggered: aboutDialog.open()
}
menuBar: MenuBar {
Menu {
title: "&File"
MenuItem {
text: "Close"
shortcut: StandardKey.Quit
}
}
Menu {
title: "&Edit"
MenuItem {
text: "quick edit"
objectName: "mnuEdit"
}
}
Menu {
title: "Window"
MenuItem {
text: "Display"
objectName: "mnuDisplay"
}
}
Menu {
title: "&Help"
MenuItem {
action: aboutAction
}
}
}
Menu {
objectName: "mnuCtx"
title: "new image..."
MenuItem {
objectName: "mnuImgPick"
text: "new Image..."
onTriggered: imgpicker.open()
}
}
SplitView {
id: mainSlider
objectName: "mainSlider"
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.top: parent.top
anchors.left: parent.left
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
orientation: Qt.Horizontal
onResizingChanged: col1.width = gridData.width / 2
Rectangle {
id: gridRect
objectName: "gridRect"
width: 300
color: "#00000000"
border.width: 4
anchors.left: parent.left
anchors.leftMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
property int count: 1
property int expcount: 1
ScrollView {
id: scview
anchors.fill: parent
anchors.margins: 4
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn
SplitView {
id: gridData
objectName: "gridData"
width: scview.width - 1
height: data1.childrenRect.height//gridRect.count * 101
Rectangle {
id: col1
objectName: "col1"
width: gridData.width / 2
color: "#00000000"
transformOrigin: Item.TopLeft
border.width: 0
height: data1.childrenRect.height
Rectangle {
id: textEdit
property int cell
x: 232
y: 622
objectName: "textEdit"
width: 200
height: 200
color: "#ffffff"
visible: false
property bool txt: true
Keys.onPressed: {
if ((event.key == Qt.Key_Return) && (event.modifiers & Qt.ControlModifier)) {
txt = true
x = -100
y = -100
visible = false
focus = true
enabled = false
opacity = 0
textEdit1.focus = false
event.accepted = true
}
if (event.key == Qt.Key_Escape) {
txt = false
x = -100
y = -100
visible = false
focus = true
enabled = false
opacity = 0
textEdit1.focus = false
event.accepted = true
}
}
TextArea {
id: textEdit1
objectName: "textEdit1"
anchors.fill: parent
clip: true
textFormat: Text.AutoText
visible: true
font.pixelSize: 12
z: 99
}
}
Column {
id: data1
objectName: "data1"
spacing: 1
anchors.fill: parent
clip: true
height: data1.childrenRect.height
Item {
id:tst6
height: 50+(tst5.subCount*40)
anchors.right: parent.right
anchors.left: parent.left
clip: true
ListView {
id:tst5
anchors.fill: parent
property int subCount: 0
model: ListModel {
id: nestedModel1
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement { itemName: "Nissan" },
ListElement { itemName: "Toyota" },
ListElement { itemName: "Chevy" },
ListElement { itemName: "Audi" }
]
}
}
delegate: Component {
id: categoryDelegate1
Column {
anchors.right: parent.right
anchors.left: parent.left
//width: 200
Rectangle {
id: categoryItem
anchors.right: parent.right
anchors.left: parent.left
border.color: "black"
border.width: 5
color: "white"
height: 50
//width: 200
Text {
anchors.verticalCenter: parent.verticalCenter
x: 15
font.pixelSize: 24
text: categoryName
}
Rectangle {
color: "red"
width: 30
height: 30
anchors.right: parent.right
anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
// Toggle the 'collapsed' property
onClicked: {
nestedModel1.setProperty(index, "collapsed", !collapsed)
if (!nestedModel1.get(index).collapsed) {
tst5.subCount = subItemLoader.subItemModel.count
} else {
tst5.subCount = 0
}
}
}
}
}
Loader {
id: subItemLoader
// This is a workaround for a bug/feature in the Loader element. If sourceComponent is set to null
// the Loader element retains the same height it had when sourceComponent was set. Setting visible
// to false makes the parent Column treat it as if it's height was 0.
visible: !collapsed
property variant subItemModel: subItems
sourceComponent: collapsed ? null : subItemColumnDelegate1
onStatusChanged: if (status == Loader.Ready)
item.model = subItemModel
}
}
}
}
Component {
id: subItemColumnDelegate1
Column {
property alias model: subItemRepeater.model
width: col1.width
Repeater {
id: subItemRepeater
delegate: Rectangle {
color: "#cccccc"
height: 40
anchors.right: parent.right
anchors.left: parent.left
//width: 200
border.color: "black"
border.width: 2
Text {
anchors.verticalCenter: parent.verticalCenter
x: 30
font.pixelSize: 18
text: itemName
}
}
}
}
}
}Item {
id:tst4
height: 50+(tst3.subCount*40)
anchors.right: parent.right
anchors.left: parent.left
ListView {
id:tst3
anchors.fill: parent
property int subCount: 0
model: ListModel {
id: nestedModel
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement { itemName: "Nissan" },
ListElement { itemName: "Toyota" },
ListElement { itemName: "Chevy" },
ListElement { itemName: "Audi" }
]
}
}
delegate: Component {
id: categoryDelegate
Column {
anchors.right: parent.right
anchors.left: parent.left
//width: 200
Rectangle {
id: categoryItem
anchors.right: parent.right
anchors.left: parent.left
border.color: "black"
border.width: 5
color: "white"
height: 50
//width: 200
Text {
anchors.verticalCenter: parent.verticalCenter
x: 15
font.pixelSize: 24
text: categoryName
}
Rectangle {
color: "red"
width: 30
height: 30
anchors.right: parent.right
anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
// Toggle the 'collapsed' property
onClicked: {
nestedModel.setProperty(index, "collapsed", !collapsed)
if (!nestedModel.get(index).collapsed) {
tst3.subCount = subItemLoader.subItemModel.count
} else {
tst3.subCount = 0
}
}
}
}
}
Loader {
id: subItemLoader
// This is a workaround for a bug/feature in the Loader element. If sourceComponent is set to null
// the Loader element retains the same height it had when sourceComponent was set. Setting visible
// to false makes the parent Column treat it as if it's height was 0.
visible: !collapsed
property variant subItemModel: subItems
sourceComponent: collapsed ? null : subItemColumnDelegate
onStatusChanged: if (status == Loader.Ready)
item.model = subItemModel
}
}
}
}
Component {
id: subItemColumnDelegate
Column {
property alias model: subItemRepeater.model
width: col1.width
Repeater {
id: subItemRepeater
delegate: Rectangle {
color: "#cccccc"
height: 40
anchors.right: parent.right
anchors.left: parent.left
//width: 200
border.color: "black"
border.width: 2
Text {
anchors.verticalCenter: parent.verticalCenter
x: 30
font.pixelSize: 18
text: itemName
}
}
}
}
}
}Item {
id: tst2
height: 50+(tst1.subCount*40)
anchors.right: parent.right
anchors.left: parent.left
ListView {
id: tst1
anchors.fill: parent
property int subCount: 0
model: ListModel {
id: nestedMdel
ListElement {
categoryName: "Cars "
collapsed: true
subIte: [
ListElement { itemName: "Nissan" },
ListElement { itemName: "Toyota" },
ListElement { itemName: "Chevy" },
ListElement { itemName: "Audi" }
]
}
}
delegate: Component {
id: categoryDlegate
Column {
anchors.right: parent.right
anchors.left: parent.left
//width: 200
Rectangle {
id: categoryItem
anchors.right: parent.right
anchors.left: parent.left
border.color: "black"
border.width: 5
color: "white"
height: 50
//width: 200
Text {
anchors.verticalCenter: parent.verticalCenter
x: 15
font.pixelSize: 24
text: categoryName
}
Rectangle {
color: "red"
width: 30
height: 30
anchors.right: parent.right
anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
// Toggle the 'collapsed' property
onClicked: {
nestedMdel.setProperty(index, "collapsed", !collapsed)
if (!nestedMdel.get(index).collapsed) {
tst1.subCount = subItemLoader.subItemModel.count
} else {
tst1.subCount = 0
}
}
}
}
}
Loader {
id: subItemLoader
// This is a workaround for a bug/feature in the Loader element. If sourceComponent is set to null
// the Loader element retains the same height it had when sourceComponent was set. Setting visible
// to false makes the parent Column treat it as if it's height was 0.
visible: !collapsed
property variant subItemModel: subIte
sourceComponent: collapsed ? null : subItemColumnDlegate
onStatusChanged: if (status == Loader.Ready)
item.model = subItemModel
}
}
}
}
Component {
id: subItemColumnDlegate
Column {
property alias model: subItemRepeater.model
width: col1.width
Repeater {
id: subItemRepeater
delegate: Rectangle {
color: "#cccccc"
height: 40
anchors.right: parent.right
anchors.left: parent.left
//width: 200
border.color: "black"
border.width: 2
Text {
anchors.verticalCenter: parent.verticalCenter
x: 30
font.pixelSize: 18
text: itemName
}
}
}
}
}
}
}
}
Rectangle {
id: col2
objectName: "col2"
color: "#00000000"
border.width: 0
Column {
id: data2
spacing: 1
objectName: "data2"
anchors.fill: parent
}
}
}
}
}
Rectangle {
id: mainView
border.width: 0
objectName: "mainView"
anchors.right: parent.right
anchors.rightMargin: 0
anchors.leftMargin: 0
anchors.left: gridRect.right
anchors.bottom: parent.bottom
anchors.top: parent.top
z: 1
clip: false
visible: true
Button {
id: button1
objectName: "btnAdd"
x: 8
y: 8
text: qsTr("Button") +data1.childrenRect.height
}
Button {
id: button2
x: 8
y: 39
text: qsTr("Button ") + tst4.height
objectName: "btnRem"
}
Button {
id: button3
x: 8
y: 70
text: qsTr("Button ") + tst2.height
objectName: "btnMem"
}
}
}
}

58
qrc.go Normal file

File diff suppressed because one or more lines are too long

137
tst.qml Normal file
View File

@ -0,0 +1,137 @@
//https://gist.github.com/elpuri/3753756
import QtQuick 2.4
import QtQuick.Controls 1.3
ApplicationWindow {
id: app1
minimumWidth: 200
minimumHeight: 50
Item {
id: tst4
height: 50 + (tst3.subCount * 40)
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
ListView {
id: tst3
anchors.fill: parent
property int subCount: 0
model: ListModel {
id: nestedModel
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "Nissan"
},
ListElement {
itemName: "Toyota"
},
ListElement {
itemName: "Chevy"
},
ListElement {
itemName: "Audi"
}
]
}
}
delegate: Component {
id: categoryDelegate
Column {
anchors.right: parent.right
anchors.left: parent.left
//width: 200
Rectangle {
id: categoryItem
anchors.right: parent.right
anchors.left: parent.left
border.color: "black"
border.width: 5
color: "white"
height: 50
//width: 200
Text {
anchors.verticalCenter: parent.verticalCenter
x: 15
font.pixelSize: 24
text: categoryName
}
Rectangle {
color: "red"
width: 30
height: 30
anchors.right: parent.right
anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
// Toggle the 'collapsed' property
onClicked: {
nestedModel.setProperty(index, "collapsed",
!collapsed)
if (!nestedModel.get(index).collapsed) {
tst3.subCount = subItemLoader.subItemModel.count
} else {
tst3.subCount = 0
}
}
}
}
}
Loader {
id: subItemLoader
// This is a workaround for a bug/feature in the Loader element. If sourceComponent is set to null
// the Loader element retains the same height it had when sourceComponent was set. Setting visible
// to false makes the parent Column treat it as if it's height was 0.
visible: !collapsed
property variant subItemModel: subItems
sourceComponent: collapsed ? null : subItemColumnDelegate
onStatusChanged: if (status == Loader.Ready)
item.model = subItemModel
}
}
}
}
Component {
id: subItemColumnDelegate
Column {
property alias model: subItemRepeater.model
width: tst4.width
Repeater {
id: subItemRepeater
delegate: Rectangle {
color: "#cccccc"
height: 40
anchors.right: parent.right
anchors.left: parent.left
//width: 200
border.color: "black"
border.width: 2
Text {
anchors.verticalCenter: parent.verticalCenter
x: 30
font.pixelSize: 18
text: itemName
}
}
}
}
}
}
}