aboutsummaryrefslogtreecommitdiffstats
path: root/demo
diff options
context:
space:
mode:
Diffstat (limited to 'demo')
-rw-r--r--demo/CMakeLists.txt6
-rw-r--r--demo/Main.qml292
2 files changed, 183 insertions, 115 deletions
diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt
index f85639b..dd46473 100644
--- a/demo/CMakeLists.txt
+++ b/demo/CMakeLists.txt
@@ -7,7 +7,11 @@ qt_add_qml_module(
VERSION
1.0
QML_FILES
- Main.qml)
+ Main.qml
+ # IMPORT_PATH sets QT_QML_IMPORT_PATH on the target, which qmlls reads to
+ # resolve imports like "import Xpl2" in .qmlls.ini.
+ IMPORT_PATH
+ "${PROJECT_BINARY_DIR}/qml")
set_target_properties(QtXpl2Demo PROPERTIES RUNTIME_OUTPUT_DIRECTORY
"${PROJECT_BINARY_DIR}/bin")
diff --git a/demo/Main.qml b/demo/Main.qml
index 82b2573..fe9f885 100644
--- a/demo/Main.qml
+++ b/demo/Main.qml
@@ -1,3 +1,5 @@
+pragma ComponentBehavior: Bound
+
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
@@ -6,170 +8,232 @@ import Xpl2
ApplicationWindow {
id: root
- width: 800
height: 600
- visible: true
title: "XPL2 Demo"
+ visible: true
+ width: 800
Connections {
- target: Xpl2Client
-
function onConnectedChanged() {
- log(Xpl2Client.connected ? "Connected" : "Disconnected");
+ debugConsole.appendLog(Xpl2Client.connected ? "Connected" :
+ "Disconnected");
}
- function onResponseReceived(response: string) {
- log("← " + response);
- responseModel.append({
- text: response
- });
+ function onErrorOccurred(error: string) {
+ debugConsole.appendLog("ERROR: " + error);
}
- function onErrorOccurred(error: string) {
- log("ERROR: " + error);
+ function onResponseReceived(response: string) {
+ debugConsole.appendLog("Received: " + response);
+ responseModel.append({
+ text: response
+ });
}
function onStatusMessage(message: string) {
- log(message);
+ debugConsole.appendLog(message);
}
- }
- function log(msg: string) {
- let ts = new Date().toLocaleTimeString(Qt.locale(), "HH:mm:ss.zzz");
- logModel.append({
- text: "[" + ts + "] " + msg
- });
- logView.positionViewAtEnd();
+ target: Xpl2Client
}
ColumnLayout {
anchors.fill: parent
- anchors.margins: 16
- spacing: 12
+ spacing: 0
- // --- Connection ---
- GroupBox {
- title: "Connection"
+ ColumnLayout {
+ Layout.fillHeight: true
Layout.fillWidth: true
+ Layout.margins: 16
+ spacing: 12
- GridLayout {
- columns: 4
- anchors.fill: parent
+ // --- Connection ---
+ GroupBox {
+ Layout.fillWidth: true
+ title: "Connection"
- Label {
- text: "Host:"
- }
- TextField {
- id: hostField
- text: Xpl2Client.host
- Layout.fillWidth: true
- onEditingFinished: Xpl2Client.host = text
- }
+ GridLayout {
+ anchors.fill: parent
+ columns: 2
- Label {
- text: "Port:"
- }
- TextField {
- id: portField
- text: Xpl2Client.port
- implicitWidth: 80
- validator: IntValidator {
- bottom: 1
- top: 65535
+ Label {
+ text: "Host:"
}
- onEditingFinished: Xpl2Client.port = parseInt(text)
- }
- Button {
- text: Xpl2Client.connected ? "Disconnect" : "Connect"
- Layout.columnSpan: 4
- Layout.alignment: Qt.AlignRight
- onClicked: {
- if (Xpl2Client.connected)
+ TextField {
+ id: hostField
+
+ Layout.fillWidth: true
+ text: Xpl2Client.host
+
+ onEditingFinished: Xpl2Client.host = text
+ }
+
+ Label {
+ text: "Command port:"
+ }
+
+ TextField {
+ id: commandPortField
+
+ Layout.fillWidth: true
+ text: Xpl2Client.commandPort
+
+ validator: IntValidator {
+ bottom: 1
+ top: 65535
+ }
+
+ onEditingFinished: Xpl2Client.commandPort = parseInt(
+ text)
+ }
+
+ Label {
+ text: "Imaging port:"
+ }
+
+ TextField {
+ id: imagingPortField
+
+ Layout.fillWidth: true
+ text: Xpl2Client.imagingPort
+
+ validator: IntValidator {
+ bottom: 1
+ top: 65535
+ }
+
+ onEditingFinished: Xpl2Client.imagingPort = parseInt(
+ text)
+ }
+
+ Label {
+ text: "Status port:"
+ }
+
+ TextField {
+ id: statusPortField
+
+ Layout.fillWidth: true
+ text: Xpl2Client.statusPort
+
+ validator: IntValidator {
+ bottom: 1
+ top: 65535
+ }
+
+ onEditingFinished: Xpl2Client.statusPort = parseInt(
+ text)
+ }
+
+ Button {
+ Layout.alignment: Qt.AlignRight
+ Layout.columnSpan: 2
+ text: Xpl2Client.connected ? "Disconnect" : "Connect"
+
+ onClicked: {
+ if (Xpl2Client.connected)
Xpl2Client.disconnectFromServer();
- else
+ else
Xpl2Client.connectToServer();
+ }
}
}
}
- }
- // --- Send Command ---
- GroupBox {
- title: "Command"
- Layout.fillWidth: true
- enabled: Xpl2Client.connected
+ // --- Send Command ---
+ GroupBox {
+ Layout.fillWidth: true
+ enabled: Xpl2Client.connected
+ title: "Command"
- RowLayout {
- anchors.fill: parent
+ RowLayout {
+ anchors.fill: parent
- TextField {
- id: cmdField
- placeholderText: "Enter command…"
- Layout.fillWidth: true
- onAccepted: sendBtn.clicked()
- }
+ TextField {
+ id: cmdField
+
+ Layout.fillWidth: true
+ placeholderText: "Enter command…"
+
+ onAccepted: sendBtn.clicked()
+ }
- Button {
- id: sendBtn
- text: "Send"
- onClicked: {
- if (cmdField.text.length > 0) {
- Xpl2Client.sendCommand(cmdField.text);
- cmdField.text = "";
+ Button {
+ id: sendBtn
+
+ text: "Send"
+
+ onClicked: {
+ if (cmdField.text.length > 0) {
+ Xpl2Client.sendCommand(cmdField.text);
+ cmdField.text = "";
+ }
}
}
}
}
- }
- // --- Responses ---
- GroupBox {
- title: "Responses"
- Layout.fillWidth: true
- Layout.fillHeight: true
+ // --- Responses ---
+ GroupBox {
+ Layout.fillHeight: true
+ Layout.fillWidth: true
+ title: "Responses"
- ListView {
- id: responseView
- anchors.fill: parent
- clip: true
- model: ListModel {
- id: responseModel
- }
+ ListView {
+ id: responseView
- delegate: Text {
- required property string text
- width: responseView.width
- wrapMode: Text.Wrap
- font.family: "monospace"
- font.pixelSize: 13
- text: model.text
+ anchors.fill: parent
+ clip: true
+
+ delegate: Text {
+ id: responseDelegate
+
+ required property string text
+
+ font.family: "monospace"
+ font.pixelSize: 13
+ text: responseDelegate.text
+ width: responseView.width
+ wrapMode: Text.Wrap
+ }
+ model: ListModel {
+ id: responseModel
+
+ }
}
}
}
- // --- Debug Log ---
- GroupBox {
- title: "Log"
+ // --- Debug Console ---
+ Rectangle {
+ id: debugConsole
+
+ function appendLog(msg) {
+ let ts = new Date().toLocaleTimeString(Qt.locale(), "HH:mm:ss");
+ debugLog.text += "[" + ts + "] " + msg + "\n";
+ debugLog.cursorPosition = debugLog.text.length;
+ }
+
Layout.fillWidth: true
- Layout.preferredHeight: 160
+ Layout.preferredHeight: 120
+ border.color: "#444"
+ color: "#1e1e1e"
+ radius: 4
- ListView {
- id: logView
+ ScrollView {
anchors.fill: parent
- clip: true
- model: ListModel {
- id: logModel
- }
+ anchors.margins: 4
+
+ TextArea {
+ id: debugLog
- delegate: Text {
- required property string text
- width: logView.width
- wrapMode: Text.Wrap
+ background: null
+ color: "#cccccc"
font.family: "monospace"
- font.pixelSize: 12
- color: "#555"
- text: model.text
+ font.pointSize: 9
+ readOnly: true
+ wrapMode: TextEdit.Wrap
}
}
}