From 43c41b49f3661df9c8d71fda9804e469a1ddf1f0 Mon Sep 17 00:00:00 2001 From: Guillaume Paran Date: Wed, 23 Aug 2017 14:27:35 +0200 Subject: [PATCH] Merge pull request #366 from jnbrunet/fix_mac_menu [RealGUI] Fixes #183 : Use the qt menu instead of the native one in Mac OS (cherry picked from commit 452d04c75558d0b447d1aff215ea1a40513868fa) --- SofaGui/CMakeLists.txt | 10 ++++++++++ SofaGui/SofaGuiConfig.cmake.in | 1 + SofaGui/config.h.in | 1 + applications/sofa/gui/qt/RealGUI.cpp | 8 ++++++++ 4 files changed, 20 insertions(+) diff --git a/SofaGui/CMakeLists.txt b/SofaGui/CMakeLists.txt index 785f9787360..5a1cef6f154 100644 --- a/SofaGui/CMakeLists.txt +++ b/SofaGui/CMakeLists.txt @@ -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) diff --git a/SofaGui/SofaGuiConfig.cmake.in b/SofaGui/SofaGuiConfig.cmake.in index 29a8341820c..a3eae6c5167 100644 --- a/SofaGui/SofaGuiConfig.cmake.in +++ b/SofaGui/SofaGuiConfig.cmake.in @@ -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) diff --git a/SofaGui/config.h.in b/SofaGui/config.h.in index 45ca191b1ac..f110883e937 100644 --- a/SofaGui/config.h.in +++ b/SofaGui/config.h.in @@ -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 diff --git a/applications/sofa/gui/qt/RealGUI.cpp b/applications/sofa/gui/qt/RealGUI.cpp index b8d0fdb5f56..b1484b3ce35 100644 --- a/applications/sofa/gui/qt/RealGUI.cpp +++ b/applications/sofa/gui/qt/RealGUI.cpp @@ -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? }