From b1e16ec1e8b6bba083a67e5a93ee3adafec8eefe Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 14 Nov 2023 21:07:20 +0100 Subject: [PATCH] Windows style: use std::array instead QPolygon Use std::array instead a dynamic QPolygon since there is no dynamic allocation needed here. Change-Id: Ica31d22a7b0d44efb901e230f14a00e2ce0a2c0a Reviewed-by: Axel Spoerl --- src/widgets/styles/qwindowsstyle.cpp | 35 +++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 8fa44e5796d..405c213c1a6 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -1940,39 +1940,36 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp QSliderDirection dir; if (orient == Qt::Horizontal) - if (tickAbove) - dir = SlUp; - else - dir = SlDown; + dir = tickAbove ? SlUp : SlDown; else - if (tickAbove) - dir = SlLeft; - else - dir = SlRight; - - QPolygon a; + dir = tickAbove ? SlLeft : SlRight; + std::array points; int d = 0; switch (dir) { case SlUp: - y1 = y1 + wi/2; + y1 = y1 + wi / 2; d = (wi + 1) / 2 - 1; - a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d); + points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2), + QPoint(x2, y1), QPoint(x1 + d, y1 - d)}; break; case SlDown: - y2 = y2 - wi/2; + y2 = y2 - wi / 2; d = (wi + 1) / 2 - 1; - a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1); + points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x1 + d, y2 + d), + QPoint(x2, y2), QPoint(x2, y1)}; break; case SlLeft: d = (he + 1) / 2 - 1; - x1 = x1 + he/2; - a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1); + x1 = x1 + he / 2; + points = {QPoint(x1, y1), QPoint(x1 - d, y1 + d), QPoint(x1,y2), + QPoint(x2, y2), QPoint(x2, y1)}; break; case SlRight: d = (he + 1) / 2 - 1; - x2 = x2 - he/2; - a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1); + x2 = x2 - he / 2; + points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2), + QPoint(x2 + d, y1 + d), QPoint(x2, y1)}; break; } @@ -1982,7 +1979,7 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp Qt::BGMode oldMode = p->backgroundMode(); p->setBackgroundMode(Qt::OpaqueMode); p->drawRect(x1, y1, x2-x1+1, y2-y1+1); - p->drawPolygon(a); + p->drawPolygon(points.data(), static_cast(points.size())); p->setBrush(oldBrush); p->setBackgroundMode(oldMode);