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"
|
2016-04-29 10:17:48 -07:00
|
|
|
"image/color"
|
2016-01-14 15:30:14 -08:00
|
|
|
"os"
|
|
|
|
|
2016-04-07 10:11:42 -07:00
|
|
|
"github.com/go-gl/glfw/v3.1/glfw"
|
2018-02-07 10:00:10 -08:00
|
|
|
"github.com/limetext/qml-go"
|
|
|
|
|
2016-03-11 14:30:04 -08:00
|
|
|
"gopkg.in/gographics/imagick.v2/imagick"
|
2016-01-11 09:10:52 -08:00
|
|
|
)
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
type Cell struct {
|
|
|
|
Font Font
|
|
|
|
image Image
|
|
|
|
index, collectionIndex int
|
|
|
|
qmlObject qml.Object
|
|
|
|
text string
|
|
|
|
textVisible bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type collection []*Cell
|
|
|
|
|
|
|
|
type Font struct {
|
|
|
|
color color.RGBA
|
|
|
|
name string
|
|
|
|
outline bool
|
|
|
|
outlineColor color.RGBA
|
|
|
|
outlineSize, size, x, y float64
|
|
|
|
}
|
|
|
|
|
|
|
|
type Image struct {
|
|
|
|
img *imagick.MagickWand
|
|
|
|
imgSource string
|
|
|
|
qmlImage qml.Object
|
|
|
|
}
|
2016-03-21 08:49:06 -07:00
|
|
|
|
2016-05-04 10:45:12 -07:00
|
|
|
type qmlVar struct {
|
2018-02-07 10:00:10 -08:00
|
|
|
FontList string
|
|
|
|
Verses string
|
|
|
|
VerseOrder string
|
|
|
|
//Img string
|
2016-01-14 22:25:53 -08:00
|
|
|
}
|
2016-05-10 09:43:49 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
type service []collection
|
2016-01-14 22:25:53 -08:00
|
|
|
|
2016-01-14 18:42:52 -08:00
|
|
|
var (
|
2018-02-07 10:00:10 -08:00
|
|
|
currentService = new(service)
|
|
|
|
err error
|
|
|
|
path string
|
|
|
|
slides collection
|
2016-01-14 18:42:52 -08:00
|
|
|
)
|
|
|
|
|
2016-01-11 09:10:52 -08:00
|
|
|
func main() {
|
2016-01-21 10:11:16 -08:00
|
|
|
|
2016-02-01 17:04:11 -08:00
|
|
|
if err = qml.Run(run); err != nil {
|
2016-01-14 15:30:14 -08:00
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-04-12 10:22:14 -07:00
|
|
|
glfw.Terminate()
|
2016-01-21 10:11:16 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-14 15:30:14 -08:00
|
|
|
func run() error {
|
2018-02-06 20:50:49 -08:00
|
|
|
engine = qml.NewEngine()
|
|
|
|
QML = &qmlVar{}
|
2018-02-07 10:00:10 -08:00
|
|
|
path = "qrc:///qml"
|
|
|
|
imagick.Initialize()
|
|
|
|
findFonts()
|
|
|
|
|
2016-05-09 09:11:56 -07:00
|
|
|
engine.Context().SetVar("go", QML)
|
2016-03-07 08:54:14 -08:00
|
|
|
engine.AddImageProvider("images", imgProvider)
|
2016-01-25 17:27:00 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
err = qmlWindows()
|
2016-01-21 10:11:16 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-01-29 20:05:16 -08:00
|
|
|
}
|
2016-01-21 10:11:16 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
currentService.Init(1)
|
2016-03-07 08:54:14 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
//signals for whole qml
|
|
|
|
setSignals()
|
2016-05-11 09:17:22 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
//image is ready for imageprovider
|
|
|
|
imgready = true
|
|
|
|
|
|
|
|
displayImg = DisplayWindow.Root().ObjectByName("displayImage")
|
|
|
|
serviceObject = serviceQml.Create(engine.Context())
|
|
|
|
serviceObject.Set("parent", MainWindow.ObjectByName("data1"))
|
|
|
|
serviceObject.Call("addLst", "shit")
|
|
|
|
|
|
|
|
//edtQmlShow()
|
|
|
|
qml.RunMain(glInit)
|
|
|
|
MainWindow.Wait()
|
|
|
|
slides.destroy()
|
|
|
|
fmt.Println(len(*currentService))
|
|
|
|
|
|
|
|
imagick.Terminate()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sv *service) Init(num int) {
|
|
|
|
if num <= 0 {
|
|
|
|
num = 1
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
2017-02-05 12:57:50 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
for index := 0; index < num; index++ {
|
|
|
|
if sv == nil {
|
|
|
|
sv.add("")
|
|
|
|
}
|
2016-05-11 09:17:22 -07:00
|
|
|
}
|
2018-02-07 10:00:10 -08:00
|
|
|
}
|
2016-05-11 09:17:22 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func (sv *service) add(name string) {
|
|
|
|
var (
|
|
|
|
sl collection
|
|
|
|
i = len(*sv)
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(name) <= 0 {
|
|
|
|
name = "Song: " + fmt.Sprint(i)
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
2016-01-29 20:05:16 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
sl.init(1)
|
|
|
|
*sv = append(*sv, sl)
|
|
|
|
//serviceObject.Call("addLst", name)
|
|
|
|
}
|
2016-03-24 09:16:15 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func (sv *service) remove(i int) {
|
|
|
|
(*sv)[i].destroy()
|
2016-05-04 10:45:12 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
copy((*sv)[i:], (*sv)[i+1:])
|
|
|
|
(*sv)[len(*sv)-1] = nil // or the zero value of T
|
|
|
|
*sv = (*sv)[:len(*sv)-1]
|
2016-02-01 17:04:11 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
}
|
2016-02-19 08:46:03 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func (sv *service) destroy() {
|
|
|
|
for i := len(*sv); i > 0; i-- {
|
|
|
|
sv.remove(i - 1)
|
|
|
|
}
|
|
|
|
}
|
2017-02-05 12:57:50 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func (sl *collection) init(num int) {
|
|
|
|
if num <= 0 {
|
|
|
|
num = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
for index := 0; index < num; index++ {
|
|
|
|
if sl == nil {
|
|
|
|
sl.add("")
|
|
|
|
}
|
|
|
|
}
|
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
|
2018-02-07 10:00:10 -08:00
|
|
|
func (sl *collection) add(text string) {
|
|
|
|
var (
|
|
|
|
cl Cell
|
|
|
|
i = len(*sl)
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(text) <= 0 {
|
|
|
|
text = "Slide" + fmt.Sprint(i)
|
|
|
|
}
|
2018-02-06 20:50:49 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.Init()
|
2016-01-19 21:12:11 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//keep the pointer/dereference (i'm not sure which it is)
|
|
|
|
//problems occur otherwise
|
2018-02-07 10:00:10 -08:00
|
|
|
// now Im not an idiot and I know what this does
|
2018-02-06 20:50:49 -08:00
|
|
|
*sl = append(*sl, &cl)
|
2016-01-19 21:12:11 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//seperate image object in QML
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.image.qmlImage.Set("source", fmt.Sprintf("image://images/cell;%d", cl.index))
|
2016-04-12 10:22:14 -07:00
|
|
|
cl.setSignal()
|
2016-05-03 10:25:23 -07:00
|
|
|
//give QML the text
|
2016-03-07 08:54:14 -08:00
|
|
|
|
2016-01-19 21:12:11 -08:00
|
|
|
}
|
2016-01-14 22:25:53 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
//(slide) remove copied from github.com/golang/go/wiki/SliceTricks
|
|
|
|
func (sl *collection) remove(i int) {
|
|
|
|
cl := (*sl)[i]
|
|
|
|
cl.text = ""
|
|
|
|
cl.image.qmlImage.Destroy()
|
|
|
|
cl.qmlObject.Destroy()
|
|
|
|
cl.image.img.Destroy()
|
|
|
|
MainWindow.ObjectByName("gridRect").Set("count", MainWindow.ObjectByName("gridRect").Int("count")-1)
|
2016-05-03 09:00:18 -07:00
|
|
|
cl.index = -1
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
copy((*sl)[i:], (*sl)[i+1:])
|
|
|
|
(*sl)[len(*sl)-1] = nil // or the zero value of T
|
|
|
|
(*sl) = (*sl)[:len(*sl)-1]
|
2016-05-03 09:00:18 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
//*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
|
|
|
|
}
|
2016-05-03 09:00:18 -07:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func (sl *collection) destroy() {
|
|
|
|
for i := len(*sl); i > 0; i-- {
|
|
|
|
sl.remove(i - 1)
|
|
|
|
}
|
2016-05-03 09:00:18 -07:00
|
|
|
}
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func (cl *Cell) Init() {
|
|
|
|
cl.text = `hello this is text`
|
2016-03-11 14:30:04 -08:00
|
|
|
cl.index = -1
|
2018-02-07 10:00:10 -08:00
|
|
|
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
|
2016-03-11 14:30:04 -08:00
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
cl.qmlObject = cellQml.Create(engine.Context())
|
|
|
|
cl.image.qmlImage = cl.qmlObject.ObjectByName("cellImg")
|
|
|
|
|
|
|
|
//load image
|
|
|
|
cl.image.img = imagick.NewMagickWand()
|
|
|
|
cl.image.img.ReadImage("logo:")
|
2016-03-11 14:30:04 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-07 10:00:10 -08:00
|
|
|
func (cl *Cell) Select() {
|
|
|
|
selectedCell = cl.index
|
|
|
|
cl.qmlObject.ObjectByName("cellMouse").Call("selected")
|
|
|
|
|
2018-02-06 20:50:49 -08:00
|
|
|
}
|
2018-02-06 20:48:54 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//not really needed
|
2018-02-07 10:00:10 -08:00
|
|
|
func (cl Cell) String() string {
|
2016-01-21 10:11:16 -08:00
|
|
|
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
2016-01-14 22:25:53 -08:00
|
|
|
}
|