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 (
|
||||
"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)
|
||||
}
|
||||
}
|
||||
|
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
|
||||
func (cl *cell) getImage(width, height int) (img *image.RGBA) {
|
||||
mw := cl.img.GetImage()
|
||||
func (cl *Cell) getImage(width, height int) (img *image.RGBA) {
|
||||
mw := cl.image.img.GetImage()
|
||||
if (width == 0) || (height == 0) {
|
||||
width = int(mw.GetImageWidth())
|
||||
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
|
||||
func (cl *cell) imgtext(width, height int) *imagick.MagickWand {
|
||||
func (cl *Cell) imgtext(width, height int) *imagick.MagickWand {
|
||||
mw := imagick.NewMagickWand()
|
||||
//defer mw.Destroy()
|
||||
dw := imagick.NewDrawingWand()
|
||||
@ -104,30 +104,30 @@ func (cl *cell) imgtext(width, height int) *imagick.MagickWand {
|
||||
mw.NewImage(uint(width), uint(height), pw)
|
||||
|
||||
// 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))
|
||||
dw.SetFillColor(pw)
|
||||
if (cl.font.name != "") || (cl.font.name != "none") {
|
||||
dw.SetFont(cl.font.name)
|
||||
if (cl.Font.name != "") || (cl.Font.name != "none") {
|
||||
dw.SetFont(cl.Font.name)
|
||||
}
|
||||
dw.SetFontSize(cl.font.size)
|
||||
dw.SetFontSize(cl.Font.size)
|
||||
|
||||
otlne := "none"
|
||||
// Add a black outline to the text
|
||||
r, g, b, _ = cl.font.outlineColor.RGBA()
|
||||
if cl.font.outline {
|
||||
r, g, b, _ = cl.Font.outlineColor.RGBA()
|
||||
if cl.Font.outline {
|
||||
otlne = fmt.Sprintf("rgb(%d,%d,%d)", r, g, b)
|
||||
}
|
||||
|
||||
pw.SetColor(otlne)
|
||||
dw.SetStrokeColor(pw)
|
||||
dw.SetStrokeWidth(cl.font.outlineSize)
|
||||
dw.SetStrokeWidth(cl.Font.outlineSize)
|
||||
|
||||
// Turn antialias on - not sure this makes a difference
|
||||
//dw.SetTextAntialias(true)
|
||||
|
||||
// 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
|
||||
mw.DrawImage(dw)
|
||||
@ -151,7 +151,7 @@ func (cl *cell) imgtext(width, height int) *imagick.MagickWand {
|
||||
return mw
|
||||
}
|
||||
|
||||
func findfonts() {
|
||||
func findFonts() {
|
||||
cmd := exec.Command("grep", "-ivE", `\-Oblique$|-Bold$|-Italic$|-Light$`)
|
||||
cmd.Stdin = strings.NewReader(strings.Join(imagick.QueryFonts("*"), "\n"))
|
||||
var out bytes.Buffer
|
||||
@ -160,8 +160,7 @@ func findfonts() {
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
QML.FontList = strings.Split(out.String(), "\n")
|
||||
QML.FontLen = len(QML.FontList)
|
||||
QML.FontList = out.String()
|
||||
}
|
||||
|
||||
func round(a float64) int {
|
||||
|
300
main.go
300
main.go
@ -9,45 +9,50 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/go-gl/glfw/v3.1/glfw"
|
||||
"github.com/lordwelch/qml"
|
||||
"github.com/limetext/qml-go"
|
||||
|
||||
"gopkg.in/gographics/imagick.v2/imagick"
|
||||
)
|
||||
|
||||
//Bool type i'm lazy wanted a toggle function
|
||||
type Bool bool
|
||||
type Cell struct {
|
||||
Font Font
|
||||
image Image
|
||||
index, collectionIndex int
|
||||
qmlObject qml.Object
|
||||
text string
|
||||
textVisible bool
|
||||
}
|
||||
|
||||
type collection []*Cell
|
||||
|
||||
type Font struct {
|
||||
color color.RGBA
|
||||
name string
|
||||
outline bool
|
||||
outlineColor color.RGBA
|
||||
outlineSize, size, x, y float64
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
img *imagick.MagickWand
|
||||
imgSource string
|
||||
qmlImage qml.Object
|
||||
}
|
||||
|
||||
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 = new(service)
|
||||
err error
|
||||
path string
|
||||
slides collection
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -56,157 +61,176 @@ 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("displayImage")
|
||||
serviceObject = serviceQml.Create(engine.Context())
|
||||
serviceObject.Set("parent", MainWindow.ObjectByName("data1"))
|
||||
serviceObject.Call("addLst", "shit")
|
||||
|
||||
//edtQmlShow()
|
||||
qml.RunMain(glInit)
|
||||
MainWindow.Wait()
|
||||
slides.destroy()
|
||||
fmt.Println(len(*currentService))
|
||||
|
||||
imagick.Terminate()
|
||||
return nil
|
||||
}
|
||||
|
||||
//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(num int) {
|
||||
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(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)
|
||||
//problems occur otherwise
|
||||
// now Im not an idiot and I know what this does
|
||||
*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.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
|
||||
func (cl cell) String() string {
|
||||
func (cl Cell) String() string {
|
||||
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
||||
}
|
||||
|
187
qml.go
187
qml.go
@ -8,90 +8,129 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lordwelch/qml"
|
||||
"github.com/limetext/qml-go"
|
||||
)
|
||||
|
||||
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
|
||||
selectedCell int //the focused cell
|
||||
rightClickCell int //the cell that was last right clicked
|
||||
cellQml qml.Object //file for the cell object
|
||||
mainQml qml.Object //main QML file
|
||||
editQml qml.Object
|
||||
textEdit qml.Object
|
||||
displayQml qml.Object
|
||||
displayImg qml.Object
|
||||
DisplayWindow *qml.Window
|
||||
MainWindow *qml.Window
|
||||
songEditWindow *qml.Window
|
||||
serviceObject qml.Object
|
||||
serviceQml qml.Object
|
||||
engine *qml.Engine
|
||||
quickEdit bool = false
|
||||
imgready bool = false
|
||||
QML *qmlVar
|
||||
)
|
||||
|
||||
func initQML() {
|
||||
window2.ObjectByName("textClrDialog").On("accepted", func() {
|
||||
/*window2.ObjectByName("textClrDialog").On("accepted", func() {
|
||||
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.OrderLen)
|
||||
qml.Changed(qv, qv.ImgLen)
|
||||
qml.Changed(qv, qv.FontLen)
|
||||
}
|
||||
}*/
|
||||
|
||||
//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)
|
||||
@ -106,64 +145,45 @@ func (cl *cell) setSignal() {
|
||||
|
||||
//setSignals() for non dynamic elements
|
||||
func setSignals() {
|
||||
window.ObjectByName("imgpicker").On("accepted", func() {
|
||||
MainWindow.ObjectByName("imgpicker").On("accepted", func() {
|
||||
//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
|
||||
slides[rhtClkCell].img.Clear()
|
||||
slides[rhtClkCell].img.ReadImage(url)
|
||||
setupScene()
|
||||
//update image preview
|
||||
slides[rhtClkCell].clearcache()
|
||||
slides[rightClickCell].image.img.Clear()
|
||||
slides[rightClickCell].image.img.ReadImage(url)
|
||||
})
|
||||
|
||||
window.ObjectByName("btnAdd").On("clicked", func() {
|
||||
slides.add()
|
||||
MainWindow.ObjectByName("btnAdd").On("clicked", func() {
|
||||
slides.add("not")
|
||||
})
|
||||
|
||||
window.ObjectByName("btnRem").On("clicked", func() {
|
||||
slides[len(slides)-1].remove()
|
||||
MainWindow.ObjectByName("btnRem").On("clicked", func() {
|
||||
slides.remove(len(slides) - 1)
|
||||
})
|
||||
|
||||
window.ObjectByName("btnMem").On("clicked", func() {
|
||||
MainWindow.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()
|
||||
MainWindow.ObjectByName("mnuEdit").On("triggered", func() {
|
||||
quickEdit = !quickEdit
|
||||
})
|
||||
|
||||
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
|
||||
var (
|
||||
str string
|
||||
cel *cell
|
||||
str string
|
||||
cell *Cell
|
||||
)
|
||||
|
||||
if !focus {
|
||||
//set text back to the cell
|
||||
str = textEdit.ObjectByName("textEdit1").String("text")
|
||||
cel = slides[textEdit.Int("cell")]
|
||||
cell = slides[textEdit.Int("cell")]
|
||||
if textEdit.Bool("txt") {
|
||||
cel.qmlcell.ObjectByName("cellText").Set("text", str)
|
||||
cel.text = str
|
||||
cell.qmlObject.ObjectByName("cellText").Set("text", str)
|
||||
cell.text = str
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -176,26 +196,27 @@ func edtQmlShow() {
|
||||
|
||||
//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])
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
//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")
|
||||
func (cl *Cell) clearcache() {
|
||||
str := cl.image.qmlImage.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)
|
||||
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.Controls 1.3
|
||||
import QtQuick.Window 2.0
|
||||
import "qml"
|
||||
//import "qml"
|
||||
import QtQuick.Layouts 1.0
|
||||
|
||||
ApplicationWindow {
|
||||
@ -14,15 +14,6 @@ ApplicationWindow {
|
||||
minimumHeight: 500
|
||||
width: 1000
|
||||
height: 600
|
||||
property bool cls: false
|
||||
|
||||
|
||||
/*function getFileDialogUrl() {
|
||||
return
|
||||
}*/
|
||||
/*onClosing: if (!cls) {
|
||||
close.accepted = false
|
||||
}*/
|
||||
|
||||
FileDialog {
|
||||
id: imgpicker
|
||||
@ -32,10 +23,6 @@ ApplicationWindow {
|
||||
objectName: "imgpicker"
|
||||
}
|
||||
|
||||
AboutDialog {
|
||||
id: aboutDialog
|
||||
}
|
||||
|
||||
Action {
|
||||
id: aboutAction
|
||||
text: "About"
|
||||
@ -125,7 +112,7 @@ ApplicationWindow {
|
||||
id: gridData
|
||||
objectName: "gridData"
|
||||
width: scview.width - 1
|
||||
height: data1.childrenRect.height//gridRect.count * 101
|
||||
height: data1.childrenRect.height //gridRect.count * 101
|
||||
|
||||
Rectangle {
|
||||
id: col1
|
||||
@ -147,7 +134,8 @@ ApplicationWindow {
|
||||
visible: false
|
||||
property bool txt: true
|
||||
Keys.onPressed: {
|
||||
if ((event.key == Qt.Key_Return) && (event.modifiers & Qt.ControlModifier)) {
|
||||
if ((event.key == Qt.Key_Return)
|
||||
&& (event.modifiers & Qt.ControlModifier)) {
|
||||
txt = true
|
||||
|
||||
x = -100
|
||||
@ -194,7 +182,6 @@ ApplicationWindow {
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
height: data1.childrenRect.height
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +221,7 @@ ApplicationWindow {
|
||||
objectName: "btnAdd"
|
||||
x: 8
|
||||
y: 8
|
||||
text: qsTr("Button") +data1.childrenRect.height
|
||||
text: qsTr("Button") + data1.childrenRect.height
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
}*/
|
||||
}
|
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