Minor UI updates

This commit is contained in:
Alex Spataru 2022-02-28 11:39:37 -06:00
parent 4034ed39c4
commit a0b8dfcfc1
3 changed files with 57 additions and 0 deletions

View File

@ -80,6 +80,7 @@ Control {
opacity: enabled ? 1 : 0.5 opacity: enabled ? 1 : 0.5
icon.color: Cpp_ThemeManager.text icon.color: Cpp_ThemeManager.text
icon.source: "qrc:/icons/refresh.svg" icon.source: "qrc:/icons/refresh.svg"
enabled: !Cpp_IO_Bluetooth.isScanning
onClicked: Cpp_IO_Bluetooth.beginScanning() onClicked: Cpp_IO_Bluetooth.beginScanning()
} }
} }
@ -114,6 +115,7 @@ Control {
// //
RowLayout { RowLayout {
spacing: app.spacing spacing: app.spacing
visible: _deviceCombo.currentIndex >= 1
Label { Label {
id: rssiLabel id: rssiLabel
@ -163,6 +165,30 @@ Control {
} }
} }
//
// Not at BLE device warning
//
RowLayout {
spacing: app.spacing
visible: opacity > 0
opacity: Cpp_IO_Bluetooth.isScanning ? 1 : 0
Behavior on opacity {NumberAnimation{}}
BusyIndicator {
width: 16
height: 16
Layout.minimumWidth: 16
Layout.minimumHeight: 16
running: Cpp_IO_Bluetooth.isScanning
}
Label {
Layout.fillWidth: true
text: qsTr("Scanning....")
}
}
// //
// Spacer // Spacer
// //

View File

@ -32,6 +32,12 @@ IO::DataSources::Bluetooth::Bluetooth()
&IO::DataSources::Bluetooth::deviceUpdated); &IO::DataSources::Bluetooth::deviceUpdated);
connect(&m_discovery, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, connect(&m_discovery, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this,
&IO::DataSources::Bluetooth::deviceDiscovered); &IO::DataSources::Bluetooth::deviceDiscovered);
connect(&m_discovery, &QBluetoothDeviceDiscoveryAgent::canceled, this,
&IO::DataSources::Bluetooth::scanningChanged);
connect(&m_discovery, &QBluetoothDeviceDiscoveryAgent::finished, this,
&IO::DataSources::Bluetooth::scanningChanged);
connect(&m_discovery, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this,
SLOT(onErrorOcurred(QBluetoothDeviceDiscoveryAgent::Error)));
// Start the device discovery process // Start the device discovery process
QTimer::singleShot(1000, this, &IO::DataSources::Bluetooth::beginScanning); QTimer::singleShot(1000, this, &IO::DataSources::Bluetooth::beginScanning);
@ -67,6 +73,15 @@ bool IO::DataSources::Bluetooth::supported() const
return m_supported; return m_supported;
} }
/**
* Returns @c true if the bluetooth discovery service is searching
* for devices
*/
bool IO::DataSources::Bluetooth::isScanning() const
{
return m_discovery.isActive();
}
/** /**
* Returns the index of the currently selected device * Returns the index of the currently selected device
*/ */
@ -113,6 +128,7 @@ void IO::DataSources::Bluetooth::beginScanning()
// Update UI // Update UI
Q_EMIT rssiChanged(); Q_EMIT rssiChanged();
Q_EMIT devicesChanged(); Q_EMIT devicesChanged();
Q_EMIT scanningChanged();
Q_EMIT servicesChanged(); Q_EMIT servicesChanged();
Q_EMIT supportedChanged(); Q_EMIT supportedChanged();
Q_EMIT currentDeviceChanged(); Q_EMIT currentDeviceChanged();
@ -226,6 +242,15 @@ void IO::DataSources::Bluetooth::deviceUpdated(const QBluetoothDeviceInfo &info,
refreshDevices(); refreshDevices();
} }
/**
* Prints the device discovery error that have occurred
*/
void IO::DataSources::Bluetooth::onErrorOcurred(
QBluetoothDeviceDiscoveryAgent::Error error)
{
qDebug() << error << m_discovery.errorString();
}
#ifdef SERIAL_STUDIO_INCLUDE_MOC #ifdef SERIAL_STUDIO_INCLUDE_MOC
# include "moc_Bluetooth.cpp" # include "moc_Bluetooth.cpp"
#endif #endif

View File

@ -58,11 +58,15 @@ class Bluetooth : public QObject
Q_PROPERTY(bool supported Q_PROPERTY(bool supported
READ supported READ supported
NOTIFY supportedChanged) NOTIFY supportedChanged)
Q_PROPERTY(bool isScanning
READ isScanning
NOTIFY scanningChanged)
// clang-format on // clang-format on
Q_SIGNALS: Q_SIGNALS:
void rssiChanged(); void rssiChanged();
void devicesChanged(); void devicesChanged();
void scanningChanged();
void servicesChanged(); void servicesChanged();
void supportedChanged(); void supportedChanged();
void currentDeviceChanged(); void currentDeviceChanged();
@ -81,6 +85,7 @@ public:
QString rssi() const; QString rssi() const;
bool supported() const; bool supported() const;
bool isScanning() const;
int currentDevice() const; int currentDevice() const;
QStringList devices() const; QStringList devices() const;
QStringList services() const; QStringList services() const;
@ -94,6 +99,7 @@ private Q_SLOTS:
void deviceDiscovered(const QBluetoothDeviceInfo &info); void deviceDiscovered(const QBluetoothDeviceInfo &info);
void deviceUpdated(const QBluetoothDeviceInfo &info, void deviceUpdated(const QBluetoothDeviceInfo &info,
QBluetoothDeviceInfo::Fields updatedFields); QBluetoothDeviceInfo::Fields updatedFields);
void onErrorOcurred(QBluetoothDeviceDiscoveryAgent::Error error);
private: private:
QString m_rssi; QString m_rssi;