diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/undo/quickundo/Button.qml | 20 | ||||
-rw-r--r-- | examples/undo/quickundo/main.qml | 74 | ||||
-rw-r--r-- | examples/undo/quickundo/quickundo.qmlproject | 16 |
3 files changed, 110 insertions, 0 deletions
diff --git a/examples/undo/quickundo/Button.qml b/examples/undo/quickundo/Button.qml new file mode 100644 index 0000000..6b1d9ec --- /dev/null +++ b/examples/undo/quickundo/Button.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 + +Rectangle { + id: root + property alias text: label.text + signal clicked() + + + width: 50 + height: 50 + Text { + id: label + anchors.centerIn: parent + } + + MouseArea { + anchors.fill: parent + onClicked: root.clicked() + } +} diff --git a/examples/undo/quickundo/main.qml b/examples/undo/quickundo/main.qml new file mode 100644 index 0000000..1b17c9a --- /dev/null +++ b/examples/undo/quickundo/main.qml @@ -0,0 +1,74 @@ +import QtQuick 2.0 +import Playground.UiHelpers.UndoFramework 1.0 + +Rectangle { + id: root + + width: 800 + height: 600 + + UndoStack { + id: stack + } + + UndoPropertyCommand { + id: moveCommand + properties: ["x", "y"] + } + + UndoCommand { + id: colorCommand + onUndo: target.color = Qt.rgba(0, 0, 0, 1); + onRedo: target.color = Qt.rgba(0.5, 0.2, 0.1, 1); + onCommandDestroyed: console.log("Command destroyed!"); + } + + Row { + anchors { + right: parent.right + top: parent.top + margins: 20 + } + spacing: 20 + + Button { + color: "red" + width: 100 + text: "Change color" + onClicked: stack.push(colorCommand, rec); + } + Button { + color: "blue" + text: "Undo" + onClicked: stack.undo(); + } + Button { + color: "green" + text: "Redo" + onClicked: stack.redo(); + } + } + + Rectangle { + id: rec + + x: 20 + y: 50 + width: 50 + height: 50 + color: "black" + + Drag.active: dragArea.drag.active + Drag.hotSpot.x: 10 + Drag.hotSpot.y: 10 + + MouseArea { + id: dragArea + + anchors.fill: parent + drag.target: parent + + onPressed: stack.push(moveCommand, parent); + } + } +} diff --git a/examples/undo/quickundo/quickundo.qmlproject b/examples/undo/quickundo/quickundo.qmlproject new file mode 100644 index 0000000..c1493d6 --- /dev/null +++ b/examples/undo/quickundo/quickundo.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "" + } + JavaScriptFiles { + directory: "" + } + ImageFiles { + directory: "" + } + /* List of plugin directories passed to QML runtime */ + //importPaths: [ "../../../src/imports/undo/" ] +} |