summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-12-01 01:15:46 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-12-01 01:15:46 (GMT)
commit6f18ee7ce50bc9b2688079e923a34c08117b3eb8 (patch)
tree77fa01f42f1dff4ae55365b01f2ce93f362e5dfc /src/declarative
parent840ffbd6187fe2573d8c00481120d4cf30aed351 (diff)
downloadQt-6f18ee7ce50bc9b2688079e923a34c08117b3eb8.zip
Qt-6f18ee7ce50bc9b2688079e923a34c08117b3eb8.tar.gz
Qt-6f18ee7ce50bc9b2688079e923a34c08117b3eb8.tar.bz2
Fix BorderImage painting at sizes less than margin size.
If the width < left+right margins or height < top+bottom margins the image was painted with the complete margins, resulting in an ugle pattern. This change reduces the size of the margins proportionately, which gives a much better appearance. Task-number: QTBUG-15736 Reviewed-by: Yann Bodson
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
index 649c8fb..c0a7d72 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
@@ -509,7 +509,7 @@ void QDeclarativeBorderImage::doUpdate()
void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QDeclarativeBorderImage);
- if (d->pix.isNull())
+ if (d->pix.isNull() || d->width() <= 0.0 || d->height() <= 0.0)
return;
bool oldAA = p->testRenderHint(QPainter::Antialiasing);
@@ -518,7 +518,23 @@ void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem
p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
const QDeclarativeScaleGrid *border = d->getScaleGrid();
- QMargins margins(border->left(), border->top(), border->right(), border->bottom());
+ int left = border->left();
+ int right = border->right();
+ qreal borderWidth = left + right;
+ if (borderWidth > 0.0 && d->width() < borderWidth) {
+ qreal diff = borderWidth - d->width() - 1;
+ left -= qRound(diff * qreal(left) / borderWidth);
+ right -= qRound(diff * qreal(right) / borderWidth);
+ }
+ int top = border->top();
+ int bottom = border->bottom();
+ qreal borderHeight = top + bottom;
+ if (borderHeight > 0.0 && d->height() < borderHeight) {
+ qreal diff = borderHeight - d->height() - 1;
+ top -= qRound(diff * qreal(top) / borderHeight);
+ bottom -= qRound(diff * qreal(bottom) / borderHeight);
+ }
+ QMargins margins(left, top, right, bottom);
QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode);
qDrawBorderPixmap(p, QRect(0, 0, (int)d->width(), (int)d->height()), margins, d->pix, d->pix.rect(), margins, rules);
if (d->smooth) {