1
0
Fork 0
mirror of https://github.com/kbumsik/VirtScreen.git synced 2025-02-15 04:41:50 +00:00
VirtScreen/main.qml

272 lines
8.2 KiB
QML
Raw Normal View History

2018-05-06 16:07:47 +00:00
import QtQuick 2.10
import QtQuick.Controls 2.3
// import QtQuick.Controls.Material 2.3
2018-05-06 16:07:47 +00:00
import QtQuick.Layouts 1.3
2018-05-07 20:15:41 +00:00
import QtQuick.Window 2.2
2018-05-06 16:07:47 +00:00
import Qt.labs.platform 1.0 as Labs
import VirtScreen.Backend 1.0
ApplicationWindow {
id: window
2018-05-07 20:15:41 +00:00
visible: false
flags: Qt.FramelessWindowHint
2018-05-06 16:07:47 +00:00
title: "Basic layouts"
// Material.theme: Material.Light
// Material.accent: Material.Teal
2018-05-06 16:07:47 +00:00
property int margin: 11
width: 380
height: 600
2018-05-07 20:15:41 +00:00
// hide screen when loosing focus
onActiveFocusItemChanged: {
if (!activeFocusItem) {
this.hide();
}
}
// virtscreen.py hackend.
Backend {
id: backend
}
2018-05-06 16:07:47 +00:00
// Timer object and function
Timer {
id: timer
function setTimeout(cb, delayTime) {
timer.interval = delayTime;
timer.repeat = false;
timer.triggered.connect(cb);
timer.start();
}
2018-05-06 16:07:47 +00:00
}
header: TabBar {
id: tabBar
position: TabBar.Header
2018-05-06 16:07:47 +00:00
width: parent.width
currentIndex: 0
TabButton {
text: qsTr("Display")
}
TabButton {
text: qsTr("VNC")
}
}
StackLayout {
width: parent.width
currentIndex: tabBar.currentIndex
ColumnLayout {
// enabled: enabler.checked
// anchors.top: parent.top
// anchors.left: parent.left
// anchors.right: parent.right
// anchors.margins: margin
GroupBox {
title: "Virtual Display"
// font.bold: true
Layout.fillWidth: true
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Label { text: "Width"; Layout.fillWidth: true }
SpinBox {
value: backend.width
2018-05-06 16:07:47 +00:00
from: 640
to: 1920
stepSize: 1
editable: true
textFromValue: function(value, locale) {
return Number(value).toLocaleString(locale, 'f', 0) + " px";
}
onValueModified: {
backend.width = value;
}
2018-05-06 16:07:47 +00:00
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Height"; Layout.fillWidth: true }
SpinBox {
value: backend.height
2018-05-06 16:07:47 +00:00
from: 360
to: 1080
stepSize : 1
editable: true
textFromValue: function(value, locale) {
return Number(value).toLocaleString(locale, 'f', 0) + " px";
}
onValueModified: {
backend.height = value;
}
2018-05-06 16:07:47 +00:00
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Portrait Mode"; Layout.fillWidth: true }
Switch {
checked: backend.portrait
onCheckedChanged: {
backend.portrait = checked;
}
}
2018-05-06 16:07:47 +00:00
}
RowLayout {
Layout.fillWidth: true
Label { text: "HiDPI (2x resolution)"; Layout.fillWidth: true }
Switch {
checked: backend.hidpi
onCheckedChanged: {
backend.hidpi = checked;
}
}
2018-05-06 16:07:47 +00:00
}
}
}
Button {
text: "Create a Virtual Display"
Layout.fillWidth: true
// Material.background: Material.Teal
// Material.foreground: Material.Grey
onClicked: {
if (!backend.virtScreenCreated) {
backend.createVirtScreen();
} else {
backend.deleteVirtScreen();
}
}
2018-05-06 16:07:47 +00:00
}
}
ColumnLayout {
// enabled: enabler.checked
// anchors.top: parent.top
// anchors.left: parent.left
// anchors.right: parent.right
// anchors.margins: margin
GroupBox {
title: "VNC Server"
Layout.fillWidth: true
// Layout.fillWidth: true
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
Label { text: "Port"; Layout.fillWidth: true }
SpinBox {
value: backend.vncPort
2018-05-06 16:07:47 +00:00
from: 1
to: 65535
stepSize: 1
editable: true
onValueModified: {
backend.vncPort = value;
}
2018-05-06 16:07:47 +00:00
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Password" }
TextField {
Layout.fillWidth: true
placeholderText: "Password";
text: backend.vncPassword;
2018-05-06 16:07:47 +00:00
echoMode: TextInput.Password;
onTextEdited: {
backend.vncPassword = text;
}
2018-05-06 16:07:47 +00:00
}
}
}
}
Button {
text: "Start VNC Server"
Layout.fillWidth: true
// Material.background: Material.Teal
// Material.foreground: Material.Grey
onClicked: {
if (backend.vncState == 'Off') {
backend.startVNC()
} else {
backend.stopVNC()
}
}
2018-05-06 16:07:47 +00:00
}
}
}
footer: ToolBar {
RowLayout {
anchors.margins: spacing
Label {
2018-05-07 00:11:30 +00:00
text: backend.vncState
2018-05-06 16:07:47 +00:00
}
Item { Layout.fillWidth: true }
CheckBox {
id: enabler
text: "Server Enabled"
checked: true
}
}
}
// Sytray Icon
Labs.SystemTrayIcon {
id: sysTrayIcon
iconSource: "icon/icon.png"
visible: true
onMessageClicked: console.log("Message clicked")
Component.onCompleted: {
// without delay, the message appears in a wierd place
timer.setTimeout (function() {
2018-05-06 16:07:47 +00:00
showMessage("Message title", "Something important came up. Click this to know more.");
}, 1000);
}
onActivated: {
2018-05-07 20:15:41 +00:00
if (window.visible) {
window.hide();
return;
}
// Move window to the corner of the primary display
var width = backend.primaryDisplayWidth;
var height = backend.primaryDisplayHeight;
var x_mid = width / 2;
var y_mid = height / 2;
window.x = (backend.cursor_x > x_mid)? width - window.width : 0;
window.y = (backend.cursor_y > y_mid)? height - window.height : 0;
2018-05-06 16:07:47 +00:00
window.show()
window.raise()
window.requestActivate()
}
menu: Labs.Menu {
Labs.MenuItem {
text: qsTr("&Quit")
onTriggered: backend.quitProgram()
2018-05-06 16:07:47 +00:00
}
}
}
}