10#include <private/qpaintengineex_p.h>
13#include <private/qhexstring_p.h>
20class PainterStateGuard {
21 Q_DISABLE_COPY_MOVE(PainterStateGuard)
23 explicit PainterStateGuard(
QPainter *
p) : m_painter(
p) {}
26 for ( ; m_level > 0; --m_level)
90 int lineWidth,
int midLineWidth)
92 if (
Q_UNLIKELY(!
p || lineWidth < 0 || midLineWidth < 0)) {
93 qWarning(
"qDrawShadeLine: Invalid parameters");
96 PainterStateGuard painterGuard(
p);
97 const qreal devicePixelRatio =
p->device()->devicePixelRatio();
100 const qreal inverseScale =
qreal(1) / devicePixelRatio;
101 p->scale(inverseScale, inverseScale);
106 lineWidth =
qRound(devicePixelRatio * lineWidth);
107 midLineWidth =
qRound(devicePixelRatio * midLineWidth);
108 p->translate(0.5, 0.5);
110 int tlw = lineWidth*2 + midLineWidth;
111 QPen oldPen =
p->pen();
126 for (
i=0;
i<lineWidth;
i++) {
127 a.setPoints(3,
x1+
i,
y+tlw-1-
i,
132 if (midLineWidth > 0) {
134 for (
i=0;
i<midLineWidth;
i++)
135 p->drawLine(
x1+lineWidth,
y+lineWidth+
i,
136 x2-lineWidth,
y+lineWidth+
i);
142 for (
i=0;
i<lineWidth;
i++) {
143 a.setPoints(3,
x1+
i,
y+tlw-
i-1,
157 for (
i=0;
i<lineWidth;
i++) {
158 a.setPoints(3,
x+
i,
y2,
163 if (midLineWidth > 0) {
165 for (
i=0;
i<midLineWidth;
i++)
166 p->drawLine(
x+lineWidth+
i,
y1+lineWidth,
x+lineWidth+
i,
y2);
172 for (
i=0;
i<lineWidth;
i++) {
173 a.setPoints(3,
x+lineWidth,
y2-
i,
175 x+tlw-
i-1,
y1+lineWidth);
217 int lineWidth,
int midLineWidth,
220 if (
w == 0 ||
h == 0)
222 if (
Q_UNLIKELY(
w < 0 ||
h < 0 || lineWidth < 0 || midLineWidth < 0)) {
223 qWarning(
"qDrawShadeRect: Invalid parameters");
227 PainterStateGuard painterGuard(
p);
228 const qreal devicePixelRatio =
p->device()->devicePixelRatioF();
231 const qreal inverseScale =
qreal(1) / devicePixelRatio;
232 p->scale(inverseScale, inverseScale);
237 lineWidth =
qRound(devicePixelRatio * lineWidth);
238 midLineWidth =
qRound(devicePixelRatio * midLineWidth);
239 p->translate(0.5, 0.5);
242 QPen oldPen =
p->pen();
249 if (lineWidth == 1 && midLineWidth == 0) {
259 p->drawLines(lines, 4);
261 int m = lineWidth+midLineWidth;
263 for (
i=0;
i<lineWidth;
i++) {
268 p->drawLines(lines, 4);
273 for (
i=0;
i<midLineWidth;
i++) {
274 p->drawRect(
x1+lineWidth+
i,
y1+lineWidth+
i,
w-
j-1,
h-
j-1);
282 for (
i=0;
i<lineWidth;
i++) {
287 p->drawLines(lines, 4);
293 int tlw = lineWidth + midLineWidth;
296 p->drawRect(
x+tlw,
y+tlw,
w-2*tlw,
h-2*tlw);
297 p->setBrush(oldBrush);
336 if (
w == 0 ||
h == 0)
339 qWarning(
"qDrawShadePanel: Invalid parameters");
342 PainterStateGuard painterGuard(
p);
343 const qreal devicePixelRatio =
p->device()->devicePixelRatioF();
344 bool isTranslated =
false;
347 const qreal inverseScale =
qreal(1) / devicePixelRatio;
348 p->scale(inverseScale, inverseScale);
353 lineWidth =
qRound(devicePixelRatio * lineWidth);
354 p->translate(0.5, 0.5);
361 if (
fill->color() == shade)
363 if (
fill->color() == light)
366 QPen oldPen =
p->pen();
379 for (
i=0;
i<lineWidth;
i++) {
384 for (
i=0;
i<lineWidth;
i++) {
396 for (
i=0;
i<lineWidth;
i++) {
401 y2 =
y+
h-lineWidth-1;
402 for (
i=0;
i<lineWidth;
i++) {
408 p->translate(-0.5, -0.5);
409 p->fillRect(
x+lineWidth,
y+lineWidth,
w-lineWidth*2,
h-lineWidth*2, *
fill);
431 int x,
int y,
int w,
int h,
439 PainterStateGuard painterGuard(
p);
440 const qreal devicePixelRatio =
p->device()->devicePixelRatioF();
441 bool isTranslated =
false;
444 const qreal inverseScale =
qreal(1) / devicePixelRatio;
445 p->scale(inverseScale, inverseScale);
450 p->translate(0.5, 0.5);
454 QPen oldPen =
p->pen();
457 p->drawPolyline(
a, 3);
460 p->drawPolyline(
b, 3);
461 if (
w > 4 &&
h > 4) {
464 p->drawPolyline(
c, 3);
467 p->drawPolyline(
d, 3);
470 p->translate(-0.5, -0.5);
581 if (
w == 0 ||
h == 0)
584 qWarning(
"qDrawPlainRect: Invalid parameters");
587 PainterStateGuard painterGuard(
p);
588 const qreal devicePixelRatio =
p->device()->devicePixelRatioF();
591 const qreal inverseScale =
qreal(1) / devicePixelRatio;
592 p->scale(inverseScale, inverseScale);
597 lineWidth =
qRound(devicePixelRatio * lineWidth);
598 p->translate(0.5, 0.5);
601 QPen oldPen =
p->pen();
605 for (
int i=0;
i<lineWidth;
i++)
606 p->drawRect(
x+
i,
y+
i,
w-
i*2 - 1,
h-
i*2 - 1);
610 p->drawRect(
x+lineWidth,
y+lineWidth,
w-lineWidth*2,
h-lineWidth*2);
613 p->setBrush(oldBrush);
654 int lineWidth,
int midLineWidth)
657 lineWidth, midLineWidth);
693 int lineWidth,
int midLineWidth,
697 lineWidth, midLineWidth,
fill);
882 , QDrawBorderPixmap::DrawingHints hints
894 const int sourceCenterTop = sourceRect.
top() + sourceMargins.
top();
895 const int sourceCenterLeft = sourceRect.
left() + sourceMargins.
left();
896 const int sourceCenterBottom = sourceRect.
bottom() - sourceMargins.
bottom() + 1;
897 const int sourceCenterRight = sourceRect.
right() - sourceMargins.
right() + 1;
898 const int sourceCenterWidth = sourceCenterRight - sourceCenterLeft;
899 const int sourceCenterHeight = sourceCenterBottom - sourceCenterTop;
901 const int targetCenterTop = targetRect.
top() + targetMargins.
top();
902 const int targetCenterLeft = targetRect.
left() + targetMargins.
left();
903 const int targetCenterBottom = targetRect.
bottom() - targetMargins.
bottom() + 1;
904 const int targetCenterRight = targetRect.
right() - targetMargins.
right() + 1;
905 const int targetCenterWidth = targetCenterRight - targetCenterLeft;
906 const int targetCenterHeight = targetCenterBottom - targetCenterTop;
914 columns =
qMax(3, 2 +
qCeil(targetCenterWidth /
qreal(sourceCenterWidth)));
916 rows =
qMax(3, 2 +
qCeil(targetCenterHeight /
qreal(sourceCenterHeight)));
918 xTarget.
resize(columns + 1);
928 xTarget[0] = targetRect.
left();
929 xTarget[1] = targetCenterLeft;
930 xTarget[columns - 1] = targetCenterRight;
931 xTarget[columns] = targetRect.
left() + targetRect.
width();
933 yTarget[0] = targetRect.
top();
934 yTarget[1] = targetCenterTop;
935 yTarget[rows - 1] = targetCenterBottom;
936 yTarget[rows] = targetRect.
top() + targetRect.
height();
938 qreal dx = targetCenterWidth;
939 qreal dy = targetCenterHeight;
941 switch (rules.horizontal) {
943 dx = targetCenterWidth;
946 dx = sourceCenterWidth;
949 dx = targetCenterWidth /
qreal(columns - 2);
953 for (
int i = 2;
i < columns - 1; ++
i)
954 xTarget[
i] = xTarget[
i - 1] + dx;
956 switch (rules.vertical) {
958 dy = targetCenterHeight;
961 dy = sourceCenterHeight;
964 dy = targetCenterHeight /
qreal(rows - 2);
968 for (
int i = 2;
i < rows - 1; ++
i)
969 yTarget[
i] = yTarget[
i - 1] + dy;
972 if (targetMargins.
top() > 0 && targetMargins.
left() > 0 && sourceMargins.
top() > 0 && sourceMargins.
left() > 0) {
973 d.x = (0.5 * (xTarget[1] + xTarget[0]));
974 d.y = (0.5 * (yTarget[1] + yTarget[0]));
975 d.sourceLeft = sourceRect.
left();
976 d.sourceTop = sourceRect.
top();
977 d.width = sourceMargins.
left();
978 d.height = sourceMargins.
top();
979 d.scaleX =
qreal(xTarget[1] - xTarget[0]) /
d.width;
980 d.scaleY =
qreal(yTarget[1] - yTarget[0]) /
d.height;
986 if (targetMargins.
top() > 0 && targetMargins.
right() > 0 && sourceMargins.
top() > 0 && sourceMargins.
right() > 0) {
987 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1]));
988 d.y = (0.5 * (yTarget[1] + yTarget[0]));
989 d.sourceLeft = sourceCenterRight;
990 d.sourceTop = sourceRect.
top();
991 d.width = sourceMargins.
right();
992 d.height = sourceMargins.
top();
993 d.scaleX =
qreal(xTarget[columns] - xTarget[columns - 1]) /
d.width;
994 d.scaleY =
qreal(yTarget[1] - yTarget[0]) /
d.height;
1000 if (targetMargins.
bottom() > 0 && targetMargins.
left() > 0 && sourceMargins.
bottom() > 0 && sourceMargins.
left() > 0) {
1001 d.x = (0.5 * (xTarget[1] + xTarget[0]));
1002 d.y =(0.5 * (yTarget[rows] + yTarget[rows - 1]));
1003 d.sourceLeft = sourceRect.
left();
1004 d.sourceTop = sourceCenterBottom;
1005 d.width = sourceMargins.
left();
1006 d.height = sourceMargins.
bottom();
1007 d.scaleX =
qreal(xTarget[1] - xTarget[0]) /
d.width;
1008 d.scaleY =
qreal(yTarget[rows] - yTarget[rows - 1]) /
d.height;
1014 if (targetMargins.
bottom() > 0 && targetMargins.
right() > 0 && sourceMargins.
bottom() > 0 && sourceMargins.
right() > 0) {
1015 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1]));
1016 d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1]));
1017 d.sourceLeft = sourceCenterRight;
1018 d.sourceTop = sourceCenterBottom;
1019 d.width = sourceMargins.
right();
1020 d.height = sourceMargins.
bottom();
1021 d.scaleX =
qreal(xTarget[columns] - xTarget[columns - 1]) /
d.width;
1022 d.scaleY =
qreal(yTarget[rows] - yTarget[rows - 1]) /
d.height;
1030 if (targetCenterWidth > 0 && sourceCenterWidth > 0) {
1031 if (targetMargins.
top() > 0 && sourceMargins.
top() > 0) {
1033 d.sourceLeft = sourceCenterLeft;
1034 d.sourceTop = sourceRect.
top();
1035 d.width = sourceCenterWidth;
1036 d.height = sourceMargins.
top();
1037 d.y = (0.5 * (yTarget[1] + yTarget[0]));
1038 d.scaleX = dx /
d.width;
1039 d.scaleY =
qreal(yTarget[1] - yTarget[0]) /
d.height;
1040 for (
int i = 1;
i < columns - 1; ++
i) {
1041 d.x = (0.5 * (xTarget[
i + 1] + xTarget[
i]));
1045 data[
data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) /
d.scaleX);
1047 if (targetMargins.
bottom() > 0 && sourceMargins.
bottom() > 0) {
1049 d.sourceLeft = sourceCenterLeft;
1050 d.sourceTop = sourceCenterBottom;
1051 d.width = sourceCenterWidth;
1052 d.height = sourceMargins.
bottom();
1053 d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1]));
1054 d.scaleX = dx /
d.width;
1055 d.scaleY =
qreal(yTarget[rows] - yTarget[rows - 1]) /
d.height;
1056 for (
int i = 1;
i < columns - 1; ++
i) {
1057 d.x = (0.5 * (xTarget[
i + 1] + xTarget[
i]));
1061 data[
data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) /
d.scaleX);
1066 if (targetCenterHeight > 0 && sourceCenterHeight > 0) {
1067 if (targetMargins.
left() > 0 && sourceMargins.
left() > 0) {
1069 d.sourceLeft = sourceRect.
left();
1070 d.sourceTop = sourceCenterTop;
1071 d.width = sourceMargins.
left();
1072 d.height = sourceCenterHeight;
1073 d.x = (0.5 * (xTarget[1] + xTarget[0]));
1074 d.scaleX =
qreal(xTarget[1] - xTarget[0]) /
d.width;
1075 d.scaleY = dy /
d.height;
1076 for (
int i = 1;
i < rows - 1; ++
i) {
1077 d.y = (0.5 * (yTarget[
i + 1] + yTarget[
i]));
1081 data[
data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) /
d.scaleY);
1083 if (targetMargins.
right() > 0 && sourceMargins.
right() > 0) {
1085 d.sourceLeft = sourceCenterRight;
1086 d.sourceTop = sourceCenterTop;
1087 d.width = sourceMargins.
right();
1088 d.height = sourceCenterHeight;
1089 d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1]));
1090 d.scaleX =
qreal(xTarget[columns] - xTarget[columns - 1]) /
d.width;
1091 d.scaleY = dy /
d.height;
1092 for (
int i = 1;
i < rows - 1; ++
i) {
1093 d.y = (0.5 * (yTarget[
i + 1] + yTarget[
i]));
1097 data[
data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) /
d.scaleY);
1102 if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) {
1104 d.sourceLeft = sourceCenterLeft;
1105 d.sourceTop = sourceCenterTop;
1106 d.width = sourceCenterWidth;
1107 d.height = sourceCenterHeight;
1108 d.scaleX = dx /
d.width;
1109 d.scaleY = dy /
d.height;
1111 qreal repeatWidth = (xTarget[columns - 1] - xTarget[columns - 2]) /
d.scaleX;
1112 qreal repeatHeight = (yTarget[rows - 1] - yTarget[rows - 2]) /
d.scaleY;
1114 for (
int j = 1;
j < rows - 1; ++
j) {
1115 d.y = (0.5 * (yTarget[
j + 1] + yTarget[
j]));
1116 for (
int i = 1;
i < columns - 1; ++
i) {
1117 d.x = (0.5 * (xTarget[
i + 1] + xTarget[
i]));
1121 data[
data.size() - 1].width = repeatWidth;
1124 for (
int i = 1;
i < columns - 1; ++
i)
1125 data[
data.size() -
i].height = repeatHeight;
1129 if (opaqueData.
size())
1131 if (translucentData.
size())
const QColor & color() const
Returns the brush color.
The QColor class provides colors based on RGB, HSV or CMYK values.
void reserve(qsizetype size)
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
This class is used in conjunction with the QPainter::drawPixmapFragments() function to specify how a ...
The QPainter class performs low-level painting on widgets and other paint devices.
void drawPixmapFragments(const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=PixmapFragmentHints())
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
QTransform combinedTransform() const
Returns the transformation matrix combining the current window/viewport and world transformation.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
bool testRenderHint(RenderHint hint) const
The QPalette class contains color groups for each widget state.
const QBrush & button() const
Returns the button brush of the current color group.
const QBrush & dark() const
Returns the dark brush of the current color group.
const QBrush & shadow() const
Returns the shadow brush of the current color group.
const QBrush & light() const
Returns the light brush of the current color group.
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
const QBrush & mid() const
Returns the mid brush of the current color group.
const QBrush & midlight() const
Returns the midlight brush of the current color group.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
\inmodule QtCore\reentrant
The QPolygon class provides a list of points using integer precision.
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
constexpr size_type size() const noexcept
void resize(qsizetype sz)
void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill)
QVarLengthArray< QPainter::PixmapFragment, 16 > QPixmapFragmentsArray
void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth)
void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, int lineWidth, const QBrush *fill)
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)
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)
void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
void qDrawWinButton(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
int qRound(qfloat16 d) noexcept
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLfloat GLfloat GLfloat x1
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h
GLfixed GLfixed GLfixed y2
The QTileRules class provides the rules used to draw a pixmap or image split into nine segments.