From ba3ed7375ba9732fb8460ec821958242f7c0e2f5 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Fri, 18 Mar 2016 10:21:14 -0700 Subject: [PATCH] allow change of image via rightclick. not finished --- main.go | 51 ++++++++++++++++++++++++++++++++------------------- main.qml | 22 ++++++++++++++++++++++ qml/cell.qml | 3 +-- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index 79a9188..41c5a07 100644 --- a/main.go +++ b/main.go @@ -26,19 +26,19 @@ type cell struct { type slide []*cell var ( - x0, y0, selSlide int - path string - qimg qml.Object - textEdit qml.Object - cellQml qml.Object - window *qml.Window - win *glfw.Window - slides slide - err error - monitors []*glfw.Monitor - projMonitor *glfw.Monitor - tex1 uint32 - texDel = false + x0, y0, selSlide, rhtClkCell int + path string + qimg qml.Object + textEdit qml.Object + cellQml qml.Object + window *qml.Window + win *glfw.Window + slides slide + err error + monitors []*glfw.Monitor + projMonitor *glfw.Monitor + tex1 uint32 + texDel = false ) func main() { @@ -244,8 +244,10 @@ func setSignals() { }) window.On("closing", func() { - win.SetShouldClose(true) - window.Set("cls", true) + if false == window.Property("cls") { + win.SetShouldClose(true) + window.Set("cls", true) + } }) @@ -301,10 +303,21 @@ func (cl *cell) setSignal() { } }) - cl.qmlcell.ObjectByName("cellMouse").On("Clicked", func() { - cl.qmlcell.ObjectByName("cellMouse").Set("focus", true) - cl.qmlcell.ObjectByName("cellMouse").Call("selected") - }) + window.ObjectByName("mnuImgPick").On("triggered", func() { + url := window.Call("openFileDialog") + slides[rhtClkCell].img.Clear + slides[rhtClkCell].img.ReadImage(url) + }) + + cl.qmlcell.ObjectByName("cellMouse").On("clicked", func(mouse qml.Object) { + if mouse.Property("button") == 2 { + window.ObjectByName("mnuCtx").Call("popup") + rhtell = cl.index + } else { + cl.qmlcell.ObjectByName("cellMouse").Set("focus", true) + cl.qmlcell.ObjectByName("cellMouse").Call("selected") + } + }) cl.qmlcell.ObjectByName("cellMouse").On("doubleClicked", func() { diff --git a/main.qml b/main.qml index b6ccaeb..8acec80 100644 --- a/main.qml +++ b/main.qml @@ -16,10 +16,21 @@ ApplicationWindow { height: 600 property bool cls: false + function openFileDialog() { + imgpicker.open() + return imgpicker.fileUrl + } + onClosing: if (!cls) { close.accepted = false } + FileDialog { + id: imgpicker + title: "Choose an image for this slide" + folder: shortcuts.pictures + } + AboutDialog { id: aboutDialog } @@ -48,6 +59,17 @@ ApplicationWindow { } } + + Menu { + objectName: "mnuCtx" + title: "new image..." + MenuItem { + objectName: "mnuImgPick" + text: "new Image..." + } + } + + SplitView { id: mainSlider objectName: "mainSlider" diff --git a/qml/cell.qml b/qml/cell.qml index 1e19232..062f01d 100644 --- a/qml/cell.qml +++ b/qml/cell.qml @@ -28,6 +28,7 @@ Rectangle { enabled: true objectName: "cellMouse" anchors.fill: parent + acceptedButtons: Qt.AllButtons onMouseXChanged: if (containsMouse) { parent.parent.border.color = "skyblue" @@ -44,13 +45,11 @@ Rectangle { parent.parent.border.color = "black" parent.parent.color = "white" parent.color = "black" - MouseXChanged(mouse) } function selected() { parent.parent.border.color = "blue" parent.parent.color = "gainsboro" - MouseXChanged(mouse) } } }