void KProgress::drawText(QPainter *p) { QRect r(contentsRect()); //QColor c(bar_color.rgb() ^ backgroundColor().rgb()); QString s; s.sprintf("%i%%", recalcValue(100)); p->setPen(text_color); //p->setRasterOp(XorROP); p->drawText(r, AlignCenter, s); p->setClipRegion( fr ); p->setPen(bar_text_color); p->drawText(r, AlignCenter, s); }
void KGameProgress::drawText(QPainter *p) { QRect r(contentsRect()); //QColor c(bar_color.rgb() ^ backgroundColor().rgb()); // Rik: Replace the tags '%p', '%v' and '%m' with the current percentage, // the current value and the maximum value respectively. QString s(format_); s.replace(QRegExp(QString::fromLatin1("%p")), QString::number(recalcValue(100))); s.replace(QRegExp(QString::fromLatin1("%v")), QString::number(value())); s.replace(QRegExp(QString::fromLatin1("%m")), QString::number(maxValue())); p->setPen(text_color); QFont font = p->font(); font.setBold(true); p->setFont(font); //p->setRasterOp(XorROP); p->drawText(r, AlignCenter, s); p->setClipRegion( fr ); p->setPen(bar_text_color); p->drawText(r, AlignCenter, s); }
void KGameProgress::drawContents(QPainter *p) { QRect cr = contentsRect(), er = cr; fr = cr; QBrush fb(bar_color), eb(backgroundColor()); if (bar_pixmap) fb.setPixmap(*bar_pixmap); if (backgroundPixmap()) eb.setPixmap(*backgroundPixmap()); switch (bar_style) { case Solid: if (orient == Horizontal) { fr.setWidth(recalcValue(cr.width())); er.setLeft(fr.right() + 1); } else { fr.setTop(cr.bottom() - recalcValue(cr.height())); er.setBottom(fr.top() - 1); } p->setBrushOrigin(cr.topLeft()); p->fillRect(fr, fb); p->fillRect(er, eb); break; case Blocked: const int margin = 2; int max, num, dx, dy; if (orient == Horizontal) { fr.setHeight(cr.height() - 2 * margin); fr.setWidth((int)(0.67 * fr.height())); fr.moveTopLeft(QPoint(cr.left() + margin, cr.top() + margin)); dx = fr.width() + margin; dy = 0; max = (cr.width() - margin) / (fr.width() + margin) + 1; num = recalcValue(max); } else { fr.setWidth(cr.width() - 2 * margin); fr.setHeight((int)(0.67 * fr.width())); fr.moveBottomLeft(QPoint(cr.left() + margin, cr.bottom() - margin)); dx = 0; dy = - (fr.height() + margin); max = (cr.height() - margin) / (fr.height() + margin) + 1; num = recalcValue(max); } p->setClipRect(cr.x() + margin, cr.y() + margin, cr.width() - margin, cr.height() - margin); for (int i = 0; i < num; i++) { p->setBrushOrigin(fr.topLeft()); p->fillRect(fr, fb); fr.moveBy(dx, dy); } if (num != max) { if (orient == Horizontal) er.setLeft(fr.right() + 1); else er.setBottom(fr.bottom() + 1); if (!er.isNull()) { p->setBrushOrigin(cr.topLeft()); p->fillRect(er, eb); } } break; } if (text_enabled && bar_style != Blocked) drawText(p); }
void KGameProgress::rangeChange() { repaint(contentsRect(), FALSE); emit percentageChanged(recalcValue(100)); }