Qt 4.8
Typedefs | Functions
qdrawutil.cpp File Reference
#include "qdrawutil.h"
#include "qbitmap.h"
#include "qpixmapcache.h"
#include "qapplication.h"
#include "qpainter.h"
#include "qpalette.h"
#include <private/qpaintengineex_p.h>
#include <qvarlengtharray.h>
#include <qmath.h>
#include <private/qstylehelper_p.h>

Go to the source code of this file.

Typedefs

typedef QVarLengthArray< QRectF, 16 > QRectFArray
 

Functions

void qDrawBorderPixmap (QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap, const QRect &sourceRect, const QMargins &sourceMargins, const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints)
 Draws the indicated sourceRect rectangle from the given pixmap into the given targetRect rectangle, using the given painter. More...
 
void qDrawPlainRect (QPainter *p, int x, int y, int w, int h, const QColor &c, int lineWidth, const QBrush *fill)
 
void qDrawPlainRect (QPainter *p, const QRect &r, const QColor &c, int lineWidth, const QBrush *fill)
 
void qDrawShadeLine (QPainter *p, int x1, int y1, int x2, int y2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth)
 
void qDrawShadeLine (QPainter *p, const QPoint &p1, const QPoint &p2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth)
 
void qDrawShadePanel (QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
 
void qDrawShadePanel (QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
 
void qDrawShadeRect (QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill)
 
void qDrawShadeRect (QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill)
 
void qDrawWinButton (QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
 
void qDrawWinButton (QPainter *p, const QRect &r, const QPalette &pal, bool sunken, const QBrush *fill)
 
void qDrawWinPanel (QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
 
void qDrawWinPanel (QPainter *p, const QRect &r, const QPalette &pal, bool sunken, const QBrush *fill)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the Windows-style panel at the rectangle specified by rect using the given painter with a line width of 2 pixels. More...
 
static void qDrawWinShades (QPainter *p, int x, int y, int w, int h, const QColor &c1, const QColor &c2, const QColor &c3, const QColor &c4, const QBrush *fill)
 This function draws a rectangle with two pixel line width. More...
 

Typedef Documentation

◆ QRectFArray

Definition at line 1086 of file qdrawutil.cpp.

Function Documentation

◆ qDrawBorderPixmap()

void qDrawBorderPixmap ( QPainter painter,
const QRect targetRect,
const QMargins targetMargins,
const QPixmap pixmap,
const QRect sourceRect,
const QMargins sourceMargins,
const QTileRules rules,
QDrawBorderPixmap::DrawingHints  hints 
)

Draws the indicated sourceRect rectangle from the given pixmap into the given targetRect rectangle, using the given painter.

Since
4.6

The pixmap will be split into nine segments according to the given targetMargins and sourceMargins structures. Finally, the pixmap will be drawn according to the given rules.

This function is used to draw a scaled pixmap, similar to CSS3 border-images

See also
Qt::TileRule, QTileRules, QMargins

Definition at line 1106 of file qdrawutil.cpp.

Referenced by QRenderRule::drawBorderImage(), QDeclarativeRectangle::drawRect(), and QDeclarativeBorderImage::paint().

1109 {
1110  if (!painter->isActive()) {
1111  qWarning("qDrawBorderPixmap: Painter not active");
1112  return;
1113  }
1114 
1115  QRectFArray sourceData[2];
1116  QRectFArray targetData[2];
1117 
1118  // source center
1119  const int sourceCenterTop = sourceRect.top() + sourceMargins.top();
1120  const int sourceCenterLeft = sourceRect.left() + sourceMargins.left();
1121  const int sourceCenterBottom = sourceRect.bottom() - sourceMargins.bottom() + 1;
1122  const int sourceCenterRight = sourceRect.right() - sourceMargins.right() + 1;
1123  const int sourceCenterWidth = sourceCenterRight - sourceCenterLeft;
1124  const int sourceCenterHeight = sourceCenterBottom - sourceCenterTop;
1125  // target center
1126  const int targetCenterTop = targetRect.top() + targetMargins.top();
1127  const int targetCenterLeft = targetRect.left() + targetMargins.left();
1128  const int targetCenterBottom = targetRect.bottom() - targetMargins.bottom() + 1;
1129  const int targetCenterRight = targetRect.right() - targetMargins.right() + 1;
1130  const int targetCenterWidth = targetCenterRight - targetCenterLeft;
1131  const int targetCenterHeight = targetCenterBottom - targetCenterTop;
1132 
1133  QVarLengthArray<qreal, 16> xTarget; // x-coordinates of target rectangles
1134  QVarLengthArray<qreal, 16> yTarget; // y-coordinates of target rectangles
1135 
1136  int columns = 3;
1137  int rows = 3;
1138  if (rules.horizontal != Qt::StretchTile && sourceCenterWidth != 0)
1139  columns = qMax(3, 2 + qCeil(targetCenterWidth / qreal(sourceCenterWidth)));
1140  if (rules.vertical != Qt::StretchTile && sourceCenterHeight != 0)
1141  rows = qMax(3, 2 + qCeil(targetCenterHeight / qreal(sourceCenterHeight)));
1142 
1143  xTarget.resize(columns + 1);
1144  yTarget.resize(rows + 1);
1145 
1146  bool oldAA = painter->testRenderHint(QPainter::Antialiasing);
1147  if (painter->paintEngine()->type() != QPaintEngine::OpenGL
1148  && painter->paintEngine()->type() != QPaintEngine::OpenGL2
1149  && oldAA && painter->combinedTransform().type() != QTransform::TxNone) {
1150  painter->setRenderHint(QPainter::Antialiasing, false);
1151  }
1152 
1153  xTarget[0] = targetRect.left();
1154  xTarget[1] = targetCenterLeft;
1155  xTarget[columns - 1] = targetCenterRight;
1156  xTarget[columns] = targetRect.left() + targetRect.width();
1157 
1158  yTarget[0] = targetRect.top();
1159  yTarget[1] = targetCenterTop;
1160  yTarget[rows - 1] = targetCenterBottom;
1161  yTarget[rows] = targetRect.top() + targetRect.height();
1162 
1163  qreal dx = targetCenterWidth;
1164  qreal dy = targetCenterHeight;
1165 
1166  switch (rules.horizontal) {
1167  case Qt::StretchTile:
1168  dx = targetCenterWidth;
1169  break;
1170  case Qt::RepeatTile:
1171  dx = sourceCenterWidth;
1172  break;
1173  case Qt::RoundTile:
1174  dx = targetCenterWidth / qreal(columns - 2);
1175  break;
1176  }
1177 
1178  for (int i = 2; i < columns - 1; ++i)
1179  xTarget[i] = xTarget[i - 1] + dx;
1180 
1181  switch (rules.vertical) {
1182  case Qt::StretchTile:
1183  dy = targetCenterHeight;
1184  break;
1185  case Qt::RepeatTile:
1186  dy = sourceCenterHeight;
1187  break;
1188  case Qt::RoundTile:
1189  dy = targetCenterHeight / qreal(rows - 2);
1190  break;
1191  }
1192 
1193  for (int i = 2; i < rows - 1; ++i)
1194  yTarget[i] = yTarget[i - 1] + dy;
1195 
1196  // corners
1197  if (targetMargins.top() > 0 && targetMargins.left() > 0 && sourceMargins.top() > 0 && sourceMargins.left() > 0) { // top left
1198  int index = bool(hints & QDrawBorderPixmap::OpaqueTopLeft);
1199  sourceData[index].append(QRectF(sourceRect.topLeft(), QSizeF(sourceMargins.left(), sourceMargins.top())));
1200  targetData[index].append(QRectF(QPointF(xTarget[0], yTarget[0]), QPointF(xTarget[1], yTarget[1])));
1201  }
1202  if (targetMargins.top() > 0 && targetMargins.right() > 0 && sourceMargins.top() > 0 && sourceMargins.right() > 0) { // top right
1203  int index = bool(hints & QDrawBorderPixmap::OpaqueTopRight);
1204  sourceData[index].append(QRectF(QPointF(sourceCenterRight, sourceRect.top()), QSizeF(sourceMargins.right(), sourceMargins.top())));
1205  targetData[index].append(QRectF(QPointF(xTarget[columns-1], yTarget[0]), QPointF(xTarget[columns], yTarget[1])));
1206  }
1207  if (targetMargins.bottom() > 0 && targetMargins.left() > 0 && sourceMargins.bottom() > 0 && sourceMargins.left() > 0) { // bottom left
1208  int index = bool(hints & QDrawBorderPixmap::OpaqueBottomLeft);
1209  sourceData[index].append(QRectF(QPointF(sourceRect.left(), sourceCenterBottom), QSizeF(sourceMargins.left(), sourceMargins.bottom())));
1210  targetData[index].append(QRectF(QPointF(xTarget[0], yTarget[rows - 1]), QPointF(xTarget[1], yTarget[rows])));
1211  }
1212  if (targetMargins.bottom() > 0 && targetMargins.right() > 0 && sourceMargins.bottom() > 0 && sourceMargins.right() > 0) { // bottom right
1213  int index = bool(hints & QDrawBorderPixmap::OpaqueBottomRight);
1214  sourceData[index].append(QRectF(QPointF(sourceCenterRight, sourceCenterBottom), QSizeF(sourceMargins.right(), sourceMargins.bottom())));
1215  targetData[index].append(QRectF(QPointF(xTarget[columns - 1], yTarget[rows - 1]), QPointF(xTarget[columns], yTarget[rows])));
1216  }
1217 
1218  // horizontal edges
1219  if (targetCenterWidth > 0 && sourceCenterWidth > 0) {
1220  if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
1221  int index = bool(hints & QDrawBorderPixmap::OpaqueTop);
1222  for (int i = 1; i < columns - 1; ++i) {
1223  if (rules.horizontal == Qt::RepeatTile && i == columns - 2) {
1224  sourceData[index].append(QRectF(QPointF(sourceCenterLeft, sourceRect.top()), QSizeF(xTarget[i + 1] - xTarget[i], sourceMargins.top())));
1225  } else {
1226  sourceData[index].append(QRectF(QPointF(sourceCenterLeft, sourceRect.top()), QSizeF(sourceCenterWidth, sourceMargins.top())));
1227  }
1228  targetData[index].append(QRectF(QPointF(xTarget[i], yTarget[0]), QPointF(xTarget[i + 1], yTarget[1])));
1229  }
1230  }
1231  if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
1232  int index = bool(hints & QDrawBorderPixmap::OpaqueBottom);
1233  for (int i = 1; i < columns - 1; ++i) {
1234  if (rules.horizontal == Qt::RepeatTile && i == columns - 2) {
1235  sourceData[index].append(QRectF(QPointF(sourceCenterLeft, sourceCenterBottom), QSizeF(xTarget[i + 1] - xTarget[i], sourceMargins.bottom())));
1236  } else {
1237  sourceData[index].append(QRectF(QPointF(sourceCenterLeft, sourceCenterBottom), QSizeF(sourceCenterWidth, sourceMargins.bottom())));
1238  }
1239  targetData[index].append(QRectF(QPointF(xTarget[i], yTarget[rows - 1]), QPointF(xTarget[i + 1], yTarget[rows])));
1240  }
1241  }
1242  }
1243 
1244  // vertical edges
1245  if (targetCenterHeight > 0 && sourceCenterHeight > 0) {
1246  if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
1247  int index = bool(hints & QDrawBorderPixmap::OpaqueLeft);
1248  for (int i = 1; i < rows - 1; ++i) {
1249  if (rules.vertical == Qt::RepeatTile && i == rows - 2) {
1250  sourceData[index].append(QRectF(QPointF(sourceRect.left(), sourceCenterTop), QSizeF(sourceMargins.left(), yTarget[i + 1] - yTarget[i])));
1251  } else {
1252  sourceData[index].append(QRectF(QPointF(sourceRect.left(), sourceCenterTop), QSizeF(sourceMargins.left(), sourceCenterHeight)));
1253  }
1254  targetData[index].append(QRectF(QPointF(xTarget[0], yTarget[i]), QPointF(xTarget[1], yTarget[i + 1])));
1255  }
1256  }
1257  if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
1258  int index = bool(hints & QDrawBorderPixmap::OpaqueRight);
1259  for (int i = 1; i < rows - 1; ++i) {
1260  if (rules.vertical == Qt::RepeatTile && i == rows - 2) {
1261  sourceData[index].append(QRectF(QPointF(sourceCenterRight, sourceCenterTop), QSizeF(sourceMargins.right(), yTarget[i + 1] - yTarget[i])));
1262  } else {
1263  sourceData[index].append(QRectF(QPointF(sourceCenterRight, sourceCenterTop), QSizeF(sourceMargins.right(), sourceCenterHeight)));
1264  }
1265  targetData[index].append(QRectF(QPointF(xTarget[columns - 1], yTarget[i]), QPointF(xTarget[columns], yTarget[i + 1])));
1266  }
1267  }
1268  }
1269 
1270  // center
1271  if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) {
1272  int index = bool(hints & QDrawBorderPixmap::OpaqueCenter);
1273  for (int j = 1; j < rows - 1; ++j) {
1274  qreal sourceHeight = (rules.vertical == Qt::RepeatTile && j == rows - 2) ? yTarget[j + 1] - yTarget[j] : sourceCenterHeight;
1275  for (int i = 1; i < columns - 1; ++i) {
1276  qreal sourceWidth = (rules.horizontal == Qt::RepeatTile && i == columns - 2) ? xTarget[i + 1] - xTarget[i] : sourceCenterWidth;
1277  sourceData[index].append(QRectF(QPointF(sourceCenterLeft, sourceCenterTop), QSizeF(sourceWidth, sourceHeight)));
1278  targetData[index].append(QRectF(QPointF(xTarget[i], yTarget[j]), QPointF(xTarget[i + 1], yTarget[j + 1])));
1279  }
1280  }
1281  }
1282 
1283  for (int i = 0; i < 2; ++i) {
1284  if (sourceData[i].size())
1285  painter->drawPixmapFragments(targetData[i].data(), sourceData[i].data(), sourceData[i].size(), pixmap, i == 1 ? QPainter::OpaqueHint : QPainter::PixmapFragmentHint(0));
1286  }
1287 
1288  if (oldAA)
1289  painter->setRenderHint(QPainter::Antialiasing, true);
1290 }
void resize(int size)
void drawPixmapFragments(const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=0)
This function is used to draw pixmap, or a sub-rectangle of pixmap, at multiple positions with differ...
Definition: qpainter.cpp:9697
double qreal
Definition: qglobal.h:1193
int qCeil(qreal v)
Definition: qmath.h:63
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool testRenderHint(RenderHint hint) const
Returns true if hint is set; otherwise returns false.
Definition: qpainter.h:457
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
TransformationType type() const
Returns the transformation type of this matrix.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void append(const T &t)
Qt::TileRule vertical
Definition: qdrawutil.h:143
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int top() const
Returns the top margin.
Definition: qmargins.h:99
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
QTransform combinedTransform() const
Returns the transformation matrix combining the current window/viewport and world transformation...
Definition: qpainter.cpp:9669
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
Qt::TileRule horizontal
Definition: qdrawutil.h:142
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
quint16 index
PixmapFragmentHint
Definition: qpainter.h:120
int left() const
Returns the left margin.
Definition: qmargins.h:96
int bottom() const
Returns the bottom margin.
Definition: qmargins.h:105
int right() const
Returns the right margin.
Definition: qmargins.h:102
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ qDrawPlainRect() [1/2]

void qDrawPlainRect ( QPainter p,
int  x,
int  y,
int  w,
int  h,
const QColor c,
int  lineWidth,
const QBrush fill 
)

Definition at line 511 of file qdrawutil.cpp.

Referenced by QWindowsMobileStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsMobileStyle::drawControl(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), and qDrawPlainRect().

513 {
514  if (w == 0 || h == 0)
515  return;
516  if (!(w > 0 && h > 0 && lineWidth >= 0)) {
517  qWarning("qDrawPlainRect: Invalid parameters");
518  }
519  QPen oldPen = p->pen();
520  QBrush oldBrush = p->brush();
521  p->setPen(c);
522  p->setBrush(Qt::NoBrush);
523  for (int i=0; i<lineWidth; i++)
524  p->drawRect(x+i, y+i, w-i*2 - 1, h-i*2 - 1);
525  if (fill) { // fill with fill color
526  p->setPen(Qt::NoPen);
527  p->setBrush(*fill);
528  p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2);
529  }
530  p->setPen(oldPen);
531  p->setBrush(oldBrush);
532 }
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
Q_CORE_EXPORT void qWarning(const char *,...)
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650

◆ qDrawPlainRect() [2/2]

void qDrawPlainRect ( QPainter p,
const QRect r,
const QColor c,
int  lineWidth,
const QBrush fill 
)

Definition at line 726 of file qdrawutil.cpp.

728 {
729  qDrawPlainRect(p, r.x(), r.y(), r.width(), r.height(), c,
730  lineWidth, fill);
731 }
unsigned char c[8]
Definition: qnumeric_p.h:62
void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, int lineWidth, const QBrush *fill)
Definition: qdrawutil.cpp:511
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252

◆ qDrawShadeLine() [1/2]

void qDrawShadeLine ( QPainter p,
int  x1,
int  y1,
int  x2,
int  y2,
const QPalette pal,
bool  sunken,
int  lineWidth,
int  midLineWidth 
)

Definition at line 93 of file qdrawutil.cpp.

Referenced by QMotifStyle::drawComplexControl(), QCommonStyle::drawControl(), QCommonStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), and qDrawShadeLine().

96 {
97  if (!(p && lineWidth >= 0 && midLineWidth >= 0)) {
98  qWarning("qDrawShadeLine: Invalid parameters");
99  return;
100  }
101  int tlw = lineWidth*2 + midLineWidth; // total line width
102  QPen oldPen = p->pen(); // save pen
103  if (sunken)
104  p->setPen(pal.color(QPalette::Dark));
105  else
106  p->setPen(pal.light().color());
107  QPolygon a;
108  int i;
109  if (y1 == y2) { // horizontal line
110  int y = y1 - tlw/2;
111  if (x1 > x2) { // swap x1 and x2
112  int t = x1;
113  x1 = x2;
114  x2 = t;
115  }
116  x2--;
117  for (i=0; i<lineWidth; i++) { // draw top shadow
118  a.setPoints(3, x1+i, y+tlw-1-i,
119  x1+i, y+i,
120  x2-i, y+i);
121  p->drawPolyline(a);
122  }
123  if (midLineWidth > 0) {
124  p->setPen(pal.mid().color());
125  for (i=0; i<midLineWidth; i++) // draw lines in the middle
126  p->drawLine(x1+lineWidth, y+lineWidth+i,
127  x2-lineWidth, y+lineWidth+i);
128  }
129  if (sunken)
130  p->setPen(pal.light().color());
131  else
132  p->setPen(pal.dark().color());
133  for (i=0; i<lineWidth; i++) { // draw bottom shadow
134  a.setPoints(3, x1+i, y+tlw-i-1,
135  x2-i, y+tlw-i-1,
136  x2-i, y+i+1);
137  p->drawPolyline(a);
138  }
139  }
140  else if (x1 == x2) { // vertical line
141  int x = x1 - tlw/2;
142  if (y1 > y2) { // swap y1 and y2
143  int t = y1;
144  y1 = y2;
145  y2 = t;
146  }
147  y2--;
148  for (i=0; i<lineWidth; i++) { // draw left shadow
149  a.setPoints(3, x+i, y2,
150  x+i, y1+i,
151  x+tlw-1, y1+i);
152  p->drawPolyline(a);
153  }
154  if (midLineWidth > 0) {
155  p->setPen(pal.mid().color());
156  for (i=0; i<midLineWidth; i++) // draw lines in the middle
157  p->drawLine(x+lineWidth+i, y1+lineWidth, x+lineWidth+i, y2);
158  }
159  if (sunken)
160  p->setPen(pal.light().color());
161  else
162  p->setPen(pal.dark().color());
163  for (i=0; i<lineWidth; i++) { // draw right shadow
164  a.setPoints(3, x+lineWidth, y2-i,
165  x+tlw-i-1, y2-i,
166  x+tlw-i-1, y1+lineWidth);
167  p->drawPolyline(a);
168  }
169  }
170  p->setPen(oldPen);
171 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
const QBrush & mid() const
Returns the mid brush of the current color group.
Definition: qpalette.h:128
Q_CORE_EXPORT void qWarning(const char *,...)
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void setPoints(int nPoints, const int *points)
Resizes the polygon to nPoints and populates it with the given points.
Definition: qpolygon.cpp:350
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen...
Definition: qpainter.cpp:5055

◆ qDrawShadeLine() [2/2]

void qDrawShadeLine ( QPainter p,
const QPoint p1,
const QPoint p2,
const QPalette pal,
bool  sunken,
int  lineWidth,
int  midLineWidth 
)

Definition at line 568 of file qdrawutil.cpp.

571 {
572  qDrawShadeLine(p, p1.x(), p1.y(), p2.x(), p2.y(), pal, sunken,
573  lineWidth, midLineWidth);
574 }
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth)
Definition: qdrawutil.cpp:93

◆ qDrawShadePanel() [1/2]

void qDrawShadePanel ( QPainter p,
int  x,
int  y,
int  w,
int  h,
const QPalette pal,
bool  sunken,
int  lineWidth,
const QBrush fill 
)

Definition at line 303 of file qdrawutil.cpp.

Referenced by QMotifStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QCDEStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QStyleSheetStyle::drawControl(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QDecorationDefault::paint(), QColorLuminancePicker::paintEvent(), and qDrawShadePanel().

306 {
307  if (w == 0 || h == 0)
308  return;
309  if (!(w > 0 && h > 0 && lineWidth >= 0)) {
310  qWarning("qDrawShadePanel: Invalid parameters");
311  }
312  QColor shade = pal.dark().color();
313  QColor light = pal.light().color();
314  if (fill) {
315  if (fill->color() == shade)
316  shade = pal.shadow().color();
317  if (fill->color() == light)
318  light = pal.midlight().color();
319  }
320  QPen oldPen = p->pen(); // save pen
321  QVector<QLineF> lines;
322  lines.reserve(2*lineWidth);
323 
324  if (sunken)
325  p->setPen(shade);
326  else
327  p->setPen(light);
328  int x1, y1, x2, y2;
329  int i;
330  x1 = x;
331  y1 = y2 = y;
332  x2 = x+w-2;
333  for (i=0; i<lineWidth; i++) { // top shadow
334  lines << QLineF(x1, y1++, x2--, y2++);
335  }
336  x2 = x1;
337  y1 = y+h-2;
338  for (i=0; i<lineWidth; i++) { // left shado
339  lines << QLineF(x1++, y1, x2++, y2--);
340  }
341  p->drawLines(lines);
342  lines.clear();
343  if (sunken)
344  p->setPen(light);
345  else
346  p->setPen(shade);
347  x1 = x;
348  y1 = y2 = y+h-1;
349  x2 = x+w-1;
350  for (i=0; i<lineWidth; i++) { // bottom shadow
351  lines << QLineF(x1++, y1--, x2, y2--);
352  }
353  x1 = x2;
354  y1 = y;
355  y2 = y+h-lineWidth-1;
356  for (i=0; i<lineWidth; i++) { // right shadow
357  lines << QLineF(x1--, y1++, x2--, y2);
358  }
359  p->drawLines(lines);
360  if (fill) // fill with fill color
361  p->fillRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, *fill);
362  p->setPen(oldPen); // restore pen
363 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
const QBrush & midlight() const
Returns the midlight brush of the current color group.
Definition: qpalette.h:136
Q_CORE_EXPORT void qWarning(const char *,...)
const QBrush & shadow() const
Returns the shadow brush of the current color group.
Definition: qpalette.h:139
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ qDrawShadePanel() [2/2]

void qDrawShadePanel ( QPainter p,
const QRect r,
const QPalette pal,
bool  sunken,
int  lineWidth,
const QBrush fill 
)

Definition at line 640 of file qdrawutil.cpp.

643 {
644  qDrawShadePanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken,
645  lineWidth, fill);
646 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
Definition: qdrawutil.cpp:303
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252

◆ qDrawShadeRect() [1/2]

void qDrawShadeRect ( QPainter p,
int  x,
int  y,
int  w,
int  h,
const QPalette pal,
bool  sunken,
int  lineWidth,
int  midLineWidth,
const QBrush fill 
)

Definition at line 204 of file qdrawutil.cpp.

Referenced by QCommonStyle::drawControl(), QWindowsStyle::drawControl(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), and qDrawShadeRect().

208 {
209  if (w == 0 || h == 0)
210  return;
211  if (! (w > 0 && h > 0 && lineWidth >= 0 && midLineWidth >= 0)) {
212  qWarning("qDrawShadeRect: Invalid parameters");
213  return;
214  }
215  QPen oldPen = p->pen();
216  if (sunken)
217  p->setPen(pal.dark().color());
218  else
219  p->setPen(pal.light().color());
220  int x1=x, y1=y, x2=x+w-1, y2=y+h-1;
221 
222  if (lineWidth == 1 && midLineWidth == 0) {// standard shade rectangle
223  p->drawRect(x1, y1, w-2, h-2);
224  if (sunken)
225  p->setPen(pal.light().color());
226  else
227  p->setPen(pal.dark().color());
228  QLineF lines[4] = { QLineF(x1+1, y1+1, x2-2, y1+1),
229  QLineF(x1+1, y1+2, x1+1, y2-2),
230  QLineF(x1, y2, x2, y2),
231  QLineF(x2,y1, x2,y2-1) };
232  p->drawLines(lines, 4); // draw bottom/right lines
233  } else { // more complicated
234  int m = lineWidth+midLineWidth;
235  int i, j=0, k=m;
236  for (i=0; i<lineWidth; i++) { // draw top shadow
237  QLineF lines[4] = { QLineF(x1+i, y2-i, x1+i, y1+i),
238  QLineF(x1+i, y1+i, x2-i, y1+i),
239  QLineF(x1+k, y2-k, x2-k, y2-k),
240  QLineF(x2-k, y2-k, x2-k, y1+k) };
241  p->drawLines(lines, 4);
242  k++;
243  }
244  p->setPen(pal.mid().color());
245  j = lineWidth*2;
246  for (i=0; i<midLineWidth; i++) { // draw lines in the middle
247  p->drawRect(x1+lineWidth+i, y1+lineWidth+i, w-j-1, h-j-1);
248  j += 2;
249  }
250  if (sunken)
251  p->setPen(pal.light().color());
252  else
253  p->setPen(pal.dark().color());
254  k = m;
255  for (i=0; i<lineWidth; i++) { // draw bottom shadow
256  QLineF lines[4] = { QLineF(x1+1+i, y2-i, x2-i, y2-i),
257  QLineF(x2-i, y2-i, x2-i, y1+i+1),
258  QLineF(x1+k, y2-k, x1+k, y1+k),
259  QLineF(x1+k, y1+k, x2-k, y1+k) };
260  p->drawLines(lines, 4);
261  k++;
262  }
263  }
264  if (fill) {
265  QBrush oldBrush = p->brush();
266  int tlw = lineWidth + midLineWidth;
267  p->setPen(Qt::NoPen);
268  p->setBrush(*fill);
269  p->drawRect(x+tlw, y+tlw, w-2*tlw, h-2*tlw);
270  p->setBrush(oldBrush);
271  }
272  p->setPen(oldPen); // restore pen
273 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
const QBrush & mid() const
Returns the mid brush of the current color group.
Definition: qpalette.h:128
Q_CORE_EXPORT void qWarning(const char *,...)
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650

◆ qDrawShadeRect() [2/2]

void qDrawShadeRect ( QPainter p,
const QRect r,
const QPalette pal,
bool  sunken,
int  lineWidth,
int  midLineWidth,
const QBrush fill 
)

Definition at line 605 of file qdrawutil.cpp.

609 {
610  qDrawShadeRect(p, r.x(), r.y(), r.width(), r.height(), pal, sunken,
611  lineWidth, midLineWidth, fill);
612 }
void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill)
Definition: qdrawutil.cpp:204
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252

◆ qDrawWinButton() [1/2]

void qDrawWinButton ( QPainter p,
int  x,
int  y,
int  w,
int  h,
const QPalette pal,
bool  sunken,
const QBrush fill 
)

Definition at line 435 of file qdrawutil.cpp.

Referenced by QWindowsStyle::drawComplexControl(), QWindowsStyle::drawControl(), QWindowsMobileStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), and qDrawWinButton().

438 {
439  if (sunken)
440  qDrawWinShades(p, x, y, w, h,
441  pal.shadow().color(), pal.light().color(), pal.dark().color(),
442  pal.button().color(), fill);
443  else
444  qDrawWinShades(p, x, y, w, h,
445  pal.light().color(), pal.shadow().color(), pal.button().color(),
446  pal.dark().color(), fill);
447 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
const QBrush & shadow() const
Returns the shadow brush of the current color group.
Definition: qpalette.h:139
static void qDrawWinShades(QPainter *p, int x, int y, int w, int h, const QColor &c1, const QColor &c2, const QColor &c3, const QColor &c4, const QBrush *fill)
This function draws a rectangle with two pixel line width.
Definition: qdrawutil.cpp:384
const QBrush & button() const
Returns the button brush of the current color group.
Definition: qpalette.h:125

◆ qDrawWinButton() [2/2]

void qDrawWinButton ( QPainter p,
const QRect r,
const QPalette pal,
bool  sunken,
const QBrush fill 
)

Definition at line 669 of file qdrawutil.cpp.

671 {
672  qDrawWinButton(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);
673 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void qDrawWinButton(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
Definition: qdrawutil.cpp:435
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252

◆ qDrawWinPanel() [1/2]

void qDrawWinPanel ( QPainter p,
int  x,
int  y,
int  w,
int  h,
const QPalette pal,
bool  sunken,
const QBrush fill 
)

Definition at line 475 of file qdrawutil.cpp.

Referenced by QCommonStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QCommonStyle::drawControl(), QCommonStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QDecorationDefault::paint(), QDecorationWindows::paintButton(), QDecorationDefault::paintButton(), and qDrawWinPanel().

478 {
479  if (sunken)
480  qDrawWinShades(p, x, y, w, h,
481  pal.dark().color(), pal.light().color(), pal.shadow().color(),
482  pal.midlight().color(), fill);
483  else
484  qDrawWinShades(p, x, y, w, h,
485  pal.light().color(), pal.shadow().color(), pal.midlight().color(),
486  pal.dark().color(), fill);
487 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
const QBrush & midlight() const
Returns the midlight brush of the current color group.
Definition: qpalette.h:136
const QBrush & shadow() const
Returns the shadow brush of the current color group.
Definition: qpalette.h:139
static void qDrawWinShades(QPainter *p, int x, int y, int w, int h, const QColor &c1, const QColor &c2, const QColor &c3, const QColor &c4, const QBrush *fill)
This function draws a rectangle with two pixel line width.
Definition: qdrawutil.cpp:384

◆ qDrawWinPanel() [2/2]

void qDrawWinPanel ( QPainter painter,
const QRect rect,
const QPalette palette,
bool  sunken,
const QBrush fill 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws the Windows-style panel at the rectangle specified by rect using the given painter with a line width of 2 pixels.

The button's interior is filled with the fill brush unless fill is 0.

The given palette specifies the shading colors. The panel appears sunken if sunken is true, otherwise raised.

Warning
This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make widgets that follow the current GUI style.

Alternatively you can use a QFrame widget and apply the QFrame::setFrameStyle() function to display a shaded panel:

See also
qDrawShadePanel(), qDrawWinButton(), QStyle

Definition at line 699 of file qdrawutil.cpp.

701 {
702  qDrawWinPanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);
703 }
void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
Definition: qdrawutil.cpp:475

◆ qDrawWinShades()

static void qDrawWinShades ( QPainter p,
int  x,
int  y,
int  w,
int  h,
const QColor c1,
const QColor c2,
const QColor c3,
const QColor c4,
const QBrush fill 
)
static

This function draws a rectangle with two pixel line width.

Warning
This function is not part of the public interface.

It is called from qDrawWinButton() and qDrawWinPanel().

c1..c4 and fill are used:

1 1 1 1 1 2 1 3 3 3 4 2 1 3 F F 4 2 1 3 F F 4 2 1 4 4 4 4 2 2 2 2 2 2 2

Definition at line 384 of file qdrawutil.cpp.

Referenced by qDrawWinButton(), and qDrawWinPanel().

389 {
390  if (w < 2 || h < 2) // can't do anything with that
391  return;
392  QPen oldPen = p->pen();
393  QPoint a[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) };
394  p->setPen(c1);
395  p->drawPolyline(a, 3);
396  QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) };
397  p->setPen(c2);
398  p->drawPolyline(b, 3);
399  if (w > 4 && h > 4) {
400  QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) };
401  p->setPen(c3);
402  p->drawPolyline(c, 3);
403  QPoint d[3] = { QPoint(x+1, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y+1) };
404  p->setPen(c4);
405  p->drawPolyline(d, 3);
406  if (fill)
407  p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill);
408  }
409  p->setPen(oldPen);
410 }
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen...
Definition: qpainter.cpp:5055
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420