mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 17:19:59 +02:00
Qt5,Qt6: fixed order of menu items when hiding/destroying handle/adding again. issue #41429
(cherry picked from commit 4f835ede52
)
Co-authored-by: zeljan1 <zeljko@holobit.hr>
This commit is contained in:
parent
e9746d8dd0
commit
6b51ba5323
@ -236,7 +236,7 @@ type
|
|||||||
procedure ShowMinimized;
|
procedure ShowMinimized;
|
||||||
procedure ShowMaximized;
|
procedure ShowMaximized;
|
||||||
procedure ShowFullScreen;
|
procedure ShowFullScreen;
|
||||||
function getActionByIndex(AIndex: Integer): QActionH;
|
function getActionByIndex(AIndex: Integer; AItem: TMenuItem): QActionH;
|
||||||
function getAutoFillBackground: Boolean;
|
function getAutoFillBackground: Boolean;
|
||||||
function getClientBounds: TRect; virtual;
|
function getClientBounds: TRect; virtual;
|
||||||
function getClientOffset: TPoint; virtual;
|
function getClientOffset: TPoint; virtual;
|
||||||
@ -4736,14 +4736,42 @@ begin
|
|||||||
QWidget_showFullScreen(Widget);
|
QWidget_showFullScreen(Widget);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TQtWidget.getActionByIndex(AIndex: Integer): QActionH;
|
function TQtWidget.getActionByIndex(AIndex: Integer; AItem: TMenuItem): QActionH;
|
||||||
var
|
var
|
||||||
ActionList: TPtrIntArray;
|
ActionList: TPtrIntArray;
|
||||||
|
WStr: WideString;
|
||||||
|
i: Integer;
|
||||||
|
AVariant: QVariantH;
|
||||||
|
AOk: Boolean;
|
||||||
|
AData: QWord;
|
||||||
begin
|
begin
|
||||||
QWidget_actions(Widget, @ActionList);
|
QWidget_actions(Widget, @ActionList);
|
||||||
if (AIndex >= 0) and (AIndex < Length(ActionList)) then
|
if (AIndex >= 0) and (AIndex < Length(ActionList)) then
|
||||||
Result := QActionH(ActionList[AIndex])
|
begin
|
||||||
else
|
for i := 0 to High(ActionList) do
|
||||||
|
begin
|
||||||
|
if AItem <> nil then
|
||||||
|
begin
|
||||||
|
AVariant := QVariant_Create;
|
||||||
|
try
|
||||||
|
QAction_data(QActionH(ActionList[i]), AVariant);
|
||||||
|
if not QVariant_isNull(AVariant) then
|
||||||
|
begin
|
||||||
|
AOk := False;
|
||||||
|
AData := QVariant_toULongLong(AVariant, @AOk);
|
||||||
|
if AIndex <= TMenuItem(AData).MenuIndex then
|
||||||
|
begin
|
||||||
|
Result := QActionH(ActionList[i]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
QVariant_destroy(AVariant);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result := QActionH(ActionList[AIndex]);
|
||||||
|
end else
|
||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -16391,6 +16419,10 @@ begin
|
|||||||
FActions.Free;
|
FActions.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if Assigned(FActionHandle) then
|
||||||
|
QAction_Destroy(FActionHandle);
|
||||||
|
FActionHandle := nil;
|
||||||
|
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -16587,6 +16619,7 @@ end;
|
|||||||
function TQtMenu.insertMenu(AIndex: Integer; AMenu: QMenuH; AItem: TMenuItem): QActionH;
|
function TQtMenu.insertMenu(AIndex: Integer; AMenu: QMenuH; AItem: TMenuItem): QActionH;
|
||||||
var
|
var
|
||||||
actionBefore: QActionH;
|
actionBefore: QActionH;
|
||||||
|
AVariant: QVariantH;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
setHasSubmenu(True);
|
setHasSubmenu(True);
|
||||||
@ -16594,12 +16627,15 @@ begin
|
|||||||
if (AItem <> nil) and not AItem.IsLine then
|
if (AItem <> nil) and not AItem.IsLine then
|
||||||
setActionGroups(AItem);
|
setActionGroups(AItem);
|
||||||
|
|
||||||
actionBefore := getActionByIndex(AIndex);
|
actionBefore := getActionByIndex(AIndex, AItem);
|
||||||
|
|
||||||
if actionBefore <> nil then
|
if actionBefore <> nil then
|
||||||
Result := QMenu_insertMenu(QMenuH(Widget), actionBefore, AMenu)
|
Result := QMenu_insertMenu(QMenuH(Widget), actionBefore, AMenu)
|
||||||
else
|
else
|
||||||
Result := QMenu_addMenu(QMenuH(Widget), AMenu);
|
Result := QMenu_addMenu(QMenuH(Widget), AMenu);
|
||||||
|
AVariant := QVariant_create(PtrUInt(AItem));
|
||||||
|
QAction_setData(Result, AVariant);
|
||||||
|
QVariant_destroy(AVariant);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TQtMenu.getHasSubMenu: boolean;
|
function TQtMenu.getHasSubMenu: boolean;
|
||||||
@ -17016,7 +17052,7 @@ begin
|
|||||||
setVisible(FVisible);
|
setVisible(FVisible);
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
actionBefore := getActionByIndex(AIndex);
|
actionBefore := getActionByIndex(AIndex, nil);
|
||||||
if actionBefore <> nil then
|
if actionBefore <> nil then
|
||||||
Result := QMenuBar_insertMenu(QMenuBarH(Widget), actionBefore, AMenu)
|
Result := QMenuBar_insertMenu(QMenuBarH(Widget), actionBefore, AMenu)
|
||||||
else
|
else
|
||||||
|
@ -233,7 +233,7 @@ type
|
|||||||
procedure ShowMinimized;
|
procedure ShowMinimized;
|
||||||
procedure ShowMaximized;
|
procedure ShowMaximized;
|
||||||
procedure ShowFullScreen;
|
procedure ShowFullScreen;
|
||||||
function getActionByIndex(AIndex: Integer): QActionH;
|
function getActionByIndex(AIndex: Integer; AItem: TMenuItem): QActionH;
|
||||||
function getAutoFillBackground: Boolean;
|
function getAutoFillBackground: Boolean;
|
||||||
function getClientBounds: TRect; virtual;
|
function getClientBounds: TRect; virtual;
|
||||||
function getClientOffset: TPoint; virtual;
|
function getClientOffset: TPoint; virtual;
|
||||||
@ -4739,14 +4739,42 @@ begin
|
|||||||
QWidget_showFullScreen(Widget);
|
QWidget_showFullScreen(Widget);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TQtWidget.getActionByIndex(AIndex: Integer): QActionH;
|
function TQtWidget.getActionByIndex(AIndex: Integer; AItem: TMenuItem): QActionH;
|
||||||
var
|
var
|
||||||
ActionList: TPtrIntArray;
|
ActionList: TPtrIntArray;
|
||||||
|
WStr: WideString;
|
||||||
|
i: Integer;
|
||||||
|
AVariant: QVariantH;
|
||||||
|
AOk: Boolean;
|
||||||
|
AData: QWord;
|
||||||
begin
|
begin
|
||||||
QWidget_actions(Widget, @ActionList);
|
QWidget_actions(Widget, @ActionList);
|
||||||
if (AIndex >= 0) and (AIndex < Length(ActionList)) then
|
if (AIndex >= 0) and (AIndex < Length(ActionList)) then
|
||||||
Result := QActionH(ActionList[AIndex])
|
begin
|
||||||
else
|
for i := 0 to High(ActionList) do
|
||||||
|
begin
|
||||||
|
if AItem <> nil then
|
||||||
|
begin
|
||||||
|
AVariant := QVariant_Create;
|
||||||
|
try
|
||||||
|
QAction_data(QActionH(ActionList[i]), AVariant);
|
||||||
|
if not QVariant_isNull(AVariant) then
|
||||||
|
begin
|
||||||
|
AOk := False;
|
||||||
|
AData := QVariant_toULongLong(AVariant, @AOk);
|
||||||
|
if AIndex <= TMenuItem(AData).MenuIndex then
|
||||||
|
begin
|
||||||
|
Result := QActionH(ActionList[i]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
QVariant_destroy(AVariant);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result := QActionH(ActionList[AIndex]);
|
||||||
|
end else
|
||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -16300,6 +16328,10 @@ begin
|
|||||||
FActions.Free;
|
FActions.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if Assigned(FActionHandle) then
|
||||||
|
QAction_Destroy(FActionHandle);
|
||||||
|
FActionHandle := nil;
|
||||||
|
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -16495,6 +16527,7 @@ end;
|
|||||||
function TQtMenu.insertMenu(AIndex: Integer; AMenu: QMenuH; AItem: TMenuItem): QActionH;
|
function TQtMenu.insertMenu(AIndex: Integer; AMenu: QMenuH; AItem: TMenuItem): QActionH;
|
||||||
var
|
var
|
||||||
actionBefore: QActionH;
|
actionBefore: QActionH;
|
||||||
|
AVariant: QVariantH;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
setHasSubmenu(True);
|
setHasSubmenu(True);
|
||||||
@ -16502,12 +16535,15 @@ begin
|
|||||||
if (AItem <> nil) and not AItem.IsLine then
|
if (AItem <> nil) and not AItem.IsLine then
|
||||||
setActionGroups(AItem);
|
setActionGroups(AItem);
|
||||||
|
|
||||||
actionBefore := getActionByIndex(AIndex);
|
actionBefore := getActionByIndex(AIndex, AItem);
|
||||||
|
|
||||||
if actionBefore <> nil then
|
if actionBefore <> nil then
|
||||||
Result := QMenu_insertMenu(QMenuH(Widget), actionBefore, AMenu)
|
Result := QMenu_insertMenu(QMenuH(Widget), actionBefore, AMenu)
|
||||||
else
|
else
|
||||||
Result := QMenu_addMenu(QMenuH(Widget), AMenu);
|
Result := QMenu_addMenu(QMenuH(Widget), AMenu);
|
||||||
|
AVariant := QVariant_create(PtrUInt(AItem));
|
||||||
|
QAction_setData(Result, AVariant);
|
||||||
|
QVariant_destroy(AVariant);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TQtMenu.getHasSubMenu: boolean;
|
function TQtMenu.getHasSubMenu: boolean;
|
||||||
@ -16922,7 +16958,7 @@ begin
|
|||||||
setVisible(FVisible);
|
setVisible(FVisible);
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
actionBefore := getActionByIndex(AIndex);
|
actionBefore := getActionByIndex(AIndex, nil);
|
||||||
if actionBefore <> nil then
|
if actionBefore <> nil then
|
||||||
Result := QMenuBar_insertMenu(QMenuBarH(Widget), actionBefore, AMenu)
|
Result := QMenuBar_insertMenu(QMenuBarH(Widget), actionBefore, AMenu)
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user