Now in in a not completely worthless state
Need to do some basic checks like bounds checking And make the images show back up
This commit is contained in:
parent
7fc9aefdd7
commit
a8534bd967
148
glfw.go
148
glfw.go
@ -3,117 +3,31 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/go-gl/gl/v2.1/gl"
|
|
||||||
"github.com/go-gl/glfw/v3.1/glfw"
|
"github.com/go-gl/glfw/v3.1/glfw"
|
||||||
"github.com/lordwelch/qml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
win *glfw.Window
|
monitorHeight int // displayed width
|
||||||
monWidth int //displayed height
|
monitors []*glfw.Monitor
|
||||||
monHeight int //displayed width
|
monitorWidth int // displayed height
|
||||||
monitors []*glfw.Monitor
|
projectorMonitor *glfw.Monitor
|
||||||
projMonitor *glfw.Monitor
|
|
||||||
tex1 *uint32 //identifier for opengl texture
|
|
||||||
texDel Bool //if texture should be deleted
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupScene() {
|
|
||||||
|
|
||||||
gl.ClearColor(0, 0, 0, 0)
|
|
||||||
if texDel {
|
|
||||||
gl.DeleteTextures(1, tex1)
|
|
||||||
}
|
|
||||||
tex1 = newTexture(*slides[selCell].getImage(monWidth, monHeight))
|
|
||||||
|
|
||||||
gl.MatrixMode(gl.PROJECTION)
|
|
||||||
gl.LoadIdentity()
|
|
||||||
gl.Ortho(-1, 1, -1, 1, 1.0, 10.0)
|
|
||||||
gl.MatrixMode(gl.MODELVIEW)
|
|
||||||
gl.LoadIdentity()
|
|
||||||
texDel = true
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawSlide() {
|
|
||||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
|
||||||
|
|
||||||
gl.MatrixMode(gl.MODELVIEW)
|
|
||||||
gl.LoadIdentity()
|
|
||||||
gl.Translatef(0, 0, -3.0)
|
|
||||||
|
|
||||||
gl.Begin(gl.QUADS)
|
|
||||||
|
|
||||||
//top left
|
|
||||||
gl.TexCoord2f(0, 0)
|
|
||||||
gl.Vertex3f(-1, 1, 0)
|
|
||||||
//top right
|
|
||||||
gl.TexCoord2f(1, 0)
|
|
||||||
gl.Vertex3f(1, 1, 0)
|
|
||||||
|
|
||||||
//bottom right
|
|
||||||
gl.TexCoord2f(1, 1)
|
|
||||||
gl.Vertex3f(1, -1, 0)
|
|
||||||
|
|
||||||
//bottom left
|
|
||||||
gl.TexCoord2f(0, 1)
|
|
||||||
gl.Vertex3f(-1, -1, 0)
|
|
||||||
|
|
||||||
gl.End()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTexture(rgba image.RGBA) *uint32 {
|
|
||||||
var texture1 uint32
|
|
||||||
gl.Enable(gl.TEXTURE_2D)
|
|
||||||
gl.GenTextures(1, &texture1)
|
|
||||||
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
|
||||||
gl.TexImage2D(
|
|
||||||
gl.TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
gl.RGBA,
|
|
||||||
int32(rgba.Rect.Size().X),
|
|
||||||
int32(rgba.Rect.Size().Y),
|
|
||||||
0,
|
|
||||||
gl.RGBA,
|
|
||||||
gl.UNSIGNED_BYTE,
|
|
||||||
gl.Ptr(rgba.Pix))
|
|
||||||
|
|
||||||
return &texture1
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkMon() {
|
func checkMon() {
|
||||||
monitors = glfw.GetMonitors()
|
monitors = glfw.GetMonitors()
|
||||||
glfw.WindowHint(glfw.ContextVersionMajor, 2)
|
|
||||||
glfw.WindowHint(glfw.ContextVersionMinor, 1)
|
|
||||||
glfw.WindowHint(glfw.AutoIconify, glfw.False)
|
|
||||||
glfw.WindowHint(glfw.Decorated, glfw.False)
|
|
||||||
|
|
||||||
if i := len(monitors); i < 2 {
|
if i := len(monitors); i < 2 {
|
||||||
fmt.Println("You only have 1 monitor!!!!!!!!!!! :-P")
|
fmt.Println("You only have 1 monitor!!!!!!!!!!! :-P")
|
||||||
monWidth = 800
|
monitorWidth = 800
|
||||||
monHeight = 600
|
monitorHeight = 600
|
||||||
|
|
||||||
win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
|
projectorMonitor = monitors[0]
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
projMonitor = monitors[0]
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("You have %d monitors\n", i)
|
fmt.Printf("You have %d monitors\n", i)
|
||||||
monWidth = monitors[1].GetVideoMode().Width
|
monitorWidth = monitors[1].GetVideoMode().Width
|
||||||
monHeight = monitors[1].GetVideoMode().Height
|
monitorHeight = monitors[1].GetVideoMode().Height
|
||||||
win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
|
projectorMonitor = monitors[1]
|
||||||
win.SetPos(monitors[1].GetPos())
|
|
||||||
fmt.Printf("Width: %d Height: %d \n", monWidth, monHeight)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
projMonitor = monitors[1]
|
|
||||||
|
|
||||||
}
|
}
|
||||||
monitorInfo()
|
monitorInfo()
|
||||||
@ -121,43 +35,23 @@ func checkMon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func monitorInfo() {
|
func monitorInfo() {
|
||||||
|
fmt.Println(len(monitors))
|
||||||
for _, mon := range monitors {
|
for _, mon := range monitors {
|
||||||
fmt.Printf("monitor name: %s\n", mon.GetName())
|
fmt.Printf("Monitor name: %s\n", mon.GetName())
|
||||||
i, t := mon.GetPos()
|
x, y := mon.GetPos()
|
||||||
fmt.Printf("position X: %d Y: %d\n", i, t)
|
fmt.Printf("Position: %v, %v\n", x, y)
|
||||||
|
fmt.Printf("Size: %v x %v\n", mon.GetVideoMode().Width, mon.GetVideoMode().Height)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func glInit() {
|
func glInit() {
|
||||||
window.Set("cls", false)
|
if err = glfw.Init(); err == nil {
|
||||||
if err = glfw.Init(); err != nil {
|
checkMon()
|
||||||
log.Fatalln("failed to initialize glfw:", err)
|
DisplayWindow.Root().Set("height", monitorHeight)
|
||||||
}
|
DisplayWindow.Root().Set("width", monitorWidth)
|
||||||
checkMon()
|
DisplayWindow.Root().Set("x", 0)
|
||||||
|
DisplayWindow.Root().Set("y", 0)
|
||||||
win.MakeContextCurrent()
|
|
||||||
|
|
||||||
if err := gl.Init(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
win.SetPos(projMonitor.GetPos())
|
|
||||||
setupScene()
|
|
||||||
|
|
||||||
qml.Func1 = func() int {
|
|
||||||
if !win.ShouldClose() {
|
|
||||||
//glfw.PollEvents()
|
|
||||||
drawSlide()
|
|
||||||
win.SwapBuffers()
|
|
||||||
return 0
|
|
||||||
|
|
||||||
}
|
|
||||||
win.Hide()
|
|
||||||
//win.Destroy()
|
|
||||||
//glfw.Terminate()
|
|
||||||
return 1
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
imagick.go
27
imagick.go
@ -67,8 +67,8 @@ func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//getImage() from imagick to image.RGBA
|
//getImage() from imagick to image.RGBA
|
||||||
func (cl *cell) getImage(width, height int) (img *image.RGBA) {
|
func (cl *Cell) getImage(width, height int) (img *image.RGBA) {
|
||||||
mw := cl.img.GetImage()
|
mw := cl.image.img.GetImage()
|
||||||
if (width == 0) || (height == 0) {
|
if (width == 0) || (height == 0) {
|
||||||
width = int(mw.GetImageWidth())
|
width = int(mw.GetImageWidth())
|
||||||
height = int(mw.GetImageHeight())
|
height = int(mw.GetImageHeight())
|
||||||
@ -91,7 +91,7 @@ func (cl *cell) getImage(width, height int) (img *image.RGBA) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adding text to image copied from example
|
// adding text to image copied from example
|
||||||
func (cl *cell) imgtext(width, height int) *imagick.MagickWand {
|
func (cl *Cell) imgtext(width, height int) *imagick.MagickWand {
|
||||||
mw := imagick.NewMagickWand()
|
mw := imagick.NewMagickWand()
|
||||||
//defer mw.Destroy()
|
//defer mw.Destroy()
|
||||||
dw := imagick.NewDrawingWand()
|
dw := imagick.NewDrawingWand()
|
||||||
@ -104,30 +104,30 @@ func (cl *cell) imgtext(width, height int) *imagick.MagickWand {
|
|||||||
mw.NewImage(uint(width), uint(height), pw)
|
mw.NewImage(uint(width), uint(height), pw)
|
||||||
|
|
||||||
// Set up a 72 point white font
|
// Set up a 72 point white font
|
||||||
r, g, b, _ := cl.font.color.RGBA()
|
r, g, b, _ := cl.Font.color.RGBA()
|
||||||
pw.SetColor(fmt.Sprintf("rgb(%d,%d,%d)", r, g, b))
|
pw.SetColor(fmt.Sprintf("rgb(%d,%d,%d)", r, g, b))
|
||||||
dw.SetFillColor(pw)
|
dw.SetFillColor(pw)
|
||||||
if (cl.font.name != "") || (cl.font.name != "none") {
|
if (cl.Font.name != "") || (cl.Font.name != "none") {
|
||||||
dw.SetFont(cl.font.name)
|
dw.SetFont(cl.Font.name)
|
||||||
}
|
}
|
||||||
dw.SetFontSize(cl.font.size)
|
dw.SetFontSize(cl.Font.size)
|
||||||
|
|
||||||
otlne := "none"
|
otlne := "none"
|
||||||
// Add a black outline to the text
|
// Add a black outline to the text
|
||||||
r, g, b, _ = cl.font.outlineColor.RGBA()
|
r, g, b, _ = cl.Font.outlineColor.RGBA()
|
||||||
if cl.font.outline {
|
if cl.Font.outline {
|
||||||
otlne = fmt.Sprintf("rgb(%d,%d,%d)", r, g, b)
|
otlne = fmt.Sprintf("rgb(%d,%d,%d)", r, g, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pw.SetColor(otlne)
|
pw.SetColor(otlne)
|
||||||
dw.SetStrokeColor(pw)
|
dw.SetStrokeColor(pw)
|
||||||
dw.SetStrokeWidth(cl.font.outlineSize)
|
dw.SetStrokeWidth(cl.Font.outlineSize)
|
||||||
|
|
||||||
// Turn antialias on - not sure this makes a difference
|
// Turn antialias on - not sure this makes a difference
|
||||||
//dw.SetTextAntialias(true)
|
//dw.SetTextAntialias(true)
|
||||||
|
|
||||||
// Now draw the text
|
// Now draw the text
|
||||||
dw.Annotation(cl.font.x, cl.font.y, cl.text)
|
dw.Annotation(cl.Font.x, cl.Font.y, cl.text)
|
||||||
|
|
||||||
// Draw the image on to the mw
|
// Draw the image on to the mw
|
||||||
mw.DrawImage(dw)
|
mw.DrawImage(dw)
|
||||||
@ -151,7 +151,7 @@ func (cl *cell) imgtext(width, height int) *imagick.MagickWand {
|
|||||||
return mw
|
return mw
|
||||||
}
|
}
|
||||||
|
|
||||||
func findfonts() {
|
func findFonts() {
|
||||||
cmd := exec.Command("grep", "-ivE", `\-Oblique$|-Bold$|-Italic$|-Light$`)
|
cmd := exec.Command("grep", "-ivE", `\-Oblique$|-Bold$|-Italic$|-Light$`)
|
||||||
cmd.Stdin = strings.NewReader(strings.Join(imagick.QueryFonts("*"), "\n"))
|
cmd.Stdin = strings.NewReader(strings.Join(imagick.QueryFonts("*"), "\n"))
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
@ -160,8 +160,7 @@ func findfonts() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
}
|
}
|
||||||
QML.FontList = strings.Split(out.String(), "\n")
|
QML.FontList = out.String()
|
||||||
QML.FontLen = len(QML.FontList)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func round(a float64) int {
|
func round(a float64) int {
|
||||||
|
300
main.go
300
main.go
@ -9,45 +9,50 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/go-gl/glfw/v3.1/glfw"
|
"github.com/go-gl/glfw/v3.1/glfw"
|
||||||
"github.com/lordwelch/qml"
|
"github.com/limetext/qml-go"
|
||||||
|
|
||||||
"gopkg.in/gographics/imagick.v2/imagick"
|
"gopkg.in/gographics/imagick.v2/imagick"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Bool type i'm lazy wanted a toggle function
|
type Cell struct {
|
||||||
type Bool bool
|
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
|
||||||
|
}
|
||||||
|
|
||||||
type qmlVar struct {
|
type qmlVar struct {
|
||||||
FontList []string
|
FontList string
|
||||||
FontLen int
|
Verses string
|
||||||
Verses []string
|
VerseOrder string
|
||||||
VerseLen int
|
//Img string
|
||||||
VerseOrder []string
|
|
||||||
OrderLen int
|
|
||||||
Img []string
|
|
||||||
ImgLen int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type cell struct {
|
type service []collection
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type slide []*cell
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
path string
|
currentService = new(service)
|
||||||
slides slide
|
err error
|
||||||
err error
|
path string
|
||||||
|
slides collection
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -56,157 +61,176 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
win.Destroy()
|
|
||||||
glfw.PollEvents()
|
|
||||||
glfw.Terminate()
|
glfw.Terminate()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
imagick.Initialize()
|
|
||||||
|
|
||||||
engine = qml.NewEngine()
|
engine = qml.NewEngine()
|
||||||
QML = &qmlVar{}
|
QML = &qmlVar{}
|
||||||
engine.Context().SetVar("go", QML)
|
|
||||||
findfonts()
|
|
||||||
engine.AddImageProvider("images", imgProvider)
|
|
||||||
path = "qrc:///qml"
|
path = "qrc:///qml"
|
||||||
|
imagick.Initialize()
|
||||||
|
findFonts()
|
||||||
|
|
||||||
mainQml, err = engine.LoadFile(path + "/main.qml")
|
engine.Context().SetVar("go", QML)
|
||||||
|
engine.AddImageProvider("images", imgProvider)
|
||||||
|
|
||||||
|
err = qmlWindows()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
edtQml, err = engine.LoadFile(path + "/qml/songEdit.qml")
|
currentService.Init(1)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cellQml, err = engine.LoadFile(path + "/qml/cell.qml")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
qlstEle, err := engine.LoadFile(path + "/lst/lstEle.qml")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
window = mainQml.CreateWindow(engine.Context())
|
|
||||||
window2 = edtQml.CreateWindow(engine.Context())
|
|
||||||
|
|
||||||
textEdit = window.ObjectByName("textEdit")
|
|
||||||
//signals for whole qml
|
//signals for whole qml
|
||||||
setSignals()
|
setSignals()
|
||||||
slides.add()
|
|
||||||
|
|
||||||
//var from GO to qml
|
|
||||||
|
|
||||||
//image is ready for imageprovider
|
//image is ready for imageprovider
|
||||||
imgready = true
|
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)
|
|
||||||
|
|
||||||
window.Wait()
|
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()
|
imagick.Terminate()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Adds a new cell
|
func (sv *service) Init(num int) {
|
||||||
func (sl *slide) add( /*cl *cell*/ ) {
|
if num <= 0 {
|
||||||
var cl cell
|
num = 1
|
||||||
cl.Init()
|
}
|
||||||
//gets the length so that the index is valid
|
|
||||||
cl.index = len(*sl)
|
|
||||||
|
|
||||||
//increase count on parent QML element
|
for index := 0; index < num; index++ {
|
||||||
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")+1)
|
if sv == nil {
|
||||||
cl.qmlcell = cellQml.Create(engine.Context())
|
sv.add("")
|
||||||
cl.qmlcell.Set("objectName", fmt.Sprintf("cellRect%d", len(*sl)))
|
}
|
||||||
cl.qmlcell.Set("parent", window.ObjectByName("data1"))
|
}
|
||||||
cl.qmlcell.Set("index", cl.index)
|
}
|
||||||
|
|
||||||
|
func (sv *service) add(name string) {
|
||||||
|
var (
|
||||||
|
sl collection
|
||||||
|
i = len(*sv)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(name) <= 0 {
|
||||||
|
name = "Song: " + fmt.Sprint(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
sl.init(1)
|
||||||
|
*sv = append(*sv, sl)
|
||||||
|
//serviceObject.Call("addLst", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sv *service) remove(i int) {
|
||||||
|
(*sv)[i].destroy()
|
||||||
|
|
||||||
|
copy((*sv)[i:], (*sv)[i+1:])
|
||||||
|
(*sv)[len(*sv)-1] = nil // or the zero value of T
|
||||||
|
*sv = (*sv)[:len(*sv)-1]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sv *service) destroy() {
|
||||||
|
for i := len(*sv); i > 0; i-- {
|
||||||
|
sv.remove(i - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sl *collection) init(num int) {
|
||||||
|
if num <= 0 {
|
||||||
|
num = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for index := 0; index < num; index++ {
|
||||||
|
if sl == nil {
|
||||||
|
sl.add("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Adds a new cell
|
||||||
|
func (sl *collection) add(text string) {
|
||||||
|
var (
|
||||||
|
cl Cell
|
||||||
|
i = len(*sl)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(text) <= 0 {
|
||||||
|
text = "Slide" + fmt.Sprint(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
cl.Init()
|
||||||
|
|
||||||
//keep the pointer/dereference (i'm not sure which it is)
|
//keep the pointer/dereference (i'm not sure which it is)
|
||||||
//problems occur otherwise
|
//problems occur otherwise
|
||||||
|
// now Im not an idiot and I know what this does
|
||||||
*sl = append(*sl, &cl)
|
*sl = append(*sl, &cl)
|
||||||
|
|
||||||
//seperate image object in QML
|
//seperate image object in QML
|
||||||
cl.qmlimg.Set("objectName", fmt.Sprintf("cellImg%d", cl.index))
|
cl.image.qmlImage.Set("source", fmt.Sprintf("image://images/cell;%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()
|
cl.setSignal()
|
||||||
//give QML the text
|
//give QML the text
|
||||||
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
cl.index = -1
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//(slide) remove copied from github.com/golang/go/wiki/SliceTricks
|
//(slide) remove copied from github.com/golang/go/wiki/SliceTricks
|
||||||
func (sl *slide) remove(i int) {
|
func (sl *collection) remove(i int) {
|
||||||
*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
|
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)
|
||||||
|
cl.index = -1
|
||||||
|
|
||||||
|
copy((*sl)[i:], (*sl)[i+1:])
|
||||||
|
(*sl)[len(*sl)-1] = nil // or the zero value of T
|
||||||
|
(*sl) = (*sl)[:len(*sl)-1]
|
||||||
|
|
||||||
|
//*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Toggle, lazy wanted a func for it
|
func (sl *collection) destroy() {
|
||||||
func (bl *Bool) Toggle() {
|
for i := len(*sl); i > 0; i-- {
|
||||||
if *bl == false {
|
sl.remove(i - 1)
|
||||||
*bl = true
|
|
||||||
} else {
|
|
||||||
*bl = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cl *Cell) Init() {
|
||||||
|
cl.text = `hello this is text`
|
||||||
|
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.qmlObject = cellQml.Create(engine.Context())
|
||||||
|
cl.image.qmlImage = cl.qmlObject.ObjectByName("cellImg")
|
||||||
|
|
||||||
|
//load image
|
||||||
|
cl.image.img = imagick.NewMagickWand()
|
||||||
|
cl.image.img.ReadImage("logo:")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cl *Cell) Select() {
|
||||||
|
selectedCell = cl.index
|
||||||
|
cl.qmlObject.ObjectByName("cellMouse").Call("selected")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//not really needed
|
//not really needed
|
||||||
func (cl cell) String() string {
|
func (cl Cell) String() string {
|
||||||
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
||||||
}
|
}
|
||||||
|
187
qml.go
187
qml.go
@ -8,90 +8,129 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lordwelch/qml"
|
"github.com/limetext/qml-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
selCell int //the focused cell
|
selectedCell int //the focused cell
|
||||||
rhtClkCell int //the cell that was last right clicked
|
rightClickCell int //the cell that was last right clicked
|
||||||
qimg qml.Object //file for the image object
|
cellQml qml.Object //file for the cell object
|
||||||
cellQml qml.Object //file for the cell object
|
mainQml qml.Object //main QML file
|
||||||
mainQml qml.Object //main QML file
|
editQml qml.Object
|
||||||
edtQml qml.Object
|
textEdit qml.Object
|
||||||
textEdit qml.Object
|
displayQml qml.Object
|
||||||
window *qml.Window
|
displayImg qml.Object
|
||||||
window2 *qml.Window
|
DisplayWindow *qml.Window
|
||||||
engine *qml.Engine
|
MainWindow *qml.Window
|
||||||
quickEdit Bool = false
|
songEditWindow *qml.Window
|
||||||
imgready Bool = false
|
serviceObject qml.Object
|
||||||
QML *qmlVar
|
serviceQml qml.Object
|
||||||
|
engine *qml.Engine
|
||||||
|
quickEdit bool = false
|
||||||
|
imgready bool = false
|
||||||
|
QML *qmlVar
|
||||||
)
|
)
|
||||||
|
|
||||||
func initQML() {
|
func initQML() {
|
||||||
window2.ObjectByName("textClrDialog").On("accepted", func() {
|
/*window2.ObjectByName("textClrDialog").On("accepted", func() {
|
||||||
window2.ObjectByName("textClrDialog").Color("color")
|
window2.ObjectByName("textClrDialog").Color("color")
|
||||||
})
|
})*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qv *qmlVar) Changed() {
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func showWindows() {
|
||||||
|
MainWindow.Show()
|
||||||
|
songEditWindow.Show()
|
||||||
|
DisplayWindow.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*func (qv *qmlVar) Changed() {
|
||||||
qml.Changed(qv, qv.VerseLen)
|
qml.Changed(qv, qv.VerseLen)
|
||||||
qml.Changed(qv, qv.OrderLen)
|
qml.Changed(qv, qv.OrderLen)
|
||||||
qml.Changed(qv, qv.ImgLen)
|
qml.Changed(qv, qv.ImgLen)
|
||||||
qml.Changed(qv, qv.FontLen)
|
qml.Changed(qv, qv.FontLen)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//signals for the cell and image in qml
|
//signals for the cell and image in qml
|
||||||
func (cl *cell) setSignal() {
|
func (cl *Cell) setSignal() {
|
||||||
cl.qmlcell.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) {
|
cl.qmlObject.ObjectByName("cellMouse").On("clicked", func(mouseEvent qml.Object) {
|
||||||
btn := musEvent.Property("button")
|
btn := mouseEvent.Property("button")
|
||||||
//right click
|
//right click
|
||||||
if btn == 2 {
|
if btn == 2 {
|
||||||
//context menu
|
//context menu
|
||||||
window.ObjectByName("mnuCtx").Call("popup")
|
MainWindow.ObjectByName("mnuCtx").Call("popup")
|
||||||
rhtClkCell = cl.index
|
rightClickCell = cl.index
|
||||||
} else {
|
} else {
|
||||||
//left click
|
//left click
|
||||||
//select and update image preview for cell
|
//select and update image preview for cell
|
||||||
selCell = cl.qmlcell.Int("index")
|
cl.Select()
|
||||||
cl.qmlcell.ObjectByName("cellMouse").Set("focus", true)
|
|
||||||
setupScene()
|
|
||||||
}
|
}
|
||||||
//update image preview
|
//update image preview
|
||||||
cl.clearcache()
|
cl.clearcache()
|
||||||
})
|
})
|
||||||
|
|
||||||
cl.qmlimg.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) {
|
cl.image.qmlImage.ObjectByName("cellMouse").On("clicked", func(mouseEvent qml.Object) {
|
||||||
btn := musEvent.Property("button")
|
btn := mouseEvent.Property("button")
|
||||||
//right click
|
//right click
|
||||||
if btn == 2 {
|
if btn == 2 {
|
||||||
//context menu
|
//context menu
|
||||||
window.ObjectByName("mnuCtx").Call("popup")
|
MainWindow.ObjectByName("mnuCtx").Call("popup")
|
||||||
rhtClkCell = cl.index
|
rightClickCell = cl.index
|
||||||
} else {
|
} else {
|
||||||
//left click
|
//left click
|
||||||
//select and update image preview for cell
|
//select and update image preview for cell
|
||||||
selCell = cl.qmlcell.Int("index")
|
cl.Select()
|
||||||
cl.qmlcell.ObjectByName("cellMouse").Set("focus", true)
|
|
||||||
setupScene()
|
|
||||||
}
|
}
|
||||||
//update image preview
|
|
||||||
cl.clearcache()
|
|
||||||
})
|
})
|
||||||
cl.qmlcell.ObjectByName("cellMouse").On("focusChanged", func(focus bool) {
|
|
||||||
|
cl.qmlObject.ObjectByName("cellMouse").On("focusChanged", func(focus bool) {
|
||||||
if focus {
|
if focus {
|
||||||
cl.qmlcell.ObjectByName("cellMouse").Call("selected")
|
cl.qmlObject.ObjectByName("cellMouse").Call("selected")
|
||||||
} else {
|
} else {
|
||||||
cl.qmlcell.ObjectByName("cellMouse").Call("notSelected")
|
cl.qmlObject.ObjectByName("cellMouse").Call("notSelected")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
cl.qmlcell.ObjectByName("cellMouse").On("doubleClicked", func() {
|
cl.qmlObject.ObjectByName("cellMouse").On("doubleClicked", func() {
|
||||||
if quickEdit {
|
if quickEdit {
|
||||||
//cover the cell with the text edit
|
//cover the cell with the text edit
|
||||||
textEdit.Set("cell", cl.index)
|
textEdit.Set("cell", cl.index)
|
||||||
textEdit.Set("x", cl.qmlcell.Int("x"))
|
textEdit.Set("x", cl.qmlObject.Int("x"))
|
||||||
textEdit.Set("y", cl.qmlcell.Int("y"))
|
textEdit.Set("y", cl.qmlObject.Int("y"))
|
||||||
textEdit.Set("height", cl.qmlcell.Int("height"))
|
textEdit.Set("height", cl.qmlObject.Int("height"))
|
||||||
textEdit.Set("z", 100)
|
textEdit.Set("z", 100)
|
||||||
textEdit.Set("visible", true)
|
textEdit.Set("visible", true)
|
||||||
textEdit.ObjectByName("textEdit1").Set("focus", true)
|
textEdit.ObjectByName("textEdit1").Set("focus", true)
|
||||||
@ -106,64 +145,45 @@ func (cl *cell) setSignal() {
|
|||||||
|
|
||||||
//setSignals() for non dynamic elements
|
//setSignals() for non dynamic elements
|
||||||
func setSignals() {
|
func setSignals() {
|
||||||
window.ObjectByName("imgpicker").On("accepted", func() {
|
MainWindow.ObjectByName("imgpicker").On("accepted", func() {
|
||||||
//delete file:// from url
|
//delete file:// from url
|
||||||
url := filepath.Clean(strings.Replace(window.ObjectByName("imgpicker").String("fileUrl"), "file:", "", 1))
|
url := filepath.Clean(strings.TrimPrefix(MainWindow.ObjectByName("imgpicker").String("fileUrl"), "file:"))
|
||||||
|
|
||||||
//replace new image
|
//replace new image
|
||||||
slides[rhtClkCell].img.Clear()
|
slides[rightClickCell].image.img.Clear()
|
||||||
slides[rhtClkCell].img.ReadImage(url)
|
slides[rightClickCell].image.img.ReadImage(url)
|
||||||
setupScene()
|
|
||||||
//update image preview
|
|
||||||
slides[rhtClkCell].clearcache()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
window.ObjectByName("btnAdd").On("clicked", func() {
|
MainWindow.ObjectByName("btnAdd").On("clicked", func() {
|
||||||
slides.add()
|
slides.add("not")
|
||||||
})
|
})
|
||||||
|
|
||||||
window.ObjectByName("btnRem").On("clicked", func() {
|
MainWindow.ObjectByName("btnRem").On("clicked", func() {
|
||||||
slides[len(slides)-1].remove()
|
slides.remove(len(slides) - 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
window.ObjectByName("btnMem").On("clicked", func() {
|
MainWindow.ObjectByName("btnMem").On("clicked", func() {
|
||||||
//run GC
|
//run GC
|
||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
})
|
})
|
||||||
|
|
||||||
window.On("closing", func() {
|
MainWindow.ObjectByName("mnuEdit").On("triggered", func() {
|
||||||
//close glfw first
|
quickEdit = !quickEdit
|
||||||
if false == window.Property("cls") {
|
|
||||||
win.SetShouldClose(true)
|
|
||||||
window.Set("cls", true)
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
window.ObjectByName("mnuDisplay").On("triggered", func() {
|
|
||||||
win.SetShouldClose(false)
|
|
||||||
window.Set("cls", false)
|
|
||||||
win.Show()
|
|
||||||
qml.ResetGLFW()
|
|
||||||
})
|
|
||||||
|
|
||||||
window.ObjectByName("mnuEdit").On("triggered", func() {
|
|
||||||
(&quickEdit).Toggle()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
|
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
|
||||||
var (
|
var (
|
||||||
str string
|
str string
|
||||||
cel *cell
|
cell *Cell
|
||||||
)
|
)
|
||||||
|
|
||||||
if !focus {
|
if !focus {
|
||||||
//set text back to the cell
|
//set text back to the cell
|
||||||
str = textEdit.ObjectByName("textEdit1").String("text")
|
str = textEdit.ObjectByName("textEdit1").String("text")
|
||||||
cel = slides[textEdit.Int("cell")]
|
cell = slides[textEdit.Int("cell")]
|
||||||
if textEdit.Bool("txt") {
|
if textEdit.Bool("txt") {
|
||||||
cel.qmlcell.ObjectByName("cellText").Set("text", str)
|
cell.qmlObject.ObjectByName("cellText").Set("text", str)
|
||||||
cel.text = str
|
cell.text = str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -176,26 +196,27 @@ func edtQmlShow() {
|
|||||||
|
|
||||||
//imgProvider() for preview images in QML
|
//imgProvider() for preview images in QML
|
||||||
func imgProvider(id string, width, height int) image.Image {
|
func imgProvider(id string, width, height int) image.Image {
|
||||||
|
var img1 image.Image
|
||||||
if imgready && (len(id) > 0) {
|
if imgready && (len(id) > 0) {
|
||||||
//fmt.Println("source (provider): ", id)
|
//fmt.Println("source (provider): ", id)
|
||||||
i1 := strings.Index(id, `;`)
|
i1 := strings.Index(id, `;`)
|
||||||
i, _ := strconv.Atoi(id[:i1])
|
i, _ := strconv.Atoi(id[:i1])
|
||||||
return slides[i].getImage(width, height)
|
img1 = slides[i].getImage(width, height)
|
||||||
|
} else {
|
||||||
|
img1 = image.NewRGBA(image.Rect(0, 0, 340, 480))
|
||||||
}
|
}
|
||||||
var img1 image.Image = image.NewRGBA(image.Rect(0, 0, 340, 480))
|
|
||||||
return img1
|
return img1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//clear cache dosen't actually clear the cache
|
//clear cache dosen't actually clear the cache
|
||||||
//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.image.qmlImage.String("source")
|
||||||
i := strings.Index(str, `;`)
|
i := strings.Index(str, `;`)
|
||||||
str1 := str[:i]
|
str1 := str[:i]
|
||||||
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)
|
||||||
cl.qmlimg.Set("source", str)
|
cl.image.qmlImage.Set("source", str)
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,25 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Image {
|
||||||
|
id: img
|
||||||
|
antialiasing: true
|
||||||
|
source: "image://images/"
|
||||||
|
objectName: "cellImg"
|
||||||
|
property int index: 0
|
||||||
|
height: 100
|
||||||
|
transformOrigin: Item.TopLeft
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.left: parent.left
|
||||||
|
//cache: false
|
||||||
|
MouseArea {
|
||||||
|
id: imgMouse
|
||||||
|
hoverEnabled: true
|
||||||
|
enabled: true
|
||||||
|
objectName: "cellMouse"
|
||||||
|
anchors.fill: parent
|
||||||
|
acceptedButtons: Qt.AllButtons
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
17
qml/Display.qml
Normal file
17
qml/Display.qml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import QtQuick 2.4
|
||||||
|
import QtQuick.Controls 1.3
|
||||||
|
|
||||||
|
ApplicationWindow {
|
||||||
|
flags: Qt.MaximumSize
|
||||||
|
Component.onCompleted: visible = true
|
||||||
|
|
||||||
|
Image {
|
||||||
|
id: image1
|
||||||
|
objectName: "displayImage"
|
||||||
|
sourceSize.height: 768
|
||||||
|
sourceSize.width: 1024
|
||||||
|
antialiasing: true
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,7 +2,7 @@ import QtQuick 2.4
|
|||||||
import QtQuick.Dialogs 1.2
|
import QtQuick.Dialogs 1.2
|
||||||
import QtQuick.Controls 1.3
|
import QtQuick.Controls 1.3
|
||||||
import QtQuick.Window 2.0
|
import QtQuick.Window 2.0
|
||||||
import "qml"
|
//import "qml"
|
||||||
import QtQuick.Layouts 1.0
|
import QtQuick.Layouts 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
@ -14,15 +14,6 @@ ApplicationWindow {
|
|||||||
minimumHeight: 500
|
minimumHeight: 500
|
||||||
width: 1000
|
width: 1000
|
||||||
height: 600
|
height: 600
|
||||||
property bool cls: false
|
|
||||||
|
|
||||||
|
|
||||||
/*function getFileDialogUrl() {
|
|
||||||
return
|
|
||||||
}*/
|
|
||||||
/*onClosing: if (!cls) {
|
|
||||||
close.accepted = false
|
|
||||||
}*/
|
|
||||||
|
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: imgpicker
|
id: imgpicker
|
||||||
@ -32,10 +23,6 @@ ApplicationWindow {
|
|||||||
objectName: "imgpicker"
|
objectName: "imgpicker"
|
||||||
}
|
}
|
||||||
|
|
||||||
AboutDialog {
|
|
||||||
id: aboutDialog
|
|
||||||
}
|
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
id: aboutAction
|
id: aboutAction
|
||||||
text: "About"
|
text: "About"
|
||||||
@ -125,7 +112,7 @@ ApplicationWindow {
|
|||||||
id: gridData
|
id: gridData
|
||||||
objectName: "gridData"
|
objectName: "gridData"
|
||||||
width: scview.width - 1
|
width: scview.width - 1
|
||||||
height: data1.childrenRect.height//gridRect.count * 101
|
height: data1.childrenRect.height //gridRect.count * 101
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: col1
|
id: col1
|
||||||
@ -147,7 +134,8 @@ ApplicationWindow {
|
|||||||
visible: false
|
visible: false
|
||||||
property bool txt: true
|
property bool txt: true
|
||||||
Keys.onPressed: {
|
Keys.onPressed: {
|
||||||
if ((event.key == Qt.Key_Return) && (event.modifiers & Qt.ControlModifier)) {
|
if ((event.key == Qt.Key_Return)
|
||||||
|
&& (event.modifiers & Qt.ControlModifier)) {
|
||||||
txt = true
|
txt = true
|
||||||
|
|
||||||
x = -100
|
x = -100
|
||||||
@ -194,7 +182,6 @@ ApplicationWindow {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
clip: true
|
clip: true
|
||||||
height: data1.childrenRect.height
|
height: data1.childrenRect.height
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +221,7 @@ ApplicationWindow {
|
|||||||
objectName: "btnAdd"
|
objectName: "btnAdd"
|
||||||
x: 8
|
x: 8
|
||||||
y: 8
|
y: 8
|
||||||
text: qsTr("Button") +data1.childrenRect.height
|
text: qsTr("Button") + data1.childrenRect.height
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
197
qml/Service.qml
Normal file
197
qml/Service.qml
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
//https://gist.github.com/elpuri/3753756
|
||||||
|
import QtQuick 2.4
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: rt
|
||||||
|
property ListElement def: ListElement {
|
||||||
|
property string cellText: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
|
||||||
|
|
||||||
|
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
|
||||||
|
<html >
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />
|
||||||
|
<title>Untitled 1</title>
|
||||||
|
<style type=\"text/css\">
|
||||||
|
.auto-style2 {
|
||||||
|
font-family: \"Times New Roman\", Times, serif;
|
||||||
|
font-size: small;
|
||||||
|
}
|
||||||
|
.auto-style3 {
|
||||||
|
background-color: #FFFF00;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<p><b>Header text</b><br/></p>
|
||||||
|
<span class=\"auto-style3\">This is paragraph text</span>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>"
|
||||||
|
property int collectionIndex: 0
|
||||||
|
property string imageSource: "image://images/list:;cell:"
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: addLst("Haha :-P")
|
||||||
|
height: ((lst.count) * 50) + (lst.subCount * 100)
|
||||||
|
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 0
|
||||||
|
function remove(List, index) {
|
||||||
|
lst.subCount--
|
||||||
|
nestedModel.get(List).subItems.remove(index, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function pop(List) {
|
||||||
|
lst.subCount--
|
||||||
|
nestedModel.get(List).subItems.remove(nestedModel.get(
|
||||||
|
List).subItems.count - 1, 1)
|
||||||
|
}
|
||||||
|
function newdef(index, txt, src) {
|
||||||
|
var item = Object.create(def)
|
||||||
|
item.collectionIndex = index
|
||||||
|
item.text = txt
|
||||||
|
item.imageSource = src
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
function remLst() {
|
||||||
|
nestedModel.remove(nestedModel.count - 1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function apppend(List, obj) {
|
||||||
|
lst.subCount++
|
||||||
|
nestedModel.get(List).subItems.append(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
function insert(List, index, obj) {
|
||||||
|
lst.subCount++
|
||||||
|
nestedModel.get(List).subItems.insert(index, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
function get(List, index) {
|
||||||
|
return nestedModel.get(List).subItems.get(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
function set(List, index, obj) {
|
||||||
|
nestedModel.get(List).subItems.set(index, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
function addLst(str) {
|
||||||
|
var newCollection
|
||||||
|
var i = 0
|
||||||
|
var temp = Qt.createComponent("Sublist.qml").createObject(rt, {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
newCollection = temp.get(0)
|
||||||
|
newCollection.name = str
|
||||||
|
newCollection.subItems.clear()
|
||||||
|
for (i = 0; i < 1; i++) {
|
||||||
|
newCollection.subItems.append(newdef(nestedModel.count, "idiot"))
|
||||||
|
}
|
||||||
|
|
||||||
|
nestedModel.append(newCollection)
|
||||||
|
}
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
id: lst
|
||||||
|
anchors.fill: parent
|
||||||
|
y: 0
|
||||||
|
height: ((lst.count) * 55) + (lst.subCount * 100)
|
||||||
|
interactive: false
|
||||||
|
property int subCount: 0
|
||||||
|
model: nestedModel
|
||||||
|
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: name
|
||||||
|
clip: true
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 15
|
||||||
|
anchors.leftMargin: 5
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
lst.subCount = lst.subCount + subItemLoader.subItemModel.count
|
||||||
|
} else {
|
||||||
|
lst.subCount = lst.subCount - subItemLoader.subItemModel.count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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: subItemColumnDelegate
|
||||||
|
onStatusChanged: if (status == Loader.Ready) {
|
||||||
|
item.model = subItemModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: subItemColumnDelegate
|
||||||
|
Column {
|
||||||
|
property alias model: subItemRepeater.model
|
||||||
|
|
||||||
|
width: rt.width
|
||||||
|
Repeater {
|
||||||
|
id: subItemRepeater
|
||||||
|
objectName: "repeater"
|
||||||
|
delegate: Cell {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ListModel {
|
||||||
|
id: nestedModel
|
||||||
|
objectName: "nestedModel"
|
||||||
|
}
|
||||||
|
}
|
@ -11,18 +11,14 @@ ApplicationWindow {
|
|||||||
ColorDialog {
|
ColorDialog {
|
||||||
id: textClrDialog
|
id: textClrDialog
|
||||||
//objectname: "textClrDialog"
|
//objectname: "textClrDialog"
|
||||||
// @disable-check M16
|
|
||||||
title: "Please choose a color for the text"
|
title: "Please choose a color for the text"
|
||||||
// @disable-check M16
|
|
||||||
showAlphaChannel: true
|
showAlphaChannel: true
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorDialog {
|
ColorDialog {
|
||||||
id: outlineClrDialog
|
id: outlineClrDialog
|
||||||
//objectname: "outlineClrDialog"
|
//objectname: "outlineClrDialog"
|
||||||
// @disable-check M16
|
|
||||||
title: "Please choose a color for the text"
|
title: "Please choose a color for the text"
|
||||||
// @disable-check M16
|
|
||||||
showAlphaChannel: true
|
showAlphaChannel: true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,9 +179,9 @@ ApplicationWindow {
|
|||||||
id: fontPicker
|
id: fontPicker
|
||||||
objectName: "fontPicker"
|
objectName: "fontPicker"
|
||||||
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
|
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
|
||||||
model: go.fontLen
|
model: go.fontList.split("\n")
|
||||||
// @disable-check M16
|
/*// @disable-check M16
|
||||||
/*delegate:Text {
|
delegate:Text {
|
||||||
text: go.fontList(index)
|
text: go.fontList(index)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@ -222,9 +218,9 @@ ApplicationWindow {
|
|||||||
ComboBox {
|
ComboBox {
|
||||||
id: versePicker
|
id: versePicker
|
||||||
objectName: "versePicker"
|
objectName: "versePicker"
|
||||||
model: go.verseLen
|
model: go.verses.split("\n")
|
||||||
// @disable-check M16
|
/*// @disable-check M16
|
||||||
/* delegate: Text {
|
delegate: Text {
|
||||||
text: go.verses(index)
|
text: go.verses(index)
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
@ -232,9 +228,9 @@ ApplicationWindow {
|
|||||||
ComboBox {
|
ComboBox {
|
||||||
id: imgPicker
|
id: imgPicker
|
||||||
objectName: "imgPicker"
|
objectName: "imgPicker"
|
||||||
model: go.imgLen
|
model: go.img.split("\n")
|
||||||
// @disable-check M16
|
/*// @disable-check M16
|
||||||
/*delegate: Text {
|
delegate: Text {
|
||||||
text: go.img(index)
|
text: go.img(index)
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
180
qml/lst/tst.qml
180
qml/lst/tst.qml
@ -1,180 +0,0 @@
|
|||||||
//https://gist.github.com/elpuri/3753756
|
|
||||||
import QtQuick 2.4
|
|
||||||
|
|
||||||
Item {
|
|
||||||
id: tst4
|
|
||||||
height: 50 + ((tst3.count - 1) * 50) + (tst3.subCount * 40)
|
|
||||||
width: 200
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: 0
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.leftMargin: 0
|
|
||||||
Component.onCompleted: {
|
|
||||||
addLst()
|
|
||||||
}
|
|
||||||
|
|
||||||
function addLst() {
|
|
||||||
var tstm
|
|
||||||
tstm = nestedModel.get(0)
|
|
||||||
tstm.subItems = [ { itemName: "test" }, { itemName: "notest" } ]
|
|
||||||
|
|
||||||
nestedModel.append(tstm)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ListView {
|
|
||||||
id: tst3
|
|
||||||
anchors.fill: parent
|
|
||||||
property int subCount: 0
|
|
||||||
model: nestedModel
|
|
||||||
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 = tst3.subCount + subItemLoader.subItemModel.count
|
|
||||||
} else {
|
|
||||||
tst3.subCount = tst3.subCount - subItemLoader.subItemModel.count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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: 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ListModel {
|
|
||||||
id: nestedModel
|
|
||||||
objectName: "nestedModel"
|
|
||||||
ListElement {
|
|
||||||
categoryName: "Cars"
|
|
||||||
collapsed: true
|
|
||||||
subItems: [
|
|
||||||
ListElement {
|
|
||||||
itemName: "Nisan"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Toyota"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Chevy"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Audi"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
ListElement {
|
|
||||||
categoryName: "Cars"
|
|
||||||
collapsed: true
|
|
||||||
subItems: [
|
|
||||||
ListElement {
|
|
||||||
itemName: "Nissa"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Toyota"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Chevy"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Audi"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
ListElement {
|
|
||||||
categoryName: "Cars"
|
|
||||||
collapsed: true
|
|
||||||
subItems: [
|
|
||||||
ListElement {
|
|
||||||
itemName: "Nissan"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Toota"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Chevy"
|
|
||||||
},
|
|
||||||
ListElement {
|
|
||||||
itemName: "Audi"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
import QtQuick 2.4
|
|
||||||
import QtQuick.Dialogs 1.1
|
|
||||||
|
|
||||||
MessageDialog {
|
|
||||||
icon: StandardIcon.Information
|
|
||||||
text: "Presentation App \nVersion: Alpha"
|
|
||||||
detailedText: "Presentation App for use in a church service\nMade in 2016 by Timmy Welch."
|
|
||||||
title: "About"
|
|
||||||
height: 100
|
|
||||||
width: 200
|
|
||||||
standardButtons: StandardButton.Close
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user