1
0
Fork 0
mirror of https://github.com/kbumsik/VirtScreen.git synced 2025-02-12 11:21:53 +00:00

Separated Cursor and Network classes out of Backend class

This commit is contained in:
Bumsik Kim 2018-06-09 11:28:34 -04:00
parent 30ffe32f82
commit 9ec6256fc1
No known key found for this signature in database
GPG key ID: E31041C8EC5B01C6
3 changed files with 54 additions and 26 deletions

View file

@ -3,8 +3,14 @@ import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import VirtScreen.Backend 1.0
import VirtScreen.Network 1.0
ColumnLayout {
// virtscreen.py Network interfaces backend.
Network {
id: network
}
GroupBox {
title: "VNC Server"
Layout.fillWidth: true
@ -98,7 +104,7 @@ ColumnLayout {
anchors.bottom: ipListView.bottom
policy: ScrollBar.AlwaysOn
}
model: backend.ipAddresses
model: network.ipAddresses
delegate: TextEdit {
text: modelData
readOnly: true

View file

@ -4,6 +4,7 @@ import Qt.labs.platform 1.0
import VirtScreen.DisplayProperty 1.0
import VirtScreen.Backend 1.0
import VirtScreen.Cursor 1.0
Item {
property alias window: mainLoader.item
@ -61,6 +62,11 @@ Item {
}
}
// virtscreen.py Cursor class.
Cursor {
id: cursor
}
// Timer object and function
Timer {
id: timer
@ -109,8 +115,8 @@ Item {
}
});
// Move window to the corner of the primary display
var cursor_x = (backend.cursor_x / window.screen.devicePixelRatio) - window.screen.virtualX;
var cursor_y = (backend.cursor_y / window.screen.devicePixelRatio) - window.screen.virtualY;
var cursor_x = (cursor.x / window.screen.devicePixelRatio) - window.screen.virtualX;
var cursor_y = (cursor.y / window.screen.devicePixelRatio) - window.screen.virtualY;
var x_mid = window.screen.width / 2;
var y_mid = window.screen.height / 2;
var x = window.screen.width - window.width; //(cursor_x > x_mid)? width - window.width : 0;

View file

@ -416,7 +416,6 @@ class Backend(QObject):
onVirtScreenCreatedChanged = pyqtSignal(bool)
onVncUsePasswordChanged = pyqtSignal(bool)
onVncStateChanged = pyqtSignal(VNCState)
onIPAddressesChanged = pyqtSignal()
onDisplaySettingClosed = pyqtSignal()
onError = pyqtSignal(str)
@ -525,28 +524,6 @@ class Backend(QObject):
self._vncState = state
self.onVncStateChanged.emit(self._vncState)
@pyqtProperty('QStringList', notify=onIPAddressesChanged)
def ipAddresses(self):
for interface in interfaces():
if interface == 'lo':
continue
addresses = ifaddresses(interface).get(AF_INET, None)
if addresses is None:
continue
for link in addresses:
if link is not None:
yield link['addr']
@pyqtProperty(int)
def cursor_x(self):
cursor = QCursor().pos()
return cursor.x()
@pyqtProperty(int)
def cursor_y(self):
cursor = QCursor().pos()
return cursor.y()
# Qt Slots
@pyqtSlot(str, int, int, bool, bool)
def createVirtScreen(self, device, width, height, portrait, hidpi, pos=''):
@ -707,6 +684,43 @@ class Backend(QObject):
QApplication.instance().quit()
class Cursor(QObject):
""" Global mouse cursor position """
def __init__(self, parent=None):
super(Cursor, self).__init__(parent)
@pyqtProperty(int)
def x(self):
cursor = QCursor().pos()
return cursor.x()
@pyqtProperty(int)
def y(self):
cursor = QCursor().pos()
return cursor.y()
class Network(QObject):
""" Backend class for network interfaces """
onIPAddressesChanged = pyqtSignal()
def __init__(self, parent=None):
super(Network, self).__init__(parent)
@pyqtProperty('QStringList', notify=onIPAddressesChanged)
def ipAddresses(self):
for interface in interfaces():
if interface == 'lo':
continue
addresses = ifaddresses(interface).get(AF_INET, None)
if addresses is None:
continue
for link in addresses:
if link is not None:
yield link['addr']
# -------------------------------------------------------------------------------
# Main Code
# -------------------------------------------------------------------------------
@ -800,6 +814,8 @@ def main_gui():
# will be called 'Person' in QML.
qmlRegisterType(DisplayProperty, 'VirtScreen.DisplayProperty', 1, 0, 'DisplayProperty')
qmlRegisterType(Backend, 'VirtScreen.Backend', 1, 0, 'Backend')
qmlRegisterType(Cursor, 'VirtScreen.Cursor', 1, 0, 'Cursor')
qmlRegisterType(Network, 'VirtScreen.Network', 1, 0, 'Network')
# Create a component factory and load the QML script.
engine = QQmlApplicationEngine()