From b3d6d7023e6f9316281abd8cd5094b5455541d6d Mon Sep 17 00:00:00 2001 From: chenhongtao Date: Tue, 26 Sep 2023 17:24:53 +0800 Subject: [PATCH] feat: support set low power percentage Log: --- src/plugin-power/operation/powerdbusproxy.cpp | 10 ++++ src/plugin-power/operation/powerdbusproxy.h | 7 +++ src/plugin-power/operation/powermodel.cpp | 10 ++++ src/plugin-power/operation/powermodel.h | 5 ++ src/plugin-power/operation/powerworker.cpp | 6 +++ src/plugin-power/operation/powerworker.h | 1 + src/plugin-power/window/generalmodule.cpp | 48 +++++++++++++++++++ src/plugin-power/window/generalmodule.h | 1 + 8 files changed, 88 insertions(+) diff --git a/src/plugin-power/operation/powerdbusproxy.cpp b/src/plugin-power/operation/powerdbusproxy.cpp index 8e21ea52b0..a1fffc74d9 100644 --- a/src/plugin-power/operation/powerdbusproxy.cpp +++ b/src/plugin-power/operation/powerdbusproxy.cpp @@ -235,6 +235,16 @@ void PowerDBusProxy::setPowerSavingModeBrightnessDropPercent(uint value) m_sysPowerInter->setProperty("PowerSavingModeBrightnessDropPercent", QVariant::fromValue(value)); } +uint PowerDBusProxy::powerSavingModeAutoBatteryPercent() +{ + return qvariant_cast(m_sysPowerInter->property("PowerSavingModeAutoBatteryPercent")); +} + +void PowerDBusProxy::setPowerSavingModeAutoBatteryPercent(uint value) +{ + m_sysPowerInter->setProperty("PowerSavingModeAutoBatteryPercent", QVariant::fromValue(value)); +} + QString PowerDBusProxy::mode() { return qvariant_cast(m_sysPowerInter->property("Mode")); diff --git a/src/plugin-power/operation/powerdbusproxy.h b/src/plugin-power/operation/powerdbusproxy.h index c04aca4db2..6046887966 100644 --- a/src/plugin-power/operation/powerdbusproxy.h +++ b/src/plugin-power/operation/powerdbusproxy.h @@ -74,9 +74,15 @@ class PowerDBusProxy : public QObject Q_PROPERTY(bool PowerSavingModeAutoWhenBatteryLow READ powerSavingModeAutoWhenBatteryLow WRITE setPowerSavingModeAutoWhenBatteryLow NOTIFY PowerSavingModeAutoWhenBatteryLowChanged) bool powerSavingModeAutoWhenBatteryLow(); void setPowerSavingModeAutoWhenBatteryLow(bool value); + Q_PROPERTY(uint PowerSavingModeBrightnessDropPercent READ powerSavingModeBrightnessDropPercent WRITE setPowerSavingModeBrightnessDropPercent NOTIFY PowerSavingModeBrightnessDropPercentChanged) uint powerSavingModeBrightnessDropPercent(); void setPowerSavingModeBrightnessDropPercent(uint value); + + Q_PROPERTY(uint PowerSavingModeAutoBatteryPercent READ powerSavingModeAutoBatteryPercent WRITE setPowerSavingModeAutoBatteryPercent NOTIFY PowerSavingModeAutoBatteryPercentChanged) + uint powerSavingModeAutoBatteryPercent(); + void setPowerSavingModeAutoBatteryPercent(uint value); + Q_PROPERTY(QString Mode READ mode NOTIFY ModeChanged) QString mode(); Q_PROPERTY(bool PowerSavingModeAuto READ powerSavingModeAuto WRITE setPowerSavingModeAuto NOTIFY PowerSavingModeAutoChanged) @@ -117,6 +123,7 @@ class PowerDBusProxy : public QObject void BatteryPercentageChanged(double value) const; void PowerSavingModeAutoWhenBatteryLowChanged(bool value) const; void PowerSavingModeBrightnessDropPercentChanged(uint value) const; + void PowerSavingModeAutoBatteryPercentChanged(uint value) const; void ModeChanged(const QString &value) const; void BatteryCapacityChanged(double value) const; diff --git a/src/plugin-power/operation/powermodel.cpp b/src/plugin-power/operation/powermodel.cpp index 64c9766036..d86584dd43 100644 --- a/src/plugin-power/operation/powermodel.cpp +++ b/src/plugin-power/operation/powermodel.cpp @@ -27,6 +27,7 @@ PowerModel::PowerModel(QObject *parent) , m_bPowerSavingModeAutoWhenQuantifyLow(0) , m_bPowerSavingModeAuto(false) , m_dPowerSavingModeLowerBrightnessThreshold(0) + , m_dPowerSavingModeAutoBatteryPercentage(0) , m_nLinePowerPressPowerBtnAction(0) , m_nLinePowerLidClosedAction(0) , m_nBatteryPressPowerBtnAction(0) @@ -204,6 +205,15 @@ void PowerModel::setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingMod } } +void PowerModel::setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModeAutoBatteryPercentage) +{ + if (dPowerSavingModeAutoBatteryPercentage != m_dPowerSavingModeAutoBatteryPercentage) { + m_dPowerSavingModeAutoBatteryPercentage = dPowerSavingModeAutoBatteryPercentage; + + Q_EMIT powerSavingModeAutoBatteryPercentageChanged(dPowerSavingModeAutoBatteryPercentage); + } +} + void PowerModel::setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction) { if (nLinePowerPressPowerBtnAction != m_nLinePowerPressPowerBtnAction) { diff --git a/src/plugin-power/operation/powermodel.h b/src/plugin-power/operation/powermodel.h index 24da35c56e..937a009928 100644 --- a/src/plugin-power/operation/powermodel.h +++ b/src/plugin-power/operation/powermodel.h @@ -80,6 +80,9 @@ class PowerModel : public QObject inline int powerSavingModeLowerBrightnessThreshold() const { return m_dPowerSavingModeLowerBrightnessThreshold; } void setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingModeLowerBrightnessThreshold); + inline int powerSavingModeAutoBatteryPercentage() const { return m_dPowerSavingModeAutoBatteryPercentage; } + void setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModeAutoBatteryPercentage); + inline int linePowerPressPowerBtnAction() const { return m_nLinePowerPressPowerBtnAction; } void setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction); @@ -146,6 +149,7 @@ class PowerModel : public QObject void powerSavingModeAutoWhenQuantifyLowChanged(const bool state); void powerSavingModeAutoChanged(const bool state); void powerSavingModeLowerBrightnessThresholdChanged(const uint level); + void powerSavingModeAutoBatteryPercentageChanged(const uint level); //electric void linePowerPressPowerBtnActionChanged(const int reply); void linePowerLidClosedActionChanged(const int reply); @@ -184,6 +188,7 @@ class PowerModel : public QObject bool m_bPowerSavingModeAutoWhenQuantifyLow; bool m_bPowerSavingModeAuto; uint m_dPowerSavingModeLowerBrightnessThreshold; + uint m_dPowerSavingModeAutoBatteryPercentage; int m_nLinePowerPressPowerBtnAction; int m_nLinePowerLidClosedAction; int m_nBatteryPressPowerBtnAction; diff --git a/src/plugin-power/operation/powerworker.cpp b/src/plugin-power/operation/powerworker.cpp index 4ba6a8239a..611b5003a8 100644 --- a/src/plugin-power/operation/powerworker.cpp +++ b/src/plugin-power/operation/powerworker.cpp @@ -44,6 +44,7 @@ PowerWorker::PowerWorker(PowerModel *model, QObject *parent) connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeAutoWhenBatteryLowChanged, m_powerModel, &PowerModel::setPowerSavingModeAutoWhenQuantifyLow); connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeAutoChanged, m_powerModel, &PowerModel::setPowerSavingModeAuto); connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeBrightnessDropPercentChanged, m_powerModel, &PowerModel::setPowerSavingModeLowerBrightnessThreshold); + connect(m_powerDBusProxy, &PowerDBusProxy::PowerSavingModeAutoBatteryPercentChanged, m_powerModel, &PowerModel::setPowerSavingModeAutoBatteryPercentage); connect(m_powerDBusProxy, &PowerDBusProxy::LinePowerPressPowerBtnActionChanged, m_powerModel, &PowerModel::setLinePowerPressPowerBtnAction); connect(m_powerDBusProxy, &PowerDBusProxy::LinePowerLidClosedActionChanged, m_powerModel, &PowerModel::setLinePowerLidClosedAction); connect(m_powerDBusProxy, &PowerDBusProxy::BatteryPressPowerBtnActionChanged, m_powerModel, &PowerModel::setBatteryPressPowerBtnAction); @@ -214,6 +215,11 @@ void PowerWorker::setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingMo m_powerDBusProxy->setPowerSavingModeBrightnessDropPercent(dPowerSavingModeLowerBrightnessThreshold); } +void PowerWorker::setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModeBatteryPercentage) +{ + m_powerDBusProxy->setPowerSavingModeAutoBatteryPercent(dPowerSavingModeBatteryPercentage); +} + void PowerWorker::setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction) { m_powerDBusProxy->setLinePowerPressPowerBtnAction(nLinePowerPressPowerBtnAction); diff --git a/src/plugin-power/operation/powerworker.h b/src/plugin-power/operation/powerworker.h index 6693d2c66b..8627a836f0 100644 --- a/src/plugin-power/operation/powerworker.h +++ b/src/plugin-power/operation/powerworker.h @@ -39,6 +39,7 @@ public Q_SLOTS: void setPowerSavingModeAutoWhenQuantifyLow(bool bLowBatteryAutoIntoSaveEnergyMode); void setPowerSavingModeAuto(bool bAutoIntoSaveEnergyMode); void setPowerSavingModeLowerBrightnessThreshold(uint dPowerSavingModeLowerBrightnessThreshold); + void setPowerSavingModeAutoBatteryPercentage(uint dPowerSavingModebatteryPentage); void setLinePowerPressPowerBtnAction(int nLinePowerPressPowerBtnAction); void setLinePowerLidClosedAction(int nLinePowerLidClosedAction); void setBatteryPressPowerBtnAction(int nBatteryPressPowerBtnAction); diff --git a/src/plugin-power/window/generalmodule.cpp b/src/plugin-power/window/generalmodule.cpp index e828883ce8..92055c0c8f 100644 --- a/src/plugin-power/window/generalmodule.cpp +++ b/src/plugin-power/window/generalmodule.cpp @@ -59,6 +59,10 @@ GeneralModule::GeneralModule(PowerModel *model, PowerWorker *work, QObject *pare &GeneralModule::requestSetPowerSavingModeLowerBrightnessThreshold, m_work, &PowerWorker::setPowerSavingModeLowerBrightnessThreshold); + connect(this, + &GeneralModule::requestSetPowerSavingModeAutoBatteryPercentage, + m_work, + &PowerWorker::setPowerSavingModeAutoBatteryPercentage); connect(this, &GeneralModule::requestSetPowerPlan, m_work, &PowerWorker::setPowerPlan); initUI(); } @@ -198,7 +202,51 @@ void GeneralModule::initUI() itemAutoPowerSavingOnLowBattery, &ItemModule::setVisible); group->appendChild(itemAutoPowerSavingOnLowBattery); + ItemModule *itemAutoPowerSavingOnBatterySlider = new ItemModule( + "decreaseBrightness", + tr("Decrease Brightness"), + [this](ModuleObject *module) -> QWidget * { + Q_UNUSED(module) + TitledSliderItem *sldLowerBrightness = + new TitledSliderItem(tr("Battery Percentage when enter power saving")); + sldLowerBrightness->setAccessibleName("Battery Percentage when enter power saving"); + QStringList annotions; + annotions << "10%" + << "20%" + << "30%" + << "50%" + << "40%"; + sldLowerBrightness->setAnnotations(annotions); + sldLowerBrightness->slider()->setRange(1, 5); + sldLowerBrightness->slider()->setPageStep(10); + sldLowerBrightness->slider()->setType(DCCSlider::Vernier); + sldLowerBrightness->slider()->setTickPosition(QSlider::NoTicks); + sldLowerBrightness->setValueLiteral( + QString("%1%").arg(m_model->powerSavingModeAutoBatteryPercentage())); + connect(m_model, + &PowerModel::powerSavingModeLowerBrightnessThresholdChanged, + sldLowerBrightness, + [sldLowerBrightness](const uint dLevel) { + sldLowerBrightness->slider()->blockSignals(true); + sldLowerBrightness->slider()->setValue(dLevel / 10); + sldLowerBrightness->slider()->blockSignals(false); + }); + connect(sldLowerBrightness->slider(), + &DCCSlider::valueChanged, + this, + [=](int value) { + sldLowerBrightness->setValueLiteral(annotions[value - 1]); + Q_EMIT requestSetPowerSavingModeAutoBatteryPercentage(value * 10); + }); + return sldLowerBrightness; + }, + false); + itemAutoPowerSavingOnBatterySlider->setVisible(m_model->haveBettary()); + connect(m_model, + &PowerModel::haveBettaryChanged, + itemAutoPowerSavingOnBatterySlider, + &ItemModule::setVisible); ItemModule *itemAutoPowerSavingOnBattery = new ItemModule("autoPowerSavingOnBattery", tr("Auto power saving on battery"), diff --git a/src/plugin-power/window/generalmodule.h b/src/plugin-power/window/generalmodule.h index 2f08942e72..f9c861876d 100644 --- a/src/plugin-power/window/generalmodule.h +++ b/src/plugin-power/window/generalmodule.h @@ -36,6 +36,7 @@ class GeneralModule : public DCC_NAMESPACE::PageModule void requestSetWakeDisplay(const bool &state); // 唤醒显示器输入密码 void requestSetPowerSaveMode(const bool &state); // 节能模式 void requestSetPowerSavingModeLowerBrightnessThreshold(const int &level); // 节能模式亮度降低 + void requestSetPowerSavingModeAutoBatteryPercentage(const int &level); // 节能模式亮度降低 void requestSetPowerPlan(const QString &powerPlan); // 性能模式的设置 public Q_SLOTS: