Add support for stock menu items to wxQt

Sets the new QAction's text and shortcut properties to the
values provided by the corresponding wxGetStockXXX() functions.

Closes https://github.com/wxWidgets/wxWidgets/pull/613
This commit is contained in:
René J.V. Bertin
2017-11-22 19:58:48 +01:00
committed by Vadim Zeitlin
parent 04209e3a3e
commit 10201c2732

View File

@@ -11,6 +11,7 @@
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/qt/private/utils.h" #include "wx/qt/private/utils.h"
#include "wx/qt/private/converter.h" #include "wx/qt/private/converter.h"
#include "wx/stockitem.h"
#include <QtWidgets/QMenu> #include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar> #include <QtWidgets/QMenuBar>
@@ -56,8 +57,9 @@ static void InsertMenuItemAction( const wxMenu *menu, const wxMenuItem *previous
{ {
QMenu *qtMenu = menu->GetHandle(); QMenu *qtMenu = menu->GetHandle();
QAction *itemAction = item->GetHandle(); QAction *itemAction = item->GetHandle();
if ( item->GetKind() == wxITEM_RADIO ) switch ( item->GetKind() )
{ {
case wxITEM_RADIO:
// If the previous menu item is a radio item then add this item to the // If the previous menu item is a radio item then add this item to the
// same action group, otherwise start a new group: // same action group, otherwise start a new group:
@@ -74,6 +76,30 @@ static void InsertMenuItemAction( const wxMenu *menu, const wxMenuItem *previous
actionGroup->addAction( itemAction ); actionGroup->addAction( itemAction );
wxASSERT_MSG( itemAction->actionGroup() == actionGroup, "Must be the same action group" ); wxASSERT_MSG( itemAction->actionGroup() == actionGroup, "Must be the same action group" );
} }
break;
case wxITEM_NORMAL:
{
wxWindowID id = item->GetId();
if ( wxIsStockID( id ) )
{
itemAction->setText( wxQtConvertString( wxGetStockLabel( id ) ) );
wxAcceleratorEntry accel = wxGetStockAccelerator( id );
QString shortcut;
if ( id == wxID_EXIT )
{
shortcut = QStringLiteral("Ctrl+Q");
}
else if ( accel.IsOk() )
{
shortcut = wxQtConvertString( accel.ToRawString() );
}
if ( !shortcut.isEmpty() )
{
itemAction->setShortcut( QKeySequence( shortcut ) );
}
}
break;
}
} }
// Insert the action into the actual menu: // Insert the action into the actual menu:
QAction *successiveItemAction = ( successiveItem != NULL ) ? successiveItem->GetHandle() : NULL; QAction *successiveItemAction = ( successiveItem != NULL ) ? successiveItem->GetHandle() : NULL;