C

Qt VNC Server - VncChat Example

// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Controls
import QtVncServer

Window {
    id: window
    width: 640
    height: 640
    visible: true
    color: "white"
    title: "Qt Vnc Chat"

    Rectangle {
        id: activeRect
        anchors.centerIn: parent
        width: parent.width * 0.75
        height: parent.height * 0.75
        radius: parent.width * 0.1

        color: grabber.serverState === VncItem.Connected ? "darkseagreen" : "salmon"

        Label {
            id: titleLabel
            anchors.top: activeRect.top
            anchors.topMargin: parent.width * 0.015
            anchors.horizontalCenter: activeRect.horizontalCenter
            text: "Qt Vnc Chat"
            font.pixelSize: window.height * 0.03
        }

        Label {
            id: portLabel
            anchors.top: titleLabel.bottom
            anchors.horizontalCenter: activeRect.horizontalCenter
            text: grabber.serverState === VncItem.Connected
                  || grabber.serverState === VncItem.Listening
                  ? "(Port " + grabber.vncPort + " is open for business)"
                  : (grabber.serverState === VncItem.InitializationFailed ? "(Error initializing server)" : "")
            font.pixelSize: window.height * 0.015
        }

        VncItem {
            id: grabber
            anchors.fill: parent

            vncPort: -1

            Rectangle {
                id: editorFrame
                anchors.fill: parent
                anchors.margins: window.width * 0.1
                radius: window.width * 0.1

                color: "gainsboro"
                TextArea {
                    id: textArea
                    anchors.fill: parent
                    anchors.margins: window.width * 0.1
                    background: null
                    placeholderText: "Say something nice"
                    placeholderTextColor: "darkslategrey"
                }
            }
        }
    }
}