diff options
Diffstat (limited to 'src/widgets/styles/qdrawutil.cpp')
-rw-r--r-- | src/widgets/styles/qdrawutil.cpp | 114 |
1 files changed, 103 insertions, 11 deletions
diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index 97507c90d5..5bdbdb1139 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -230,8 +230,8 @@ void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, p->scale(inverseScale, inverseScale); x = qRound(devicePixelRatio * x); y = qRound(devicePixelRatio * y); - w = qRound(devicePixelRatio * w); - h = qRound(devicePixelRatio * h); + w = devicePixelRatio * w; + h = devicePixelRatio * h; lineWidth = qRound(devicePixelRatio * lineWidth); midLineWidth = qRound(devicePixelRatio * midLineWidth); p->translate(0.5, 0.5); @@ -297,7 +297,6 @@ void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, p->setPen(oldPen); // restore pen } - /*! \fn void qDrawShadePanel(QPainter *painter, int x, int y, int width, int height, const QPalette &palette, bool sunken, @@ -346,8 +345,8 @@ void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, p->scale(inverseScale, inverseScale); x = qRound(devicePixelRatio * x); y = qRound(devicePixelRatio * y); - w = qRound(devicePixelRatio * w); - h = qRound(devicePixelRatio * h); + w = devicePixelRatio * w; + h = devicePixelRatio * h; lineWidth = qRound(devicePixelRatio * lineWidth); p->translate(0.5, 0.5); isTranslated = true; @@ -409,7 +408,6 @@ void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, p->setPen(oldPen); // restore pen } - /*! \internal This function draws a rectangle with two pixel line width. @@ -443,8 +441,8 @@ static void qDrawWinShades(QPainter *p, p->scale(inverseScale, inverseScale); x = qRound(devicePixelRatio * x); y = qRound(devicePixelRatio * y); - w = qRound(devicePixelRatio * w); - h = qRound(devicePixelRatio * h); + w = devicePixelRatio * w; + h = devicePixelRatio * h; p->translate(0.5, 0.5); isTranslated = true; } @@ -590,8 +588,8 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, p->scale(inverseScale, inverseScale); x = qRound(devicePixelRatio * x); y = qRound(devicePixelRatio * y); - w = qRound(devicePixelRatio * w); - h = qRound(devicePixelRatio * h); + w = devicePixelRatio * w; + h = devicePixelRatio * h; lineWidth = qRound(devicePixelRatio * lineWidth); p->translate(0.5, 0.5); } @@ -611,6 +609,74 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, p->setBrush(oldBrush); } +/*! + \fn void qDrawPlainRoundedRect(QPainter *painter, int x, int y, + int width, int height, qreal rx, qreal ry, + const QColor &lineColor, int lineWidth, + const QBrush *fill) + \since 6.7 + \relates <qdrawutil.h> + + Draws the plain rounded rectangle beginning at (\a x, \a y) + with the given \a width and \a height, + using the horizontal \a rx and vertical radius \a ry, + specified \a painter, \a lineColor and \a lineWidth. + The rectangle's interior is filled with the \a + fill brush unless \a fill is \nullptr. + + \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 plain rectangle: + + \snippet code/src_gui_painting_qdrawutil.cpp 4 + + \sa qDrawShadeRect(), QStyle +*/ + +// ### Qt7: Pass QPen instead of QColor for frame drawing +void qDrawPlainRoundedRect(QPainter *p, int x, int y, int w, int h, + qreal rx, qreal ry, const QColor &c, + int lineWidth, const QBrush *fill) +{ + if (w == 0 || h == 0) + return; + if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) { + qWarning("qDrawPlainRect: Invalid parameters"); + } + + PainterStateGuard painterGuard(p); + const qreal devicePixelRatio = p->device()->devicePixelRatio(); + if (!qFuzzyCompare(devicePixelRatio, qreal(1))) { + painterGuard.save(); + const qreal inverseScale = qreal(1) / devicePixelRatio; + p->scale(inverseScale, inverseScale); + x = qRound(devicePixelRatio * x); + y = qRound(devicePixelRatio * y); + w = devicePixelRatio * w; + h = devicePixelRatio * h; + lineWidth = qRound(devicePixelRatio * lineWidth); + p->translate(0.5, 0.5); + } + + p->save(); + p->setPen(c); + p->setBrush(Qt::NoBrush); + for (int i=0; i<lineWidth; i++) { + QRectF rect(x+i, y+i, w-i*2 - 1, h-i*2 - 1); + rect.marginsRemoved(QMarginsF(0.5,0.5,0.5,0.5)); + p->drawRoundedRect(rect, rx, ry); + } + if (fill) { // fill with fill color + p->setPen(Qt::NoPen); + p->setBrush(*fill); + p->drawRoundedRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, rx, ry); + } + p->restore(); +} + /***************************************************************************** Overloaded functions. *****************************************************************************/ @@ -819,6 +885,32 @@ void qDrawPlainRect(QPainter *p, const QRect &r, const QColor &c, lineWidth, fill); } +/*! + \fn void qDrawPlainRoundedRect(QPainter *painter, const QRect &rect, + qreal rx, qreal ry, + const QColor &lineColor, int lineWidth, + const QBrush *fill) + \since 6.7 + \relates <qdrawutil.h> + \overload + + Draws the plain rectangle specified by \a rect using + the horizontal \a rx and vertical radius \a ry, + the given \a painter, \a lineColor and \a lineWidth. + The rectangle's interior is filled with the + \a fill brush unless \a fill is \nullptr. + + \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 plain rectangle: + + \snippet code/src_gui_painting_qdrawutil.cpp 9 + + \sa qDrawShadeRect(), QStyle +*/ /*! \class QTileRules @@ -878,7 +970,7 @@ typedef QVarLengthArray<QPainter::PixmapFragment, 16> QPixmapFragmentsArray; void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap, const QRect &sourceRect,const QMargins &sourceMargins, const QTileRules &rules -#ifndef Q_CLANG_QDOC +#ifndef Q_QDOC , QDrawBorderPixmap::DrawingHints hints #endif ) |