diff --git a/glfw.go b/glfw.go index 65d02a5..a859def 100644 --- a/glfw.go +++ b/glfw.go @@ -3,117 +3,31 @@ package main import ( "fmt" - "image" - "log" - "github.com/go-gl/gl/v2.1/gl" "github.com/go-gl/glfw/v3.1/glfw" - "github.com/lordwelch/qml" ) var ( - win *glfw.Window - monWidth int //displayed height - monHeight int //displayed width - monitors []*glfw.Monitor - projMonitor *glfw.Monitor - tex1 *uint32 //identifier for opengl texture - texDel Bool //if texture should be deleted + monitorHeight int // displayed width + monitors []*glfw.Monitor + monitorWidth int // displayed height + projectorMonitor *glfw.Monitor ) -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() { 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 { fmt.Println("You only have 1 monitor!!!!!!!!!!! :-P") - monWidth = 800 - monHeight = 600 + monitorWidth = 800 + monitorHeight = 600 - win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil) - if err != nil { - panic(err) - } - projMonitor = monitors[0] + projectorMonitor = monitors[0] } else { fmt.Printf("You have %d monitors\n", i) - monWidth = monitors[1].GetVideoMode().Width - monHeight = monitors[1].GetVideoMode().Height - win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil) - win.SetPos(monitors[1].GetPos()) - fmt.Printf("Width: %d Height: %d \n", monWidth, monHeight) - if err != nil { - panic(err) - } - projMonitor = monitors[1] + monitorWidth = monitors[1].GetVideoMode().Width + monitorHeight = monitors[1].GetVideoMode().Height + projectorMonitor = monitors[1] } monitorInfo() @@ -121,43 +35,23 @@ func checkMon() { } func monitorInfo() { + fmt.Println(len(monitors)) for _, mon := range monitors { - fmt.Printf("monitor name: %s\n", mon.GetName()) - i, t := mon.GetPos() - fmt.Printf("position X: %d Y: %d\n", i, t) + fmt.Printf("Monitor name: %s\n", mon.GetName()) + x, y := mon.GetPos() + fmt.Printf("Position: %v, %v\n", x, y) + fmt.Printf("Size: %v x %v\n", mon.GetVideoMode().Width, mon.GetVideoMode().Height) } } func glInit() { - window.Set("cls", false) - if err = glfw.Init(); err != nil { - log.Fatalln("failed to initialize glfw:", err) - } - checkMon() - - 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 - + if err = glfw.Init(); err == nil { + checkMon() + DisplayWindow.Root().Set("height", monitorHeight) + DisplayWindow.Root().Set("width", monitorWidth) + DisplayWindow.Root().Set("x", 0) + DisplayWindow.Root().Set("y", 0) } } diff --git a/main.go b/main.go index a5e93b0..13ec643 100644 --- a/main.go +++ b/main.go @@ -9,45 +9,52 @@ import ( "os" "github.com/go-gl/glfw/v3.1/glfw" - "github.com/lordwelch/qml" + "gopkg.in/gographics/imagick.v2/imagick" + "gopkg.in/qml.v1" ) -//Bool type i'm lazy wanted a toggle function type Bool bool +type Cell struct { + fnt 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 { - FontList []string - FontLen int - Verses []string - VerseLen int - VerseOrder []string - OrderLen int - Img []string - ImgLen int + FontList string + Verses string + VerseOrder string + //Img string } -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 - } -} - -type slide []*cell +type service []collection var ( - path string - slides slide - err error + currentService service + err error + path string + slides collection ) func main() { @@ -56,157 +63,189 @@ func main() { 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{} - engine.Context().SetVar("go", QML) - findfonts() - engine.AddImageProvider("images", imgProvider) 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 { return err } - edtQml, err = engine.LoadFile(path + "/qml/songEdit.qml") - if err != nil { - return err - } + currentService.Init(1) - 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 setSignals() - slides.add() - - //var from GO to qml //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) - window.Wait() + displayImg = DisplayWindow.Root().ObjectByName("image1") + serviceObject = serviceQml.Create(engine.Context()) + serviceObject.Set("parent", MainWindow.ObjectByName("data1")) + serviceObject.Call("addCollection") + + //edtQmlShow() + qml.RunMain(glInit) + MainWindow.Wait() + slides.destroy() imagick.Terminate() return nil } -//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) +func (sv service) Init(int num) { + if num <= 0 { + num = 1 + } - //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) + for index := 0; index < num; index++ { + if sv == nil { + sv.add("") + } + } +} + +func (sv service) add(string name) { + var ( + sl collection + int i = len(sv) + ) + + if len(name) <= 0 { + name = "Song: " + fmt.Sprint(i) + } + + sl.init() + sv = append(sv, sl) + //?serviceObj.Call(addCollection, name, 1) +} + +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(int num) { + if num <= 0 { + num = 1 + } + + for index := 0; index < num; index++ { + if sl == nil { + sl.add("") + } + } +} + +//Adds a new cell +func (sl collection) add(string text) { + var ( + cl Cell + int i = len(sl) + ) + + if len(name) <= 0 { + name = "Slide" + fmt.Sprint(i) + } + + cl.Init() //keep the pointer/dereference (i'm not sure which it is) //problems occur otherwise - *sl = append(*sl, &cl) + //*sl = append(*sl, &cl) + sl = append(sl, &cl) //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.image.qmlImage.Set("source", fmt.Sprintf("image://images/cell;%d", cl.index)) cl.setSignal() //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 -func (sl *slide) remove(i int) { - *sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil +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) + 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 (bl *Bool) Toggle() { - if *bl == false { - *bl = true - } else { - *bl = false +func (sl collection) destroy() { + for i := len(sl); i > 0; i-- { + sl.remove(i - 1) } } +func (cl *Cell) Init() { + cl.text = `hello this is text` + cl.index = -1 + cl.fnt.color, cl.fnt.outlineColor = color.RGBA{0, 0, 0, 1}, color.RGBA{1, 1, 1, 1} + cl.fnt.name = "none" + cl.fnt.outline = false + cl.fnt.outlineSize = 1 + cl.fnt.size = 35 + cl.fnt.x, cl.fnt.y = 10, 30 + + cl.qmlObject = cellQml.Create(engine.Context()) + cl.image.qmlImage = imgQml.Create(engine.Context()) + + //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") + +} + +/*func (cl *Cell) Texture() glbase.Texture { + fmt.Println("index: ", cl.index, " ", cl.img.tex) + fmt.Println("error tex:", gl.GetError()) + if cl.img.tex == 0 { + cl.img.tex = newTexture(*cl.getImage(monWidth, monHeight)) + fmt.Println("new texture", cl.img.tex) + } + return cl.img.tex +}*/ + //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) } + +func (bl *Bool) Flip() { + *bl = !*bl +} diff --git a/qml.go b/qml.go index 405d8ca..7714fb0 100644 --- a/qml.go +++ b/qml.go @@ -8,90 +8,183 @@ import ( "strconv" "strings" - "github.com/lordwelch/qml" + "gopkg.in/qml.v1" ) var ( - selCell int //the focused cell - rhtClkCell int //the cell that was last right clicked - qimg qml.Object //file for the image object - cellQml qml.Object //file for the cell object - mainQml qml.Object //main QML file - edtQml qml.Object - textEdit qml.Object - window *qml.Window - window2 *qml.Window - engine *qml.Engine - quickEdit Bool = false - imgready Bool = false - QML *qmlVar + cellQml qml.Object //file for the cell object + displayImg qml.Object + displayQml qml.Object + DisplayWindow *qml.Window + editQml qml.Object + engine *qml.Engine + imgQml qml.Object //file for the image object + imgready Bool = false + MainWindow *qml.Window + mainQml qml.Object //main QML file + QML *qmlVar //misc var qml needs + quickEdit Bool = false + rightClickCell int //the cell that was last right clicked + selectedCell int //the focused cell + serviceObject qml.Object + serviceQml qml.Object + songEditWindow *qml.Window + textEdit qml.Object ) -func initQML() { - window2.ObjectByName("textClrDialog").On("accepted", func() { - window2.ObjectByName("textClrDialog").Color("color") - }) +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 (qv *qmlVar) Changed() { - qml.Changed(qv, qv.VerseLen) - qml.Changed(qv, qv.OrderLen) - qml.Changed(qv, qv.ImgLen) - qml.Changed(qv, qv.FontLen) +func showWindows() { + MainWindow.Show() + songEditWindow.Show() + DisplayWindow.Show() +} + +//imgProvider() for preview images in QML +func imgProvider(id string, width, height int) image.Image { + var img1 image.Image + if imgready && (len(id) > 0) { + //fmt.Println("source (provider): ", id) + i1 := strings.Index(id, `;`) + i, _ := strconv.Atoi(id[i1+1:]) + img1 = slides[i].getImage(width, height) + + } else { + img1 = image.NewRGBA(image.Rect(0, 0, 340, 480)) + } + + return img1 + +} + +func edtQmlShow() { + //slc := window2.ObjectByName("fontPicker").Property("model") + //fmt.Println(slc) +} + +//setSignals() for non dynamic elements +func setSignals() { + MainWindow.ObjectByName("imgpicker").On("accepted", func() { + //delete "file://" from url + url := filepath.Clean(strings.Replace(MainWindow.ObjectByName("imgpicker").String("fileUrl"), "file:", "", 1)) + + //replace new image + slides[rightClickCell].image.img.Clear() + slides[rightClickCell].image.img.ReadImage(url) + }) + + MainWindow.ObjectByName("btnAdd").On("clicked", func() { + slides.add() + }) + + MainWindow.ObjectByName("btnRem").On("clicked", func() { + slides.remove(len(slides) - 1) + }) + + MainWindow.ObjectByName("btnMem").On("clicked", func() { + //run GC + debug.FreeOSMemory() + }) + + MainWindow.ObjectByName("mnuEdit").On("triggered", func() { + quickEdit.Flip() + }) + + textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) { + var ( + str string + cel *Cell + ) + + if !focus { + //set text back to the cell + str = textEdit.ObjectByName("textEdit1").String("text") + cel = slides[textEdit.Int("cell")] + if textEdit.Bool("txt") { + cel.qmlObject.ObjectByName("cellText").Set("text", str) + cel.text = str + } + } + }) } //signals for the cell and image in qml -func (cl *cell) setSignal() { - cl.qmlcell.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) { - btn := musEvent.Property("button") +func (cl *Cell) setSignal() { + cl.qmlObject.ObjectByName("cellMouse").On("clicked", func(mouseEvent qml.Object) { + btn := mouseEvent.Property("button") //right click if btn == 2 { //context menu - window.ObjectByName("mnuCtx").Call("popup") - rhtClkCell = cl.index + MainWindow.ObjectByName("mnuCtx").Call("popup") + rightClickCell = cl.index } else { //left click - //select and update image preview for cell - selCell = cl.qmlcell.Int("index") - cl.qmlcell.ObjectByName("cellMouse").Set("focus", true) - setupScene() + cl.Select() + } - //update image preview - cl.clearcache() + }) - cl.qmlimg.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) { - btn := musEvent.Property("button") + cl.image.qmlImage.ObjectByName("cellMouse").On("clicked", func(mouseEvent qml.Object) { + btn := mouseEvent.Property("button") //right click if btn == 2 { //context menu - window.ObjectByName("mnuCtx").Call("popup") - rhtClkCell = cl.index + MainWindow.ObjectByName("mnuCtx").Call("popup") + rightClickCell = cl.index } else { //left click - //select and update image preview for cell - selCell = cl.qmlcell.Int("index") - cl.qmlcell.ObjectByName("cellMouse").Set("focus", true) - setupScene() + cl.Select() } - //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 { - cl.qmlcell.ObjectByName("cellMouse").Call("selected") + cl.qmlObject.ObjectByName("cellMouse").Call("selected") } 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 { //cover the cell with the text edit textEdit.Set("cell", cl.index) - textEdit.Set("x", cl.qmlcell.Int("x")) - textEdit.Set("y", cl.qmlcell.Int("y")) - textEdit.Set("height", cl.qmlcell.Int("height")) + textEdit.Set("x", cl.qmlObject.Int("x")) + textEdit.Set("y", cl.qmlObject.Int("y")) + textEdit.Set("height", cl.qmlObject.Int("height")) textEdit.Set("z", 100) textEdit.Set("visible", true) textEdit.ObjectByName("textEdit1").Set("focus", true) @@ -103,99 +196,3 @@ func (cl *cell) setSignal() { }) } - -//setSignals() for non dynamic elements -func setSignals() { - window.ObjectByName("imgpicker").On("accepted", func() { - //delete file:// from url - url := filepath.Clean(strings.Replace(window.ObjectByName("imgpicker").String("fileUrl"), "file:", "", 1)) - - //replace new image - slides[rhtClkCell].img.Clear() - slides[rhtClkCell].img.ReadImage(url) - setupScene() - //update image preview - slides[rhtClkCell].clearcache() - }) - - window.ObjectByName("btnAdd").On("clicked", func() { - slides.add() - }) - - window.ObjectByName("btnRem").On("clicked", func() { - slides[len(slides)-1].remove() - }) - - window.ObjectByName("btnMem").On("clicked", func() { - //run GC - debug.FreeOSMemory() - }) - - window.On("closing", func() { - //close glfw first - 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) { - var ( - str string - cel *cell - ) - - if !focus { - //set text back to the cell - str = textEdit.ObjectByName("textEdit1").String("text") - cel = slides[textEdit.Int("cell")] - if textEdit.Bool("txt") { - cel.qmlcell.ObjectByName("cellText").Set("text", str) - cel.text = str - } - } - }) -} - -func edtQmlShow() { - //slc := window2.ObjectByName("fontPicker").Property("model") - //fmt.Println(slc) -} - -//imgProvider() for preview images in QML -func imgProvider(id string, width, height int) image.Image { - if imgready && (len(id) > 0) { - //fmt.Println("source (provider): ", id) - i1 := strings.Index(id, `;`) - i, _ := strconv.Atoi(id[:i1]) - return slides[i].getImage(width, height) - - } - var img1 image.Image = image.NewRGBA(image.Rect(0, 0, 340, 480)) - return img1 - -} - -//clear cache dosen't actually clear the cache -//just gives a new source so that the cache isn't used -func (cl *cell) clearcache() { - str := cl.qmlimg.String("source") - 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) - cl.qmlimg.Set("source", str) -} diff --git a/qml/qml/AboutDialog.qml b/qml/AboutDialog.qml similarity index 100% rename from qml/qml/AboutDialog.qml rename to qml/AboutDialog.qml diff --git a/qml/Cell.qml b/qml/Cell.qml new file mode 100644 index 0000000..a6d6d8b --- /dev/null +++ b/qml/Cell.qml @@ -0,0 +1,94 @@ +import QtQuick 2.4 + +Rectangle { + id: rectangle1 + height: 100 + anchors.left: parent.left + anchors.right: parent.right + + Rectangle { + id: cellRect + objectName: "cellRect" + property int index: 0 + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.top: parent.top + border.width: 2 + border.color: "black" + width: rectangle1.width / 2 + + Text { + id: displayText + enabled: true + objectName: "cellText" + text: cellText //"Hello\nMy\nName\nIs\n\"Timmy\"" + anchors.fill: parent + anchors.leftMargin: 3 + clip: true + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + + MouseArea { + id: cellMouse + hoverEnabled: true + enabled: true + objectName: "cellMouse" + anchors.fill: parent + acceptedButtons: Qt.AllButtons + + onMouseXChanged: cellHover() + onExited: focusChanged(focus) + + function cellHover() { + if (containsMouse) { + parent.parent.border.color = "skyblue" + parent.parent.color = "darkblue" + parent.color = "white" + } else if (focus) { + parent.color = "black" + } + } + + function notSelected() { + + parent.parent.border.color = "black" + parent.parent.color = "white" + parent.color = "black" + cellHover() + } + + function selected() { + focus = true + parent.parent.border.color = "blue" + parent.parent.color = "gainsboro" + parent.color = "black" + cellHover() + } + } + } + } + Rectangle { + anchors.left: cellRect.right + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.top: parent.top + anchors.leftMargin: 0 + Image { + id: img + antialiasing: true + source: imgSource + objectName: "cellImg" + property int index: 0 + anchors.fill: parent + fillMode: Image.Stretch + cache: false + MouseArea { + id: cellMse + anchors.fill: parent + hoverEnabled: true + enabled: true + objectName: "cellMouse" + acceptedButtons: Qt.AllButtons + } + } + } +} diff --git a/qml/Dsplay.qml b/qml/Dsplay.qml new file mode 100644 index 0000000..5ebd864 --- /dev/null +++ b/qml/Dsplay.qml @@ -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 + } + +} diff --git a/qml/Main.qml b/qml/Main.qml new file mode 100644 index 0000000..f7fd463 --- /dev/null +++ b/qml/Main.qml @@ -0,0 +1,208 @@ +import QtQuick 2.4 +import QtQuick.Dialogs 1.2 +import QtQuick.Controls 1.3 +import QtQuick.Window 2.0 +import QtQuick.Layouts 1.0 + +ApplicationWindow { + id: applicationWindow1 + //title: "Presentation App" + visible: true + objectName: "applicationWindow1" + //minimumWidth: 500 + //minimumHeight: 500 + width: 1000 + height: 600 + property variant mlst + + Component.onCompleted: { +// mlst = Qt.createComponent("Lst.qml").createObject(data1, {}) + } + FileDialog { + id: imgpicker + title: "Choose an image for this slide" + objectName: "imgpicker" + } + + AboutDialog { + id: aboutDialog + } + + Action { + id: aboutAction + text: "About" + onTriggered: aboutDialog.open() + } + + Action { + id: quitAction + text: "Close" + onTriggered: Qt.quit() + } + + menuBar: MenuBar { + Menu { + title: "&File" + MenuItem { + action: quitAction + } + } + 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 + anchors.fill: parent + objectName: "mainSlider" + orientation: Qt.Horizontal + + //onResizingChanged: col1.width = gridData.width / 2 + ScrollView { + id: scview + frameVisible: false + anchors.margins: 4 + horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff + verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn + flickableItem.boundsBehavior: Flickable.StopAtBounds + + Rectangle { + id: col1 + width: scview.width - 22 + height: data1.childrenRect.height + objectName: "col1" + color: "#00000000" + 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 + clip: true + height: data1.childrenRect.height + } + } + } + + Rectangle { + id: mainView + border.width: 0 + objectName: "mainView" + //anchors.left: scview.right + z: 1 + clip: false + visible: true + + Button { + id: button1 + objectName: "btnAdd" + x: 8 + y: 8 + text: "Button add" +// onClicked: applicationWindow1.mlst.addLst("Nobody") + } + + Button { + id: button2 + x: 8 + y: 43 + text: "Button rem" + objectName: "btnRem" +// onClicked: applicationWindow1.mlst.remLst() + } + + Button { + id: button5 + x: 8 + y: 78 + text: "Button mem" + objectName: "btnMem" + } + } + } +} diff --git a/qml/lst/tst.qml b/qml/Service.qml similarity index 51% rename from qml/lst/tst.qml rename to qml/Service.qml index e9d40ad..6fbb46a 100644 --- a/qml/lst/tst.qml +++ b/qml/Service.qml @@ -1,30 +1,91 @@ //https://gist.github.com/elpuri/3753756 import QtQuick 2.4 +import QtQuick.Controls 1.3 Item { - id: tst4 - height: 50 + ((tst3.count - 1) * 50) + (tst3.subCount * 40) - width: 200 + id: rt + property ListElement def: ListElement { + property string cellText: "Hello\nMy\nName\nIs\n\"Timmy\"" + 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.rightMargin: 0 anchors.left: parent.left - anchors.leftMargin: 0 - Component.onCompleted: { - addLst() + + function remove(List, index) { + lst.subCount-- + nestedModel.get(List).subItems.remove(index, 1) } - function addLst() { - var tstm - tstm = nestedModel.get(0) - tstm.subItems = [ { itemName: "test" }, { itemName: "notest" } ] - - nestedModel.append(tstm) - + 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) + } + + // Button { + // id: btn + // width: 100 + // text: "add" + // onClicked: { + // addLst() + // } + // } ListView { - id: tst3 + id: lst anchors.fill: parent + y: 0 + height: ((lst.count) * 55) + (lst.subCount * 100) + interactive: false property int subCount: 0 model: nestedModel delegate: Component { @@ -48,13 +109,19 @@ Item { anchors.verticalCenter: parent.verticalCenter x: 15 font.pixelSize: 24 - text: categoryName + 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 @@ -66,9 +133,9 @@ Item { onClicked: { nestedModel.setProperty(index, "collapsed", !collapsed) if (!nestedModel.get(index).collapsed) { - tst3.subCount = tst3.subCount + subItemLoader.subItemModel.count + lst.subCount = lst.subCount + subItemLoader.subItemModel.count } else { - tst3.subCount = tst3.subCount - subItemLoader.subItemModel.count + lst.subCount = lst.subCount - subItemLoader.subItemModel.count } } } @@ -82,10 +149,12 @@ Item { // 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) + onStatusChanged: if (status == Loader.Ready) { item.model = subItemModel + } } } } @@ -93,88 +162,20 @@ Item { Component { id: subItemColumnDelegate + Column { property alias model: subItemRepeater.model + width: rt.width - 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 - } - } + objectName: "repeater" + delegate: Cell {} } } } 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" - } - ] - } } } - diff --git a/qml/qml/songEdit.qml b/qml/SongEdit.qml similarity index 93% rename from qml/qml/songEdit.qml rename to qml/SongEdit.qml index ccf6e89..3859e31 100644 --- a/qml/qml/songEdit.qml +++ b/qml/SongEdit.qml @@ -11,18 +11,14 @@ ApplicationWindow { ColorDialog { id: textClrDialog //objectname: "textClrDialog" - // @disable-check M16 title: "Please choose a color for the text" - // @disable-check M16 showAlphaChannel: true } ColorDialog { id: outlineClrDialog //objectname: "outlineClrDialog" - // @disable-check M16 title: "Please choose a color for the text" - // @disable-check M16 showAlphaChannel: true } @@ -183,9 +179,9 @@ ApplicationWindow { id: fontPicker objectName: "fontPicker" Layout.alignment: Qt.AlignLeft | Qt.AlignTop - model: go.fontLen - // @disable-check M16 - /*delegate:Text { + model: go.fontList.split("\n") + /*// @disable-check M16 + delegate:Text { text: go.fontList(index) }*/ @@ -222,9 +218,9 @@ ApplicationWindow { ComboBox { id: versePicker objectName: "versePicker" - model: go.verseLen - // @disable-check M16 - /* delegate: Text { + model: go.verses.split("\n") + /*// @disable-check M16 + delegate: Text { text: go.verses(index) }*/ } @@ -232,9 +228,9 @@ ApplicationWindow { ComboBox { id: imgPicker objectName: "imgPicker" - model: go.imgLen - // @disable-check M16 - /*delegate: Text { + model: go.img.split("\n") + /*// @disable-check M16 + delegate: Text { text: go.img(index) }*/ } diff --git a/qml/Sublist.qml b/qml/Sublist.qml new file mode 100644 index 0000000..f80d539 --- /dev/null +++ b/qml/Sublist.qml @@ -0,0 +1,16 @@ +import QtQuick 2.4 +import QtQuick.Controls 1.3 + +ListModel { + id: nestedModel1 + objectName: "nestedModel1" + ListElement { + name: "Cars" + collapsed: true + subItems: [ + ListElement { + itemName: "idiot" + } + ] + } +} diff --git a/qml/lst/lstEle.qml b/qml/lst/lstEle.qml deleted file mode 100644 index 9765b6f..0000000 --- a/qml/lst/lstEle.qml +++ /dev/null @@ -1,28 +0,0 @@ -import QtQuick 2.4 - -ListModel { - id: nestedModel - objectName: "nestedModel" - function get1() { - console.log(get(0)) - return get(0) - } - ListElement { - categoryName: "Cars" - collapsed: true - subItems: [ - ListElement { - itemName: "tst" - }, - ListElement { - itemName: "Tota" - }, - ListElement { - itemName: "vy" - }, - ListElement { - itemName: "Audio Adrenaline" - } - ] - } -} diff --git a/qml/main.qml b/qml/main.qml deleted file mode 100644 index 8c143e5..0000000 --- a/qml/main.qml +++ /dev/null @@ -1,257 +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: 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 - - } - } - - 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: 43 - text: qsTr("Button ") - objectName: "btnRem" - } - - Button { - id: button3 - x: 8 - y: 78 - text: qsTr("Button ") - objectName: "btnMem" - } - } - } -} diff --git a/qml/qml/cell.qml b/qml/qml/cell.qml deleted file mode 100644 index 765e98b..0000000 --- a/qml/qml/cell.qml +++ /dev/null @@ -1,62 +0,0 @@ -import QtQuick 2.4 - -Rectangle { - objectName: "cellRect" - property int index: 0 - height: 100 - border.width: 2 - border.color: "black" - anchors.right: parent.right - anchors.left: parent.left - - Text { - id: cellText - enabled: true - objectName: "cellText" - text: "" - clip: true - wrapMode: Text.WrapAtWordBoundaryOrAnywhere - anchors.fill: parent - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.leftMargin: 2 - - MouseArea { - id: cellMouse - hoverEnabled: true - enabled: true - objectName: "cellMouse" - anchors.fill: parent - acceptedButtons: Qt.AllButtons - - onMouseXChanged: cellHover() - onExited: focusChanged(focus) - - function cellHover() { - if (containsMouse) { - parent.parent.border.color = "skyblue" - parent.parent.color = "darkblue" - parent.color = "white" - } else if (focus) { - parent.color = "black" - } - } - - function notSelected() { - - parent.parent.border.color = "black" - parent.parent.color = "white" - parent.color = "black" - cellHover() - } - - function selected() { - parent.parent.border.color = "blue" - parent.color = "black" - parent.parent.color = "gainsboro" - cellHover() - } - } - } -} diff --git a/qml/qml/fileDialogs.qml b/qml/qml/fileDialogs.qml deleted file mode 100644 index a725a8b..0000000 --- a/qml/qml/fileDialogs.qml +++ /dev/null @@ -1,13 +0,0 @@ -import QtQuick 2.2 -import QtQuick.Dialogs 1.0 - -FileDialog { - id: imgDialog - title: "Please choose an image" - folder: shortcuts.home - onAccepted: { - } - onRejected: { - } - Component.onCompleted: visible = true -} diff --git a/qml/qml/img.qml b/qml/qml/img.qml deleted file mode 100644 index 1614a19..0000000 --- a/qml/qml/img.qml +++ /dev/null @@ -1,23 +0,0 @@ -import QtQuick 2.4 - -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: cellMouse - hoverEnabled: true - enabled: true - objectName: "cellMouse" - anchors.fill: parent - acceptedButtons: Qt.AllButtons - } -}