diff --git a/glfw.go b/glfw.go index eb579e8..65d02a5 100644 --- a/glfw.go +++ b/glfw.go @@ -109,7 +109,7 @@ func checkMon() { 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) + fmt.Printf("Width: %d Height: %d \n", monWidth, monHeight) if err != nil { panic(err) } diff --git a/main.go b/main.go index dbf7b1c..906e16b 100644 --- a/main.go +++ b/main.go @@ -6,8 +6,8 @@ import ( "os" "path/filepath" - "github.com/kardianos/osext" "github.com/go-gl/glfw/v3.1/glfw" + "github.com/kardianos/osext" "github.com/lordwelch/qml" "gopkg.in/gographics/imagick.v2/imagick" ) @@ -36,9 +36,9 @@ func main() { fmt.Fprintf(os.Stderr, "error: %v\n", err) os.Exit(1) } - win.Destroy() - glfw.PollEvents() - glfw.Terminate() + win.Destroy() + glfw.PollEvents() + glfw.Terminate() } @@ -109,7 +109,6 @@ func (sl *slide) add( /*cl *cell*/ ) { //keep the pointer/dereference (i'm not sure which it is) //problems occur otherwise *sl = append(*sl, &cl) - cl.setSignal() //seperate image object in QML cl.qmlimg = qimg.Create(nil) @@ -117,6 +116,7 @@ func (sl *slide) add( /*cl *cell*/ ) { 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() } diff --git a/qml.go b/qml.go index c0bf74f..aa0982d 100644 --- a/qml.go +++ b/qml.go @@ -43,6 +43,23 @@ func (cl *cell) setSignal() { cl.clearcache() }) + cl.qmlimg.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) { + btn := musEvent.Property("button") + //right click + if btn == 2 { + //context menu + window.ObjectByName("mnuCtx").Call("popup") + rhtClkCell = 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() + } + //update image preview + cl.clearcache() + }) cl.qmlcell.ObjectByName("cellMouse").On("focusChanged", func(focus bool) { if focus { cl.qmlcell.ObjectByName("cellMouse").Call("selected") @@ -107,7 +124,10 @@ func setSignals() { }) window.ObjectByName("mnuDisplay").On("triggered", func() { - qml.RunMain(glInit) + win.SetShouldClose(false) + window.Set("cls", false) + win.Show() + qml.ResetGLFW() }) window.ObjectByName("mnuEdit").On("triggered", func() { diff --git a/qml/img.qml b/qml/img.qml index 7a52a4e..1614a19 100644 --- a/qml/img.qml +++ b/qml/img.qml @@ -12,4 +12,12 @@ Image { 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 + } }