From cae6316d3adf36a76fb7c51c6119f98f418d635b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDeljan=20Rikalo?= Date: Wed, 4 Oct 2023 14:44:36 +0000 Subject: [PATCH] Revert "Qt5, Qt6: removed TQtWSCustomTabControl.GetDefaultClientRect since it does not..." This reverts commit 1d4695e3be66f80e875b989467eb32d91d7d97ac --- lcl/interfaces/qt5/qtpagecontrol.inc | 101 +++++++++++++++++++++++++++ lcl/interfaces/qt5/qtwscomctrls.pp | 3 + lcl/interfaces/qt6/qtpagecontrol.inc | 101 +++++++++++++++++++++++++++ lcl/interfaces/qt6/qtwscomctrls.pp | 3 + 4 files changed, 208 insertions(+) diff --git a/lcl/interfaces/qt5/qtpagecontrol.inc b/lcl/interfaces/qt5/qtpagecontrol.inc index 46e1b2580e..87487148c2 100644 --- a/lcl/interfaces/qt5/qtpagecontrol.inc +++ b/lcl/interfaces/qt5/qtpagecontrol.inc @@ -185,6 +185,107 @@ begin end; end; +class function TQtWSCustomTabControl.GetDefaultClientRect( + const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer; + var aClientRect: TRect): boolean; +var + dx, dy: integer; + ATabWidget: TQtTabWidget; + ASize: TSize; + HSpace: Integer; + Overlap: Integer; + VSpace: Integer; + BaseHeight: Integer; + TabOverLap: Integer; + ShiftVertical: Integer; +begin + Result := False; + if AWinControl.HandleAllocated then + begin + if TQtWidget(AWinControl.Handle).ChildOfComplexWidget <> ccwTTabControl then + begin + ATabWidget := TQtTabWidget(AWinControl.Handle); + if ATabWidget.testAttribute(QtWA_PendingResizeEvent) or not ATabWidget.testAttribute(QtWA_Mapped) then + begin + // we must recalculate aclientrect since we have pending resize event + // and clientrect won't be accurate.issue #21805 + Result := True; + dx := GetPixelMetric(QStylePM_DefaultFrameWidth, nil, ATabWidget.Widget); + // HSpace := GetPixelMetric(QStylePM_TabBarTabHSpace, nil, nil); + VSpace := GetPixelMetric(QStylePM_TabBarTabVSpace, nil, ATabWidget.Widget); + Overlap := GetPixelMetric(QStylePM_TabBarBaseOverlap, nil, ATabWidget.Widget); + TabOverLap := GetPixelMetric(QStylePM_TabBarTabOverlap, nil, ATabWidget.Widget); + BaseHeight := GetPixelMetric(QStylePM_TabBarBaseHeight, nil, ATabWidget.Widget); + ShiftVertical := GetPixelMetric(QStylePM_TabBarTabShiftVertical, nil, ATabWidget.Widget); + + // trigger sizing, do not remove + ATabWidget.TabBar.sizeHint(@ASize); + + if ATabWidget.getTabPosition in [QTabWidgetNorth, QTabWidgetSouth] then + begin + if TCustomTabControl(AWinControl).ShowTabs then + dy := ATabWidget.TabBar.getHeight + else + dy := 0; + + if (BaseHeight < ShiftVertical) then + begin + if (Overlap = 0) then + begin + BaseHeight := BaseHeight + TabOverLap; + dx := dx + (TabOverlap * 2); + end else + begin + BaseHeight := BaseHeight * 2; + dx := dx + BaseHeight; + end; + end; + + if (Overlap > VSpace) then + BaseHeight := BaseHeight * 2; + + if (VSpace > TabOverLap) then + dx := dx + Overlap; + + aClientRect := Rect(0, 0, + Max(0, aWidth - (BaseHeight * 2)), + Max(0, aHeight - dx - dy)); + end else + begin + if TCustomTabControl(AWinControl).ShowTabs then + dy := ATabWidget.TabBar.getWidth + else + dy := 0; + + VSpace := 0; + HSpace := 0; + + if BaseHeight < ShiftVertical then + VSpace := TabOverLap - BaseHeight; + if (Overlap < dx) then + begin + VSpace := OverLap; + if OverLap = 0 then + begin + VSpace := TabOverLap * 2; + HSpace := BaseHeight; + end; + end; + + aClientRect := Rect(0,0, + Max(0, aWidth - dx - dy - VSpace), + Max(0, aHeight - (dx + Overlap + VSpace + HSpace))); + end; + end; + end; + end else + begin + dx := GetPixelMetric(QStylePM_TabBarBaseHeight, nil, nil); + aClientRect := Rect(0,0, Max(0, aWidth - (dx * 2)), Max(0, aHeight - (dx * 2))); + Result := True; + end; +end; + class procedure TQtWSCustomTabControl.AddPage(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const AIndex: integer); var diff --git a/lcl/interfaces/qt5/qtwscomctrls.pp b/lcl/interfaces/qt5/qtwscomctrls.pp index b35edc2a57..3a0a85569c 100644 --- a/lcl/interfaces/qt5/qtwscomctrls.pp +++ b/lcl/interfaces/qt5/qtwscomctrls.pp @@ -53,6 +53,9 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override; + class function GetDefaultClientRect(const AWinControl: TWinControl; + const {%H-}aLeft, {%H-}aTop, aWidth, aHeight: integer; var aClientRect: TRect + ): boolean; override; class procedure AddPage(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const AIndex: integer); override; class procedure MovePage(const ATabControl: TCustomTabControl; diff --git a/lcl/interfaces/qt6/qtpagecontrol.inc b/lcl/interfaces/qt6/qtpagecontrol.inc index 46e1b2580e..87487148c2 100644 --- a/lcl/interfaces/qt6/qtpagecontrol.inc +++ b/lcl/interfaces/qt6/qtpagecontrol.inc @@ -185,6 +185,107 @@ begin end; end; +class function TQtWSCustomTabControl.GetDefaultClientRect( + const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer; + var aClientRect: TRect): boolean; +var + dx, dy: integer; + ATabWidget: TQtTabWidget; + ASize: TSize; + HSpace: Integer; + Overlap: Integer; + VSpace: Integer; + BaseHeight: Integer; + TabOverLap: Integer; + ShiftVertical: Integer; +begin + Result := False; + if AWinControl.HandleAllocated then + begin + if TQtWidget(AWinControl.Handle).ChildOfComplexWidget <> ccwTTabControl then + begin + ATabWidget := TQtTabWidget(AWinControl.Handle); + if ATabWidget.testAttribute(QtWA_PendingResizeEvent) or not ATabWidget.testAttribute(QtWA_Mapped) then + begin + // we must recalculate aclientrect since we have pending resize event + // and clientrect won't be accurate.issue #21805 + Result := True; + dx := GetPixelMetric(QStylePM_DefaultFrameWidth, nil, ATabWidget.Widget); + // HSpace := GetPixelMetric(QStylePM_TabBarTabHSpace, nil, nil); + VSpace := GetPixelMetric(QStylePM_TabBarTabVSpace, nil, ATabWidget.Widget); + Overlap := GetPixelMetric(QStylePM_TabBarBaseOverlap, nil, ATabWidget.Widget); + TabOverLap := GetPixelMetric(QStylePM_TabBarTabOverlap, nil, ATabWidget.Widget); + BaseHeight := GetPixelMetric(QStylePM_TabBarBaseHeight, nil, ATabWidget.Widget); + ShiftVertical := GetPixelMetric(QStylePM_TabBarTabShiftVertical, nil, ATabWidget.Widget); + + // trigger sizing, do not remove + ATabWidget.TabBar.sizeHint(@ASize); + + if ATabWidget.getTabPosition in [QTabWidgetNorth, QTabWidgetSouth] then + begin + if TCustomTabControl(AWinControl).ShowTabs then + dy := ATabWidget.TabBar.getHeight + else + dy := 0; + + if (BaseHeight < ShiftVertical) then + begin + if (Overlap = 0) then + begin + BaseHeight := BaseHeight + TabOverLap; + dx := dx + (TabOverlap * 2); + end else + begin + BaseHeight := BaseHeight * 2; + dx := dx + BaseHeight; + end; + end; + + if (Overlap > VSpace) then + BaseHeight := BaseHeight * 2; + + if (VSpace > TabOverLap) then + dx := dx + Overlap; + + aClientRect := Rect(0, 0, + Max(0, aWidth - (BaseHeight * 2)), + Max(0, aHeight - dx - dy)); + end else + begin + if TCustomTabControl(AWinControl).ShowTabs then + dy := ATabWidget.TabBar.getWidth + else + dy := 0; + + VSpace := 0; + HSpace := 0; + + if BaseHeight < ShiftVertical then + VSpace := TabOverLap - BaseHeight; + if (Overlap < dx) then + begin + VSpace := OverLap; + if OverLap = 0 then + begin + VSpace := TabOverLap * 2; + HSpace := BaseHeight; + end; + end; + + aClientRect := Rect(0,0, + Max(0, aWidth - dx - dy - VSpace), + Max(0, aHeight - (dx + Overlap + VSpace + HSpace))); + end; + end; + end; + end else + begin + dx := GetPixelMetric(QStylePM_TabBarBaseHeight, nil, nil); + aClientRect := Rect(0,0, Max(0, aWidth - (dx * 2)), Max(0, aHeight - (dx * 2))); + Result := True; + end; +end; + class procedure TQtWSCustomTabControl.AddPage(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const AIndex: integer); var diff --git a/lcl/interfaces/qt6/qtwscomctrls.pp b/lcl/interfaces/qt6/qtwscomctrls.pp index 5d4a9dee0e..c5db8532d4 100644 --- a/lcl/interfaces/qt6/qtwscomctrls.pp +++ b/lcl/interfaces/qt6/qtwscomctrls.pp @@ -51,6 +51,9 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override; + class function GetDefaultClientRect(const AWinControl: TWinControl; + const {%H-}aLeft, {%H-}aTop, aWidth, aHeight: integer; var aClientRect: TRect + ): boolean; override; class procedure AddPage(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const AIndex: integer); override; class procedure MovePage(const ATabControl: TCustomTabControl;