diff options
Diffstat (limited to 'examples/wayland/custom-extension/compositor/qml/main.qml')
-rw-r--r-- | examples/wayland/custom-extension/compositor/qml/main.qml | 116 |
1 files changed, 40 insertions, 76 deletions
diff --git a/examples/wayland/custom-extension/compositor/qml/main.qml b/examples/wayland/custom-extension/compositor/qml/main.qml index fcd7eba79..9907263da 100644 --- a/examples/wayland/custom-extension/compositor/qml/main.qml +++ b/examples/wayland/custom-extension/compositor/qml/main.qml @@ -1,58 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Wayland module -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick import QtWayland.Compositor -import QtWayland.Compositor.WlShell +import QtWayland.Compositor.XdgShell -import com.theqtcompany.customextension 1.0 +import io.qt.examples.customextension 1.0 WaylandCompositor { id: comp @@ -81,36 +34,38 @@ WaylandCompositor { property int fontSize: 12 onSurfaceDestroyed: { - var index = itemList.indexOf(chrome); + var index = itemList.indexOf(chrome) if (index > -1) { var listCopy = itemList - listCopy.splice(index, 1); + listCopy.splice(index, 1) itemList = listCopy } chrome.destroy() } + transform: [ Rotation { id: xRot - origin.x: chrome.width/2; origin.y: chrome.height/2; + origin.x: chrome.width / 2; origin.y: chrome.height / 2 angle: 0 axis { x: 1; y: 0; z: 0 } }, Rotation { id: yRot - origin.x: chrome.width/2; origin.y: chrome.height/2; + origin.x: chrome.width / 2; origin.y: chrome.height / 2 angle: 0 axis { x: 0; y: 1; z: 0 } } ] + NumberAnimation { id: spinAnimation running: false loops: 2 - target: yRot; - property: "angle"; - from: 0; to: 360; - duration: 400; + target: yRot + property: "angle" + from: 0; to: 360 + duration: 400 } function doSpin(ms) { @@ -129,18 +84,21 @@ WaylandCompositor { easing.type: Easing.OutBounce duration: 1000 } + function doBounce(ms) { console.log("bounce " + ms) // using the 'ms' argument is left as an exercise for the reader... bounceAnimation.start() } + +//! [setFontSize] onFontSizeChanged: { custom.setFontSize(surface, fontSize) } +//! [setFontSize] } } - Component { id: customObjectComponent Rectangle { @@ -150,7 +108,7 @@ WaylandCompositor { width: 100 height: 100 - radius: width/2 + radius: width / 2 x: Math.random() * (defaultOutput.surfaceArea.width - 100) y: Math.random() * (defaultOutput.surfaceArea.height - 100) @@ -167,53 +125,59 @@ WaylandCompositor { Connections { target: obj - onResourceDestroyed: { + function onResourceDestroyed() { customItem.destroy() } } } } - WlShell { - id: defaultShell - onWlShellSurfaceCreated: { - var item = chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": shellSurface } ); - var w = defaultOutput.surfaceArea.width/2 - var h = defaultOutput.surfaceArea.height/2 - item.x = Math.random()*w - item.y = Math.random()*h + XdgShell { + onToplevelCreated: (toplevel, xdgSurface) => { + var item = chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": xdgSurface } ) + var w = defaultOutput.surfaceArea.width / 2 + var h = defaultOutput.surfaceArea.height / 2 + item.x = Math.random() * w + item.y = Math.random() * h var listCopy = itemList // List properties cannot be modified through Javascript operations listCopy.push(item) itemList = listCopy } } +//! [CustomExtension] CustomExtension { id: custom - onSurfaceAdded: { + onSurfaceAdded: (surface) => { var item = itemForSurface(surface) item.isCustom = true } - onBounce: { + + onBounce: (surface, ms) => { var item = itemForSurface(surface) item.doBounce(ms) } - onSpin: { + + onSpin: (surface, ms) => { var item = itemForSurface(surface) item.doSpin(ms) } - onCustomObjectCreated: { - var item = customObjectComponent.createObject(defaultOutput.surfaceArea, { "color": obj.color, "text": obj.text, "obj": obj } ); + + onCustomObjectCreated: (obj) => { + var item = customObjectComponent.createObject(defaultOutput.surfaceArea, + { "color": obj.color, + "text": obj.text, + "obj": obj } ) } } function setDecorations(shown) { var n = itemList.length for (var i = 0; i < n; i++) { - // TODO: we only need to do it once for each client if (itemList[i].isCustom) custom.showDecorations(itemList[i].surface.client, shown) } } +//! [CustomExtension] } |