From 4626ee4e450ee6ab96ad361b7b4563d91f3cb595 Mon Sep 17 00:00:00 2001 From: Andrew Lake Date: Sun, 9 Mar 2008 00:15:32 +0000 Subject: [PATCH] Allow tiled svg center element. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=783642 --- svgpanel.cpp | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/svgpanel.cpp b/svgpanel.cpp index d5d75d3fb..5610d947a 100644 --- a/svgpanel.cpp +++ b/svgpanel.cpp @@ -61,6 +61,7 @@ public: //element is contentWidth x contentHeight bool noBorderPadding : 1; bool stretchBorders : 1; + bool tileCenter : 1; }; SvgPanel::SvgPanel(const QString& imagePath, QObject* parent) @@ -199,21 +200,42 @@ void SvgPanel::Private::generateBackground() //CENTER - if (contentHeight > 0 && contentWidth > 0) { - QSizeF scaledSize = QSizeF(panelSize.width() - - (leftWidth + rightWidth) + - panelSize.width()*(((qreal)(leftWidth + rightWidth)) / panelSize.width()), - panelSize.height() - - (topHeight + bottomHeight) + - panelSize.height()*(((qreal)(topHeight + bottomHeight)) / panelSize.height())); + if (tileCenter) { + if (contentHeight > 0 && contentWidth > 0) { + int centerTileHeight; + int centerTileWidth; + centerTileHeight = background->elementSize("center").height(); + centerTileWidth = background->elementSize("center").width(); + QPixmap center(centerTileWidth, centerTileHeight); + center.fill(Qt::transparent); - background->resize(scaledSize.width(), scaledSize.height()); - background->paint(&p, QRect(contentLeft - leftWidth, contentTop - topHeight, - contentWidth + leftWidth*2, contentHeight + topHeight*2), - "center"); - background->resize(); + { + QPainter centerPainter(¢er); + centerPainter.setCompositionMode(QPainter::CompositionMode_Source); + background->paint(¢erPainter, QPoint(0, 0), "center"); + } + + p.drawTiledPixmap(QRect(contentLeft - leftWidth, contentTop - topHeight, + contentWidth + leftWidth*2, contentHeight + topHeight*2), center); + } + } else { + if (contentHeight > 0 && contentWidth > 0) { + QSizeF scaledSize = QSizeF(panelSize.width() - + (leftWidth + rightWidth) + + panelSize.width()*(((qreal)(leftWidth + rightWidth)) / panelSize.width()), + panelSize.height() - + (topHeight + bottomHeight) + + panelSize.height()*(((qreal)(topHeight + bottomHeight)) / panelSize.height())); + + background->resize(scaledSize.width(), scaledSize.height()); + background->paint(&p, QRect(contentLeft - leftWidth, contentTop - topHeight, + contentWidth + leftWidth*2, contentHeight + topHeight*2), + "center"); + background->resize(); + } } + // Corners if (bFlags & DrawTopBorder) { if (!origined) { @@ -373,6 +395,7 @@ void SvgPanel::updateSizes() } //since it's rectangular, topWidth and bottomWidth must be the same + d->tileCenter = d->background->elementExists("hint-tile-center"); d->noBorderPadding = d->background->elementExists("hint-no-border-padding"); d->stretchBorders = d->background->elementExists("hint-stretch-borders"); emit repaintNeeded();