2016-03-27 13:01:51 -07:00
|
|
|
// PresentationApp project qml.go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime/debug"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
"github.com/limetext/qml-go"
|
2016-03-27 13:01:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-02-07 10:00:10 -08:00
|
|
|
selectedCell int //the focused cell
|
|
|
|
rightClickCell int //the cell that was last right clicked
|
|
|
|
cellQml qml.Object //file for the cell object
|
|
|
|
mainQml qml.Object //main QML file
|
|
|
|
editQml qml.Object
|
|
|
|
textEdit qml.Object
|
|
|
|
displayQml qml.Object
|
|
|
|
displayImg qml.Object
|
|
|
|
DisplayWindow *qml.Window
|
|
|
|
MainWindow *qml.Window
|
|
|
|
songEditWindow *qml.Window
|
|
|
|
serviceObject qml.Object
|
|
|
|
serviceQml qml.Object
|
|
|
|
engine *qml.Engine
|
|
|
|
quickEdit bool = false
|
|
|
|
imgready bool = false
|
|
|
|
QML *qmlVar
|
2016-03-27 13:01:51 -07:00
|
|
|
)
|
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
func initQML() {
|
2018-02-07 10:00:10 -08:00
|
|
|
/*window2.ObjectByName("textClrDialog").On("accepted", func() {
|
2018-02-06 20:50:49 -08:00
|
|
|
window2.ObjectByName("textClrDialog").Color("color")
|
2018-02-07 10:00:10 -08:00
|
|
|
})*/
|
|
|
|
}
|
|
|
|
|
|
|
|
func qmlWindows() error {
|
|
|
|
mainQml, err = engine.LoadFile(path + "/Main.qml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
displayQml, err = engine.LoadFile(path + "/Display.qml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
editQml, err = engine.LoadFile(path + "/SongEdit.qml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cellQml, err = engine.LoadFile(path + "/Cell.qml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceQml, err = engine.LoadFile(path + "/Service.qml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow = mainQml.CreateWindow(engine.Context())
|
|
|
|
songEditWindow = editQml.CreateWindow(engine.Context())
|
|
|
|
DisplayWindow = displayQml.CreateWindow(engine.Context())
|
|
|
|
|
|
|
|
textEdit = MainWindow.ObjectByName("textEdit")
|
|
|
|
return nil
|
2016-05-09 09:11:56 -07:00
|
|
|
}
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func showWindows() {
|
|
|
|
MainWindow.Show()
|
|
|
|
songEditWindow.Show()
|
|
|
|
DisplayWindow.Show()
|
|
|
|
}
|
|
|
|
|
|
|
|
/*func (qv *qmlVar) Changed() {
|
2018-02-06 20:50:49 -08:00
|
|
|
qml.Changed(qv, qv.VerseLen)
|
|
|
|
qml.Changed(qv, qv.OrderLen)
|
|
|
|
qml.Changed(qv, qv.ImgLen)
|
|
|
|
qml.Changed(qv, qv.FontLen)
|
2018-02-07 10:00:10 -08:00
|
|
|
}*/
|
2016-05-04 10:45:12 -07:00
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
//signals for the cell and image in qml
|
2018-02-07 10:00:10 -08:00
|
|
|
func (cl *Cell) setSignal() {
|
|
|
|
cl.qmlObject.ObjectByName("cellMouse").On("clicked", func(mouseEvent qml.Object) {
|
|
|
|
btn := mouseEvent.Property("button")
|
2018-02-06 20:50:49 -08:00
|
|
|
//right click
|
|
|
|
if btn == 2 {
|
|
|
|
//context menu
|
2018-02-07 10:00:10 -08:00
|
|
|
MainWindow.ObjectByName("mnuCtx").Call("popup")
|
|
|
|
rightClickCell = cl.index
|
2018-02-06 20:50:49 -08:00
|
|
|
} else {
|
|
|
|
//left click
|
|
|
|
//select and update image preview for cell
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.Select()
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
|
|
|
//update image preview
|
|
|
|
cl.clearcache()
|
|
|
|
})
|
2016-03-27 13:01:51 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.image.qmlImage.ObjectByName("cellMouse").On("clicked", func(mouseEvent qml.Object) {
|
|
|
|
btn := mouseEvent.Property("button")
|
2018-02-06 20:50:49 -08:00
|
|
|
//right click
|
|
|
|
if btn == 2 {
|
|
|
|
//context menu
|
2018-02-07 10:00:10 -08:00
|
|
|
MainWindow.ObjectByName("mnuCtx").Call("popup")
|
|
|
|
rightClickCell = cl.index
|
2018-02-06 20:50:49 -08:00
|
|
|
} else {
|
|
|
|
//left click
|
|
|
|
//select and update image preview for cell
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.Select()
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
|
|
|
})
|
2018-02-07 10:00:10 -08:00
|
|
|
|
|
|
|
cl.qmlObject.ObjectByName("cellMouse").On("focusChanged", func(focus bool) {
|
2018-02-06 20:50:49 -08:00
|
|
|
if focus {
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.qmlObject.ObjectByName("cellMouse").Call("selected")
|
2018-02-06 20:50:49 -08:00
|
|
|
} else {
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.qmlObject.ObjectByName("cellMouse").Call("notSelected")
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
|
|
|
})
|
2016-03-27 13:01:51 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.qmlObject.ObjectByName("cellMouse").On("doubleClicked", func() {
|
2018-02-06 20:50:49 -08:00
|
|
|
if quickEdit {
|
|
|
|
//cover the cell with the text edit
|
|
|
|
textEdit.Set("cell", cl.index)
|
2018-02-07 10:00:10 -08:00
|
|
|
textEdit.Set("x", cl.qmlObject.Int("x"))
|
|
|
|
textEdit.Set("y", cl.qmlObject.Int("y"))
|
|
|
|
textEdit.Set("height", cl.qmlObject.Int("height"))
|
2018-02-06 20:50:49 -08:00
|
|
|
textEdit.Set("z", 100)
|
|
|
|
textEdit.Set("visible", true)
|
|
|
|
textEdit.ObjectByName("textEdit1").Set("focus", true)
|
|
|
|
textEdit.Set("enabled", true)
|
2016-03-27 13:01:51 -07:00
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
//set the text
|
|
|
|
textEdit.ObjectByName("textEdit1").Set("text", cl.text)
|
|
|
|
}
|
|
|
|
})
|
2016-03-27 13:01:51 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//setSignals() for non dynamic elements
|
|
|
|
func setSignals() {
|
2018-02-07 10:00:10 -08:00
|
|
|
MainWindow.ObjectByName("imgpicker").On("accepted", func() {
|
2018-02-06 20:50:49 -08:00
|
|
|
//delete file:// from url
|
2018-02-07 10:00:10 -08:00
|
|
|
url := filepath.Clean(strings.TrimPrefix(MainWindow.ObjectByName("imgpicker").String("fileUrl"), "file:"))
|
2016-03-27 13:01:51 -07:00
|
|
|
|
|
|
|
//replace new image
|
2018-02-07 10:00:10 -08:00
|
|
|
slides[rightClickCell].image.img.Clear()
|
|
|
|
slides[rightClickCell].image.img.ReadImage(url)
|
2016-03-27 13:01:51 -07:00
|
|
|
})
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
MainWindow.ObjectByName("btnAdd").On("clicked", func() {
|
|
|
|
slides.add("not")
|
2016-03-27 13:01:51 -07:00
|
|
|
})
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
MainWindow.ObjectByName("btnRem").On("clicked", func() {
|
|
|
|
slides.remove(len(slides) - 1)
|
2016-03-27 13:01:51 -07:00
|
|
|
})
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
MainWindow.ObjectByName("btnMem").On("clicked", func() {
|
2016-03-27 13:01:51 -07:00
|
|
|
//run GC
|
|
|
|
debug.FreeOSMemory()
|
|
|
|
})
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
MainWindow.ObjectByName("mnuEdit").On("triggered", func() {
|
|
|
|
quickEdit = !quickEdit
|
2016-03-27 13:01:51 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
|
|
|
|
var (
|
2018-02-07 10:00:10 -08:00
|
|
|
str string
|
|
|
|
cell *Cell
|
2016-03-27 13:01:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
if !focus {
|
|
|
|
//set text back to the cell
|
|
|
|
str = textEdit.ObjectByName("textEdit1").String("text")
|
2018-02-07 10:00:10 -08:00
|
|
|
cell = slides[textEdit.Int("cell")]
|
2016-03-27 13:01:51 -07:00
|
|
|
if textEdit.Bool("txt") {
|
2018-02-07 10:00:10 -08:00
|
|
|
cell.qmlObject.ObjectByName("cellText").Set("text", str)
|
|
|
|
cell.text = str
|
2016-03-27 13:01:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
func edtQmlShow() {
|
|
|
|
//slc := window2.ObjectByName("fontPicker").Property("model")
|
|
|
|
//fmt.Println(slc)
|
|
|
|
}
|
2017-02-05 12:57:50 -08:00
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
//imgProvider() for preview images in QML
|
|
|
|
func imgProvider(id string, width, height int) image.Image {
|
2018-02-07 10:00:10 -08:00
|
|
|
var img1 image.Image
|
2018-02-06 20:50:49 -08:00
|
|
|
if imgready && (len(id) > 0) {
|
|
|
|
//fmt.Println("source (provider): ", id)
|
|
|
|
i1 := strings.Index(id, `;`)
|
|
|
|
i, _ := strconv.Atoi(id[:i1])
|
2018-02-07 10:00:10 -08:00
|
|
|
img1 = slides[i].getImage(width, height)
|
|
|
|
} else {
|
|
|
|
img1 = image.NewRGBA(image.Rect(0, 0, 340, 480))
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
|
|
|
return img1
|
2017-02-05 12:57:50 -08:00
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
2016-03-27 13:01:51 -07:00
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
//clear cache dosen't actually clear the cache
|
|
|
|
//just gives a new source so that the cache isn't used
|
2018-02-07 10:00:10 -08:00
|
|
|
func (cl *Cell) clearcache() {
|
|
|
|
str := cl.image.qmlImage.String("source")
|
2018-02-06 20:50:49 -08:00
|
|
|
i := strings.Index(str, `;`)
|
|
|
|
str1 := str[:i]
|
|
|
|
i1, _ := strconv.Atoi(str[i+1:])
|
|
|
|
str = str1 + `;` + strconv.Itoa(i1+1)
|
|
|
|
//fmt.Println("new source (click): ", str)
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.image.qmlImage.Set("source", str)
|
2016-03-27 13:01:51 -07:00
|
|
|
}
|