paint the background as the same size of the progress bar, no more empty

areas before and after
support for stretched bars

svn path=/trunk/KDE/kdelibs/; revision=900723
This commit is contained in:
Marco Martin 2008-12-23 13:05:37 +00:00
parent 38ab27d842
commit d1e083f211

View File

@ -122,11 +122,41 @@ public:
QRectF barRect()
{
QRectF elementRect;
if (labels.count() > 0) {
return image->elementRect("background");
elementRect = image->elementRect("background");
} else {
return QRectF(QPoint(0,0), meter->size());
elementRect = QRectF(QPoint(0,0), meter->size());
}
if (image->hasElement("hint-bar-stretch")) {
return elementRect;
}
QSize imageSize = image->size();
image->resize();
QSize tileSize = image->elementSize("bar-active-center");
if (elementRect.width() > elementRect.height()) {
qreal ratio = tileSize.height() / tileSize.width();
int numTiles = elementRect.width()/(elementRect.height()/ratio);
tileSize = QSize(elementRect.width()/numTiles, elementRect.height());
QPoint center = elementRect.center().toPoint();
elementRect.setWidth(tileSize.width()*numTiles);
elementRect.moveCenter(center);
} else {
qreal ratio = tileSize.width() / tileSize.height();
int numTiles = elementRect.height()/(elementRect.width()/ratio);
tileSize = QSize(elementRect.width(), elementRect.height()/numTiles);
QPoint center = elementRect.center().toPoint();
elementRect.setHeight(tileSize.height()*numTiles);
elementRect.moveCenter(center);
}
return elementRect;
}
void paintBackground(QPainter *p)
@ -151,6 +181,11 @@ public:
void paintBar(QPainter *p, const QString &prefix)
{
QRectF elementRect = barRect();
if (image->hasElement("hint-bar-stretch")) {
image->resizeFrame(elementRect.size());
image->paintFrame(p);
} else {
QSize imageSize = image->size();
image->resize();
QSize tileSize = image->elementSize("bar-active-center");
@ -159,18 +194,10 @@ public:
qreal ratio = tileSize.height() / tileSize.width();
int numTiles = elementRect.width()/(elementRect.height()/ratio);
tileSize = QSize(elementRect.width()/numTiles, elementRect.height());
QPoint center = elementRect.center().toPoint();
elementRect.setWidth(tileSize.width()*numTiles);
elementRect.moveCenter(center);
} else {
qreal ratio = tileSize.width() / tileSize.height();
int numTiles = elementRect.height()/(elementRect.width()/ratio);
tileSize = QSize(elementRect.width(), elementRect.height()/numTiles);
QPoint center = elementRect.center().toPoint();
elementRect.setHeight(tileSize.height()*numTiles);
elementRect.moveCenter(center);
}
image->setElementPrefix(prefix);
@ -178,6 +205,7 @@ public:
p->drawTiledPixmap(elementRect, image->framePixmap());
image->resize(imageSize);
}
}
void paintForeground(QPainter *p)
{