2 // C++ Implementation: batteryicon
4 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
6 // Copyright: See COPYING file that comes with this distribution
8 #include "batteryicon.h"
17 CBatteryIcon::CBatteryIcon(QString batteryName
, Settings
* settings
, QMenu
* contextMenu
, QObject
* parent
) :
18 QSystemTrayIcon(parent
),
19 m_BatteryName(batteryName
),
23 m_Icon
.fill(Qt::transparent
);
25 setContextMenu(contextMenu
);
30 CBatteryIcon::~CBatteryIcon() {
33 void CBatteryIcon::updateData(int chargeFull
, int chargeFullDesign
, int chargeNow
, int currentNow
, int status
) {
34 QString newToolTip
= tr("QBat - %1: %2%").arg(m_BatteryName
) +'\n';
37 newToolTip
= newToolTip
.arg((int)(100.0 * chargeNow
/ chargeFull
));
39 newToolTip
= newToolTip
.arg('-');
42 case UI_BATTERY_DISCHARGING
:
43 newToolTip
+= tr("status: %1").arg(tr("dischaging"));
46 qreal remainingTime
= (qreal
)chargeNow
/ (qreal
)currentNow
;
47 int remainingHours
= (int)remainingTime
;
48 int remainungMinutes
= (int)(remainingTime
* 60) % 60;
49 newToolTip
+= tr("remaining time: %1:%2").arg(remainingHours
, 2, 10, QChar('0')).arg(remainungMinutes
, 2, 10, QChar('0'));
52 case UI_BATTERY_CHARGING
:
53 newToolTip
+= tr("status: %1").arg(tr("charging"));
56 newToolTip
+= tr("status: %1").arg(tr("full"));
59 newToolTip
+= tr("status: %1").arg(tr("unknown"));
64 if (status
!= UI_BATTERY_FULL
)
65 newToolTip
+= tr("current rate: %1A").arg(qRound(currentNow
/ 100000.0) / 10.0) + '\n';
67 newToolTip
+= tr("current capacity: %2mAh").arg(chargeNow
/ 1000) + '\n';
70 newToolTip
+= tr("last full capacity: %3mAh").arg(chargeFull
/ 1000) + '\n';
73 newToolTip
+= tr("design capacity: %4mAh").arg(chargeFullDesign
/ 1000);
75 setToolTip(newToolTip
);
76 m_Icon
.fill(Qt::transparent
);
78 QPainter
painter(&m_Icon
);
80 if (chargeNow
!= chargeFull
) {
81 painter
.setPen(QColor(m_Settings
->colors
[UI_COLOR_PEN
]));
82 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_EMPTY
]));
83 painter
.drawRect(0, 5, 31, 26);
85 painter
.setPen(Qt::NoPen
);
86 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_CHARGED
]));
87 painter
.drawRect(1, 6 + 25 - (int)(25.0 * chargeNow
/ chargeFull
), 30, (int)(25.0 * chargeNow
/ chargeFull
));
89 painter
.setPen(QColor(m_Settings
->colors
[UI_COLOR_PEN
]));
90 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_POLE
]));
93 painter
.setPen(QColor(m_Settings
->colors
[UI_COLOR_PEN_FULL
]));
94 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_FULL
]));
95 painter
.drawRect(0, 5, 31, 26);
97 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_POLE_FULL
]));
99 painter
.drawRect(9, 0, 13, 5);
101 painter
.setBrush(Qt::NoBrush
);
102 painter
.font().setPixelSize(16);
103 painter
.drawText(1, 12, 30, 16, Qt::AlignHCenter
, QString::number((int)(100.0 * chargeNow
/ chargeFull
)));