You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
10 KiB

6 months ago
/******************************************************************
Copyright © Deng Zhimao Co., Ltd. 1990-2030. All rights reserved.
* @projectName wireless
* @brief MyWireless.qml
* @author Deng Zhimao
* @email 1252699831@qq.com
* @date 2020-07-01
*******************************************************************/
import wirelessModel 1.0
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.1
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11
import QtQuick.Window 2.11
import QtQuick.VirtualKeyboard 2.2
import an.qml.comnet 1.0
import "./set/helpbutton"
import "./set/wireless"
ApplicationWindow {
id: window
visible: true
property int mystate
property bool wirelessonFlag: true
width: WINenv ? 800 : Screen.desktopAvailableWidth
height: WINenv ? 480 : Screen.desktopAvailableHeight
property bool smallScreen: width == 480 ? true : false
color: "#1f1e58"
onVisibleChanged: {
formState.state == 'right' ? formState.state = '' : formState.state = 'right'
}
Component.onCompleted: {
window.x = parent.width
}
Item {
id: formState
states: State {
name: "right"
PropertyChanges {
target: window
x: 0
}
}
transitions: Transition {
NumberAnimation {
property: "x"
easing.type: Easing.InOutQuart
duration: 500
}
}
}
Comnet{
id:setapp;
onValueFromCpp:{
console.log("value from cpp :" + val);
window.close()
}
}
Button{
display: AbstractButton.IconOnly //只显示icon
icon.source: "/set/wireless/imges/return.png"
icon.width:40 //宽度
icon.height:40 //高度
icon.color:"transparent" //颜色
x:0 // 设置按钮的横坐标
y:0 // 设置纵坐标
width: 40
height: 40
// 信号槽连接
onClicked:
{
setapp.getValFromQml(123);
// console.log(lockRect.destroy());
}
}
WirelessListModel {
id: myWirelessListModel
onCurrentIndexChanged: {
playList.currentIndex = currentIndex
}
onReturnMainWinWifiResult: {
mystate = state
}
onWirelessReadyChanged: {
if (readyFlag)
wlanText.text = "WLAN"
}
}
MyWifiKeyInput{
id: wifiDialog
x: 0
y: 0
height: parent.height
width: parent.width
onToggleConnet: {
if (wifiDialog.pskValue != "")
myWirelessListModel.getMyWifiSSIDPSK(wifiDialog.ssidValue, wifiDialog.pskValue)
else
myWirelessListModel.passwordLessConnection(wifiDialog.ssidValue)
}
}
ListView {
id: playList
visible: true
anchors.top: parent.top
anchors.topMargin: 135
anchors.left: parent.left
anchors.bottom: parent.bottom
width: parent.width
orientation:ListView.Vertical
clip: true
z: 1
spacing: 5
model: myWirelessListModel
delegate: Rectangle {
id: itembg
width: playList.width
height: 50
color: mouserArea.pressed ? Qt.rgba(46, 46, 46, 0.1) : "transparent"
MouseArea {
id: mouserArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
mystate = 0
myWirelessListModel.currentIndex = index
//console.log(wifiName.text)
wifiDialog.ssidValue = wifiName.text
wifiDialog.message = "请输入" + (wifiName.text + "的密码")
wifiDialog.open()
}
}
Text {
id: wifiName
verticalAlignment: Text.AlignVCenter
height: 50
anchors.right: parent.right
anchors.rightMargin: 150
anchors.left: wifiLevelIcon.right
anchors.leftMargin: 20
text: title
elide: Text.ElideRight
color: mouserArea.pressed ? "#0a7ad8" : "white"
font.pixelSize: 20
}
Image {
id: wifiLevelIcon
anchors.left: parent.left
anchors.leftMargin: 20
anchors.verticalCenter: parent.verticalCenter
width: 30
height: 22
source: wifilevl(level)
function wifilevl(arg){
var intArg = parseInt(arg)
switch (intArg){
case 0:
return "qrc:/set/wireless/imges/level0.png"
case 1:
return "qrc:/set/wireless/imges/level1.png"
case 2:
return "qrc:/set/wireless/imges/level2.png"
case 3:
return "qrc:/set/wireless/imges/level3.png"
case 4:
return "qrc:/set/wireless/imges/level4.png"
case 5:
return "qrc:/set/wireless/imges/level5.png"
default:
return "qrc:/set/wireless/imges/level5.png"
}
}
}
Text {
id: connectStateText
text: connectsate()
anchors.left: wifiName.right
anchors.leftMargin: 5
anchors.right: parent.right
horizontalAlignment:Text.AlignHCenter
anchors.verticalCenter: parent.verticalCenter
color: "white"
function connectsate(){
if (wifiDialog.ssidValue === wifiName.text) {
switch (mystate){
case 1:
return qsTr("已连接")
case 2:
return qsTr("密码错误/已断开")
case 3:
return qsTr("正在连接...")
default:
return qsTr("")
}
} else return qsTr("")
}
}
}
}
Item {
anchors.top: parent.top
anchors.bottom: playList.top
anchors.right: parent.right
anchors.left: parent.left
Text {
id: wlanText
width: parent.width - 100
anchors.top: parent.top
anchors.topMargin: 50
anchors.left: parent.left
anchors.leftMargin: 20
verticalAlignment: Text.AlignVCenter
font.pointSize: 15
text: qsTr("WLAN")
color: "#27d7f0"
}
Text {
id: refreshText
width: 100
anchors.verticalCenter: refreshBtn.verticalCenter
anchors.left: wlanText.left
verticalAlignment: Text.AlignVCenter
font.pointSize: 15
text: qsTr("选取附近的WLAN")
color: "#27d7f0"
}
RoundButton {
id: refreshBtn
width: 50
height: 50
enabled: wlanSwitch.checked
opacity: wlanSwitch.checked ? 1 : 0
anchors.top: wlanSwitch.bottom
anchors.horizontalCenter: wlanSwitch.horizontalCenter
Image {
id: refreshImage
width: 20
height: 20
anchors.centerIn: parent
source: "qrc:/set/wireless/imges/refresh.png"
}
background: Rectangle {
anchors.fill: parent
color: "transparent"
}
onClicked: {
//if (wlanSwitch.checked) {
refreshAnima.running = true
wlanText.text = "Scanning..."
//}
if(playList.count != 0 && wlanSwitch.checked)
myWirelessListModel.remove(0, playList.count - 1)
}
RotationAnimator {
id: refreshAnima
target: refreshBtn
from: 0
to: 360
duration: 1000
//loops: Animation.Infinite
running: false
onRunningChanged: {
if (running === false) {
from = refreshBtn.rotation;
to = from+360;
}
}
onStopped: {
if (wlanSwitch.checked) {
myWirelessListModel.wirelessInit()
}
}
}
}
Switch{
id: wlanSwitch
hoverEnabled: true
anchors.verticalCenter: wlanText.verticalCenter
anchors.left: wlanText.right
onPressed: {
if (wirelessonFlag)
wlanText.text = "Scanning..."
else
wlanText.text = "WLAN"
wirelessonFlag = !wirelessonFlag
}
onToggled: {
if(checked){
//console.log("ok")
//if(!WINenv)
myWirelessListModel.wirelessInit()
}
else {
if(playList.count != 0)
myWirelessListModel.remove(0, playList.count - 1)
if(!WINenv)
myWirelessListModel.wirelessClose()
mystate = 0
//console.log("no")
}
}
//onCheckableChanged: {}
}
Rectangle {
id: line
height: 1
color: "#27d7f0"
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.leftMargin: 20
anchors.right: parent.right
anchors.rightMargin: 20
}
}
}