Revert "Qt5, Qt6: removed TQtWSCustomTabControl.GetDefaultClientRect since it does not..."

This reverts commit 1d4695e3be
This commit is contained in:
Željan Rikalo 2023-10-04 14:44:36 +00:00
parent 3b4b6dd3ed
commit cae6316d3a
4 changed files with 208 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;