qt: insert menu items to proper position (tracker issue: #0010842)

git-svn-id: trunk@14412 -
This commit is contained in:
paul 2008-03-05 02:02:04 +00:00
parent e536a2251a
commit df83fa1a25
2 changed files with 46 additions and 2 deletions

View File

@ -152,6 +152,7 @@ type
procedure ShowNormal;
procedure ShowMinimized;
procedure ShowMaximized;
function getActionByIndex(AIndex: Integer): QActionH;
function getClientBounds: TRect; virtual;
function getEnabled: Boolean;
function getFocusPolicy: QtFocusPolicy;
@ -942,6 +943,7 @@ type
procedure PopUp(pos: PQtPoint; at: QActionH = nil);
function actionHandle: QActionH;
function addMenu(AMenu: QMenuH): QActionH;
function insertMenu(AIndex: Integer; AMenu: QMenuH): QActionH;
function getVisible: Boolean; override;
function getText: WideString; override;
procedure setChecked(p1: Boolean);
@ -965,6 +967,7 @@ type
constructor Create(const AParent: QWidgetH); overload;
public
function addMenu(AMenu: QMenuH): QActionH;
function insertMenu(AIndex: Integer; AMenu: QMenuH): QActionH;
function getGeometry: TRect; override;
end;
@ -2433,6 +2436,17 @@ begin
QWidget_showMaximized(Widget);
end;
function TQtWidget.getActionByIndex(AIndex: Integer): QActionH;
var
ActionList: TIntArray;
begin
QWidget_actions(Widget, @ActionList);
if (AIndex > 0) and (AIndex < Length(ActionList)) then
Result := QActionH(ActionList[AIndex])
else
Result := nil;
end;
function TQtWidget.getEnabled: Boolean;
begin
Result := QWidget_isEnabled(Widget);
@ -6628,6 +6642,18 @@ begin
Result := QMenu_addMenu(QMenuH(Widget), AMenu);
end;
function TQtMenu.insertMenu(AIndex: Integer; AMenu: QMenuH): QActionH;
var
actionBefore: QActionH;
begin
setHasSubmenu(True);
actionBefore := getActionByIndex(AIndex);
if actionBefore <> nil then
Result := QMenu_insertMenu(QMenuH(Widget), actionBefore, AMenu)
else
Result := QMenu_addMenu(QMenuH(Widget), AMenu);
end;
function TQtMenu.getVisible: Boolean;
begin
Result := QAction_isVisible(ActionHandle);
@ -6762,6 +6788,22 @@ begin
Result := QMenuBar_addMenu(QMenuBarH(Widget), AMenu);
end;
function TQtMenuBar.insertMenu(AIndex: Integer; AMenu: QMenuH): QActionH;
var
actionBefore: QActionH;
begin
if not FVisible then
begin
FVisible := True;
setVisible(FVisible);
end;
actionBefore := getActionByIndex(AIndex);
if actionBefore <> nil then
Result := QMenuBar_insertMenu(QMenuBarH(Widget), actionBefore, AMenu)
else
Result := QMenuBar_addMenu(QMenuBarH(Widget), AMenu);
end;
function TQtMenuBar.getGeometry: TRect;
begin
Result := inherited getGeometry;

View File

@ -104,10 +104,12 @@ begin
Widget := TQtWidget(AMenuItem.Parent.Handle);
if Widget is TQtMenuBar then
TQtMenuBar(Widget).addMenu(QMenuH(TQtMenu(AMenuItem.Handle).Widget))
TQtMenuBar(Widget).insertMenu(AMenuItem.Parent.VisibleIndexOf(AMenuItem),
QMenuH(TQtMenu(AMenuItem.Handle).Widget))
else
if Widget is TQtMenu then
TQtMenu(Widget).addMenu(QMenuH(TQtMenu(AMenuItem.Handle).Widget));
TQtMenu(Widget).insertMenu(AMenuItem.Parent.VisibleIndexOf(AMenuItem),
QMenuH(TQtMenu(AMenuItem.Handle).Widget));
end;
class function TQtWSMenuItem.CreateMenuFromMenuItem(const AMenuItem: TMenuItem): TQtMenu;