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
);
77 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, 4, 27, 23);
85 painter
.setPen(Qt::NoPen
);
86 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_CHARGED
]));
88 int chargedPixels
= (int)(21 * (float)chargeNow
/ (float)chargeFull
);
90 painter
.drawRect(1, 1 + 26 - chargedPixels
, 26, chargedPixels
);
92 painter
.setPen(QColor(m_Settings
->colors
[UI_COLOR_PEN
]));
93 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_POLE
]));
96 painter
.setPen(QColor(m_Settings
->colors
[UI_COLOR_PEN_FULL
]));
97 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_FULL
]));
98 painter
.drawRect(0, 4, 27, 23);
100 painter
.setBrush(QColor(m_Settings
->colors
[UI_COLOR_BRUSH_POLE_FULL
]));
102 painter
.drawRect(8, 0, 11, 4);
104 painter
.setBrush(Qt::NoBrush
);
106 ((QFont
&)painter
.font()).setPixelSize(15);
107 painter
.drawText(1, 10, 26, 15, Qt::AlignHCenter
, QString::number((int)(100.0 * chargeNow
/ chargeFull
)));