# Razor-qt/razor-qt

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

2 parents 8c32f68 + 7f6c483 commit df167c65f9d74f97eb95ea71bcb7353ce620dd00 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 = + ""; + } + else { + chargeGraphics = + QString("") + .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(""): // Minus + QString(""); // Plus + + QString svg = + QString("\n" + "\n" + "\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) {