Permalink
Browse files

Merge branch 'master' of https://github.com/Razor-qt/razor-qt

  • Loading branch information...
2 parents 8c32f68 + 7f6c483 commit df167c65f9d74f97eb95ea71bcb7353ce620dd00 @kuzmas kuzmas committed Oct 27, 2012
Showing with 88 additions and 1 deletion.
  1. +88 −1 razorqt-autosuspend/src/trayicon.cpp
@@ -163,6 +163,93 @@ void TrayIcon::settingsChanged()
QIcon TrayIcon::getBuiltInIcon(double chargeLevel, bool discharging)
{
+ // See http://www.w3.org/TR/SVG/Overview.html
+ // and regarding circle-arch in particular:
+ // http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
+
+ // We show charge with a segment of a circle.
+ // We start at the top of the circle
+ // The starting point of the circle segment is at the top (12 o'clock or (0,1) or pi/2
+ // and it moves counter-clockwise as the charge increases
+ // First we calculate in floating point numbers, using a circle with center
+ // in (0,0) and a radius of 1
+ double angle = 2*M_PI*chargeLevel/100 + M_PI_2;
+ qDebug() << "Angle:" << angle;
+ double segment_endpoint_x = cos(angle);
+ double segment_endpoint_y = sin(angle);
+
+ // svg uses an coordinate system with (0,0) at the topmost left corner,
+ // y increasing downwards and x increasing left-to-right.
+ // We draw the circle segments with center at (100,100) and radius 100 for the
+ // outer and radius 60 for the inner. The segments will (unless fully charged,
+ // where they go full circle) be radially connected at the endpoints.
+ QString chargeGraphics;
+
+ if (chargeLevel < 0.5)
+ {
+ chargeGraphics = "";
+ }
+ else if (chargeLevel > 99.5)
+ {
+ chargeGraphics =
+ "<path d='M 100,0 A 100,100 0 1,0 101,0 z M 100,40 A 60,60 0 1,0 101,40 z' stroke-width='0'/>";
+ }
+ else {
+ chargeGraphics =
+ QString("<path d='M 100,0 A 100,100 0 %1,0 %2,%3 L %4,%5 A 60,60 0 %1,1 100,40 z'/>")
+ .arg(angle > M_PI + M_PI_2 ? 1 : 0) // %1
+ .arg(round(100*(1 + segment_endpoint_x))) // %2
+ .arg(round(100*(1 - segment_endpoint_y))) // %3
+ .arg(round(100*(1 + 0.6*segment_endpoint_x))) // %4
+ .arg(round(100*(1 - 0.6*segment_endpoint_y))); // %5
+ }
+
+ QString chargeColor;
+ int lowLevel = mSettings.value(POWERLOWLEVEL_KEY, 5).toInt();
+ if (discharging && chargeLevel <= lowLevel + 10)
+ {
+ chargeColor = "rgb(200,40,40)";
+ }
+ else if (discharging && chargeLevel <= lowLevel + 30)
+ {
+ int fac = chargeLevel - lowLevel - 10;
+ chargeColor = QString("rgb(%1,%2,40)").arg(40 + 200 - fac*8).arg(40 + fac*8);
+ }
+ else
+ chargeColor = "rgb(40,200,40)";
+
+
+ QString sign =
+ discharging ?
+ QString("<path d='M 60,100 h 80' stroke='black' stroke-width='20' />"): // Minus
+ QString("<path d='M 60,100 h 80 M 100,60 v 80' stroke='black' stroke-width='20' />"); // Plus
+
+ QString svg =
+ QString("<?xml version='1.0' standalone='no'?>\n"
+ "<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>\n"
+ "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='0 0 210 210'>\n"
+ " <circle cx='100' cy='100' r='100' fill='rgb(210,210,210)' stroke-width='0'/>\n"
+ " <circle cx='100' cy='100' r='55' fill='rgb(255,255,255)' stroke-width='0'/>\n"
+ " <g fill-rule='evenodd' fill='%2' stroke-width='0'>\n"
+ " %1\n"
+ " </g>\n"
+ " %3\n"
+ "</svg>\n").arg(chargeGraphics).arg(chargeColor).arg(sign);
+
+ qDebug() << svg;
+
+ // Paint the svg on a pixmap and create an icon from that.
+ QSvgRenderer render(svg.toAscii());
+ QPixmap pixmap(render.defaultSize());
+ pixmap.fill(QColor(0,0,0,0));
+ QPainter painter(&pixmap);
+ render.render(&painter);
+ return QIcon(pixmap);
+
+}
+
+/*QIcon TrayIcon::getBuiltInIcon(double chargeLevel, bool discharging)
+{
// See http://www.w3.org/TR/SVG/Overview.html
// and regarding circle-arch in particular:
// http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
@@ -228,7 +315,7 @@ QIcon TrayIcon::getBuiltInIcon(double chargeLevel, bool discharging)
QPainter painter(&pixmap);
render.render(&painter);
return QIcon(pixmap);
-}
+}*/
void TrayIcon::showStatus(ActivationReason reason)
{

0 comments on commit df167c6

Please sign in to comment.