scanner.qml Example File
declarative-connectivity/scanner/scanner.qml
import Qt 4.7
import QtMobility.connectivity 1.2
Rectangle {
id: top
property BluetoothService currentService
property alias minimalDiscovery: myModel.minimalDiscovery
property alias uuidFilder: myModel.uuidFilter
anchors.fill: parent
BluetoothDiscoveryModel {
id: myModel
minimalDiscovery: true
onDiscoveryChanged: busy.running = discovery;
}
Rectangle {
id: busy
property bool running: true
width: top.width/1.2;
x: top.width/2-width/2
anchors.top: top.top;
height: 20;
radius: 5
color: "#1c56f3"
Text {
id: text
text: "<b>Scanning</b>"
x: busy.width/2-paintedWidth/2
y: busy.height/2-paintedHeight/2
}
SequentialAnimation on color {
id: busyThrobber
ColorAnimation { easing.type: Easing.InOutSine; from: "#1c56f3"; to: "white"; duration: 1000; }
ColorAnimation { easing.type: Easing.InOutSine; to: "#1c56f3"; from: "white"; duration: 1000 }
loops: Animation.Infinite
}
states: [
State {
name: "stopped"
when: !busy.running
PropertyChanges { target: busy; height: 0; }
PropertyChanges { target: busyThrobber; running: false }
PropertyChanges { target: text; visible: false }
}
]
transitions: [
Transition {
from: "*"
to: "stopped"
reversible: true
NumberAnimation { target: busy; property: "height"; to: 0; duration: 200 }
}
]
}
Component {
id: del;
Item {
id: item
function item_clicked(service) {
console.log("Clicked " + service.deviceName + service.deviceAddress);
top.currentService = service;
}
property int text_height: 5+(bticon.height > bttext.height ? bticon.height : bttext.height)
height: text_height
width: parent.width
Column {
anchors.fill: item
Row {
width: parent.width
Image {
id: bticon
source: icon;
width: del.height;
}
Text {
id: bttext
text: name;
font.family: "FreeSerif"
font.pointSize: 12
}
}
Text {
function get_details(s) {
var str = "Address: " + s.deviceAddress;
if(s.serviceName) { str += "<br>Service: " + s.serviceName; }
if(s.serviceDescription) { str += "<br>Description: " + s.serviceDescription; }
if(s.serviceProtocol) { str += "<br>Port: " + s.serviceProtocol; }
if(s.servicePort) { str += "<br>Port: " + s.servicePort; }
return str;
}
id: details
opacity: 0.0
text: get_details(service)
font: bttext.font
x: bticon.width
}
}
MouseArea {
anchors.fill: parent
onClicked: item.state = ((item.state == "details") ? "" : "details")
}
states: [
State {
name: "details"
PropertyChanges { target: item; height: item.text_height+details.height; }
PropertyChanges { target: details; opacity: 1.0 }
}
]
transitions: [
Transition {
from: "*"
to: "details"
reversible: true
NumberAnimation { target: item; property: "height"; duration: 200 }
NumberAnimation { target: details; property: "lopacity"; duration: 200 }
}
]
}
}
Component {
id: highlightBox
Rectangle {
id: background
anchors.fill: del
border.color: "#34ca57"
radius: 5
border.width: 2
}
}
ListView {
id: mainList
width: top.width
anchors.top: busy.bottom
anchors.bottom: fullbutton.top
model: myModel
highlight: highlightBox
delegate: del
focus: true
}
Rectangle {
id: fullbutton
function button_clicked() {
myModel.minimalDiscovery = !myModel.minimalDiscovery;
fullbutton.state = fullbutton.state == "clicked" ? "" : "clicked";
myModel.setDiscovery(true);
}
anchors.bottom: top.bottom
anchors.margins: 3
width: top.width-6
x: 3
height: 20
radius: 5
border.width: 1
color: "white"
Text {
id: label
text: "Full Discovery"
x: parent.width/2-paintedWidth/2;
y: parent.height/2-paintedHeight/2;
}
MouseArea {
anchors.fill: parent
onClicked: fullbutton.button_clicked();
}
states: [
State {
name: "clicked"
PropertyChanges { target: fullbutton; color: "#1c56f3" }
}
]
transitions: [
Transition {
from: "*"
to: "details"
reversible: true
ColorAnimation { duration: 200 }
}
]
}
}
[+] Documentation Feedback