summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qdrawutil.cpp
diff options
context:
space:
mode:
authorJens Bache-Wiig <jbache@trolltech.com>2009-08-31 16:15:13 (GMT)
committerJens Bache-Wiig <jbache@trolltech.com>2009-08-31 16:20:51 (GMT)
commit758f4735bcae034ac25730e53bb371df3b7d6e8a (patch)
tree7086950b36e5b46ab5a034839c1e489904e51fc1 /src/gui/painting/qdrawutil.cpp
parente70980b2aacbc758a0cd1e2246633278f7c505ab (diff)
downloadQt-758f4735bcae034ac25730e53bb371df3b7d6e8a.zip
Qt-758f4735bcae034ac25730e53bb371df3b7d6e8a.tar.gz
Qt-758f4735bcae034ac25730e53bb371df3b7d6e8a.tar.bz2
Make QMargins a proper class
Since we need QMargins for other things then the CSS helper functions in drawutil, we have to make it more generic. It is already useful for QWidget::contentsMargins for example. This ensures we have some flexibility on how to use and modify it in the future. Reviewed-by: mbm
Diffstat (limited to 'src/gui/painting/qdrawutil.cpp')
-rw-r--r--src/gui/painting/qdrawutil.cpp137
1 files changed, 58 insertions, 79 deletions
diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp
index 59a5063..2220206 100644
--- a/src/gui/painting/qdrawutil.cpp
+++ b/src/gui/painting/qdrawutil.cpp
@@ -1038,27 +1038,6 @@ void qDrawItem(QPainter *p, Qt::GUIStyle gs,
#endif
/*!
- \class QMargins
- \since 4.6
-
- Holds the borders used to split a pixmap into nine segments in order to
- draw it, similar to \l{http://www.w3.org/TR/css3-background/}
- {CSS3 border-images}.
-
- \sa Qt::TileRule, QTileRules
-*/
-
-/*! \fn QMargins::QMargins(int margin)
- Constructs a QMargins with the top, left, bottom, and
- right margins set to \a margin.
-*/
-
-/*! \fn QMargins::QMargins(int topMargin, int leftMargin, int bottomMargin, int rightMargin)
- Constructs a QMargins with the given \a topMargin, \a leftMargin,
- \a bottomMargin, and \a rightMargin.
- */
-
-/*!
\class QTileRules
\since 4.6
@@ -1195,79 +1174,79 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
// source center
const int sourceTop = sourceRect.top();
const int sourceLeft = sourceRect.left();
- const int sourceCenterTop = sourceTop + sourceMargins.top;
- const int sourceCenterLeft = sourceLeft + sourceMargins.left;
- const int sourceCenterBottom = sourceRect.bottom() - sourceMargins.bottom + 1;
- const int sourceCenterRight = sourceRect.right() - sourceMargins.right + 1;
- const int sourceCenterWidth = sourceCenterRight - sourceMargins.left;
- const int sourceCenterHeight = sourceCenterBottom - sourceMargins.top;
+ const int sourceCenterTop = sourceTop + sourceMargins.top();
+ const int sourceCenterLeft = sourceLeft + sourceMargins.left();
+ const int sourceCenterBottom = sourceRect.bottom() - sourceMargins.bottom() + 1;
+ const int sourceCenterRight = sourceRect.right() - sourceMargins.right() + 1;
+ const int sourceCenterWidth = sourceCenterRight - sourceMargins.left();
+ const int sourceCenterHeight = sourceCenterBottom - sourceMargins.top();
// target center
const int targetTop = targetRect.top();
const int targetLeft = targetRect.left();
- const int targetCenterTop = targetTop + targetMargins.top;
- const int targetCenterLeft = targetLeft + targetMargins.left;
- const int targetCenterBottom = targetRect.bottom() - targetMargins.bottom + 1;
- const int targetCenterRight = targetRect.right() - targetMargins.right + 1;
+ const int targetCenterTop = targetTop + targetMargins.top();
+ const int targetCenterLeft = targetLeft + targetMargins.left();
+ const int targetCenterBottom = targetRect.bottom() - targetMargins.bottom() + 1;
+ const int targetCenterRight = targetRect.right() - targetMargins.right() + 1;
const int targetCenterWidth = targetCenterRight - targetCenterLeft;
const int targetCenterHeight = targetCenterBottom - targetCenterTop;
// corners
- if (targetMargins.top > 0 && targetMargins.left > 0 && sourceMargins.top > 0 && sourceMargins.left > 0) { // top left
- const QRect targetTopLeftRect(targetLeft, targetTop, targetMargins.left, targetMargins.top);
- const QRect sourceTopLeftRect(sourceLeft, sourceTop, sourceMargins.left, sourceMargins.top);
+ if (targetMargins.top() > 0 && targetMargins.left() > 0 && sourceMargins.top() > 0 && sourceMargins.left() > 0) { // top left
+ const QRect targetTopLeftRect(targetLeft, targetTop, targetMargins.left(), targetMargins.top());
+ const QRect sourceTopLeftRect(sourceLeft, sourceTop, sourceMargins.left(), sourceMargins.top());
qDrawPixmap(painter, targetTopLeftRect, pixmap, sourceTopLeftRect);
}
- if (targetMargins.top > 0 && targetMargins.right > 0 && sourceMargins.top > 0 && sourceMargins.right > 0) { // top right
- const QRect targetTopRightRect(targetCenterRight, targetTop, targetMargins.right, targetMargins.top);
- const QRect sourceTopRightRect(sourceCenterRight, sourceTop, sourceMargins.right, sourceMargins.top);
+ if (targetMargins.top() > 0 && targetMargins.right() > 0 && sourceMargins.top() > 0 && sourceMargins.right() > 0) { // top right
+ const QRect targetTopRightRect(targetCenterRight, targetTop, targetMargins.right(), targetMargins.top());
+ const QRect sourceTopRightRect(sourceCenterRight, sourceTop, sourceMargins.right(), sourceMargins.top());
qDrawPixmap(painter, targetTopRightRect, pixmap, sourceTopRightRect);
}
- if (targetMargins.bottom > 0 && targetMargins.left > 0 && sourceMargins.bottom > 0 && sourceMargins.left > 0) { // bottom left
- const QRect targetBottomLeftRect(targetLeft, targetCenterBottom, targetMargins.left, targetMargins.bottom);
- const QRect sourceBottomLeftRect(sourceLeft, sourceCenterBottom, sourceMargins.left, sourceMargins.bottom);
+ if (targetMargins.bottom() > 0 && targetMargins.left() > 0 && sourceMargins.bottom() > 0 && sourceMargins.left() > 0) { // bottom left
+ const QRect targetBottomLeftRect(targetLeft, targetCenterBottom, targetMargins.left(), targetMargins.bottom());
+ const QRect sourceBottomLeftRect(sourceLeft, sourceCenterBottom, sourceMargins.left(), sourceMargins.bottom());
qDrawPixmap(painter, targetBottomLeftRect, pixmap, sourceBottomLeftRect);
}
- if (targetMargins.bottom > 0 && targetMargins.right > 0 && sourceMargins.bottom > 0 && sourceMargins.right > 0) { // bottom right
- const QRect targetBottomRightRect(targetCenterRight, targetCenterBottom, targetMargins.right, targetMargins.bottom);
- const QRect sourceBottomRightRect(sourceCenterRight, sourceCenterBottom, sourceMargins.right, sourceMargins.bottom);
+ if (targetMargins.bottom() > 0 && targetMargins.right() > 0 && sourceMargins.bottom() > 0 && sourceMargins.right() > 0) { // bottom right
+ const QRect targetBottomRightRect(targetCenterRight, targetCenterBottom, targetMargins.right(), targetMargins.bottom());
+ const QRect sourceBottomRightRect(sourceCenterRight, sourceCenterBottom, sourceMargins.right(), sourceMargins.bottom());
qDrawPixmap(painter, targetBottomRightRect, pixmap, sourceBottomRightRect);
}
// horizontal edges
switch (rules.horizontal) {
case Qt::Stretch:
- if (targetMargins.top > 0 && sourceMargins.top > 0) { // top
- const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top);
- const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top);
+ if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
+ const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top());
+ const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top());
qDrawPixmap(painter, targetTopRect, pixmap, sourceTopRect);
}
- if (targetMargins.bottom > 0 && sourceMargins.bottom > 0) { // bottom
- const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom);
- const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom);
+ if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
+ const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom());
+ const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());
qDrawPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
}
break;
case Qt::Repeat:
- if (targetMargins.top > 0 && sourceMargins.top > 0) { // top
- const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top);
- const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top);
+ if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
+ const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top());
+ const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top());
qDrawHorizontallyRepeatedPixmap(painter, targetTopRect, pixmap, sourceTopRect);
}
- if (targetMargins.bottom > 0 && sourceMargins.bottom > 0) { // bottom
- const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom);
- const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom);
+ if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
+ const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom());
+ const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());
qDrawHorizontallyRepeatedPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
}
break;
case Qt::Round:
- if (targetMargins.top > 0 && sourceMargins.top > 0) { // top
- const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top);
- const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top);
+ if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
+ const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top());
+ const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top());
qDrawHorizontallyRoundedPixmap(painter, targetTopRect, pixmap, sourceTopRect);
}
- if (targetMargins.bottom > 0 && sourceMargins.bottom > 0) { // bottom
- const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom);
- const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom);
+ if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
+ const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom());
+ const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());
qDrawHorizontallyRoundedPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
}
break;
@@ -1276,38 +1255,38 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
// vertical edges
switch (rules.vertical) {
case Qt::Stretch:
- if (targetMargins.left > 0 && sourceMargins.left > 0) { // left
- const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left, targetCenterHeight);
- const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left, sourceCenterHeight);
+ if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
+ const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left(), targetCenterHeight);
+ const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
qDrawPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
}
- if (targetMargins.right > 0 && sourceMargins.right > 0) { // right
- const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right, targetCenterHeight);
- const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right, sourceCenterHeight);
+ if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
+ const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right(), targetCenterHeight);
+ const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
qDrawPixmap(painter, targetRightRect, pixmap, sourceRightRect);
}
break;
case Qt::Repeat:
- if (targetMargins.left > 0 && sourceMargins.left > 0) { // left
- const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left, targetCenterHeight);
- const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left, sourceCenterHeight);
+ if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
+ const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left(), targetCenterHeight);
+ const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
qDrawVerticallyRepeatedPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
}
- if (targetMargins.right > 0 && sourceMargins.right > 0) { // right
- const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right, targetCenterHeight);
- const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right, sourceCenterHeight);
+ if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
+ const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right(), targetCenterHeight);
+ const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
qDrawVerticallyRepeatedPixmap(painter, targetRightRect, pixmap, sourceRightRect);
}
break;
case Qt::Round:
- if (targetMargins.left > 0 && sourceMargins.left > 0) { // left
- const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left, targetCenterHeight);
- const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left, sourceCenterHeight);
+ if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
+ const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left(), targetCenterHeight);
+ const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
qDrawVerticallyRoundedPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
}
- if (targetMargins.right > 0 && sourceMargins.right > 0) { // right
- const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right, targetCenterHeight);
- const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right, sourceCenterHeight);
+ if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
+ const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right(), targetCenterHeight);
+ const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
qDrawVerticallyRoundedPixmap(painter, targetRightRect, pixmap, sourceRightRect);
}
break;