mirror of
https://gitdl.cn/https://github.com/chakralinux/desktop.git
synced 2025-01-25 11:02:13 +08:00
94 lines
3.3 KiB
Plaintext
94 lines
3.3 KiB
Plaintext
diff -Naur kdebase-workspace-4.3.98.orig/plasma/generic/applets/battery/battery.cpp kdebase-workspace-4.3.98/plasma/generic/applets/battery/battery.cpp
|
|
--- kdebase-workspace-4.3.98.orig/plasma/generic/applets/battery/battery.cpp 2010-01-31 20:30:45.000000000 +0100
|
|
+++ kdebase-workspace-4.3.98/plasma/generic/applets/battery/battery.cpp 2010-02-01 22:44:24.000000000 +0100
|
|
@@ -61,6 +61,7 @@
|
|
#include <Plasma/CheckBox>
|
|
#include <Plasma/ComboBox>
|
|
#include <Plasma/IconWidget>
|
|
+#include <Plasma/ToolTipManager>
|
|
|
|
|
|
Battery::Battery(QObject *parent, const QVariantList &args)
|
|
@@ -224,6 +225,8 @@
|
|
qRound(contentsRect().height() / 10)));
|
|
update();
|
|
}
|
|
+
|
|
+ Plasma::ToolTipManager::self()->registerWidget(this);
|
|
}
|
|
|
|
void Battery::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data)
|
|
@@ -254,6 +257,11 @@
|
|
setStatus(Plasma::ActiveStatus);
|
|
}
|
|
|
|
+ // if the tooltip is visible, keep the displayed data up-to-date
|
|
+ if (Plasma::ToolTipManager::self()->isVisible(this)) {
|
|
+ toolTipAboutToShow();
|
|
+ }
|
|
+
|
|
updateStatus();
|
|
update();
|
|
}
|
|
@@ -994,4 +1002,47 @@
|
|
return m_acAlpha;
|
|
}
|
|
|
|
+void Battery::toolTipAboutToShow()
|
|
+{
|
|
+ int battery_num = 0;
|
|
+ int battery_charge = 0;
|
|
+ bool has_battery = false;
|
|
+ QHashIterator<QString, QHash<QString, QVariant > > battery_data(m_batteries_data);
|
|
+ while (battery_data.hasNext()) {
|
|
+ battery_data.next();
|
|
+ if (battery_data.value()["Plugged in"].toBool()) {
|
|
+ battery_charge += battery_data.value()["Percent"].toInt();
|
|
+ has_battery = true;
|
|
+ ++battery_num;
|
|
+ }
|
|
+ }
|
|
+ if (battery_num > 1) {
|
|
+ battery_charge = battery_charge / battery_num;
|
|
+ }
|
|
+
|
|
+ QString content = "";
|
|
+ QString state = battery_data.value()["State"].toString();
|
|
+ if (state == "Discharging") {
|
|
+ content += i18n("Discharging: %1% charged", battery_charge);
|
|
+ }
|
|
+ else if (state == "Charging") {
|
|
+ content += i18n("Charging: %1% charged", battery_charge);
|
|
+ }
|
|
+ else if (state == "NoCharge") {
|
|
+ content += i18n("Fully charged (%1%)", battery_charge);
|
|
+ }
|
|
+
|
|
+ if (m_showRemainingTime && (state=="Charging" || state=="Discharging" )) {
|
|
+ QTime t = QTime(m_hours, m_minutes);
|
|
+ KLocale tmpLocale(*KGlobal::locale());
|
|
+ tmpLocale.setTimeFormat("%k:%M");
|
|
+
|
|
+ content += "<br/>";
|
|
+ content += i18n("Estimated time remaining %1").arg(tmpLocale.formatTime(t, false, true)); // minutes, hours as duration
|
|
+ }
|
|
+
|
|
+ Plasma::ToolTipManager::self()->setContent(this, Plasma::ToolTipContent(content, "", KIcon("battery")));
|
|
+}
|
|
+
|
|
+
|
|
#include "battery.moc"
|
|
diff -Naur kdebase-workspace-4.3.98.orig/plasma/generic/applets/battery/battery.h kdebase-workspace-4.3.98/plasma/generic/applets/battery/battery.h
|
|
--- kdebase-workspace-4.3.98.orig/plasma/generic/applets/battery/battery.h 2010-01-20 00:19:14.000000000 +0100
|
|
+++ kdebase-workspace-4.3.98/plasma/generic/applets/battery/battery.h 2010-02-01 22:44:24.000000000 +0100
|
|
@@ -71,7 +71,8 @@
|
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
|
void configAccepted();
|
|
void readColors();
|
|
-
|
|
+ void toolTipAboutToShow();
|
|
+
|
|
protected:
|
|
void createConfigurationInterface(KConfigDialog *parent);
|
|
void setEmbedded(const bool embedded);
|