reuse updateChargingStatus

This commit is contained in:
uncor3
2026-04-08 18:19:44 +03:00
parent 384d7a2587
commit 6934d48bb3
2 changed files with 28 additions and 17 deletions
+27 -16
View File
@@ -140,7 +140,6 @@ DeviceInfoWidget::DeviceInfoWidget(
m_lightningIconLabel =
new ZIconLabel(QIcon(":/resources/icons/MdiLightningBolt.png"),
" Charging", 1.0, this);
updateChargingStatusIcon();
m_batteryWidget = new BatteryWidget(
qBound<int>(1, device->deviceInfo.batteryInfo.currentBatteryLevel, 100),
@@ -151,12 +150,9 @@ DeviceInfoWidget::DeviceInfoWidget(
chargingLayout->addWidget(m_lightningIconLabel);
chargingLayout->addWidget(m_batteryWidget);
m_chargingWattsWithCableTypeLabel = new QLabel(
QString::number(device->deviceInfo.batteryInfo.watts) + "W" + "/" +
(device->deviceInfo.batteryInfo.usbConnectionType ==
BatteryInfo::ConnectionType::USB
? "USB"
: "USB-C"));
m_chargingWattsWithCableTypeLabel = new QLabel();
updateChargingStatus();
headerLayout->addWidget(devProductType);
headerLayout->addWidget(diskCapacityLabel);
@@ -374,20 +370,35 @@ void DeviceInfoWidget::updateBatteryInfo(const QString &diagnostics)
else
parseDeviceBattery(xml_doc, d);
/*UI*/
updateChargingStatusIcon();
m_chargingWattsWithCableTypeLabel->setText(
QString::number(d.batteryInfo.watts) + "W" + "/" +
(d.batteryInfo.usbConnectionType == BatteryInfo::ConnectionType::USB
? "USB"
: "USB-C"));
updateChargingStatus();
}
void DeviceInfoWidget::updateChargingStatus()
{
auto &d = m_device->deviceInfo;
int watts = d.batteryInfo.watts;
auto setValues = [this, d]() {
m_chargingWattsWithCableTypeLabel->setText(
QString::number(d.batteryInfo.watts) + "W" + "/" +
(d.batteryInfo.usbConnectionType == BatteryInfo::ConnectionType::USB
? "USB"
: "USB-C"));
};
// watts can be 0 device is not charging
if (watts) {
setValues();
} else if (d.isWireless) {
m_chargingWattsWithCableTypeLabel->setText("Wireless");
} else {
setValues();
}
m_batteryWidget->updateContext(
d.batteryInfo.isCharging,
qBound<int>(1, d.batteryInfo.currentBatteryLevel, 100));
}
void DeviceInfoWidget::updateChargingStatusIcon()
{
if (m_device->deviceInfo.batteryInfo.isCharging) {
m_chargingStatusLabel->setText("Charging");
m_chargingStatusLabel->setStyleSheet(
+1 -1
View File
@@ -56,7 +56,7 @@ private slots:
private:
const std::shared_ptr<iDescriptorDevice> m_device;
void updateBatteryInfo(const QString &diagnostics);
void updateChargingStatusIcon();
void updateChargingStatus();
QLabel *m_chargingStatusLabel;
QLabel *m_chargingWattsWithCableTypeLabel;
BatteryWidget *m_batteryWidget;