scale the svg elements at the right size in case of stretched borders

and/or
not tiled center element.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=803061
This commit is contained in:
Marco Martin 2008-05-01 19:51:41 +00:00
parent f3e1fd618f
commit 5939dfc87c

View File

@ -337,6 +337,15 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
// the transparent border around the svg seems to vary in size depending on the size of the svg and as a result increasing the // the transparent border around the svg seems to vary in size depending on the size of the svg and as a result increasing the
// svg image by 2 all around didn't resolve the issue. For now it resizes based on the border size. // svg image by 2 all around didn't resolve the issue. For now it resizes based on the border size.
//if we must stretch the center or the borders we compute how much we will have to stretch
//the svg to get the desired element sizes
QSizeF scaledContentSize(0,0);
if (q->elementSize(prefix + "center").width() > 0 &&
q->elementSize(prefix + "center").height() > 0 &&
(!panel->tileCenter || panel->stretchBorders)) {
scaledContentSize = QSizeF(contentWidth * ((qreal)q->size().width() / (qreal)q->elementSize(prefix + "center").width()),
contentHeight * ((qreal)q->size().height() / (qreal)q->elementSize(prefix + "center").height()));
}
//CENTER //CENTER
if (panel->tileCenter) { if (panel->tileCenter) {
@ -354,21 +363,17 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
q->paint(&centerPainter, QPoint(0, 0), prefix + "center"); q->paint(&centerPainter, QPoint(0, 0), prefix + "center");
} }
p.drawTiledPixmap(QRect(contentLeft - panel->leftWidth, contentTop - panel->topHeight, p.drawTiledPixmap(QRect(panel->leftWidth, panel->topHeight,
contentWidth + panel->leftWidth*2, contentHeight + panel->topHeight*2), center); contentWidth, contentHeight),
prefix + "center"), center);
} }
} else { } else {
if (contentHeight > 0 && contentWidth > 0) { if (contentHeight > 0 && contentWidth > 0) {
QSizeF scaledSize = QSizeF(panel->panelSize.width() -
(panel->leftWidth + panel->rightWidth) +
panel->panelSize.width()*(((qreal)(panel->leftWidth + panel->rightWidth)) / panel->panelSize.width()),
panel->panelSize.height() -
(panel->topHeight + panel->bottomHeight) +
panel->panelSize.height()*(((qreal)(panel->topHeight + panel->bottomHeight)) / panel->panelSize.height()));
q->resize(scaledSize.width(), scaledSize.height()); q->resize(scaledContentSize);
q->paint(&p, QRect(contentLeft - panel->leftWidth, contentTop - panel->topHeight,
contentWidth + panel->leftWidth*2, contentHeight + panel->topHeight*2), q->paint(&p, QRect(panel->leftWidth, panel->topHeight,
contentWidth, contentHeight),
prefix + "center"); prefix + "center");
q->resize(); q->resize();
} }
@ -412,6 +417,9 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
// Sides // Sides
if (panel->stretchBorders) { if (panel->stretchBorders) {
if (panel->enabledBorders & LeftBorder || panel->enabledBorders & RightBorder) {
q->resize(q->size().width(), scaledContentSize.height());
if (panel->enabledBorders & LeftBorder) { if (panel->enabledBorders & LeftBorder) {
q->paint(&p, QRect(leftOffset, contentTop, panel->leftWidth, contentHeight), prefix + "left"); q->paint(&p, QRect(leftOffset, contentTop, panel->leftWidth, contentHeight), prefix + "left");
} }
@ -420,6 +428,12 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
q->paint(&p, QRect(rightOffset, contentTop, panel->rightWidth, contentHeight), prefix + "right"); q->paint(&p, QRect(rightOffset, contentTop, panel->rightWidth, contentHeight), prefix + "right");
} }
q->resize();
}
if (panel->enabledBorders & TopBorder || panel->enabledBorders & BottomBorder) {
q->resize(scaledContentSize.width(), q->size().height());
if (panel->enabledBorders & TopBorder) { if (panel->enabledBorders & TopBorder) {
q->paint(&p, QRect(contentLeft, topOffset, contentWidth, panel->topHeight), prefix + "top"); q->paint(&p, QRect(contentLeft, topOffset, contentWidth, panel->topHeight), prefix + "top");
} }
@ -427,6 +441,9 @@ void PanelSvg::Private::generateBackground(PanelData *panel)
if (panel->enabledBorders & BottomBorder) { if (panel->enabledBorders & BottomBorder) {
q->paint(&p, QRect(contentLeft, bottomOffset, contentWidth, panel->bottomHeight), prefix + "bottom"); q->paint(&p, QRect(contentLeft, bottomOffset, contentWidth, panel->bottomHeight), prefix + "bottom");
} }
q->resize();
}
} else { } else {
if (panel->enabledBorders & LeftBorder) { if (panel->enabledBorders & LeftBorder) {
QPixmap left(panel->leftWidth, leftHeight); QPixmap left(panel->leftWidth, leftHeight);