From d7b94bfffa32b4e8368857dbaa7034d18703a118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDeljan=20Rikalo?= Date: Wed, 6 Oct 2021 11:37:19 +0200 Subject: [PATCH] Qt,Qt5: fixed problem with drawing primitives when antialiasing enabled. issue #39416 (cherry picked from commit e8317fb53458885f49253c7fc915dbb38b08c487) --- lcl/interfaces/qt/qtobjects.pas | 24 ++++++++++++++++++++++++ lcl/interfaces/qt/qtwinapi.inc | 10 ++++++++-- lcl/interfaces/qt5/qtobjects.pas | 24 ++++++++++++++++++++++++ lcl/interfaces/qt5/qtwinapi.inc | 11 ++++++++--- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/lcl/interfaces/qt/qtobjects.pas b/lcl/interfaces/qt/qtobjects.pas index 904e2995a3..baf00272cb 100644 --- a/lcl/interfaces/qt/qtobjects.pas +++ b/lcl/interfaces/qt/qtobjects.pas @@ -428,10 +428,12 @@ type procedure drawPoint(x1: Integer; y1: Integer); procedure drawRect(x1: Integer; y1: Integer; w: Integer; h: Integer; const AQtBugWorkaroundNeeded: Boolean = False); + procedure drawRectF(x1: double; y1: double; w: double; h: double); procedure drawRoundRect(x, y, w, h, rx, ry: Integer); procedure drawText(x: Integer; y: Integer; s: PWideString); overload; procedure drawText(x,y,w,h,flags: Integer; s:PWideString); overload; procedure drawLine(x1: Integer; y1: Integer; x2: Integer; y2: Integer); + procedure drawLineF(x1: double; y1: double; x2: double; y2: double); procedure drawEllipse(x: Integer; y: Integer; w: Integer; h: Integer); procedure drawPixmap(p: PQtPoint; pm: QPixmapH; sr: PRect); procedure drawPolyLine(P: PPoint; NumPts: Integer); @@ -2790,6 +2792,16 @@ begin QPen_setWidthF(QPainter_pen(Widget), PW); end; +procedure TQtDeviceContext.drawRectF(x1: double; y1: double; w: double; + h: double); +var + R: QRectFH; +begin + R := QRectF_Create(x1 + 0.5, y1 + 0.5, w, h); + QPainter_drawRect(Widget, R); + QRectF_Destroy(R); +end; + procedure TQtDeviceContext.drawRoundRect(x, y, w, h, rx, ry: Integer); begin QPainter_drawRoundedRect(Widget, x, y, w, h, rx, ry); @@ -2930,6 +2942,18 @@ begin QPainter_drawLine(Widget, x1, y1, x2, y2); end; +procedure TQtDeviceContext.drawLineF(x1: double; y1: double; x2: double; + y2: double); +var + APt1, APt2: TQtPointF; +begin + APt1.x := x1 + 0.5; + APt1.y := y1 + 0.5; + APt2.x := x2 + 0.5; + APt2.y := y2 + 0.5; + QPainter_drawLine(Widget, PQtPointF(@APt1), PQtPointF(@APt2)); +end; + {------------------------------------------------------------------------------ Function: TQtDeviceContext.drawEllipse Params: None diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index a715878df4..9979ad5e89 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -5106,7 +5106,10 @@ begin LastPos := Point(X, Y); if TQtDeviceContext(DC).pen.getCosmetic then LastPos := TQtDeviceContext(DC).GetLineLastPixelPos(PenPos, LastPos); - TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y); + if QPainter_testRenderHint(TQtDeviceContext(DC).Widget, QPainterAntialiasing) then + TQtDeviceContext(DC).drawLineF(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y) + else + TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y); MoveToEx(DC, X, Y, nil); Result := True; @@ -5515,7 +5518,10 @@ begin (QPaintEngine_type(TQtDeviceContext(DC).PaintEngine) = QPaintEngineRaster) and QPen_isCosmetic(QPainter_pen(TQtDeviceContext(DC).Widget)); - TQtDeviceContext(DC).drawRect(R.Left, R.Top, R.Right - R.Left - 1, R.Bottom - R.Top - 1, B); + if QPainter_testRenderHint(TQtDeviceContext(DC).Widget, QPainterAntialiasing) then + TQtDeviceContext(DC).drawRectF(R.Left, R.Top, R.Right - R.Left - 1, R.Bottom - R.Top - 1) + else + TQtDeviceContext(DC).drawRect(R.Left, R.Top, R.Right - R.Left - 1, R.Bottom - R.Top - 1, B); Result := True; end; diff --git a/lcl/interfaces/qt5/qtobjects.pas b/lcl/interfaces/qt5/qtobjects.pas index 1638a19a07..6756e0f9a6 100644 --- a/lcl/interfaces/qt5/qtobjects.pas +++ b/lcl/interfaces/qt5/qtobjects.pas @@ -425,10 +425,12 @@ type procedure drawPoint(x1: Integer; y1: Integer); procedure drawRect(x1: Integer; y1: Integer; w: Integer; h: Integer); + procedure drawRectF(x1: double; y1: double; w: double; h: double); procedure drawRoundRect(x, y, w, h, rx, ry: Integer); procedure drawText(x: Integer; y: Integer; s: PWideString); overload; procedure drawText(x,y,w,h,flags: Integer; s:PWideString); overload; procedure drawLine(x1: Integer; y1: Integer; x2: Integer; y2: Integer); + procedure drawLineF(x1: double; y1: double; x2: double; y2: double); procedure drawEllipse(x: Integer; y: Integer; w: Integer; h: Integer); procedure drawPixmap(p: PQtPoint; pm: QPixmapH; sr: PRect); procedure drawPolyLine(P: PPoint; NumPts: Integer); @@ -2786,6 +2788,16 @@ begin QPainter_drawRect(Widget, x1, y1, w, h); end; +procedure TQtDeviceContext.drawRectF(x1: double; y1: double; w: double; + h: double); +var + R: QRectFH; +begin + R := QRectF_Create(x1 + 0.5, y1 + 0.5, w, h); + QPainter_drawRect(Widget, R); + QRectF_Destroy(R); +end; + procedure TQtDeviceContext.drawRoundRect(x, y, w, h, rx, ry: Integer); begin QPainter_drawRoundedRect(Widget, x, y, w, h, rx, ry); @@ -2900,6 +2912,18 @@ begin QPainter_drawLine(Widget, x1, y1, x2, y2); end; +procedure TQtDeviceContext.drawLineF(x1: double; y1: double; x2: double; + y2: double); +var + APt1, APt2: TQtPointF; +begin + APt1.x := x1 + 0.5; + APt1.y := y1 + 0.5; + APt2.x := x2 + 0.5; + APt2.y := y2 + 0.5; + QPainter_drawLine(Widget, PQtPointF(@APt1), PQtPointF(@APt2)); +end; + {------------------------------------------------------------------------------ Function: TQtDeviceContext.drawEllipse Params: None diff --git a/lcl/interfaces/qt5/qtwinapi.inc b/lcl/interfaces/qt5/qtwinapi.inc index df00591bd0..c1e6e180a7 100644 --- a/lcl/interfaces/qt5/qtwinapi.inc +++ b/lcl/interfaces/qt5/qtwinapi.inc @@ -5049,7 +5049,10 @@ begin LastPos := Point(X, Y); if TQtDeviceContext(DC).pen.getCosmetic then LastPos := TQtDeviceContext(DC).GetLineLastPixelPos(PenPos, LastPos); - TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y); + if QPainter_testRenderHint(TQtDeviceContext(DC).Widget, QPainterAntialiasing) then + TQtDeviceContext(DC).drawLineF(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y) + else + TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y); MoveToEx(DC, X, Y, nil); Result := True; @@ -5461,8 +5464,10 @@ begin R := NormalizeRect(Rect(X1, Y1, X2, Y2)); if IsRectEmpty(R) then Exit(True); - - TQtDeviceContext(DC).drawRect(R.Left, R.Top, R.Right - R.Left - 1, R.Bottom - R.Top - 1); + if QPainter_testRenderHint(TQtDeviceContext(DC).Widget, QPainterAntialiasing) then + TQtDeviceContext(DC).drawRectF(R.Left, R.Top, R.Right - R.Left - 1, R.Bottom - R.Top - 1) + else + TQtDeviceContext(DC).drawRect(R.Left, R.Top, R.Right - R.Left - 1, R.Bottom - R.Top - 1); Result := True; end;