PresentationApp/main.go

213 lines
4.5 KiB
Go
Raw Normal View History

2016-01-11 09:10:52 -08:00
// PresentationApp project main.go
2016-05-10 09:43:49 -07:00
//go:generate genqrc qml
2016-01-11 09:10:52 -08:00
package main
import (
"fmt"
"image/color"
"os"
2016-04-07 10:11:42 -07:00
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/lordwelch/qml"
2016-03-11 14:30:04 -08:00
"gopkg.in/gographics/imagick.v2/imagick"
2016-01-11 09:10:52 -08:00
)
//Bool type i'm lazy wanted a toggle function
type Bool bool
2016-05-04 10:45:12 -07:00
type qmlVar struct {
FontList []string
FontLen int
Verses []string
VerseLen int
VerseOrder []string
OrderLen int
Img []string
ImgLen int
}
type cell struct {
text string
img *imagick.MagickWand
qmlimg qml.Object
qmlcell qml.Object
index int
font struct {
name string
outlineSize, size, x, y float64
color color.RGBA
outlineColor color.RGBA
outline Bool
}
2016-01-14 22:25:53 -08:00
}
2016-05-10 09:43:49 -07:00
type slide []*cell
2016-01-14 22:25:53 -08:00
var (
path string
slides slide
err error
)
2016-01-11 09:10:52 -08:00
func main() {
2016-02-01 17:04:11 -08:00
if err = qml.Run(run); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
win.Destroy()
glfw.PollEvents()
glfw.Terminate()
}
func run() error {
imagick.Initialize()
engine = qml.NewEngine()
QML = &qmlVar{}
2016-05-09 09:11:56 -07:00
engine.Context().SetVar("go", QML)
findfonts()
2016-03-07 08:54:14 -08:00
engine.AddImageProvider("images", imgProvider)
path = "qrc:///qml"
2016-01-25 17:27:00 -08:00
mainQml, err = engine.LoadFile(path + "/main.qml")
if err != nil {
return err
}
edtQml, err = engine.LoadFile(path + "/qml/songEdit.qml")
if err != nil {
return err
2016-03-07 08:54:14 -08:00
}
cellQml, err = engine.LoadFile(path + "/qml/cell.qml")
if err != nil {
return err
2016-05-11 09:17:22 -07:00
}
qimg, err = engine.LoadFile(path + "/qml/img.qml")
if err != nil {
return err
}
qlst, err := engine.LoadFile(path + "/lst/tst.qml")
if err != nil {
return err
2016-05-11 09:17:22 -07:00
}
qlstEle, err := engine.LoadFile(path + "/lst/lstEle.qml")
if err != nil {
return err
}
window = mainQml.CreateWindow(engine.Context())
window2 = edtQml.CreateWindow(engine.Context())
2016-03-24 09:16:15 -07:00
textEdit = window.ObjectByName("textEdit")
//signals for whole qml
setSignals()
slides.add()
2016-05-04 10:45:12 -07:00
//var from GO to qml
2016-02-01 17:04:11 -08:00
//image is ready for imageprovider
imgready = true
tstlst :=qlst.Create(engine.Context())
tstlst.Set("parent", window.ObjectByName("data1"))
tstLlst := qlstEle.Create(engine.Context())
tstLlst.Call("get1")
//fmt.Println(tstLlst.Property("id1"))
tstlst.Call("addLst") //.Call("get1") //).(qml.Object).Create(engine.Context()).Set("parent", qlst.ObjectByName("nestedModel"))
window.Show()
window2.Show()
edtQmlShow()
slides[0].clearcache()
qml.RunMain(glInit)
2016-02-19 08:46:03 -08:00
window.Wait()
imagick.Terminate()
return nil
2016-01-11 09:10:52 -08:00
}
2016-01-14 22:25:53 -08:00
2016-03-23 19:52:46 -07:00
//Adds a new cell
func (sl *slide) add( /*cl *cell*/ ) {
var cl cell
cl.Init()
//gets the length so that the index is valid
cl.index = len(*sl)
//increase count on parent QML element
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")+1)
cl.qmlcell = cellQml.Create(engine.Context())
cl.qmlcell.Set("objectName", fmt.Sprintf("cellRect%d", len(*sl)))
cl.qmlcell.Set("parent", window.ObjectByName("data1"))
cl.qmlcell.Set("index", cl.index)
2016-03-23 19:52:46 -07:00
//keep the pointer/dereference (i'm not sure which it is)
//problems occur otherwise
*sl = append(*sl, &cl)
2016-03-23 19:52:46 -07:00
//seperate image object in QML
cl.qmlimg.Set("objectName", fmt.Sprintf("cellImg%d", cl.index))
cl.qmlimg.Set("source", fmt.Sprintf("image://images/%d"+`;`+"0", cl.index))
cl.qmlimg.Set("parent", window.ObjectByName("data2"))
cl.qmlimg.Set("index", cl.index)
cl.setSignal()
//give QML the text
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
2016-03-07 08:54:14 -08:00
}
2016-01-14 22:25:53 -08:00
func (cl *cell) Init() {
cl.text = "hello this is text\nhaha\nhdsjfklfhaskjd"
cl.index = -1
cl.font.color, cl.font.outlineColor = color.RGBA{0, 0, 0, 1}, color.RGBA{1, 1, 1, 1}
cl.font.name = "none"
cl.font.outline = false
cl.font.outlineSize = 1
cl.font.size = 35
cl.font.x, cl.font.y = 10, 30
cl.qmlcell = cellQml.Create(engine.Context())
cl.qmlimg = qimg.Create(engine.Context())
//load image
cl.img = imagick.NewMagickWand()
cl.img.ReadImage("logo:")
}
//(cell) remove() should destroy everything for this cell
func (cl *cell) remove() {
cl.text = ""
cl.qmlimg.Destroy()
cl.qmlcell.Destroy()
cl.img.Destroy()
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")-1)
slides.remove(cl.index)
2016-03-11 14:30:04 -08:00
cl.index = -1
}
//(slide) remove copied from github.com/golang/go/wiki/SliceTricks
func (sl *slide) remove(i int) {
*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
2016-03-11 14:30:04 -08:00
}
//Toggle, lazy wanted a func for it
func (bl *Bool) Toggle() {
if *bl == false {
*bl = true
} else {
*bl = false
}
}
2016-03-23 19:52:46 -07:00
//not really needed
func (cl cell) String() string {
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
2016-01-14 22:25:53 -08:00
}