/*SPDX-FileCopyrightText: Joshua Goins <josh@redstrate.com>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Windowimport QtQuick.Layoutsimport QtQuick.Shapesimport QtQuick.Controls as QQC2import org.kde.kirigami as Kirigamiimport org.kde.plasma.tablet.kcmQQC2.ApplicationWindow {id: rootrequired property var tabletEventsproperty bool toolDown: falseminimumWidth: 400minimumHeight: 200title: i18ndc("kcm_tablet", "@title", "Tablet Tester")function insideDrawingSquare(local_x: real, local_y: real): bool {return local_x >= 0 &&local_y >= 0 &&local_x <= drawingSquare.width &&local_y <= drawingSquare.height;}function scrollLogToBottom(): void {logScrollView.QQC2.ScrollBar.vertical.position = 1.0 - logScrollView.QQC2.ScrollBar.vertical.size;}Connections {target: tabletEventsfunction onToolDown(hardware_serial_hi: int, hardware_serial_lo: int, window_x: real, window_y: real): void {const local = drawingSquare.mapFromItem(container, window_x, window_y);if (insideDrawingSquare(local.x, local.y)) {root.toolDown = true;penPath.path = [];penLogText.append(i18nd("kcm_tablet", "Stylus press X=%1 Y=%2", local.x, local.y));scrollLogToBottom();}}function onToolUp(hardware_serial_hi: int, hardware_serial_lo: int, window_x: real, window_y: real): void {const local = drawingSquare.mapFromItem(container, window_x, window_y);root.toolDown = false;penLogText.append(i18nd("kcm_tablet", "Stylus release X=%1 Y=%2", local.x, local.y));scrollLogToBottom();}function onToolMotion(hardware_serial_hi: int, hardware_serial_lo: int, window_x: real, window_y: real): void {const local = drawingSquare.mapFromItem(container, window_x, window_y);if (insideDrawingSquare(local.x, local.y) && root.toolDown) {penPath.path.push(local);penLogText.append(i18nd("kcm_tablet", "Stylus move X=%1 Y=%2", local.x, local.y));scrollLogToBottom();}}}Item {id: containeranchors.fill: parentRowLayout {id: layoutspacing: Kirigami.Units.largeSpacinganchors {fill: parentmargins: Kirigami.Units.largeSpacing}Rectangle {id: drawingSquareimplicitWidth: 220implicitHeight: 220color: Kirigami.Theme.backgroundColorclip: trueLayout.fillHeight: trueLayout.preferredWidth: Math.round(root.width / 3)Kirigami.Theme.inherit: falseKirigami.Theme.colorSet: Kirigami.Theme.View// Vertical linesRepeater {id: verticalRepeatermodel: 8delegate: Shape {id: verticalShapeanchors.fill: parentKirigami.Theme.inherit: falseKirigami.Theme.colorSet: Kirigami.Theme.WindowShapePath {strokeWidth: 1strokeColor: Kirigami.Theme.backgroundColorfillColor: "transparent"startX: line.xPathLine {id: linex: index * (verticalShape.width / verticalRepeater.count)y: verticalShape.height}}}}// Horizontal linesRepeater {id: horizontalRepeatermodel: 8delegate: Shape {id: horizontalShapeanchors.fill: parentKirigami.Theme.inherit: falseKirigami.Theme.colorSet: Kirigami.Theme.WindowShapePath {strokeWidth: 1strokeColor: Kirigami.Theme.backgroundColorfillColor: "transparent"startY: line.yPathLine {id: linex: horizontalShape.widthy: index * (horizontalShape.height / horizontalRepeater.count) - 1}}}}// Pen PathShape {anchors.fill: parentShapePath {strokeWidth: 2strokeColor: Kirigami.Theme.highlightColorfillColor: "transparent"PathPolyline {id: penPath}}}// This is here just to catch events from going to the window, nothing moreMouseArea {anchors.fill: parent}}ColumnLayout {Layout.fillWidth: trueLayout.fillHeight: trueLayout.preferredHeight: drawingSquare.implicitHeightspacing: Kirigami.Units.largeSpacingQQC2.ScrollView {id: logScrollViewLayout.fillWidth: trueLayout.fillHeight: trueQQC2.TextArea {id: penLogTexttext: i18nd("kcm_tablet", "## Legend:\n# X, Y - event coordinate\n")readOnly: truewrapMode: TextEdit.Wrap}}QQC2.Button {text: i18ndc("kcm_tablet", "Clear the event log", "Clear")icon.name: "edit-clear-symbolic"onClicked: {penLogText.clear();penPath.path = [];}Layout.fillWidth: true}}}}// FIXME: For some reason, setting this declaratively ends up with a broken window until it's resized.Component.onCompleted: width = 730}