/** Handle paintEvent (ie. animate icon) */ void TopLevel::paintEvent(QPaintEvent *) { QPixmap *pm = &mugPixmap; if (running) { if (useTrayVis) pm = &teaAnim1Pixmap; // this is 'mugPixmap' plus brown content else pm = &teaNotReadyPixmap; // generic "steeping" icon } else { // use simple two-frame "animation" // FIXME: how about using a QMovie instead? (eg. MNG) if (ready) { if (firstFrame) pm = &teaAnim1Pixmap; else pm = &teaAnim2Pixmap; } } // overlay pie chart onto tray icon QPixmap base(*pm); // make copy of base pixmap if (useTrayVis && running) { // extend mask QBitmap mask = *(base.mask()); QPainter pm(&mask); pm.setBrush(Qt::color1); // fill with "foreground-colour" pm.setPen(Qt::NoPen); // no border needed/wanted pm.drawPie(0+1, 9+1, 11, 11, 90*16, -360*16); // full circle of small size pm.drawPie(0, 9, 13, 13, 90*16, percentDone*16); // pie part of big size pm.end(); base.setMask(mask); // draw pie chart QPainter px(&base); px.setPen(QPen(Qt::black, 0)); // black border px.setBrush(QColor(192, 0, 0)); // red fill colour for small circle px.drawPie(0+1, 9+1, 11, 11, 90*16, -360*16); px.setBrush(QColor(0, 192, 0)); // green fill colour for pie part px.drawPie(0, 9, 13, 13, 90*16, percentDone*16); px.end(); } // FIXME: over-emphasize first and last few percent? (for better visibility) // FIXME: some optimizations (eg. store pre-drawn QPixmap with small circle) // (and use drawEllipse() instead of drawPie() for small circle!) // set new tray icon QPainter p(this); int x = 1 + (12 - pm->width()/2); int y = 1 + (12 - pm->height()/2); p.drawPixmap(x, y, base); p.end(); }