moving away from GLFW mostly

switching to a list of lists
qml is way out of sync
need to figure out how much the signals need to be changed
and the best way to update the preview text for the qml
This commit is contained in:
lordwelch 2017-02-05 13:57:50 -07:00
parent 3569a7d502
commit 73bbf9b01a
15 changed files with 778 additions and 899 deletions

148
glfw.go
View File

@ -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
} }
} }

315
main.go
View File

@ -9,45 +9,52 @@ import (
"os" "os"
"github.com/go-gl/glfw/v3.1/glfw" "github.com/go-gl/glfw/v3.1/glfw"
"github.com/lordwelch/qml"
"gopkg.in/gographics/imagick.v2/imagick" "gopkg.in/gographics/imagick.v2/imagick"
"gopkg.in/qml.v1"
) )
//Bool type i'm lazy wanted a toggle function
type Bool bool 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 { 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 service
slides slide err error
err error path string
slides collection
) )
func main() { func main() {
@ -56,157 +63,189 @@ 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("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() imagick.Terminate()
return nil return nil
} }
//Adds a new cell func (sv service) Init(int num) {
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(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) //keep the pointer/dereference (i'm not sure which it is)
//problems occur otherwise //problems occur otherwise
*sl = append(*sl, &cl) //*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.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 //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)
} }
func (bl *Bool) Flip() {
*bl = !*bl
}

291
qml.go
View File

@ -8,90 +8,183 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/lordwelch/qml" "gopkg.in/qml.v1"
) )
var ( var (
selCell int //the focused cell cellQml qml.Object //file for the cell object
rhtClkCell int //the cell that was last right clicked displayImg qml.Object
qimg qml.Object //file for the image object displayQml qml.Object
cellQml qml.Object //file for the cell object DisplayWindow *qml.Window
mainQml qml.Object //main QML file editQml qml.Object
edtQml qml.Object engine *qml.Engine
textEdit qml.Object imgQml qml.Object //file for the image object
window *qml.Window imgready Bool = false
window2 *qml.Window MainWindow *qml.Window
engine *qml.Engine mainQml qml.Object //main QML file
quickEdit Bool = false QML *qmlVar //misc var qml needs
imgready Bool = false quickEdit Bool = false
QML *qmlVar 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() { func qmlWindows() error {
window2.ObjectByName("textClrDialog").On("accepted", func() { mainQml, err = engine.LoadFile(path + "/Main.qml")
window2.ObjectByName("textClrDialog").Color("color") 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() { func showWindows() {
qml.Changed(qv, qv.VerseLen) MainWindow.Show()
qml.Changed(qv, qv.OrderLen) songEditWindow.Show()
qml.Changed(qv, qv.ImgLen) DisplayWindow.Show()
qml.Changed(qv, qv.FontLen) }
//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 //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 cl.Select()
selCell = cl.qmlcell.Int("index")
cl.qmlcell.ObjectByName("cellMouse").Set("focus", true)
setupScene()
} }
//update image preview
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 cl.Select()
selCell = cl.qmlcell.Int("index")
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)
@ -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)
}

94
qml/Cell.qml Normal file
View File

@ -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
}
}
}
}

17
qml/Dsplay.qml Normal file
View 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
}
}

208
qml/Main.qml Normal file
View File

@ -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"
}
}
}
}

View File

@ -1,30 +1,91 @@
//https://gist.github.com/elpuri/3753756 //https://gist.github.com/elpuri/3753756
import QtQuick 2.4 import QtQuick 2.4
import QtQuick.Controls 1.3
Item { Item {
id: tst4 id: rt
height: 50 + ((tst3.count - 1) * 50) + (tst3.subCount * 40) property ListElement def: ListElement {
width: 200 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.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 0
Component.onCompleted: { function remove(List, index) {
addLst() lst.subCount--
nestedModel.get(List).subItems.remove(index, 1)
} }
function addLst() { function pop(List) {
var tstm lst.subCount--
tstm = nestedModel.get(0) nestedModel.get(List).subItems.remove(nestedModel.get( List).subItems.count - 1, 1)
tstm.subItems = [ { itemName: "test" }, { itemName: "notest" } ]
nestedModel.append(tstm)
} }
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 { ListView {
id: tst3 id: lst
anchors.fill: parent anchors.fill: parent
y: 0
height: ((lst.count) * 55) + (lst.subCount * 100)
interactive: false
property int subCount: 0 property int subCount: 0
model: nestedModel model: nestedModel
delegate: Component { delegate: Component {
@ -48,13 +109,19 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
x: 15 x: 15
font.pixelSize: 24 font.pixelSize: 24
text: categoryName text: name
clip: true
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: 15
anchors.leftMargin: 5
} }
Rectangle { Rectangle {
color: "red" color: "red"
width: 30 width: 30
height: 30 height: 30
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 15 anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -66,9 +133,9 @@ Item {
onClicked: { onClicked: {
nestedModel.setProperty(index, "collapsed", !collapsed) nestedModel.setProperty(index, "collapsed", !collapsed)
if (!nestedModel.get(index).collapsed) { if (!nestedModel.get(index).collapsed) {
tst3.subCount = tst3.subCount + subItemLoader.subItemModel.count lst.subCount = lst.subCount + subItemLoader.subItemModel.count
} else { } 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 // 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. // to false makes the parent Column treat it as if it's height was 0.
visible: !collapsed visible: !collapsed
property variant subItemModel: subItems property variant subItemModel: subItems
sourceComponent: subItemColumnDelegate sourceComponent: subItemColumnDelegate
onStatusChanged: if (status == Loader.Ready) onStatusChanged: if (status == Loader.Ready) {
item.model = subItemModel item.model = subItemModel
}
} }
} }
} }
@ -93,88 +162,20 @@ Item {
Component { Component {
id: subItemColumnDelegate id: subItemColumnDelegate
Column { Column {
property alias model: subItemRepeater.model property alias model: subItemRepeater.model
width: rt.width
width: tst4.width
Repeater { Repeater {
id: subItemRepeater id: subItemRepeater
delegate: Rectangle { objectName: "repeater"
color: "#cccccc" delegate: Cell {}
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 { ListModel {
id: nestedModel id: nestedModel
objectName: "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"
}
]
}
} }
} }

View File

@ -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)
}*/ }*/
} }

16
qml/Sublist.qml Normal file
View File

@ -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"
}
]
}
}

View File

@ -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"
}
]
}
}

View File

@ -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"
}
}
}
}

View File

@ -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()
}
}
}
}

View File

@ -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
}

View File

@ -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
}
}