From 73e66bad2670c67403f9470835884a3069e97ce6 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sat, 23 Aug 2014 21:48:24 +1200 Subject: [PATCH 01/25] Added new exit dialog. --- buttleofx/MainWindow.qml | 35 +++-------- buttleofx/gui/dialogs/ExitDialog.qml | 90 ++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 27 deletions(-) create mode 100644 buttleofx/gui/dialogs/ExitDialog.qml diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index df988b6d..e0af916d 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -1,10 +1,10 @@ -import QtQuick 2.0 -import QtQuick.Controls 1.0 -import QtQuick.Layouts 1.0 import QtQml 2.1 +import QtQuick 2.0 import QuickMamba 1.0 -import QtQuick.Dialogs 1.1 import QtQuick.Window 2.1 +import QtQuick.Dialogs 1.1 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 import QtQuick.LocalStorage 2.0 import "gui/graph/qml" @@ -13,6 +13,7 @@ import "gui/paramEditor/qml" import "gui/browser/qml" import "gui/plugin/qml" import "gui/shortcut/qml" +import "gui/dialogs" ApplicationWindow { property var settingsDatabase: getInitializedDatabase() @@ -65,7 +66,7 @@ ApplicationWindow { property variant view3: [player, browser, advancedParamEditor, graphEditor] property string urlOfFileToSave: _buttleData.urlOfFileToSave - + width: 1200 height: 800 id: mainWindowQML @@ -209,28 +210,8 @@ ApplicationWindow { } } - MessageDialog { + ExitDialog { id: closeButtle - title: "Save the graph?" - icon: StandardIcon.Warning - modality: Qt.WindowStaysOnTopHint && Qt.WindowModal - text: urlOfFileToSave == "" ? "Save graph changes before closing ?" : "Save " + _buttleData.getFileName(urlOfFileToSave) + " changes before closing ?" - detailedText: "If you don't save the graph, unsaved modifications will be lost. " - standardButtons: StandardButton.Yes | StandardButton.No | StandardButton.Abort - Component.onCompleted: visible = false - - onYes: { - if(urlOfFileToSave!="") { - _buttleData.saveData(urlOfFileToSave) - } else { - finderSaveGraph.open() - finderSaveGraph.close() - finderSaveGraph.open() - } - } - onNo: { - Qt.quit() - } } menuBar: MenuBar { @@ -288,7 +269,7 @@ ApplicationWindow { if (!_buttleData.graphCanBeSaved) { Qt.quit() } else { - closeButtle.open() + closeButtle.visible = true } } } diff --git a/buttleofx/gui/dialogs/ExitDialog.qml b/buttleofx/gui/dialogs/ExitDialog.qml new file mode 100644 index 00000000..9bfa68c0 --- /dev/null +++ b/buttleofx/gui/dialogs/ExitDialog.qml @@ -0,0 +1,90 @@ +import QtQuick 2.1 +import QtQuick.Window 2.1 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 +import QtQuick.Controls.Styles 1.0 + +Window { + id: exitDialog + width: 425 + height: 100 + title: "Save Changes?" + color: "#141414" + flags: Qt.Dialog + modality: Qt.WindowModal + visible: false + + Component { + id: buttonStyle + + ButtonStyle { + background: Rectangle { + radius: 6 + implicitWidth: 100 + implicitHeight: 25 + + border.color: control.hovered ? "#00B2A1" : "#9F9C99" + border.width: control.hovered ? 3 : 2 + + gradient: Gradient { + GradientStop { position: 0; color: control.pressed ? "#EFEBE7" : "#EFEBE7" } + GradientStop { position: .5; color: control.pressed ? "#D9D9D9" : "#EFEBE7" } + GradientStop { position: 0; color: control.pressed ? "#EFEBE7" : "#EFEBE7" } + } + } + } + } + + ColumnLayout { + anchors.centerIn: parent + spacing: 15 + + RowLayout { + spacing: 20 + + Image { + source: "/home/james/git/ButtleOFX/buttleofx/gui/img/icons/logo_icon.png" + } + + Text { + text: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost" + color: "#FEFEFE" + } + } + + RowLayout { + anchors.horizontalCenter: parent.horizontalCenter + spacing: 6 + + Button { + id: saveButton + text: "Save" + style: buttonStyle + + onClicked: { + if (urlOfFileToSave != "") { + _buttleData.saveData(urlOfFileToSave) + } else { + finderSaveGraph.open() + finderSaveGraph.close() + finderSaveGraph.open() + } + } + } + + Button { + id: discardButton + text: "Discard" + style: buttonStyle + onClicked: Qt.quit() + } + + Button { + id: abortButton + text: "Abort" + style: buttonStyle + onClicked: exitDialog.visible = false + } + } + } +} From b4edbc8d967ce5f6fd51dc30ace3bbbabf5db4ab Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sun, 24 Aug 2014 15:35:41 +1200 Subject: [PATCH 02/25] Some code cleanups. --- buttleofx/MainWindow.qml | 64 +++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index e0af916d..a8e3878d 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -66,7 +66,7 @@ ApplicationWindow { property variant view3: [player, browser, advancedParamEditor, graphEditor] property string urlOfFileToSave: _buttleData.urlOfFileToSave - + width: 1200 height: 800 id: mainWindowQML @@ -83,7 +83,6 @@ ApplicationWindow { player.changeViewer(1) } if ((event.key == Qt.Key_2) && (event.modifiers & Qt.KeypadModifier)) { - player.changeViewer(2) } if ((event.key == Qt.Key_3) && (event.modifiers & Qt.KeypadModifier)) { @@ -282,7 +281,7 @@ ApplicationWindow { id: undoRedoStack title: "Undo/Redo stack" - property variant undoRedoList:_buttleData.graphCanBeSaved ? _buttleManager.undoRedoStack:_buttleManager.undoRedoStack + property variant undoRedoList: _buttleData.graphCanBeSaved ? _buttleManager.undoRedoStack:_buttleManager.undoRedoStack Instantiator { model: undoRedoStack.undoRedoList @@ -394,9 +393,10 @@ ApplicationWindow { Instantiator { model: _buttleData.getMenu(1,"") + Menu { id: firstMenu - title:object + title: object __parentContentItem: nodesMenu.__contentItem // To remove warning Instantiator { @@ -426,11 +426,11 @@ ApplicationWindow { } Instantiator { - model: _buttleData.getMenu(2,firstMenu.title) + model: _buttleData.getMenu(2, firstMenu.title) Menu { id: secondMenu - title:object + title: object __parentContentItem: nodesMenu.__contentItem // To remove warning Instantiator { @@ -460,11 +460,11 @@ ApplicationWindow { } Instantiator { - model: _buttleData.getMenu(3,secondMenu.title) + model: _buttleData.getMenu(3, secondMenu.title) Menu { id: thirdMenu - title:object + title: object __parentContentItem: nodesMenu.__contentItem // To remove warning Instantiator { @@ -494,10 +494,10 @@ ApplicationWindow { } Instantiator { - model: _buttleData.getMenu(4,thirdMenu.title) + model: _buttleData.getMenu(4, thirdMenu.title) Menu { - id:fourthMenu + id: fourthMenu title: object __parentContentItem: nodesMenu.__contentItem // To remove warning @@ -528,7 +528,7 @@ ApplicationWindow { } Instantiator { - model: _buttleData.getMenu(5,fourthMenu.title) + model: _buttleData.getMenu(5, fourthMenu.title) Menu { id: fifthMenu @@ -601,7 +601,6 @@ ApplicationWindow { } } - Menu { title: "View" @@ -616,7 +615,7 @@ ApplicationWindow { browserView.checked = false advancedView.checked = false selectedView = 1 - saveSetting("view",selectedView) + saveSetting("view", selectedView) lastSelectedDefaultView = view1 topLeftView.visible = true bottomLeftView.visible = true @@ -637,7 +636,7 @@ ApplicationWindow { defaultView.checked = false advancedView.checked = false selectedView = 2 - saveSetting("view",selectedView) + saveSetting("view", selectedView) lastSelectedDefaultView = view2 topLeftView.visible = true bottomLeftView.visible = true @@ -658,9 +657,9 @@ ApplicationWindow { defaultView.checked = false browserView.checked = false selectedView = 3 - saveSetting("view",selectedView) + saveSetting("view", selectedView) lastSelectedDefaultView = view3 - topLeftView.visible=true + topLeftView.visible = true bottomLeftView.visible = true topRightView.visible = true bottomRightView.visible = false @@ -674,29 +673,29 @@ ApplicationWindow { MenuItem { text: "Browser" checkable: true - checked: browser.parent.visible==true ? true : false - onTriggered: browser.parent.visible == false ? browser.parent.visible=true : browser.parent.visible=false + checked: browser.parent.visible == true ? true : false + onTriggered: browser.parent.visible == false ? browser.parent.visible = true : browser.parent.visible = false } MenuItem { text: "Viewer" checkable: true checked: player.parent.visible==true ? true : false - onTriggered: player.parent.visible == false ? player.parent.visible=true : player.parent.visible=false + onTriggered: player.parent.visible == false ? player.parent.visible = true : player.parent.visible = false } MenuItem { text: "Graph" checkable: true checked: graphEditor.parent.visible==true ? true : false - onTriggered: graphEditor.parent.visible == false ? graphEditor.parent.visible=true : graphEditor.parent.visible=false + onTriggered: graphEditor.parent.visible == false ? graphEditor.parent.visible = true : graphEditor.parent.visible = false } MenuItem { text: "Parameters" checkable: true checked: paramEditor.parent.visible==true ? true : false - onTriggered: paramEditor.parent.visible == false ? paramEditor.parent.visible=true : paramEditor.parent.visible=false + onTriggered: paramEditor.parent.visible == false ? paramEditor.parent.visible = true : paramEditor.parent.visible = false } */ } @@ -713,7 +712,6 @@ ApplicationWindow { } */ - // This rectangle represents the zone under the menu, it allows to define the anchors.fill and margins for the SplitterRow Rectangle { id: modulsContainer @@ -777,7 +775,7 @@ ApplicationWindow { view2[1] break case 3: - if(advancedParamEditor.displayGraph) + if (advancedParamEditor.displayGraph) view3[3] else view3[1] @@ -831,7 +829,7 @@ ApplicationWindow { implicitWidth: parent.width implicitHeight: topRightView.visible ? 0.5 * parent.height : parent.height z: -1 - visible: selectedView ==3 ? false : true + visible: selectedView == 3 ? false : true children: switch (selectedView) { @@ -857,7 +855,7 @@ ApplicationWindow { id: subviews visible: false - property variant parentBeforeFullscreen : null + property variant parentBeforeFullscreen: null Player { id: player @@ -874,7 +872,7 @@ ApplicationWindow { } } onButtonFullscreenClicked: - if (parent != fullscreenContent){ + if (parent != fullscreenContent) { subviews.parentBeforeFullscreen = parent fullscreenWindow.visibility = Window.FullScreen fullscreenContent.children = player @@ -886,8 +884,8 @@ ApplicationWindow { anchors.fill: parent onButtonCloseClicked: { - if (parent!=fullscreenContent) { - selectedView=-1 + if (parent != fullscreenContent) { + selectedView = -1 parent.visible = false } else { fullscreenWindow.visibility = Window.Hidden @@ -895,7 +893,7 @@ ApplicationWindow { } } onButtonFullscreenClicked: - if (parent != fullscreenContent){ + if (parent != fullscreenContent) { subviews.parentBeforeFullscreen = parent fullscreenWindow.visibility = Window.FullScreen fullscreenContent.children = graphEditor @@ -909,7 +907,7 @@ ApplicationWindow { currentParamNode: _buttleData.currentParamNodeWrapper ? _buttleData.currentParamNodeWrapper : null onButtonCloseClicked: { - if (parent!=fullscreenContent) { + if (parent != fullscreenContent) { selectedView =- 1 parent.visible = false } else { @@ -918,7 +916,7 @@ ApplicationWindow { } } onButtonFullscreenClicked: - if (parent != fullscreenContent){ + if (parent != fullscreenContent) { subviews.parentBeforeFullscreen = parent fullscreenWindow.visibility = Window.FullScreen fullscreenContent.children = paramEditor @@ -939,7 +937,7 @@ ApplicationWindow { } } onButtonFullscreenClicked: - if (parent != fullscreenContent){ + if (parent != fullscreenContent) { subviews.parentBeforeFullscreen = parent fullscreenWindow.visibility = Window.FullScreen fullscreenContent.children = advancedParamEditor @@ -960,7 +958,7 @@ ApplicationWindow { } } onButtonFullscreenClicked: - if (parent != fullscreenContent){ + if (parent != fullscreenContent) { subviews.parentBeforeFullscreen = parent fullscreenWindow.visibility = Window.FullScreen fullscreenContent.children = browser From 0089ca5c2137fac5947904aab63855f4e0f85c10 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sun, 31 Aug 2014 22:51:00 +1200 Subject: [PATCH 03/25] Moar cleanups. --- buttleofx/MainWindow.qml | 55 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index a8e3878d..ca4625d2 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -70,14 +70,13 @@ ApplicationWindow { width: 1200 height: 800 id: mainWindowQML - title:"ButtleOFX" + title: "ButtleOFX" // TopFocusHandler { // anchors.fill: parent // } Keys.onPressed: { - // Viewer if ((event.key == Qt.Key_1) && (event.modifiers & Qt.KeypadModifier)) { player.changeViewer(1) @@ -117,7 +116,7 @@ ApplicationWindow { } } - property bool aNodeIsSelected:true + property bool aNodeIsSelected: true // Window of hint for plugins PluginWindow { @@ -150,7 +149,7 @@ ApplicationWindow { FileDialog { id: finderSaveGraph title: "Save the graph" - nameFilters: [ "All files (*)" ] + nameFilters: [ "All files (*)" ] selectedNameFilter: "All files (*)" onAccepted: { @@ -167,15 +166,15 @@ ApplicationWindow { title:"Save the graph?" icon: StandardIcon.Warning modality: Qt.WindowStaysOnTopHint && Qt.WindowModal - text: urlOfFileToSave == "" ? "Save graph changes before closing ?" : "Save " + _buttleData.getFileName(urlOfFileToSave) + " changes before closing ?" - detailedText: "If you don't save the graph, unsaved modifications will be lost. " + text: urlOfFileToSave == "" ? "Save graph changes before closing?" : "Save " + _buttleData.getFileName(urlOfFileToSave) + " changes before closing?" + detailedText: "If you don't save the graph, unsaved modifications will be lost." standardButtons: StandardButton.Yes | StandardButton.No | StandardButton.Abort Component.onCompleted: visible = false onYes: { - if(urlOfFileToSave!="") { + if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) - } else{ + } else { finderSaveGraph.open() } } @@ -190,13 +189,13 @@ ApplicationWindow { title: "Save the graph?" icon: StandardIcon.Warning modality: Qt.WindowStaysOnTopHint && Qt.WindowModal - text: urlOfFileToSave == "" ? "Save graph changes before closing ?" : "Save " + _buttleData.getFileName(urlOfFileToSave) + " changes before closing ?" - detailedText: "If you don't save the graph, unsaved modifications will be lost. " + text: urlOfFileToSave == "" ? "Save graph changes before closing?" : "Save " + _buttleData.getFileName(urlOfFileToSave) + " changes before closing?" + detailedText: "If you don't save the graph, unsaved modifications will be lost." standardButtons: StandardButton.Yes | StandardButton.No | StandardButton.Abort Component.onCompleted: visible = false onYes: { - if (urlOfFileToSave!="") { + if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) _buttleData.newData() } else { @@ -281,7 +280,7 @@ ApplicationWindow { id: undoRedoStack title: "Undo/Redo stack" - property variant undoRedoList: _buttleData.graphCanBeSaved ? _buttleManager.undoRedoStack:_buttleManager.undoRedoStack + property variant undoRedoList: _buttleData.graphCanBeSaved ? _buttleManager.undoRedoStack : _buttleManager.undoRedoStack Instantiator { model: undoRedoStack.undoRedoList @@ -392,7 +391,7 @@ ApplicationWindow { title: "Nodes" Instantiator { - model: _buttleData.getMenu(1,"") + model: _buttleData.getMenu(1, "") Menu { id: firstMenu @@ -673,29 +672,41 @@ ApplicationWindow { MenuItem { text: "Browser" checkable: true - checked: browser.parent.visible == true ? true : false - onTriggered: browser.parent.visible == false ? browser.parent.visible = true : browser.parent.visible = false + checked: browser.parent.visible + + onTriggered: { + browser.parent.visible = !browser.parent.visible + } } MenuItem { text: "Viewer" checkable: true - checked: player.parent.visible==true ? true : false - onTriggered: player.parent.visible == false ? player.parent.visible = true : player.parent.visible = false + checked: player.parent.visible + + onTriggered: { + player.parent.visible = !player.parent.visible + } } MenuItem { text: "Graph" checkable: true - checked: graphEditor.parent.visible==true ? true : false - onTriggered: graphEditor.parent.visible == false ? graphEditor.parent.visible = true : graphEditor.parent.visible = false + checked: graphEditor.parent.visible + + onTriggered: { + graphEditor.parent.visible = !graphEditor.parent.visible + } } MenuItem { text: "Parameters" checkable: true - checked: paramEditor.parent.visible==true ? true : false - onTriggered: paramEditor.parent.visible == false ? paramEditor.parent.visible = true : paramEditor.parent.visible = false + checked: paramEditor.parent.visible + + onTriggered: { + paramEditor.parent.visible = !paramEditor.parent.visible + } } */ } @@ -829,7 +840,7 @@ ApplicationWindow { implicitWidth: parent.width implicitHeight: topRightView.visible ? 0.5 * parent.height : parent.height z: -1 - visible: selectedView == 3 ? false : true + visible: !selectedView children: switch (selectedView) { From 1c044a2525232a6352bb2c2e92acfaab174a3551 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Wed, 3 Sep 2014 21:43:10 +1200 Subject: [PATCH 04/25] Initial commit for a new file viewer dialog, not properly hooked up yet because it's completely non-functional. Changed the exit dialog to use signals instead of global variables and switched to using relative paths for the ButtleOFX logo. --- buttleofx/MainWindow.qml | 14 ++ buttleofx/gui/dialogs/ExitDialog.qml | 18 +-- buttleofx/gui/dialogs/FileViewerDialog.qml | 173 +++++++++++++++++++++ 3 files changed, 195 insertions(+), 10 deletions(-) create mode 100644 buttleofx/gui/dialogs/FileViewerDialog.qml diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index ca4625d2..7605c111 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -210,6 +210,20 @@ ApplicationWindow { ExitDialog { id: closeButtle + + onSaveButtonClicked: { + if (urlOfFileToSave != "") { + _buttleData.saveData(urlOfFileToSave) + } else { + closeButtle.visible = false + finderSaveGraph.open() +// finderSaveGraph.close() +// finderSaveGraph.open() + } +// Qt.quit() + } + onDiscardButtonClicked: Qt.quit() + onAbortButtonClicked: closeButtle.visible = false } menuBar: MenuBar { diff --git a/buttleofx/gui/dialogs/ExitDialog.qml b/buttleofx/gui/dialogs/ExitDialog.qml index 9bfa68c0..74bfe3fe 100644 --- a/buttleofx/gui/dialogs/ExitDialog.qml +++ b/buttleofx/gui/dialogs/ExitDialog.qml @@ -14,6 +14,10 @@ Window { modality: Qt.WindowModal visible: false + signal saveButtonClicked + signal discardButtonClicked + signal abortButtonClicked + Component { id: buttonStyle @@ -43,7 +47,7 @@ Window { spacing: 20 Image { - source: "/home/james/git/ButtleOFX/buttleofx/gui/img/icons/logo_icon.png" + source: "../img/icons/logo_icon.png" } Text { @@ -62,13 +66,7 @@ Window { style: buttonStyle onClicked: { - if (urlOfFileToSave != "") { - _buttleData.saveData(urlOfFileToSave) - } else { - finderSaveGraph.open() - finderSaveGraph.close() - finderSaveGraph.open() - } + exitDialog.saveButtonClicked() } } @@ -76,14 +74,14 @@ Window { id: discardButton text: "Discard" style: buttonStyle - onClicked: Qt.quit() + onClicked: exitDialog.discardButtonClicked() } Button { id: abortButton text: "Abort" style: buttonStyle - onClicked: exitDialog.visible = false + onClicked: exitDialog.abortButtonClicked() } } } diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml new file mode 100644 index 00000000..fdbee7d9 --- /dev/null +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -0,0 +1,173 @@ +import QtQuick 2.1 +import QtQuick.Window 2.1 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 +import QtQuick.Controls.Styles 1.0 +import Qt.labs.folderlistmodel 2.1 + +Window { + id: mainWindow + width: 630 + height: 380 + flags: Qt.Dialog + color: "#141414" + + FolderListModel { + id: folderModel + showDirsFirst: true + folder: "/home/james/" + } + + ColumnLayout { + anchors.fill: parent + anchors.margins: 4 + + RowLayout { + id: headerBar + anchors.top: parent.top + anchors.leftMargin: parent.spacing + anchors.rightMargin: parent.spacing + + Button { + id: parentFolderButton + width: 15 + height: 15 + + iconSource: + if (hovered) { + "../img/buttons/browser/parent_hover.png" + } else { + "../img/buttons/browser/parent.png" + } + + style: + ButtonStyle { + background: Rectangle { + anchors.fill: parent + color: "transparent" + } + } + + onClicked: { folderModel.folder = folderModel.parentFolder } + } + + Rectangle { + Layout.fillWidth: true + height: 24 + color: "black" + radius: 5 + border.color: "grey" + + TextInput { + x: 5 + y: 4 + + readOnly: true + selectByMouse: true + Layout.fillWidth: true + + color: "white" + text: folderModel.folder + selectionColor: "#00b2a1" + } + } + } + + ScrollView { + anchors.top: headerBar.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: bottomRow.top + anchors.bottomMargin: 4 + + GridView { + id: folderView + model: folderModel + cellWidth: 100 + cellHeight: 100 + highlightFollowsCurrentItem: false + + highlight: Rectangle { + width: folderView.cellWidth + height: folderView.cellHeight + color: "#00b2a1" + radius: 4 + + x: folderView.currentItem.x + y: folderView.currentItem.y + Behavior on x { SmoothedAnimation { duration: -1; velocity: -1 } } + Behavior on y { SmoothedAnimation { duration: -1; velocity: -1 } } + } + + delegate: Rectangle { + width: folderView.cellWidth + height: folderView.cellHeight + color: "transparent" + + Column { + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + + Image { + anchors.horizontalCenter: parent.horizontalCenter + width: 55 + height: 55 + source: folderModel.isFolder(index) ? "../img/buttons/browser/folder-icon.png" : "../img/buttons/browser/file-icon.png" + } + Text { + width: folderView.cellWidth - 10 + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WrapAnywhere + text: fileName + color: "white" + } + } + + MouseArea { + anchors.fill: parent + onClicked: folderView.currentIndex = index + + onDoubleClicked: { + if (folderModel.isFolder(index)) { + folderModel.folder = folderModel.get(index, "filePath") + } + } + } + } + } + } + + RowLayout { + id: bottomRow + Layout.fillWidth: true + Layout.fillHeight: true + anchors.bottom: parent.bottom + + TextField { + Layout.fillWidth: true + } + + Button { + text: "Save" + + style: + ButtonStyle { + background: Rectangle { + radius: 6 + implicitWidth: 100 + implicitHeight: 25 + + border.color: control.hovered ? "#00B2A1" : "#9F9C99" + border.width: control.hovered ? 3 : 2 + + gradient: Gradient { + GradientStop { position: 0; color: control.pressed ? "#EFEBE7" : "#EFEBE7" } + GradientStop { position: .5; color: control.pressed ? "#D9D9D9" : "#EFEBE7" } + GradientStop { position: 0; color: control.pressed ? "#EFEBE7" : "#EFEBE7" } + } + } + } + } + } + } +} From 83e5d21c50e84f74f94b0fc9e41358660e75529d Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Wed, 3 Sep 2014 22:59:50 +1200 Subject: [PATCH 05/25] Added support for image previews (when possible). --- buttleofx/gui/dialogs/FileViewerDialog.qml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index fdbee7d9..da037e06 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -112,7 +112,21 @@ Window { anchors.horizontalCenter: parent.horizontalCenter width: 55 height: 55 - source: folderModel.isFolder(index) ? "../img/buttons/browser/folder-icon.png" : "../img/buttons/browser/file-icon.png" + asynchronous: true + fillMode: Image.PreserveAspectFit + sourceSize.width: width + sourceSize.height: height + property variant supportedFormats: ["bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm"] + + source: { + if (folderModel.isFolder(index)) { + "../img/buttons/browser/folder-icon.png" + } else if (supportedFormats.indexOf(folderModel.get(index, "fileSuffix").toLowerCase()) != -1) { + folderModel.get(index, "filePath") + } else { + "../img/buttons/browser/file-icon.png" + } + } } Text { width: folderView.cellWidth - 10 From 97d2151cabf4ce5e615ff2be69275c7cb8267d7c Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Thu, 4 Sep 2014 10:29:28 +1200 Subject: [PATCH 06/25] Minor fix to remove the 'file://' prefix from the path bar. --- buttleofx/gui/dialogs/FileViewerDialog.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index da037e06..60173d46 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -67,7 +67,7 @@ Window { Layout.fillWidth: true color: "white" - text: folderModel.folder + text: folderModel.folder.toString().substring(7) selectionColor: "#00b2a1" } } From c789763a61dfa00e6a46a567061864e70d5f5d13 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Thu, 4 Sep 2014 22:13:53 +1200 Subject: [PATCH 07/25] Hooked up the new file dialog to open when saving a new graph. --- buttleofx/MainWindow.qml | 37 ++++++++++++++-------- buttleofx/gui/dialogs/FileViewerDialog.qml | 10 +++++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 7605c111..a393f6c8 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -146,19 +146,28 @@ ApplicationWindow { } } - FileDialog { + FileViewerDialog { id: finderSaveGraph title: "Save the graph" - nameFilters: [ "All files (*)" ] - selectedNameFilter: "All files (*)" + buttonText: "Save" + property bool quit: false - onAccepted: { - if (finderSaveGraph.fileUrl) { - _buttleData.saveData(finderSaveGraph.fileUrl) + onButtonClicked: { + if (finderSaveGraph.entryBarText != "") { + _buttleData.urlOfFileToSave = (finderSaveGraph.currentFolder + "/" + finderSaveGraph.entryBarText).substring(7) + + if (_buttleData.urlOfFileToSave.substr(-5) != ".bofx") { + _buttleData.urlOfFileToSave += ".bofx" + } + + _buttleData.saveData(_buttleData.urlOfFileToSave) + finderSaveGraph.visible = false + + if (quit) { + Qt.quit() + } } } - - selectExisting: false } MessageDialog { @@ -175,7 +184,8 @@ ApplicationWindow { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - finderSaveGraph.open() + finderSaveGraph.quit = false + finderSaveGraph.visible = true } } onNo: { @@ -199,7 +209,8 @@ ApplicationWindow { _buttleData.saveData(urlOfFileToSave) _buttleData.newData() } else { - finderSaveGraph.open() + finderSaveGraph.quit = false + finderSaveGraph.visible = true _buttleData.newData() } } @@ -216,11 +227,9 @@ ApplicationWindow { _buttleData.saveData(urlOfFileToSave) } else { closeButtle.visible = false - finderSaveGraph.open() -// finderSaveGraph.close() -// finderSaveGraph.open() + finderSaveGraph.quit = true + finderSaveGraph.visible = true } -// Qt.quit() } onDiscardButtonClicked: Qt.quit() onAbortButtonClicked: closeButtle.visible = false diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index 60173d46..a1b4ab38 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -11,6 +11,12 @@ Window { height: 380 flags: Qt.Dialog color: "#141414" + visible: false + property string buttonText: "" + property string currentFolder: folderModel.folder + property string entryBarText: entryBar.text + + signal buttonClicked FolderListModel { id: folderModel @@ -158,11 +164,12 @@ Window { anchors.bottom: parent.bottom TextField { + id: entryBar Layout.fillWidth: true } Button { - text: "Save" + text: buttonText style: ButtonStyle { @@ -181,6 +188,7 @@ Window { } } } + onClicked: mainWindow.buttonClicked() } } } From 8a7e56236f6e9095d5d048f8ad946129dfa7b614 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Thu, 4 Sep 2014 23:33:30 +1200 Subject: [PATCH 08/25] Fixed buttleData.saveData(), previously it would save in the current directory if a QUrl was passed to it. Also removed file extension checks elsewhere, since this is covered in saveData(). --- buttleofx/MainWindow.qml | 4 ---- buttleofx/data/buttleData.py | 6 +++--- buttleofx/main.py | 2 -- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index a393f6c8..838ceead 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -156,10 +156,6 @@ ApplicationWindow { if (finderSaveGraph.entryBarText != "") { _buttleData.urlOfFileToSave = (finderSaveGraph.currentFolder + "/" + finderSaveGraph.entryBarText).substring(7) - if (_buttleData.urlOfFileToSave.substr(-5) != ".bofx") { - _buttleData.urlOfFileToSave += ".bofx" - } - _buttleData.saveData(_buttleData.urlOfFileToSave) finderSaveGraph.visible = false diff --git a/buttleofx/data/buttleData.py b/buttleofx/data/buttleData.py index 1cb7af8d..2270c7fb 100644 --- a/buttleofx/data/buttleData.py +++ b/buttleofx/data/buttleData.py @@ -649,11 +649,11 @@ def saveData(self, url): """ Saves all data in a json file """ + # If called from Python, it could be a str or a QUrl if isinstance(url, str): - # If called from Python, it could be a str or a QUrl. - filepath = QtCore.QUrl.fromLocalFile(url).toLocalFile() + filepath = url else: - filepath = QtCore.QUrl(url).toLocalFile() + filepath = url.toString() if not filepath.lower().endswith(".bofx"): filepath = filepath + ".bofx" diff --git a/buttleofx/main.py b/buttleofx/main.py index 3748201b..2b79db96 100644 --- a/buttleofx/main.py +++ b/buttleofx/main.py @@ -109,8 +109,6 @@ def eventFilter(self, receiver, event): # This project has never been saved, so ask the user on which file to save. dialog = QtWidgets.QFileDialog() fileToSave = dialog.getSaveFileName(None, "Save the graph", browser.getFirstFolder())[0] - if not (fileToSave.endswith(".bofx")): - fileToSave += ".bofx" buttleData.urlOfFileToSave = fileToSave buttleData.saveData(fileToSave) # Close the application From 1b9ca13ced12e0c0182173bc3a02610b1d4c4658 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Fri, 5 Sep 2014 22:47:00 +1200 Subject: [PATCH 09/25] The QUrl stuff was messing things up. Note: with this change, we'll have to stick to passing in absolute paths to buttleData.loadData(). --- buttleofx/data/buttleData.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/buttleofx/data/buttleData.py b/buttleofx/data/buttleData.py index 2270c7fb..4547c103 100644 --- a/buttleofx/data/buttleData.py +++ b/buttleofx/data/buttleData.py @@ -524,12 +524,9 @@ def loadData(self, url='buttleofx/backup/data.bofx'): """ Loads all data from a Json file (the default Json file if no url is given) """ - - filepath = QtCore.QUrl(url).toLocalFile() - self.newData() - with open(filepath, 'r') as f: + with open(url, 'r') as f: read_data = f.read() decoded = json.loads(read_data, object_hook=_decode_dict) @@ -563,7 +560,7 @@ def loadData(self, url='buttleofx/backup/data.bofx'): f.closed - self.urlOfFileToSave = filepath + self.urlOfFileToSave = url @QtCore.pyqtSlot() def newData(self): From 30b3108cce516e0ca849ed20eb72ad2a768ca180 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Fri, 5 Sep 2014 22:48:35 +1200 Subject: [PATCH 10/25] The file dialog now displays the filename of the selected file in the text entry bar. --- buttleofx/gui/dialogs/FileViewerDialog.qml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index a1b4ab38..2cfff5bb 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -145,7 +145,14 @@ Window { MouseArea { anchors.fill: parent - onClicked: folderView.currentIndex = index + onClicked: { + folderView.currentIndex = index + if (!folderModel.isFolder(index)) { + entryBar.text = folderModel.get(index, "fileName") + } else { + entryBar.text = "" + } + } onDoubleClicked: { if (folderModel.isFolder(index)) { From bed97967c26ee4a47967de5466954e93ddb2db31 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Fri, 5 Sep 2014 22:50:50 +1200 Subject: [PATCH 11/25] Switched finderLoadGraph to be a FileViewerDialog. The whole open/save workflow is a bit buggy still, will need a bit more work. --- buttleofx/MainWindow.qml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 838ceead..cad0dc42 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -133,15 +133,15 @@ ApplicationWindow { title: "Shortcuts" } - FileDialog { + FileViewerDialog { id: finderLoadGraph title: "Open a graph" - nameFilters: [ "All files (*)" ] - selectedNameFilter: "All files (*)" + buttonText: "Open" - onAccepted: { - if (finderLoadGraph.fileUrl) { - _buttleData.loadData(finderLoadGraph.fileUrl) + onButtonClicked: { + if (finderLoadGraph.entryBarText != "") { + _buttleData.loadData((finderLoadGraph.currentFolder + "/" + finderLoadGraph.entryBarText).substring(7)) + finderLoadGraph.visible = false } } } @@ -185,7 +185,7 @@ ApplicationWindow { } } onNo: { - finderLoadGraph.open() + finderLoadGraph.visible = true } onRejected: {} } @@ -254,7 +254,7 @@ ApplicationWindow { onTriggered: { if (!_buttleData.graphCanBeSaved) { - finderLoadGraph.open() + finderLoadGraph.visible = true } else { openGraph.open() openGraph.close() @@ -273,7 +273,7 @@ ApplicationWindow { MenuItem { text: "Save As" shortcut: "Ctrl+Shift+S" - onTriggered: finderSaveGraph.open() + onTriggered: finderSaveGraph.visible = true } MenuSeparator { } From 6bca292266ceccc37655b6c5da41ab7ea002e13e Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sat, 6 Sep 2014 21:39:51 +1200 Subject: [PATCH 12/25] General improvements to the file dialog: It now opens at the users home dir first by means of the new _buttleData.homeDir property and FileViewerDialog.folderModelFolder property, replaced FileViewerDialog.currentFolder with FileViewerDialog.currentFile, and changed the way the URL bar text is assigned. --- buttleofx/MainWindow.qml | 8 +++++-- buttleofx/data/buttleData.py | 4 ++++ buttleofx/gui/dialogs/FileViewerDialog.qml | 28 +++++++++++++++------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index cad0dc42..04deedf9 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -135,12 +135,14 @@ ApplicationWindow { FileViewerDialog { id: finderLoadGraph + visible: false title: "Open a graph" buttonText: "Open" + folderModelFolder: _buttleData.homeDir onButtonClicked: { if (finderLoadGraph.entryBarText != "") { - _buttleData.loadData((finderLoadGraph.currentFolder + "/" + finderLoadGraph.entryBarText).substring(7)) + _buttleData.loadData(finderLoadGraph.currentFile) finderLoadGraph.visible = false } } @@ -148,13 +150,15 @@ ApplicationWindow { FileViewerDialog { id: finderSaveGraph + visible: false title: "Save the graph" buttonText: "Save" + folderModelFolder: _buttleData.homeDir property bool quit: false onButtonClicked: { if (finderSaveGraph.entryBarText != "") { - _buttleData.urlOfFileToSave = (finderSaveGraph.currentFolder + "/" + finderSaveGraph.entryBarText).substring(7) + _buttleData.urlOfFileToSave = finderSaveGraph.currentFile _buttleData.saveData(_buttleData.urlOfFileToSave) finderSaveGraph.visible = false diff --git a/buttleofx/data/buttleData.py b/buttleofx/data/buttleData.py index 4547c103..a11870e5 100644 --- a/buttleofx/data/buttleData.py +++ b/buttleofx/data/buttleData.py @@ -736,6 +736,9 @@ def zoom(self, width, height, nodeWidth, zoomCoeff, graphPreviousWidth, graphPre def getButtlePath(self): return self._buttlePath + def getHomeDir(self): + return os.path.expanduser("~") + def getCurrentConnectionWrapper(self): """ Returns the current currentConnectionWrapper. @@ -1036,6 +1039,7 @@ def graphCanBeSaved(self): # filePath buttlePath = QtCore.pyqtProperty(str, getButtlePath, constant=True) + homeDir = QtCore.pyqtProperty(str, getHomeDir, constant=True) # Current param, view, and selected node currentParamNodeChanged = QtCore.pyqtSignal() diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index 2cfff5bb..d29af0f3 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -6,22 +6,28 @@ import QtQuick.Controls.Styles 1.0 import Qt.labs.folderlistmodel 2.1 Window { - id: mainWindow + id: fileViewerWindow width: 630 height: 380 flags: Qt.Dialog color: "#141414" - visible: false - property string buttonText: "" - property string currentFolder: folderModel.folder + + property string buttonText + property string folderModelFolder property string entryBarText: entryBar.text + property string currentFile: (folderModel.folder + "/" + entryBarText).substring(7) // We use .substring() to remove the 'file://' prefix signal buttonClicked + // The way the URL bar is updated is a bit kludgy because if we do simple bindings + // the bar will be empty the first time it's started. Hence the Component.onCompleted() call + // and the assignments every time the parentFolderButton is pressed or the current folder is changed. + Component.onCompleted: urlBar.text = folderModelFolder + FolderListModel { id: folderModel showDirsFirst: true - folder: "/home/james/" + folder: folderModelFolder } ColumnLayout { @@ -54,7 +60,10 @@ Window { } } - onClicked: { folderModel.folder = folderModel.parentFolder } + onClicked: { + folderModel.folder = folderModel.parentFolder + urlBar.text = folderModel.folder.toString().substring(7) + } } Rectangle { @@ -65,6 +74,7 @@ Window { border.color: "grey" TextInput { + id: urlBar x: 5 y: 4 @@ -73,7 +83,6 @@ Window { Layout.fillWidth: true color: "white" - text: folderModel.folder.toString().substring(7) selectionColor: "#00b2a1" } } @@ -156,7 +165,8 @@ Window { onDoubleClicked: { if (folderModel.isFolder(index)) { - folderModel.folder = folderModel.get(index, "filePath") + folderModel.folder = folderModel.get(index, "filePath") + urlBar.text = folderModel.get(index, "filePath") } } } @@ -195,7 +205,7 @@ Window { } } } - onClicked: mainWindow.buttonClicked() + onClicked: fileViewerWindow.buttonClicked() } } } From a03e85951cdaf3e57a2b3eaf02d441a9d3cd1d9e Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sun, 7 Sep 2014 07:44:00 +1200 Subject: [PATCH 13/25] Moved visible property from ExitDialog.qml to the dialogs themselves in MainWindow.qml, and exposed the text of the dialog as a property so it can be modified more easily. --- buttleofx/MainWindow.qml | 2 ++ buttleofx/gui/dialogs/ExitDialog.qml | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 04deedf9..08f83f9b 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -221,6 +221,8 @@ ApplicationWindow { ExitDialog { id: closeButtle + visible: false + dialogText: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost" onSaveButtonClicked: { if (urlOfFileToSave != "") { diff --git a/buttleofx/gui/dialogs/ExitDialog.qml b/buttleofx/gui/dialogs/ExitDialog.qml index 74bfe3fe..c07237e2 100644 --- a/buttleofx/gui/dialogs/ExitDialog.qml +++ b/buttleofx/gui/dialogs/ExitDialog.qml @@ -12,7 +12,8 @@ Window { color: "#141414" flags: Qt.Dialog modality: Qt.WindowModal - visible: false + + property string dialogText signal saveButtonClicked signal discardButtonClicked @@ -51,7 +52,7 @@ Window { } Text { - text: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost" + text: dialogText color: "#FEFEFE" } } From 7789f0958465ea9adf949debd63bcc3333bed2b6 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Mon, 8 Sep 2014 21:21:57 +1200 Subject: [PATCH 14/25] Replaced the openGraph dialog with an ExitDialog, removed the abortButtonClicked signal from ExitDialog.qml since it's always handled the same way (hide the ExitDialog), and set the ExitDialog to hide itself automatically when a button is clicked instead of having to do it manually when instanced. Fixed up the interaction between the ExitDialog's and finderSaveGraph, we now pass a bool in signals from the ExitDialog's to trigger finderSaveGraph.show(). The bool indicates whether to create a new graph or quit the application. --- buttleofx/MainWindow.qml | 73 +++++++++++++--------------- buttleofx/gui/dialogs/ExitDialog.qml | 9 ++-- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 08f83f9b..efdd572b 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -154,7 +154,13 @@ ApplicationWindow { title: "Save the graph" buttonText: "Save" folderModelFolder: _buttleData.homeDir - property bool quit: false + + property bool quit + + function show(doQuit) { + quit = doQuit + finderSaveGraph.visible = true + } onButtonClicked: { if (finderSaveGraph.entryBarText != "") { @@ -163,24 +169,23 @@ ApplicationWindow { _buttleData.saveData(_buttleData.urlOfFileToSave) finderSaveGraph.visible = false + // There are currently only two callers of finderSaveGraph, openGraph and newGraph, + // so we can get away with this simple for/else statement. if (quit) { Qt.quit() + } else { + _buttleData.newData() } } } } - MessageDialog { + ExitDialog { id: openGraph - title:"Save the graph?" - icon: StandardIcon.Warning - modality: Qt.WindowStaysOnTopHint && Qt.WindowModal - text: urlOfFileToSave == "" ? "Save graph changes before closing?" : "Save " + _buttleData.getFileName(urlOfFileToSave) + " changes before closing?" - detailedText: "If you don't save the graph, unsaved modifications will be lost." - standardButtons: StandardButton.Yes | StandardButton.No | StandardButton.Abort - Component.onCompleted: visible = false - - onYes: { + visible: false + dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" + + onSaveButtonClicked: { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { @@ -188,35 +193,28 @@ ApplicationWindow { finderSaveGraph.visible = true } } - onNo: { + onDiscardButtonClicked: { finderLoadGraph.visible = true } - onRejected: {} } - MessageDialog { + ExitDialog { id: newGraph - title: "Save the graph?" - icon: StandardIcon.Warning - modality: Qt.WindowStaysOnTopHint && Qt.WindowModal - text: urlOfFileToSave == "" ? "Save graph changes before closing?" : "Save " + _buttleData.getFileName(urlOfFileToSave) + " changes before closing?" - detailedText: "If you don't save the graph, unsaved modifications will be lost." - standardButtons: StandardButton.Yes | StandardButton.No | StandardButton.Abort - Component.onCompleted: visible = false - - onYes: { + visible: false + dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" + + signal showDialog(bool quit) + + Component.onCompleted: newGraph.showDialog.connect(finderSaveGraph.show) + + onSaveButtonClicked: { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) - _buttleData.newData() } else { - finderSaveGraph.quit = false - finderSaveGraph.visible = true - _buttleData.newData() + newGraph.showDialog(false) } } - onNo: { - _buttleData.newData() - } + onDiscardButtonClicked: _buttleData.newData() } ExitDialog { @@ -224,17 +222,18 @@ ApplicationWindow { visible: false dialogText: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost" + signal showDialog(bool quit) + + Component.onCompleted: closeButtle.showDialog.connect(finderSaveGraph.show) + onSaveButtonClicked: { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - closeButtle.visible = false - finderSaveGraph.quit = true - finderSaveGraph.visible = true + closeButtle.showDialog(true) } } onDiscardButtonClicked: Qt.quit() - onAbortButtonClicked: closeButtle.visible = false } menuBar: MenuBar { @@ -249,7 +248,7 @@ ApplicationWindow { if (!_buttleData.graphCanBeSaved) { _buttleData.newData() } else { - newGraph.open() + newGraph.visible = true } } } @@ -262,9 +261,7 @@ ApplicationWindow { if (!_buttleData.graphCanBeSaved) { finderLoadGraph.visible = true } else { - openGraph.open() - openGraph.close() - openGraph.open() + openGraph.visible = true } } } diff --git a/buttleofx/gui/dialogs/ExitDialog.qml b/buttleofx/gui/dialogs/ExitDialog.qml index c07237e2..5517212f 100644 --- a/buttleofx/gui/dialogs/ExitDialog.qml +++ b/buttleofx/gui/dialogs/ExitDialog.qml @@ -17,7 +17,6 @@ Window { signal saveButtonClicked signal discardButtonClicked - signal abortButtonClicked Component { id: buttonStyle @@ -68,6 +67,7 @@ Window { onClicked: { exitDialog.saveButtonClicked() + exitDialog.visible = false } } @@ -75,14 +75,17 @@ Window { id: discardButton text: "Discard" style: buttonStyle - onClicked: exitDialog.discardButtonClicked() + onClicked: { + exitDialog.discardButtonClicked() + exitDialog.visible = false + } } Button { id: abortButton text: "Abort" style: buttonStyle - onClicked: exitDialog.abortButtonClicked() + onClicked: exitDialog.visible = false } } } From 425aa8b7a1dbd2cb85c90d9bd8825de3a637b4af Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Tue, 9 Sep 2014 19:34:43 +1200 Subject: [PATCH 15/25] Added comment, and switched to using a FileViewerDialog for openGraph. --- buttleofx/MainWindow.qml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index efdd572b..7b434ca0 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -157,6 +157,7 @@ ApplicationWindow { property bool quit + // This receives a bool that tells us whether to close ButtleOFX or to create a new graph function show(doQuit) { quit = doQuit finderSaveGraph.visible = true @@ -185,12 +186,15 @@ ApplicationWindow { visible: false dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" + signal showDialog(bool quit) + + Component.onCompleted: openGraph.showDialog.connect(finderSaveGraph.show) + onSaveButtonClicked: { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - finderSaveGraph.quit = false - finderSaveGraph.visible = true + openGraph.showDialog(true) } } onDiscardButtonClicked: { From 605e16e5e2b680ec6b59d75b87ce23de1b83abc6 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sat, 13 Sep 2014 21:13:14 +1200 Subject: [PATCH 16/25] Reverted 1b9ca13. --- buttleofx/data/buttleData.py | 5 +++-- buttleofx/gui/dialogs/FileViewerDialog.qml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/buttleofx/data/buttleData.py b/buttleofx/data/buttleData.py index a11870e5..2f32b4c5 100644 --- a/buttleofx/data/buttleData.py +++ b/buttleofx/data/buttleData.py @@ -524,9 +524,10 @@ def loadData(self, url='buttleofx/backup/data.bofx'): """ Loads all data from a Json file (the default Json file if no url is given) """ + filepath = QtCore.QUrl(url).toLocalFile() self.newData() - with open(url, 'r') as f: + with open(filepath, 'r') as f: read_data = f.read() decoded = json.loads(read_data, object_hook=_decode_dict) @@ -560,7 +561,7 @@ def loadData(self, url='buttleofx/backup/data.bofx'): f.closed - self.urlOfFileToSave = url + self.urlOfFileToSave = filepath @QtCore.pyqtSlot() def newData(self): diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index d29af0f3..9d06c2d6 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -15,7 +15,7 @@ Window { property string buttonText property string folderModelFolder property string entryBarText: entryBar.text - property string currentFile: (folderModel.folder + "/" + entryBarText).substring(7) // We use .substring() to remove the 'file://' prefix + property string currentFile: folderModel.folder + "/" + entryBarText signal buttonClicked From ece3a338aa524cf6d6c979ab311799eadf1eb060 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sat, 13 Sep 2014 21:56:09 +1200 Subject: [PATCH 17/25] Rewrote the showDialog signals to send a string describing the action to be taken, and set buttleData.saveData() to use .toLocalFile() to turn URL's into proper paths. --- buttleofx/MainWindow.qml | 33 ++++++++++++++++++--------------- buttleofx/data/buttleData.py | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 7b434ca0..7d344c10 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -155,11 +155,13 @@ ApplicationWindow { buttonText: "Save" folderModelFolder: _buttleData.homeDir - property bool quit + // Acceptable values are the verb parts of the callers: 'open', 'new', and 'close' + property string action - // This receives a bool that tells us whether to close ButtleOFX or to create a new graph - function show(doQuit) { - quit = doQuit + // This initializer function takes in the action being done by the user so we know + // what to do when called. + function show(doAction) { + action = doAction finderSaveGraph.visible = true } @@ -170,12 +172,13 @@ ApplicationWindow { _buttleData.saveData(_buttleData.urlOfFileToSave) finderSaveGraph.visible = false - // There are currently only two callers of finderSaveGraph, openGraph and newGraph, - // so we can get away with this simple for/else statement. - if (quit) { - Qt.quit() - } else { + if (action == "open") { + _buttleData.newData() // Todo: Only clear the graph if the user actually decides to save + finderLoadGraph.visible = true + } else if (action == "new") { _buttleData.newData() + } else if (action == "close") { + Qt.quit() } } } @@ -186,7 +189,7 @@ ApplicationWindow { visible: false dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" - signal showDialog(bool quit) + signal showDialog(string quit) Component.onCompleted: openGraph.showDialog.connect(finderSaveGraph.show) @@ -194,7 +197,7 @@ ApplicationWindow { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - openGraph.showDialog(true) + openGraph.showDialog("open") } } onDiscardButtonClicked: { @@ -207,7 +210,7 @@ ApplicationWindow { visible: false dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" - signal showDialog(bool quit) + signal showDialog(string quit) Component.onCompleted: newGraph.showDialog.connect(finderSaveGraph.show) @@ -215,7 +218,7 @@ ApplicationWindow { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - newGraph.showDialog(false) + newGraph.showDialog("new") } } onDiscardButtonClicked: _buttleData.newData() @@ -226,7 +229,7 @@ ApplicationWindow { visible: false dialogText: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost" - signal showDialog(bool quit) + signal showDialog(string quit) Component.onCompleted: closeButtle.showDialog.connect(finderSaveGraph.show) @@ -234,7 +237,7 @@ ApplicationWindow { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - closeButtle.showDialog(true) + closeButtle.showDialog("close") } } onDiscardButtonClicked: Qt.quit() diff --git a/buttleofx/data/buttleData.py b/buttleofx/data/buttleData.py index 2f32b4c5..43b68acc 100644 --- a/buttleofx/data/buttleData.py +++ b/buttleofx/data/buttleData.py @@ -651,7 +651,7 @@ def saveData(self, url): if isinstance(url, str): filepath = url else: - filepath = url.toString() + filepath = url.toLocalFile() if not filepath.lower().endswith(".bofx"): filepath = filepath + ".bofx" From 6cc09b4e4f034bcc3e5290211f912a7b1a5eb3c8 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Mon, 22 Sep 2014 21:30:28 +1200 Subject: [PATCH 18/25] Some cleanups for the dialogs. Of particular note, the message in ExitDialog.qml is initialized to a default value, and we now send the filepath of the selected file in FileViewerDialog.qml with the buttonClicked() signal (cleaner since we don't need the extra property). --- buttleofx/MainWindow.qml | 8 ++++---- buttleofx/gui/dialogs/ExitDialog.qml | 7 +++---- buttleofx/gui/dialogs/FileViewerDialog.qml | 14 +++++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 7d344c10..83509ccb 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -142,7 +142,7 @@ ApplicationWindow { onButtonClicked: { if (finderLoadGraph.entryBarText != "") { - _buttleData.loadData(finderLoadGraph.currentFile) + _buttleData.loadData(currentFile) finderLoadGraph.visible = false } } @@ -155,7 +155,8 @@ ApplicationWindow { buttonText: "Save" folderModelFolder: _buttleData.homeDir - // Acceptable values are the verb parts of the callers: 'open', 'new', and 'close' + // Acceptable values are the verb parts of the callers ID's, i.e. 'open', + // 'new', and 'close' property string action // This initializer function takes in the action being done by the user so we know @@ -167,7 +168,7 @@ ApplicationWindow { onButtonClicked: { if (finderSaveGraph.entryBarText != "") { - _buttleData.urlOfFileToSave = finderSaveGraph.currentFile + _buttleData.urlOfFileToSave = currentFile _buttleData.saveData(_buttleData.urlOfFileToSave) finderSaveGraph.visible = false @@ -227,7 +228,6 @@ ApplicationWindow { ExitDialog { id: closeButtle visible: false - dialogText: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost" signal showDialog(string quit) diff --git a/buttleofx/gui/dialogs/ExitDialog.qml b/buttleofx/gui/dialogs/ExitDialog.qml index 5517212f..b41e1ce9 100644 --- a/buttleofx/gui/dialogs/ExitDialog.qml +++ b/buttleofx/gui/dialogs/ExitDialog.qml @@ -13,7 +13,7 @@ Window { flags: Qt.Dialog modality: Qt.WindowModal - property string dialogText + property string dialogText: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost." signal saveButtonClicked signal discardButtonClicked @@ -46,9 +46,7 @@ Window { RowLayout { spacing: 20 - Image { - source: "../img/icons/logo_icon.png" - } + Image { source: "../img/icons/logo_icon.png" } Text { text: dialogText @@ -75,6 +73,7 @@ Window { id: discardButton text: "Discard" style: buttonStyle + onClicked: { exitDialog.discardButtonClicked() exitDialog.visible = false diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index 9d06c2d6..70fa1e79 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -9,15 +9,14 @@ Window { id: fileViewerWindow width: 630 height: 380 - flags: Qt.Dialog color: "#141414" + flags: Qt.Dialog property string buttonText property string folderModelFolder property string entryBarText: entryBar.text - property string currentFile: folderModel.folder + "/" + entryBarText - signal buttonClicked + signal buttonClicked(string currentFile) // The way the URL bar is updated is a bit kludgy because if we do simple bindings // the bar will be empty the first time it's started. Hence the Component.onCompleted() call @@ -143,17 +142,19 @@ Window { } } } + Text { + text: fileName + color: "white" width: folderView.cellWidth - 10 horizontalAlignment: Text.AlignHCenter wrapMode: Text.WrapAnywhere - text: fileName - color: "white" } } MouseArea { anchors.fill: parent + onClicked: { folderView.currentIndex = index if (!folderModel.isFolder(index)) { @@ -162,7 +163,6 @@ Window { entryBar.text = "" } } - onDoubleClicked: { if (folderModel.isFolder(index)) { folderModel.folder = folderModel.get(index, "filePath") @@ -205,7 +205,7 @@ Window { } } } - onClicked: fileViewerWindow.buttonClicked() + onClicked: fileViewerWindow.buttonClicked(folderModel.folder + "/" + entryBarText) } } } From 6639c29b8b5b9fa24b1ca122e517557543f438b7 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Fri, 3 Oct 2014 21:02:33 +1300 Subject: [PATCH 19/25] Simplified the way we assign the current folder to the URL bar. Todo: fix it so that the current URL is displayed when the dialog is launched from the file menu, which is broken with this commit. On the upside, it now displays properly when the dialog is launched when the user hits the close button or hits Alt + F4 (haven't committed that bit of the code yet). --- buttleofx/gui/dialogs/FileViewerDialog.qml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/buttleofx/gui/dialogs/FileViewerDialog.qml b/buttleofx/gui/dialogs/FileViewerDialog.qml index 70fa1e79..0f1088b1 100644 --- a/buttleofx/gui/dialogs/FileViewerDialog.qml +++ b/buttleofx/gui/dialogs/FileViewerDialog.qml @@ -18,11 +18,6 @@ Window { signal buttonClicked(string currentFile) - // The way the URL bar is updated is a bit kludgy because if we do simple bindings - // the bar will be empty the first time it's started. Hence the Component.onCompleted() call - // and the assignments every time the parentFolderButton is pressed or the current folder is changed. - Component.onCompleted: urlBar.text = folderModelFolder - FolderListModel { id: folderModel showDirsFirst: true @@ -61,7 +56,6 @@ Window { onClicked: { folderModel.folder = folderModel.parentFolder - urlBar.text = folderModel.folder.toString().substring(7) } } @@ -77,6 +71,7 @@ Window { x: 5 y: 4 + text: folderModel.folder.toString().substring(7) readOnly: true selectByMouse: true Layout.fillWidth: true @@ -166,7 +161,6 @@ Window { onDoubleClicked: { if (folderModel.isFolder(index)) { folderModel.folder = folderModel.get(index, "filePath") - urlBar.text = folderModel.get(index, "filePath") } } } From 396aad9ad9d2074ceb783f2e36f2fd49d6faf36c Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Sun, 5 Oct 2014 07:41:05 +1300 Subject: [PATCH 20/25] And at long last, a fix for the bug that started it all, #72 :P This just replaces the QMessageDialog's for the close event with our own. Todo: figure out how to make the dialogs modal. --- buttleofx/main.py | 74 ++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/buttleofx/main.py b/buttleofx/main.py index 2b79db96..65c93b86 100644 --- a/buttleofx/main.py +++ b/buttleofx/main.py @@ -74,49 +74,57 @@ class EventFilter(QtCore.QObject): - def eventFilter(self, receiver, event): - buttleData = ButtleDataSingleton().get() - browser = FileModelBrowserSingleton().get() + def __init__(self, app, engine): + self.mainApp = app + self.mainEngine = engine + self.buttleData = ButtleDataSingleton().get() + super(EventFilter, self).__init__() + + def onSaveDialogButtonClicked(self, fileToSave): + self.buttleData.urlOfFileToSave = fileToSave + self.buttleData.saveData(QtCore.QUrl(self.buttleData.urlOfFileToSave)) + QtCore.QCoreApplication.quit() + + def onExitDialogDiscardButtonClicked(self): + QtCore.QCoreApplication.quit() + + def onExitDialogSaveButtonClicked(self): + if self.buttleData.urlOfFileToSave: + self.buttleData.saveData(self.buttleData.urlOfFileToSave) + QtCore.QCoreApplication.quit() + else: + saveDialogComponent = QtQml.QQmlComponent(self.mainEngine) + saveDialogComponent.loadUrl(QtCore.QUrl("ButtleOFX/buttleofx/gui/dialogs/FileViewerDialog.qml")) + + saveDialog = saveDialogComponent.create() + QtQml.QQmlProperty.write(saveDialog, "title", "Save the graph") + QtQml.QQmlProperty.write(saveDialog, "buttonText", "Save") + QtQml.QQmlProperty.write(saveDialog, "folderModelFolder", self.buttleData.getHomeDir()) + + saveDialog.buttonClicked.connect(self.onSaveDialogButtonClicked) + saveDialog.show() + def eventFilter(self, receiver, event): if event.type() == QtCore.QEvent.KeyPress: - # If alt f4 event ignored + # If Alt F4 event ignored if event.modifiers() == QtCore.Qt.AltModifier and event.key() == QtCore.Qt.Key_F4: event.ignore() if event.type() != QtCore.QEvent.Close: return super(EventFilter, self).eventFilter(receiver, event) if not isinstance(receiver, QtQuick.QQuickWindow) or not receiver.title() == "ButtleOFX": return False - if not buttleData.graphCanBeSaved: + if not self.buttleData.graphCanBeSaved: return False - msgBox = QtWidgets.QMessageBox() - msgBox.setText("Save graph changes before closing ?") - msgBox.setModal(True) - msgBox.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) - msgBox.setInformativeText("If you don't save the graph, unsaved modifications will be lost.") - msgBox.setStandardButtons( - QtWidgets.QMessageBox.Save | QtWidgets.QMessageBox.Discard | QtWidgets.QMessageBox.Abort) - msgBox.setDefaultButton(QtWidgets.QMessageBox.Save) - ret = msgBox.exec_() - - if ret == QtWidgets.QMessageBox.Save: - if buttleData.urlOfFileToSave: - # Save on the already existing file - buttleData.saveData(buttleData.urlOfFileToSave) - # Close the application - return super(EventFilter, self).eventFilter(receiver, event) - - # This project has never been saved, so ask the user on which file to save. - dialog = QtWidgets.QFileDialog() - fileToSave = dialog.getSaveFileName(None, "Save the graph", browser.getFirstFolder())[0] - buttleData.urlOfFileToSave = fileToSave - buttleData.saveData(fileToSave) - # Close the application - return super(EventFilter, self).eventFilter(receiver, event) + exitDialogComponent = QtQml.QQmlComponent(self.mainEngine) + # Note that we give the path relative to run_buttleofx.sh, because that becomes the PWD when this is run. + # We also do this for the saveDialogComponent in self.onExitDialogSaveButtonClicked(). + exitDialogComponent.loadUrl(QtCore.QUrl("ButtleOFX/buttleofx/gui/dialogs/ExitDialog.qml")) - if ret == QtWidgets.QMessageBox.Discard: - # Close the application - return super(EventFilter, self).eventFilter(receiver, event) + exitDialog = exitDialogComponent.create() + exitDialog.saveButtonClicked.connect(self.onExitDialogSaveButtonClicked) + exitDialog.discardButtonClicked.connect(self.onExitDialogDiscardButtonClicked) + exitDialog.show() # Don't call the parent class, so we don't close the application return True @@ -281,7 +289,7 @@ def main(argv, app): print("Watch directory:", parentDir) qic.addFilesFromDirectory(parentDir, recursive=True) - aFilter = EventFilter() + aFilter = EventFilter(app, engine) app.installEventFilter(aFilter) topLevel.show() From b1aab846f410f6796ce7f1fd7a2a3cdca895c134 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Mon, 13 Oct 2014 20:58:42 +1300 Subject: [PATCH 21/25] Simplified the ridiculous interation between dialogs, fixed a TODO so that the graph is only cleared when necessary, and made some wee cleanups. --- buttleofx/MainWindow.qml | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 83509ccb..3c7b3dd5 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -122,9 +122,9 @@ ApplicationWindow { PluginWindow { id: doc title: "Plugin's Documentation" - selectedNodeLabel: _buttleData.currentSelectedNodeWrappers.count!=0 ? _buttleData.currentSelectedNodeWrappers.get(0).name : "" - selectedNodeDoc: _buttleData.currentSelectedNodeWrappers.count!=0 ? _buttleData.currentSelectedNodeWrappers.get(0).pluginDoc : "" - selectedNodeGroup: _buttleData.currentSelectedNodeWrappers.count!=0 ? _buttleData.currentSelectedNodeWrappers.get(0).pluginGroup : "" + selectedNodeLabel: _buttleData.currentSelectedNodeWrappers.count != 0 ? _buttleData.currentSelectedNodeWrappers.get(0).name : "" + selectedNodeDoc: _buttleData.currentSelectedNodeWrappers.count != 0 ? _buttleData.currentSelectedNodeWrappers.get(0).pluginDoc : "" + selectedNodeGroup: _buttleData.currentSelectedNodeWrappers.count != 0 ? _buttleData.currentSelectedNodeWrappers.get(0).pluginGroup : "" } // Window of shortcuts @@ -142,6 +142,7 @@ ApplicationWindow { onButtonClicked: { if (finderLoadGraph.entryBarText != "") { + _buttleData.newData() _buttleData.loadData(currentFile) finderLoadGraph.visible = false } @@ -169,12 +170,11 @@ ApplicationWindow { onButtonClicked: { if (finderSaveGraph.entryBarText != "") { _buttleData.urlOfFileToSave = currentFile - _buttleData.saveData(_buttleData.urlOfFileToSave) + finderSaveGraph.visible = false if (action == "open") { - _buttleData.newData() // Todo: Only clear the graph if the user actually decides to save finderLoadGraph.visible = true } else if (action == "new") { _buttleData.newData() @@ -190,15 +190,11 @@ ApplicationWindow { visible: false dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" - signal showDialog(string quit) - - Component.onCompleted: openGraph.showDialog.connect(finderSaveGraph.show) - onSaveButtonClicked: { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - openGraph.showDialog("open") + finderSaveGraph.show("open") } } onDiscardButtonClicked: { @@ -211,15 +207,11 @@ ApplicationWindow { visible: false dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" - signal showDialog(string quit) - - Component.onCompleted: newGraph.showDialog.connect(finderSaveGraph.show) - onSaveButtonClicked: { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - newGraph.showDialog("new") + finderSaveGraph.show("new") } } onDiscardButtonClicked: _buttleData.newData() @@ -229,15 +221,11 @@ ApplicationWindow { id: closeButtle visible: false - signal showDialog(string quit) - - Component.onCompleted: closeButtle.showDialog.connect(finderSaveGraph.show) - onSaveButtonClicked: { if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - closeButtle.showDialog("close") + finderSaveGraph.show("close") } } onDiscardButtonClicked: Qt.quit() From 747ad26711340793df66202945753a7f04383a52 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Mon, 13 Oct 2014 21:47:50 +1300 Subject: [PATCH 22/25] Replaced the QtQuick dialogs with our own. --- buttleofx/gui/graph/qml/FinderLoadGraph.qml | 18 ----- buttleofx/gui/graph/qml/FinderSaveGraph.qml | 19 ----- buttleofx/gui/graph/qml/Tools.qml | 85 ++++++++++++++++++--- 3 files changed, 75 insertions(+), 47 deletions(-) delete mode 100644 buttleofx/gui/graph/qml/FinderLoadGraph.qml delete mode 100644 buttleofx/gui/graph/qml/FinderSaveGraph.qml diff --git a/buttleofx/gui/graph/qml/FinderLoadGraph.qml b/buttleofx/gui/graph/qml/FinderLoadGraph.qml deleted file mode 100644 index 5462f2f6..00000000 --- a/buttleofx/gui/graph/qml/FinderLoadGraph.qml +++ /dev/null @@ -1,18 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Dialogs 1.0 - -FileDialog { - signal getFileUrl(string fileurl) - - id: finderLoadGraph - title: "Open a graph" - folder: _buttleData.buttlePath - nameFilters: ["ButtleOFX Graph files (*.bofx)", "All files (*)"] - selectedNameFilter: "All files (*)" - - onAccepted: { - console.log(finderLoadGraph.fileUrl) - _buttleData.loadData(finderLoadGraph.fileUrl) - getFileUrl(finderLoadGraph.fileUrl) - } -} diff --git a/buttleofx/gui/graph/qml/FinderSaveGraph.qml b/buttleofx/gui/graph/qml/FinderSaveGraph.qml deleted file mode 100644 index 34a964f7..00000000 --- a/buttleofx/gui/graph/qml/FinderSaveGraph.qml +++ /dev/null @@ -1,19 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Dialogs 1.0 - -FileDialog { - signal getFileUrl(string fileurl) - - id: finderSaveGraph - title: "Save the graph" - folder: _buttleData.buttlePath - nameFilters: ["ButtleOFX Graph files (*.bofx)", "All files (*)"] - selectedNameFilter: "All files (*)" - - onAccepted: { - _buttleData.saveData(finderSaveGraph.fileUrl) - getFileUrl(finderSaveGraph.fileUrl) - } - - selectExisting: false -} diff --git a/buttleofx/gui/graph/qml/Tools.qml b/buttleofx/gui/graph/qml/Tools.qml index 4c6d22f0..f14029cd 100644 --- a/buttleofx/gui/graph/qml/Tools.qml +++ b/buttleofx/gui/graph/qml/Tools.qml @@ -1,7 +1,7 @@ import QtQuick 2.0 -import QtQuick.Dialogs 1.0 import "../../plugin/qml" +import "../../dialogs" Rectangle { id: tools @@ -13,6 +13,72 @@ Rectangle { signal clickCreationNode(string nodeType) + FileViewerDialog { + id: finderLoadGraph + visible: false + title: "Open a graph" + buttonText: "Open" + folderModelFolder: _buttleData.homeDir + + onButtonClicked: { + if (finderLoadGraph.entryBarText != "") { + _buttleData.newData() + _buttleData.loadData(currentFile) + finderLoadGraph.visible = false + } + } + } + + FileViewerDialog { + id: finderSaveGraph + visible: false + title: "Save the graph" + buttonText: "Save" + folderModelFolder: _buttleData.homeDir + + // Acceptable values are the verb parts of the callers ID's, i.e. 'open' + // and 'save' (in which case we do no additional work). + property string action + + // This initializer function takes in the action being done by the user so we know + // what to do when called. + function show(doAction) { + action = doAction + finderSaveGraph.visible = true + } + + onButtonClicked: { + if (finderSaveGraph.entryBarText != "") { + _buttleData.urlOfFileToSave = currentFile + _buttleData.saveData(_buttleData.urlOfFileToSave) + + finderSaveGraph.visible = false + + if (action == "open") { + finderLoadGraph.visible = true + } + } + } + } + + ExitDialog { + id: openGraph + visible: false + dialogText: "Do you want to save before closing this file?
If you don't, all unsaved changes will be lost" + + onSaveButtonClicked: { + if (urlOfFileToSave != "") { + _buttleData.saveData(urlOfFileToSave) + finderLoadGraph.visible = true + } else { + finderSaveGraph.show("open") + } + } + onDiscardButtonClicked: { + finderLoadGraph.visible = true + } + } + gradient: Gradient { GradientStop { position: 0.0; color: gradian2 } GradientStop { position: 0.85; color: gradian2 } @@ -39,13 +105,13 @@ Rectangle { locked: false onClicked: { - if (pluginVisible==true){ - pluginVisible=false + if (pluginVisible == true){ + pluginVisible = false } else { - pluginVisible=true + pluginVisible = true } - editNode=false + editNode = false } } @@ -62,11 +128,9 @@ Rectangle { editNode = false if (!_buttleData.graphCanBeSaved) { - finderLoadGraph.open() + finderLoadGraph.visible = true } else { - openGraph.open() - openGraph.close() - openGraph.open() + openGraph.visible = true } } } @@ -82,10 +146,11 @@ Rectangle { onClicked: { pluginVisible = false editNode = false + if (urlOfFileToSave != "") { _buttleData.saveData(urlOfFileToSave) } else { - finderSaveGraph.open() + finderSaveGraph.show("save") } } } From 00b83ac73776ca6f563ddc27ec69fb09fd3b2e6a Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Mon, 13 Oct 2014 21:51:31 +1300 Subject: [PATCH 23/25] Removed modality property. --- buttleofx/gui/dialogs/ExitDialog.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/buttleofx/gui/dialogs/ExitDialog.qml b/buttleofx/gui/dialogs/ExitDialog.qml index b41e1ce9..9f8e9aa3 100644 --- a/buttleofx/gui/dialogs/ExitDialog.qml +++ b/buttleofx/gui/dialogs/ExitDialog.qml @@ -11,7 +11,6 @@ Window { title: "Save Changes?" color: "#141414" flags: Qt.Dialog - modality: Qt.WindowModal property string dialogText: "Do you want to save before exiting?
If you don't, all unsaved changes will be lost." From 8353dbe1430d5048c1f12873108d792f710cff2e Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Thu, 22 Jan 2015 21:37:35 +1300 Subject: [PATCH 24/25] Whitespace cleanup to satisfy flake. --- buttleofx/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttleofx/main.py b/buttleofx/main.py index 0521e507..c8d81dec 100644 --- a/buttleofx/main.py +++ b/buttleofx/main.py @@ -124,7 +124,7 @@ def eventFilter(self, receiver, event): exitDialog = exitDialogComponent.create() exitDialog.saveButtonClicked.connect(self.onExitDialogSaveButtonClicked) exitDialog.discardButtonClicked.connect(self.onExitDialogDiscardButtonClicked) - exitDialog.show() + exitDialog.show() # Don't call the parent class, so we don't close the application return True From 1c9b9b3f29b7c1e3ae9498a1434b1733ac602959 Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Fri, 23 Jan 2015 08:30:38 +1300 Subject: [PATCH 25/25] Fixed bug that would hide the graph widget on startup. Seems to have been introduced by mistake in 0089ca5. --- buttleofx/MainWindow.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buttleofx/MainWindow.qml b/buttleofx/MainWindow.qml index 3c7b3dd5..028b10e7 100644 --- a/buttleofx/MainWindow.qml +++ b/buttleofx/MainWindow.qml @@ -857,7 +857,7 @@ ApplicationWindow { implicitWidth: parent.width implicitHeight: topRightView.visible ? 0.5 * parent.height : parent.height z: -1 - visible: !selectedView + visible: selectedView != 3 children: switch (selectedView) {