From df83fa1a25eb2b2c3ab93d37f01e991450c3ead9 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 5 Mar 2008 02:02:04 +0000 Subject: [PATCH] qt: insert menu items to proper position (tracker issue: #0010842) git-svn-id: trunk@14412 - --- lcl/interfaces/qt/qtwidgets.pas | 42 +++++++++++++++++++++++++++++++++ lcl/interfaces/qt/qtwsmenus.pp | 6 +++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index 24792f1988..dfbbd0dad0 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -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; diff --git a/lcl/interfaces/qt/qtwsmenus.pp b/lcl/interfaces/qt/qtwsmenus.pp index 34aebf9050..9af022300c 100644 --- a/lcl/interfaces/qt/qtwsmenus.pp +++ b/lcl/interfaces/qt/qtwsmenus.pp @@ -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;