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

QML: Better layout using anchors, auto change with binding

This commit is contained in:
Bumsik Kim 2018-05-10 04:12:03 -04:00
parent df362568f6
commit 85b0670a92
No known key found for this signature in database
GPG key ID: E31041C8EC5B01C6

120
main.qml
View file

@ -73,22 +73,24 @@ ApplicationWindow {
currentIndex: tabBar.currentIndex currentIndex: tabBar.currentIndex
ColumnLayout { ColumnLayout {
// enabled: enabler.checked anchors.top: parent.top
// anchors.top: parent.top anchors.left: parent.left
// anchors.left: parent.left anchors.right: parent.right
// anchors.right: parent.right anchors.margins: margin
// anchors.margins: margin
GroupBox { GroupBox {
title: "Virtual Display" title: "Virtual Display"
// font.bold: true // font.bold: true
Layout.fillWidth: true anchors.left: parent.left
anchors.right: parent.right
enabled: backend.virtScreenCreated ? false : true
ColumnLayout { ColumnLayout {
Layout.fillWidth: true anchors.left: parent.left
anchors.right: parent.right
RowLayout { RowLayout {
Layout.fillWidth: true
Label { text: "Width"; Layout.fillWidth: true } Label { text: "Width"; Layout.fillWidth: true }
SpinBox { SpinBox {
value: backend.virt.width value: backend.virt.width
@ -99,11 +101,11 @@ ApplicationWindow {
onValueModified: { onValueModified: {
backend.virt.width = value; backend.virt.width = value;
} }
textFromValue: function(value, locale) { return value; }
} }
} }
RowLayout { RowLayout {
Layout.fillWidth: true
Label { text: "Height"; Layout.fillWidth: true } Label { text: "Height"; Layout.fillWidth: true }
SpinBox { SpinBox {
value: backend.virt.height value: backend.virt.height
@ -114,11 +116,11 @@ ApplicationWindow {
onValueModified: { onValueModified: {
backend.virt.height = value; backend.virt.height = value;
} }
textFromValue: function(value, locale) { return value; }
} }
} }
RowLayout { RowLayout {
Layout.fillWidth: true
Label { text: "Portrait Mode"; Layout.fillWidth: true } Label { text: "Portrait Mode"; Layout.fillWidth: true }
Switch { Switch {
checked: backend.portrait checked: backend.portrait
@ -129,7 +131,6 @@ ApplicationWindow {
} }
RowLayout { RowLayout {
Layout.fillWidth: true
Label { text: "HiDPI (2x resolution)"; Layout.fillWidth: true } Label { text: "HiDPI (2x resolution)"; Layout.fillWidth: true }
Switch { Switch {
checked: backend.hidpi checked: backend.hidpi
@ -140,10 +141,16 @@ ApplicationWindow {
} }
RowLayout { RowLayout {
Layout.fillWidth: true anchors.left: parent.left
Label { text: "Device"; Layout.fillWidth: true } anchors.right: parent.right
Label { id: deviceLabel; text: "Device"; }
ComboBox { ComboBox {
id: deviceComboBox id: deviceComboBox
anchors.left: deviceLabel.right
anchors.right: parent.right
anchors.leftMargin: 120
textRole: "name" textRole: "name"
model: [] model: []
@ -175,10 +182,13 @@ ApplicationWindow {
Button { Button {
id: virtScreenButton id: virtScreenButton
text: "Enable Virtual Screen" text: backend.virtScreenCreated ? "Disable Virtual Screen" : "Enable Virtual Screen"
Layout.fillWidth: true
anchors.left: parent.left
anchors.right: parent.right
// Material.background: Material.Teal // Material.background: Material.Teal
// Material.foreground: Material.Grey // Material.foreground: Material.Grey
enabled: backend.vncState == Backend.OFF ? true : false
Popup { Popup {
id: busyDialog id: busyDialog
@ -196,7 +206,6 @@ ApplicationWindow {
} }
onClicked: { onClicked: {
virtScreenButton.enabled = false;
busyDialog.open(); busyDialog.open();
// Give a very short delay to show busyDialog. // Give a very short delay to show busyDialog.
timer.setTimeout (function() { timer.setTimeout (function() {
@ -211,33 +220,27 @@ ApplicationWindow {
Component.onCompleted: { Component.onCompleted: {
backend.onVirtScreenCreatedChanged.connect(function(created) { backend.onVirtScreenCreatedChanged.connect(function(created) {
busyDialog.close(); busyDialog.close();
virtScreenButton.enabled = true;
if (created) {
virtScreenButton.text = "Disable Virtual Screen"
} else {
virtScreenButton.text = "Enable Virtual Screen"
}
}); });
} }
} }
} }
ColumnLayout { ColumnLayout {
// enabled: enabler.checked anchors.top: parent.top
// anchors.top: parent.top anchors.left: parent.left
// anchors.left: parent.left anchors.right: parent.right
// anchors.right: parent.right anchors.margins: margin
// anchors.margins: margin
GroupBox { GroupBox {
title: "VNC Server" title: "VNC Server"
Layout.fillWidth: true anchors.left: parent.left
// Layout.fillWidth: true anchors.right: parent.right
ColumnLayout { ColumnLayout {
Layout.fillWidth: true anchors.left: parent.left
anchors.right: parent.right
RowLayout { RowLayout {
Layout.fillWidth: true
Label { text: "Port"; Layout.fillWidth: true } Label { text: "Port"; Layout.fillWidth: true }
SpinBox { SpinBox {
value: backend.vncPort value: backend.vncPort
@ -248,14 +251,20 @@ ApplicationWindow {
onValueModified: { onValueModified: {
backend.vncPort = value; backend.vncPort = value;
} }
textFromValue: function(value, locale) { return value; }
} }
} }
RowLayout { RowLayout {
Layout.fillWidth: true anchors.left: parent.left
Label { text: "Password" } anchors.right: parent.right
Label { id: passwordLabel; text: "Password" }
TextField { TextField {
Layout.fillWidth: true anchors.left: passwordLabel.right
anchors.right: parent.right
anchors.margins: margin
placeholderText: "Password"; placeholderText: "Password";
text: backend.vncPassword; text: backend.vncPassword;
echoMode: TextInput.Password; echoMode: TextInput.Password;
@ -269,45 +278,30 @@ ApplicationWindow {
Button { Button {
id: vncButton id: vncButton
text: "Start VNC Server" anchors.left: parent.left
enabled: false anchors.right: parent.right
Layout.fillWidth: true
text: backend.vncState == Backend.OFF ? "Start VNC Server" : "Stop VNC Server"
enabled: backend.virtScreenCreated ? true : false
// Material.background: Material.Teal // Material.background: Material.Teal
// Material.foreground: Material.Grey // Material.foreground: Material.Grey
onClicked: { onClicked: backend.vncState == Backend.OFF ? backend.startVNC() : backend.stopVNC()
if (backend.vncState == Backend.OFF) {
backend.startVNC()
} else {
backend.stopVNC()
}
}
Component.onCompleted: {
backend.onVncStateChanged.connect(function(state) {
if (state == Backend.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;
}
});
}
} }
} }
} }
footer: ToolBar { footer: ToolBar {
RowLayout { RowLayout {
anchors.margins: spacing anchors.left: parent.left
anchors.right: parent.right
anchors.margins: margin
Label { Label {
id: vncStateLabel id: vncStateLabel
text: backend.vncState text: backend.vncState == Backend.OFF ? "Off" :
backend.vncState == Backend.WAITING ? "Waiting" :
backend.vncState == Backend.CONNECTED ? "Connected" :
"Server state error!"
} }
Item { Layout.fillWidth: true } Item { Layout.fillWidth: true }
CheckBox { CheckBox {