import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import SortFilterProxyModel 0.2
import Wifi 1.0
import "qrc:/Ui_Controls"
Rectangle {
anchors.fill: parent
color: "black"
function f_setWifiFilter(wifiStatus)
{
if (wifiStatus === WifiManage.WifiConnected ||
wifiStatus === WifiManage.WifiRouterConnected ||
wifiStatus === WifiManage.WifiLinking) {
if (WifiManage.currWifi.mac != "") {
// 将当前wifi过滤
wifiProxyModel.filterStr = String("^((?!%1).)*$").arg(WifiManage.currWifi.mac)
}
} else {
wifiProxyModel.filterStr = "[\\s\\S]"
}
}
Component.onCompleted: {
globalJs.f_getWifiList()
busyIndicator.isRunning = true
f_setWifiFilter(WifiManage.wifiStatus)
}
Connections {
target: dlg
function onSig_accetped(flag) {
if (flag) {
if (WifiManage.currWifi.mac != "") {
// 将当前wifi过滤
wifiProxyModel.filterStr = String("^((?!%1).)*$").arg(WifiManage.currWifi.mac)
}
}
}
}
Connections {
target: WifiManage
function onGetWifiListEnd() {
if (visible) {
busyIndicator.isRunning = false
}
}
function onWifiStatusChanged(wifiStatus) {
if (wifiStatus === WifiManage.WifiConnected ||
wifiStatus === WifiManage.WifiRouterConnected ||
wifiStatus === WifiManage.WifiLinking) {
console.log("________________", WifiManage.currWifi.mac)
if (WifiManage.currWifi.mac != "") {
// 将当前wifi过滤
wifiProxyModel.filterStr = String("^((?!%1).)*$").arg(WifiManage.currWifi.mac)
}
} else {
wifiProxyModel.filterStr = "[\\s\\S]"
}
}
}
// <返回
Item {
id: backItem
width: parent.width
height: lineHeight
MouseArea {
anchors.fill: parent
onClicked: {
wifiStackView.f_pop()
}
}
Image {
anchors.left: parent.left
anchors.leftMargin: 30
anchors.verticalCenter: parent.verticalCenter
source: "qrc:/img/rightArrow.png"
sourceSize: Qt.size(64, 64)
mirror: true
}
Text {
anchors.centerIn: parent
text: qsTr("Wifi")
font.pixelSize: 30
color: "white"
}
}
SortFilterProxyModel {
id: wifiProxyModel
property string filterStr: "[\\s\\S]"
sourceModel: wifiModel
filters: RegExpFilter {
roleName: "mac"
pattern: wifiProxyModel.filterStr
caseSensitivity: Qt.CaseInsensitive
}
sorters: RoleSorter { roleName: "rssi"; sortOrder: Qt.DescendingOrder }
}
Flickable {
id: wifiFlick
clip: true
anchors.top: backItem.bottom
width: parent.width
height: parent.height-backItem.height
contentWidth: width
contentHeight: colLay.height
ScrollBar.vertical: ScrollBar{}
ColumnLayout {
id: colLay
Item {
id: currWifiItem
width: wifiFlick.width
height: 120
visible: {
if (WifiManage.wifiStatus == WifiManage.WifiConnected ||
WifiManage.wifiStatus == WifiManage.WifiRouterConnected ||
WifiManage.wifiStatus == WifiManage.WifiLinking) {
return true
} else {
return false
}
}
Loader {
id: wifiStatusLoader
anchors.verticalCenter: parent.verticalCenter
sourceComponent: {
if (WifiManage.wifiStatus == WifiManage.WifiLinking) {
return connectingCom
} else {
return connectStatusCom
}
}
Component {
id: connectingCom
Item {
width: 94
height: lineHeight
Component.onCompleted: {
wifiBusy.isRunning = true
}
Ui_BusyIndicator {
id: wifiBusy
anchors.left: parent.left
anchors.leftMargin: 30
anchors.verticalCenter: parent.verticalCenter
}
Timer {
interval: 15000
running: wifiBusy.isRunning
repeat: false
onTriggered: {
WifiManage.wifiStatus = WifiManage.WifiNoConnected
wifiBusy.isRunning = false
}
}
}
}
Component {
id: connectStatusCom
Item {
width: 94
height: lineHeight
Image {
anchors.left: parent.left
anchors.leftMargin: 30
anchors.verticalCenter: parent.verticalCenter
sourceSize: Qt.size(44, 44)
source: {
if (WifiManage.wifiStatus == WifiManage.WifiConnected) {
return "qrc:/img/pass.png"
} else {
return "qrc:/img/wifi_error3.png"
}
}
}
}
}
}
Rectangle {
anchors.centerIn: parent
width: parent.width
height: lineHeight
color: listBkgColor
Text {
anchors.left: parent.left
anchors.leftMargin: wifiStatusLoader.width
anchors.verticalCenter: parent.verticalCenter
text: WifiManage.currWifi.name
font.pixelSize: 30
color: "white"
}
Row {
anchors.right: parent.right
anchors.rightMargin: 30
anchors.verticalCenter: parent.verticalCenter
spacing: 20
Image {
visible: WifiManage.currWifi.isLock
source: "qrc:/img/lock.png"
sourceSize: Qt.size(64, 64)
}
Image {
anchors.verticalCenter: parent.verticalCenter
source: switch (WifiManage.currWifi.rssi) {
case 1:
return "qrc:/img/RSSI_1.png"
case 2:
return "qrc:/img/RSSI_2.png"
case 3:
return "qrc:/img/RSSI_3.png"
case 4:
return "qrc:/img/RSSI_4.png"
default:
return "qrc:/img/RSSI.png"
}
sourceSize: Qt.size(64, 64)
}
Image {
source: "qrc:/img/info.png"
sourceSize: Qt.size(64, 64)
}
}
}
}
// 网络
Item {
width: wifiFlick.width
height: 60
Row {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 30
spacing: 20
Text {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("Network")
font.pixelSize: 30
color: "white"
}
Timer {
interval: 15000
running: busyIndicator.isRunning
repeat: false
onTriggered: {
busyIndicator.isRunning = false
}
}
Ui_BusyIndicator {
id: busyIndicator
anchors.verticalCenter: parent.verticalCenter
}
}
}
ListView {
id: wifiView
interactive: false
width: wifiFlick.width
height: count*90
model: wifiProxyModel
delegate: Item {
width: wifiView.width
height: lineHeight
MouseArea {
anchors.fill: parent
onClicked: {
var obj = {}
obj.name = name
obj.isLock = isLock
obj.rssi = rssi
obj.mac = mac
obj.ip = ip
dlg.f_openDlg(0, obj)
}
}
Text {
anchors.left: parent.left
anchors.leftMargin: wifiStatusLoader.width
anchors.verticalCenter: parent.verticalCenter
text: name
font.pixelSize: 30
color: "white"
}
Row {
anchors.right: parent.right
anchors.rightMargin: 30
anchors.verticalCenter: parent.verticalCenter
spacing: 20
Image {
visible: isLock
source: "qrc:/img/lock.png"
sourceSize: Qt.size(64, 64)
}
Image {
anchors.verticalCenter: parent.verticalCenter
source: switch (rssi) {
case 1:
return "qrc:/img/RSSI_1.png"
case 2:
return "qrc:/img/RSSI_2.png"
case 3:
return "qrc:/img/RSSI_3.png"
case 4:
return "qrc:/img/RSSI_4.png"
default:
return "qrc:/img/RSSI.png"
}
sourceSize: Qt.size(64, 64)
}
Image {
source: "qrc:/img/info.png"
sourceSize: Qt.size(64, 64)
}
}
Rectangle {
anchors.bottom: parent.bottom
anchors.right: parent.right
width: parent.width-wifiStatusLoader.width
height: 1
color: "#30FFFFFF"
}
}
}
Item {
width: wifiFlick.width
height: 270
}
}
}
}
qml WIFI列表过滤当前正在连接的wifi
最新推荐文章于 2023-04-07 11:12:05 发布