| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QDRAWUTIL_H |
| 5 | #define QDRAWUTIL_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtCore/qnamespace.h> |
| 9 | #include <QtCore/qstring.h> // char*->QString conversion |
| 10 | #include <QtCore/qmargins.h> |
| 11 | #include <QtGui/qpixmap.h> |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | |
| 15 | class QPainter; |
| 16 | class QPalette; |
| 17 | class QPoint; |
| 18 | class QColor; |
| 19 | class QBrush; |
| 20 | class QRect; |
| 21 | |
| 22 | // |
| 23 | // Standard shade drawing |
| 24 | // |
| 25 | |
| 26 | Q_WIDGETS_EXPORT void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, |
| 27 | const QPalette &pal, bool sunken = true, |
| 28 | int lineWidth = 1, int midLineWidth = 0); |
| 29 | |
| 30 | Q_WIDGETS_EXPORT void qDrawShadeLine(QPainter *p, const QPoint &p1, const QPoint &p2, |
| 31 | const QPalette &pal, bool sunken = true, |
| 32 | int lineWidth = 1, int midLineWidth = 0); |
| 33 | |
| 34 | Q_WIDGETS_EXPORT void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, |
| 35 | const QPalette &pal, bool sunken = false, |
| 36 | int lineWidth = 1, int midLineWidth = 0, |
| 37 | const QBrush *fill = nullptr); |
| 38 | |
| 39 | Q_WIDGETS_EXPORT void qDrawShadeRect(QPainter *p, const QRect &r, |
| 40 | const QPalette &pal, bool sunken = false, |
| 41 | int lineWidth = 1, int midLineWidth = 0, |
| 42 | const QBrush *fill = nullptr); |
| 43 | |
| 44 | Q_WIDGETS_EXPORT void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, |
| 45 | const QPalette &pal, bool sunken = false, |
| 46 | int lineWidth = 1, const QBrush *fill = nullptr); |
| 47 | |
| 48 | Q_WIDGETS_EXPORT void qDrawShadePanel(QPainter *p, const QRect &r, |
| 49 | const QPalette &pal, bool sunken = false, |
| 50 | int lineWidth = 1, const QBrush *fill = nullptr); |
| 51 | |
| 52 | Q_WIDGETS_EXPORT void qDrawWinButton(QPainter *p, int x, int y, int w, int h, |
| 53 | const QPalette &pal, bool sunken = false, |
| 54 | const QBrush *fill = nullptr); |
| 55 | |
| 56 | Q_WIDGETS_EXPORT void qDrawWinButton(QPainter *p, const QRect &r, |
| 57 | const QPalette &pal, bool sunken = false, |
| 58 | const QBrush *fill = nullptr); |
| 59 | |
| 60 | Q_WIDGETS_EXPORT void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, |
| 61 | const QPalette &pal, bool sunken = false, |
| 62 | const QBrush *fill = nullptr); |
| 63 | |
| 64 | Q_WIDGETS_EXPORT void qDrawWinPanel(QPainter *p, const QRect &r, |
| 65 | const QPalette &pal, bool sunken = false, |
| 66 | const QBrush *fill = nullptr); |
| 67 | |
| 68 | Q_WIDGETS_EXPORT void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &, |
| 69 | int lineWidth = 1, const QBrush *fill = nullptr); |
| 70 | |
| 71 | Q_WIDGETS_EXPORT void qDrawPlainRect(QPainter *p, const QRect &r, const QColor &, |
| 72 | int lineWidth = 1, const QBrush *fill = nullptr); |
| 73 | |
| 74 | Q_WIDGETS_EXPORT void qDrawPlainRoundedRect(QPainter *p, int x, int y, int w, int h, |
| 75 | qreal rx, qreal ry, const QColor &, int lineWidth = 1, |
| 76 | const QBrush *fill = nullptr); |
| 77 | |
| 78 | inline void qDrawPlainRoundedRect(QPainter *painter, const QRect& rect, qreal rx, qreal ry, |
| 79 | const QColor &lineColor, int lineWidth = 1, |
| 80 | const QBrush *fill = nullptr) |
| 81 | { |
| 82 | qDrawPlainRoundedRect(p: painter, x: rect.x(), y: rect.y(), w: rect.width(), h: rect.height(), |
| 83 | rx, ry, lineColor, lineWidth, fill); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | struct QTileRules |
| 88 | { |
| 89 | inline QTileRules(Qt::TileRule horizontalRule, Qt::TileRule verticalRule) |
| 90 | : horizontal(horizontalRule), vertical(verticalRule) {} |
| 91 | inline QTileRules(Qt::TileRule rule = Qt::StretchTile) |
| 92 | : horizontal(rule), vertical(rule) {} |
| 93 | Qt::TileRule horizontal; |
| 94 | Qt::TileRule vertical; |
| 95 | }; |
| 96 | |
| 97 | #ifndef Q_QDOC |
| 98 | // For internal use only. |
| 99 | namespace QDrawBorderPixmap |
| 100 | { |
| 101 | enum DrawingHint |
| 102 | { |
| 103 | OpaqueTopLeft = 0x0001, |
| 104 | OpaqueTop = 0x0002, |
| 105 | OpaqueTopRight = 0x0004, |
| 106 | OpaqueLeft = 0x0008, |
| 107 | OpaqueCenter = 0x0010, |
| 108 | OpaqueRight = 0x0020, |
| 109 | OpaqueBottomLeft = 0x0040, |
| 110 | OpaqueBottom = 0x0080, |
| 111 | OpaqueBottomRight = 0x0100, |
| 112 | OpaqueCorners = OpaqueTopLeft | OpaqueTopRight | OpaqueBottomLeft | OpaqueBottomRight, |
| 113 | OpaqueEdges = OpaqueTop | OpaqueLeft | OpaqueRight | OpaqueBottom, |
| 114 | OpaqueFrame = OpaqueCorners | OpaqueEdges, |
| 115 | OpaqueAll = OpaqueCenter | OpaqueFrame |
| 116 | }; |
| 117 | |
| 118 | Q_DECLARE_FLAGS(DrawingHints, DrawingHint) |
| 119 | } |
| 120 | #endif |
| 121 | |
| 122 | Q_WIDGETS_EXPORT void qDrawBorderPixmap(QPainter *painter, |
| 123 | const QRect &targetRect, |
| 124 | const QMargins &targetMargins, |
| 125 | const QPixmap &pixmap, |
| 126 | const QRect &sourceRect, |
| 127 | const QMargins &sourceMargins, |
| 128 | const QTileRules &rules = QTileRules() |
| 129 | #ifndef Q_QDOC |
| 130 | , QDrawBorderPixmap::DrawingHints hints = QDrawBorderPixmap::DrawingHints() |
| 131 | #endif |
| 132 | ); |
| 133 | |
| 134 | inline void qDrawBorderPixmap(QPainter *painter, |
| 135 | const QRect &target, |
| 136 | const QMargins &margins, |
| 137 | const QPixmap &pixmap) |
| 138 | { |
| 139 | qDrawBorderPixmap(painter, targetRect: target, targetMargins: margins, pixmap, sourceRect: pixmap.rect(), sourceMargins: margins); |
| 140 | } |
| 141 | |
| 142 | QT_END_NAMESPACE |
| 143 | |
| 144 | #endif // QDRAWUTIL_H |
| 145 | |