Created
June 14, 2016 17:24
-
-
Save oKcerG/79a69de5826917123582480e85e3c317 to your computer and use it in GitHub Desktop.
PoC detachable QML Item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import QtQuick.Window 2.2 | |
Item { | |
id: root | |
readonly property alias dragging: mouseArea.pressed | |
property bool lol: true | |
property Window targetWindow: lol ? win2 : window1 | |
implicitWidth: draggable.childrenRect.width | |
implicitHeight: draggable.childrenRect.height | |
default property alias data: draggable.data | |
Item { | |
id: draggable | |
implicitWidth: childrenRect.width | |
implicitHeight: childrenRect.height | |
} | |
MouseArea { | |
id: mouseArea | |
anchors.fill: draggable | |
property Window window: null | |
z: 1 | |
Component { | |
id: windowComponent | |
Window { | |
visible: true | |
color: "transparent" | |
flags: Qt.Tool | Qt.FramelessWindowHint | Qt.WindowDoesNotAcceptFocus | |
width: draggable.width | |
height: draggable.height | |
data: draggable | |
property real offsetX | |
property real offsetY | |
x: root.Window.window.x + root.x + mouseArea.mouseX - offsetX | |
y: root.Window.window.y + root.y + mouseArea.mouseY - offsetY | |
} | |
} | |
onPressed: { | |
draggable.x = 0; | |
draggable.y = 0; | |
window = windowComponent.createObject(Window.window, {offsetX: mouseX, offsetY: mouseY}) | |
} | |
onReleased: { | |
window.x = window.x; | |
window.y = window.y; | |
root.x = window.x - targetWindow.x | |
root.y = window.y - targetWindow.y | |
root.parent = targetWindow.contentItem; | |
draggable.parent = root; | |
window.destroy(); | |
window = null; | |
lol = !lol; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.6 | |
import QtQuick.Window 2.2 | |
Window { | |
id: window1 | |
visible: true | |
width: 640 | |
height: 480 | |
property int yolo: 10 | |
DraggableItem { | |
id: draggable | |
x: 200 | |
Rectangle { | |
color: draggable.dragging ? "pink" : "orange" | |
width: 100 | |
height: width | |
radius: width/2 | |
} | |
Text { | |
text: "Coucou" | |
} | |
} | |
Window { | |
id: win2 | |
width: 640 | |
height: 480 | |
x: 800 | |
y: 100 | |
visible: true | |
Rectangle { | |
id: win2Content | |
anchors.fill: parent | |
color: "green" | |
} | |
} | |
QtObject { | |
property url test | |
Component.onCompleted: print(typeof(test)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment