mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix(power): 电池图标需求变更
按照新需求确定一下电池电量每个阶段对应的图标,增加一个满电时电源插入时的电量图标 Log: 电池图标需求变更 Bug: https://pms.uniontech.com/zentao/bug-view-34462.html
This commit is contained in:
parent
c1c3633103
commit
d0b1e3550d
@ -1037,8 +1037,8 @@ void MainWindow::onRegionMonitorChanged(int x, int y, const QString &key)
|
||||
void MainWindow::updateRegionMonitorWatch()
|
||||
{
|
||||
if (!m_registerKey.isEmpty()) {
|
||||
m_eventInter->UnregisterArea(m_registerKey);
|
||||
qDebug() << "register area clear";
|
||||
bool ret = m_eventInter->UnregisterArea(m_registerKey);
|
||||
qDebug() << "register area clear:" << ret;
|
||||
m_registerKey.clear();
|
||||
}
|
||||
|
||||
|
@ -33,15 +33,6 @@
|
||||
|
||||
using SystemPowerInter = com::deepin::system::Power;
|
||||
|
||||
// from https://upower.freedesktop.org/docs/Device.html#Device:State
|
||||
enum BatteryState {
|
||||
UNKNOWN = 0, // 未知
|
||||
CHARGING = 1, // 充电中
|
||||
DIS_CHARGING = 2, // 放电
|
||||
NOT_CHARGED = 3, // 未充
|
||||
FULLY_CHARGED = 4 // 充满
|
||||
};
|
||||
|
||||
class PowerPlugin : public QObject, PluginsItemInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -67,14 +67,14 @@ QPixmap PowerStatusWidget::getBatteryIcon()
|
||||
const BatteryPercentageMap data = m_powerInter->batteryPercentage();
|
||||
const uint value = uint(qMin(100.0, qMax(0.0, data.value("Display"))));
|
||||
const int percentage = int(std::round(value));
|
||||
// onBattery应该表示的是当前是否使用电池在供电,为true表示没插入电源
|
||||
const bool plugged = !m_powerInter->onBattery();
|
||||
const BatteryState batteryState = static_cast<BatteryState>(m_powerInter->batteryState()["Display"]);
|
||||
|
||||
/*根据新需求,电池电量显示分别是*/
|
||||
/* 0-5%、6-10%、11%-20%、21-30%、31-40%、41-50%、51-60%、61%-70%、71-80%、81-90%、91-100% */
|
||||
QString percentageStr;
|
||||
if (percentage < 0) {
|
||||
percentageStr = "000";
|
||||
} else if (percentage <= 5 && percentage >= 0) {
|
||||
if (percentage <= 5) {
|
||||
percentageStr = "000";
|
||||
} else if (percentage <= 10) {
|
||||
percentageStr = "010";
|
||||
@ -100,9 +100,14 @@ QPixmap PowerStatusWidget::getBatteryIcon()
|
||||
percentageStr = "100";
|
||||
}
|
||||
|
||||
QString iconStr = QString("battery-%1-%2")
|
||||
.arg(percentageStr)
|
||||
.arg(plugged ? "plugged-symbolic" : "symbolic");
|
||||
QString iconStr;
|
||||
if (batteryState == BatteryState::FULLY_CHARGED && plugged) {
|
||||
iconStr = QString("battery-full-charged-symbolic");
|
||||
} else {
|
||||
iconStr = QString("battery-%1-%2")
|
||||
.arg(percentageStr)
|
||||
.arg(plugged ? "plugged-symbolic" : "symbolic");
|
||||
}
|
||||
|
||||
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
||||
iconStr.append(PLUGIN_MIN_ICON_NAME);
|
||||
|
@ -28,6 +28,15 @@
|
||||
|
||||
#define POWER_KEY "power"
|
||||
|
||||
// from https://upower.freedesktop.org/docs/Device.html#Device:State
|
||||
enum BatteryState {
|
||||
UNKNOWN = 0, // 未知
|
||||
CHARGING = 1, // 充电中
|
||||
DIS_CHARGING = 2, // 放电
|
||||
NOT_CHARGED = 3, // 未充
|
||||
FULLY_CHARGED = 4 // 充满
|
||||
};
|
||||
|
||||
class PowerStatusWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Loading…
x
Reference in New Issue
Block a user