1
0
Fork 0
mirror of https://github.com/kbumsik/VirtScreen.git synced 2025-03-09 15:40:18 +00:00
VirtScreen/main.qml

344 lines
11 KiB
QML
Raw Normal View History

2018-05-06 12:07:47 -04:00
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
2018-05-06 12:07:47 -04:00
import QtQuick.Layouts 1.3
2018-05-07 16:15:41 -04:00
import QtQuick.Window 2.2
2018-05-06 12:07:47 -04:00
import Qt.labs.platform 1.0 as Labs
import VirtScreen.Backend 1.0
ApplicationWindow {
id: window
2018-05-07 16:15:41 -04:00
visible: false
flags: Qt.FramelessWindowHint
2018-05-06 12:07:47 -04:00
title: "Basic layouts"
Material.theme: Material.Light
Material.accent: Material.Teal
2018-05-06 12:07:47 -04:00
property int margin: 11
width: 380
height: 600
2018-05-07 16:15:41 -04:00
// hide screen when loosing focus
onActiveFocusItemChanged: {
if ((!activeFocusItem) && (!sysTrayIcon.clicked)) {
2018-05-07 16:15:41 -04:00
this.hide();
}
}
// virtscreen.py backend.
Backend {
id: backend
}
2018-05-06 12:07:47 -04:00
// Timer object and function
Timer {
id: timer
function setTimeout(cb, delayTime) {
timer.interval = delayTime;
timer.repeat = false;
timer.triggered.connect(cb);
timer.triggered.connect(function() {
timer.triggered.disconnect(cb);
});
timer.start();
}
2018-05-06 12:07:47 -04:00
}
header: TabBar {
id: tabBar
position: TabBar.Header
2018-05-06 12:07:47 -04: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 12:07:47 -04: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 12:07:47 -04:00
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Height"; Layout.fillWidth: true }
SpinBox {
value: backend.height
2018-05-06 12:07:47 -04: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 12:07:47 -04:00
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Portrait Mode"; Layout.fillWidth: true }
Switch {
checked: backend.portrait
onCheckedChanged: {
backend.portrait = checked;
}
}
2018-05-06 12:07:47 -04:00
}
RowLayout {
Layout.fillWidth: true
Label { text: "HiDPI (2x resolution)"; Layout.fillWidth: true }
Switch {
checked: backend.hidpi
onCheckedChanged: {
backend.hidpi = checked;
}
}
2018-05-06 12:07:47 -04:00
}
}
}
Button {
id: virtScreenButton
text: "Enable Virtual Screen"
2018-05-06 12:07:47 -04:00
Layout.fillWidth: true
// Material.background: Material.Teal
// Material.foreground: Material.Grey
Popup {
id: busyDialog
modal: true
closePolicy: Popup.NoAutoClose
x: (parent.width - width) / 2
y: (parent.height - height) / 2
BusyIndicator {
x: (parent.width - width) / 2
y: (parent.height - height) / 2
running: true
}
}
onClicked: {
virtScreenButton.enabled = false;
busyDialog.open();
// Give a very short delay to show busyDialog.
timer.setTimeout (function() {
if (!backend.virtScreenCreated) {
backend.createVirtScreen();
} else {
backend.deleteVirtScreen();
}
}, 200);
}
Component.onCompleted: {
backend.onVirtScreenCreatedChanged.connect(function(created) {
busyDialog.close();
virtScreenButton.enabled = true;
if (created) {
virtScreenButton.text = "Disable Virtual Screen"
} else {
virtScreenButton.text = "Enable Virtual Screen"
}
});
}
2018-05-06 12:07:47 -04: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 12:07:47 -04:00
from: 1
to: 65535
stepSize: 1
editable: true
onValueModified: {
backend.vncPort = value;
}
2018-05-06 12:07:47 -04:00
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Password" }
TextField {
Layout.fillWidth: true
placeholderText: "Password";
text: backend.vncPassword;
2018-05-06 12:07:47 -04:00
echoMode: TextInput.Password;
onTextEdited: {
backend.vncPassword = text;
}
2018-05-06 12:07:47 -04:00
}
}
}
}
Button {
id: vncButton
2018-05-06 12:07:47 -04:00
text: "Start VNC Server"
enabled: false
2018-05-06 12:07:47 -04:00
Layout.fillWidth: true
// Material.background: Material.Teal
// Material.foreground: Material.Grey
onClicked: {
if (backend.vncState == 'Off') {
backend.startVNC()
} else {
backend.stopVNC()
}
}
Component.onCompleted: {
backend.onVncStateChanged.connect(function(state) {
if (state == "Off") {
vncButton.text = "Start VNC Server";
} else {
vncButton.text = "Stop VNC Server";
}
});
backend.onVirtScreenCreatedChanged.connect(function(created) {
if (created) {
vncButton.enabled = true;
} else {
vncButton.enabled = false;
}
});
}
2018-05-06 12:07:47 -04:00
}
}
}
footer: ToolBar {
RowLayout {
anchors.margins: spacing
Label {
id: vncStateLabel
2018-05-06 20:11:30 -04:00
text: backend.vncState
2018-05-06 12:07:47 -04:00
}
Item { Layout.fillWidth: true }
CheckBox {
id: enabler
text: "Server Enabled"
checked: true
}
}
Component.onCompleted: {
backend.onVncStateChanged.connect(function(state) {
vncStateLabel.text = state;
});
}
2018-05-06 12:07:47 -04:00
}
// Sytray Icon
Labs.SystemTrayIcon {
id: sysTrayIcon
iconSource: "icon/icon.png"
visible: true
property bool clicked: false
2018-05-06 12:07:47 -04:00
onMessageClicked: console.log("Message clicked")
Component.onCompleted: {
// without delay, the message appears in a wierd place
timer.setTimeout (function() {
2018-05-07 23:45:17 -04:00
showMessage("VirtScreen is running",
"The program will keep running in the system tray.\n" +
"To terminate the program, choose \"Quit\" in the \n" +
"context menu of the system tray entry.");
}, 7000);
2018-05-06 12:07:47 -04:00
}
onActivated: function(reason) {
console.log(reason);
2018-05-07 16:15:41 -04:00
if (window.visible) {
window.hide();
return;
}
sysTrayIcon.clicked = true;
2018-05-07 16:15:41 -04:00
// 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;
2018-05-09 08:32:07 -04:00
window.x = width - window.width; //(backend.cursor_x > x_mid)? width - window.width : 0;
2018-05-07 16:15:41 -04:00
window.y = (backend.cursor_y > y_mid)? height - window.height : 0;
window.show();
window.raise();
window.requestActivate();
timer.setTimeout (function() {
sysTrayIcon.clicked = false;
}, 200);
2018-05-06 12:07:47 -04:00
}
menu: Labs.Menu {
Labs.MenuItem {
text: qsTr("&Quit")
onTriggered: backend.quitProgram()
2018-05-06 12:07:47 -04:00
}
}
}
}