Skip to content

Commit

Permalink
Merge pull request sofa-framework#366 from jnbrunet/fix_mac_menu
Browse files Browse the repository at this point in the history
[RealGUI] Fixes sofa-framework#183 : Use the qt menu instead of the native one in Mac OS
(cherry picked from commit 452d04c)
  • Loading branch information
guparan authored and matthieu-nesme committed Sep 6, 2017
1 parent 9c1c387 commit 43c41b4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions SofaGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ if(NOT SOFA_NO_OPENGL)
set(SOFA_HAVE_QWT 1) # cmakedefine
endif()

## Qt native menu
set(DEFAULT_SOFAGUI_ENABLE_NATIVE_MENU ON)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(DEFAULT_SOFAGUI_ENABLE_NATIVE_MENU OFF)
endif()

option(SOFAGUI_ENABLE_NATIVE_MENU "Enable Qt to use the operating system's native menu for the Qt GUI" ${DEFAULT_SOFAGUI_ENABLE_NATIVE_MENU})
if(SOFAGUI_ENABLE_NATIVE_MENU)
set(SOFA_GUI_NATIVE_MENU 1)
endif()

set(SOFA_GUI_QT 1) # cmakedefine
list(APPEND SOFAGUI_TARGETS SofaGuiQt)
Expand Down
1 change: 1 addition & 0 deletions SofaGui/SofaGuiConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(SOFA_GUI_QT @SOFA_GUI_QT@)
set(SOFA_GUI_INTERACTION @SOFA_GUI_INTERACTION@)
set(SOFA_GUI_QTVIEWER @SOFA_GUI_QTVIEWER@)
set(SOFA_GUI_QGLVIEWER @SOFA_GUI_QGLVIEWER@)
set(SOFA_GUI_NATIVE_MENU @SOFA_GUI_NATIVE_MENU@)
set(SOFA_QT5 @SOFA_QT5@)

if(SOFA_HAVE_QT)
Expand Down
1 change: 1 addition & 0 deletions SofaGui/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#cmakedefine SOFA_GUI_QGLVIEWER
#cmakedefine SOFA_GUI_QTVIEWER
#cmakedefine SOFA_GUI_INTERACTION
#cmakedefine SOFA_GUI_NATIVE_MENU
#cmakedefine SOFA_HAVE_QWT

#endif
8 changes: 8 additions & 0 deletions applications/sofa/gui/qt/RealGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ void RealGUI::InitApplication( RealGUI* _gui)
QString pathIcon=(sofa::helper::system::DataRepository.getFirstPath() + std::string( "/icons/SOFA.png" )).c_str();
application->setWindowIcon(QIcon(pathIcon));

#ifdef SOFA_GUI_NATIVE_MENU
// Use the OS'native menu instead of the Qt one
_gui->menubar->setNativeMenuBar(true);
#else
// Use the qt menu instead of the native one in order to standardize the way the menu is showed on every OS
_gui->menubar->setNativeMenuBar(false);
#endif

// show the gui
_gui->show(); // adding extra line in the console?
}
Expand Down

0 comments on commit 43c41b4

Please sign in to comment.