As a follow-up on reports in the thread "LyX on OS X 10.9" from some months ago, I build LyX(master) + Qt5(stable) (CMake + XCode).

I replaced the Q_WS_MACX macro by Q_OS_MACX and QMaxStyle by QProxyStyle and observed then (at least) 2 issues:

1) When starting up the menu bar is not visible; One must switch to another app and then bring lyx to the foreground to make the menu bar appear. 2) When closing the (last) window the menu bar disappears mostly, except for the LyX menu. This was also reported by Stephan Witt, but I did observe no crash.

When closing the last window Qt5 should switch to the "default menu bar" but apparently it doesn't find one and creates it's own minimal default menu bar. The default menu bar is created by GlobalMenuBar() (in GuiApplication.cpp) which has a constructor GlobalMenuBar() : new QMenuBar(0); according to the Qt docs the first parent-less QMenuBar created will be used as the default menu bar. Apparently Qt5 does not detect the QMenuBar(0) created via a subclass;

When replacing the GlobalMenuBar() by a base QMenuBar(0) problem 2) is solved.

GlobalMenuBar() was introduced to override the event() function to handle QEvent::ShortcutOverride events but shortcuts seem to work without using the GlobalMenuBar (Cmd-Q and Cmd-, work as expected; Cmd-N and Cmd-O only work after first activating one of them via the menu, but the latter also happens in LyX211 and may not be related to Qt5). Building LyX + Qt4.8.6 confirms that GlobalMenuBar's event() is not called when issuing a shortcut with no window present. I assume that these standard mac-shortcuts are handled automatically by Qt.

If someone wants to check this, see the attached patch, which includes all changes (but does not solve issue 1)).

Patrick De Visschere
diff --git a/src/frontends/qt4/CategorizedCombo.cpp 
b/src/frontends/qt4/CategorizedCombo.cpp
index 1fd7f35..e8611de 100644
--- a/src/frontends/qt4/CategorizedCombo.cpp
+++ b/src/frontends/qt4/CategorizedCombo.cpp
@@ -455,7 +455,7 @@ bool CategorizedCombo::eventFilter(QObject * o, QEvent * e)
 
 void CategorizedCombo::setIconSize(QSize size)
 {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        bool small = size.height() < 20;
        setAttribute(Qt::WA_MacSmallSize, small);
        setAttribute(Qt::WA_MacNormalSize, !small);
diff --git a/src/frontends/qt4/FileDialog.cpp b/src/frontends/qt4/FileDialog.cpp
index 8f63d2e..3b75056 100644
--- a/src/frontends/qt4/FileDialog.cpp
+++ b/src/frontends/qt4/FileDialog.cpp
@@ -35,7 +35,7 @@
  *
  * Therefore there is a tradeoff in enabling or disabling this (JMarc)
  */
-#if defined(Q_WS_MACX) || (defined(Q_WS_WIN) && !defined(Q_OS_CYGWIN))
+#if (defined(Q_OS_MACX)) && QT_VERSION > 0x050000 || defined(Q_WS_MACX) || 
(defined(Q_WS_WIN) && !defined(Q_OS_CYGWIN))
 #define USE_NATIVE_FILEDIALOG 1
 #endif
 
diff --git a/src/frontends/qt4/FindAndReplace.cpp 
b/src/frontends/qt4/FindAndReplace.cpp
index 3309803..108e035 100644
--- a/src/frontends/qt4/FindAndReplace.cpp
+++ b/src/frontends/qt4/FindAndReplace.cpp
@@ -613,7 +613,7 @@ void FindAndReplaceWidget::updateGUI()
 Dialog * createGuiSearchAdv(GuiView & lv)
 {
        FindAndReplace * gui = new FindAndReplace(lv, Qt::RightDockWidgetArea);
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        // On Mac show and floating
        gui->setFloating(true);
 #endif
diff --git a/src/frontends/qt4/GuiApplication.cpp 
b/src/frontends/qt4/GuiApplication.cpp
index 660b122..b1a6cfe 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -72,7 +72,7 @@
 #include "support/Systemcall.h"
 #include "support/TempFile.h"
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
 #include "support/AppleScript.h"
 #include "support/linkback/LinkBackProxy.h"
 #endif
@@ -127,9 +127,9 @@
 #include <objidl.h>
 #endif // Q_WS_WIN
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
 #include <QMacPasteboardMime>
-#endif // Q_WS_MACX
+#endif // Q_OS_MACX
 
 #include "support/bind.h"
 #include <boost/crc.hpp>
@@ -662,7 +662,7 @@ public:
        }
 };
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
 // QMacPasteboardMimeGraphics can only be compiled on Mac.
 
 class QMacPasteboardMimeGraphics : public QMacPasteboardMime
@@ -940,9 +940,10 @@ struct GuiApplication::Private
        QHash<int, GuiView *> views_;
 
        /// Only used on mac.
-       GlobalMenuBar * global_menubar_;
+       //GlobalMenuBar * global_menubar_;
+       QMenuBar * global_menubar_;
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        /// Linkback mime handler for MacOSX.
        QMacPasteboardMimeGraphics mac_pasteboard_mime_;
 #endif
@@ -961,7 +962,7 @@ GuiApplication * guiApp;
 
 GuiApplication::~GuiApplication()
 {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        closeAllLinkBackLinks();
 #endif
        delete d;
@@ -989,7 +990,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        if (lyxrc.quit_on_last_window_closed)
                setQuitOnLastWindowClosed(false);
        */
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        // FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
        // seems to be the default case for applications like LyX.
        setQuitOnLastWindowClosed(false);
@@ -2323,14 +2324,15 @@ void GuiApplication::execBatchCommands()
                // Gives some error box here.
                return;
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
 #if QT_VERSION > 0x040600
        
setAttribute(Qt::AA_MacDontSwapCtrlAndMeta,lyxrc.mac_dontswap_ctrl_meta);
 #endif
        // Create the global default menubar which is shown for the dialogs
        // and if no GuiView is visible.
        // This must be done after the session was recovered to know the "last 
files".
-       d->global_menubar_ = new GlobalMenuBar;
+       //d->global_menubar_ = new GlobalMenuBar;
+       d->global_menubar_ = new QMenuBar(0);
        d->menus_.fillMenuBar(d->global_menubar_, 0, true);
 #endif
 
diff --git a/src/frontends/qt4/GuiCharacter.cpp 
b/src/frontends/qt4/GuiCharacter.cpp
index 2d2c3e2..8d9ea6c 100644
--- a/src/frontends/qt4/GuiCharacter.cpp
+++ b/src/frontends/qt4/GuiCharacter.cpp
@@ -213,7 +213,7 @@ GuiCharacter::GuiCharacter(GuiView & lv)
        bc().addReadOnly(toggleallCB);
        bc().addReadOnly(autoapplyCB);
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        // On Mac it's common to have tool windows which are always in the
        // foreground and are hidden when the main window is not focused.
        setWindowFlags(Qt::Tool);
diff --git a/src/frontends/qt4/GuiClipboard.cpp 
b/src/frontends/qt4/GuiClipboard.cpp
index d96dd26..c8fe6a5 100644
--- a/src/frontends/qt4/GuiClipboard.cpp
+++ b/src/frontends/qt4/GuiClipboard.cpp
@@ -30,9 +30,9 @@
 #include "support/lstrings.h"
 #include "support/lyxtime.h"
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
 #include "support/linkback/LinkBackProxy.h"
-#endif // Q_WS_MACX
+#endif // Q_OS_MACX
 
 #include "frontends/alert.h"
 
@@ -313,7 +313,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, 
GraphicsType type) cons
        // write the (LinkBack) PDF data
        f.write(ar);
        if (type == LinkBackGraphicsType) {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
                void const * linkBackData;
                unsigned linkBackLen;
                getLinkBackData(&linkBackData, &linkBackLen);
@@ -324,7 +324,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, 
GraphicsType type) cons
 #else
                // only non-Mac this should never happen
                LATTEST(false);
-#endif // Q_WS_MACX
+#endif // Q_OS_MACX
        }
 
        f.close();
@@ -488,11 +488,11 @@ bool 
GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const
 
        // handle LinkBack for Mac
        if (type == LinkBackGraphicsType)
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
                return isLinkBackDataInPasteboard();
 #else
                return false;
-#endif // Q_WS_MACX
+#endif // Q_OS_MACX
        
        // get mime data
        QStringList const & formats = cache_.formats();
diff --git a/src/frontends/qt4/GuiFontLoader.cpp 
b/src/frontends/qt4/GuiFontLoader.cpp
index 4559e33..518f187 100644
--- a/src/frontends/qt4/GuiFontLoader.cpp
+++ b/src/frontends/qt4/GuiFontLoader.cpp
@@ -265,7 +265,7 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f)
                        QString family = 
makeFontName(toqstr(lyxrc.roman_font_name),
                                toqstr(lyxrc.roman_font_foundry)); 
                        font.setFamily(family);
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
 #if QT_VERSION >= 0x040300 //&& QT_VERSION < 0x040800
                        // Workaround for a Qt bug, see 
http://www.lyx.org/trac/ticket/3684
                        // and 
http://bugreports.qt.nokia.com/browse/QTBUG-11145.
diff --git a/src/frontends/qt4/GuiKeySymbol.cpp 
b/src/frontends/qt4/GuiKeySymbol.cpp
index 27b593b..4b7e344 100644
--- a/src/frontends/qt4/GuiKeySymbol.cpp
+++ b/src/frontends/qt4/GuiKeySymbol.cpp
@@ -704,7 +704,7 @@ docstring const KeySymbol::print(KeyModifier mod, bool 
forgui) const
        if (forgui)
                str = seq.toString(QKeySequence::NativeText);
        else {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
                // Qt/Mac does not use Command and friends in the
                // portable case, but the windows-like Control+x (bug 5421).
                str = seq.toString(QKeySequence::NativeText);
diff --git a/src/frontends/qt4/GuiParagraph.cpp 
b/src/frontends/qt4/GuiParagraph.cpp
index 975b651..2ec32b0 100644
--- a/src/frontends/qt4/GuiParagraph.cpp
+++ b/src/frontends/qt4/GuiParagraph.cpp
@@ -61,7 +61,7 @@ GuiParagraph::GuiParagraph(GuiView & lv)
        connect(labelWidth, SIGNAL(textChanged(QString)),
                this, SLOT(changed()));
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        // On Mac it's common to have tool windows which are always in the
        // foreground and are hidden when the main window is not focused.
        setWindowFlags(Qt::Tool);
diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp
index d5ce945..30603a8 100644
--- a/src/frontends/qt4/GuiPrefs.cpp
+++ b/src/frontends/qt4/GuiPrefs.cpp
@@ -500,7 +500,7 @@ PrefInput::PrefInput(GuiPreferences * form)
 
        // reveal checkbox for switching Ctrl and Meta on Mac:
        bool swapcb = false;
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
 #if QT_VERSION > 0x040600
        swapcb = true;
 #endif
diff --git a/src/frontends/qt4/GuiSpellchecker.cpp 
b/src/frontends/qt4/GuiSpellchecker.cpp
index 98eaace..706c4a2 100644
--- a/src/frontends/qt4/GuiSpellchecker.cpp
+++ b/src/frontends/qt4/GuiSpellchecker.cpp
@@ -614,7 +614,7 @@ void GuiSpellchecker::updateView()
 Dialog * createGuiSpellchecker(GuiView & lv) 
 { 
        GuiSpellchecker * gui = new GuiSpellchecker(lv, 
Qt::RightDockWidgetArea);
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        gui->setFloating(true);
 #endif
        return gui;
diff --git a/src/frontends/qt4/GuiToc.cpp b/src/frontends/qt4/GuiToc.cpp
index 9711bb6..9754530 100644
--- a/src/frontends/qt4/GuiToc.cpp
+++ b/src/frontends/qt4/GuiToc.cpp
@@ -98,7 +98,7 @@ bool GuiToc::getStatus(Cursor & cur, FuncRequest const & cmd,
 Dialog * createGuiToc(GuiView & lv)
 {
        GuiToc * toc;
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        // On Mac show at the right and floating
        toc = new GuiToc(lv, Qt::RightDockWidgetArea);
        toc->setFloating(true);
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index a7cbbe4..2e15afb 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -448,7 +448,7 @@ GuiView::GuiView(int id)
        // We don't want to keep the window in memory if it is closed.
        setAttribute(Qt::WA_DeleteOnClose, true);
 
-#if (!defined(Q_WS_WIN) && !defined(Q_WS_MACX))
+#if (!defined(Q_WS_WIN) && !defined(Q_OS_MACX))
        // QIcon::fromTheme was introduced in Qt 4.6
 #if (QT_VERSION >= 0x040600)
        // assign an icon to main form. We do not do it under Qt/Win or Qt/Mac,
@@ -1064,7 +1064,7 @@ void GuiView::on_lastWorkAreaRemoved()
                return;
        }
 
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        // On Mac we also close the last window because the application stay
        // resident in memory. On other platforms we don't close the last
        // window because this would quit the application.
diff --git a/src/frontends/qt4/GuiWorkArea.cpp 
b/src/frontends/qt4/GuiWorkArea.cpp
index 4e4d3d4..0f0a7ca 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -61,8 +61,8 @@
 #endif
 #include <QDrag>
 #include <QHelpEvent>
-#ifdef Q_WS_MACX
-#include <QMacStyle>
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
+#include <QProxyStyle>
 #endif
 #include <QMainWindow>
 #include <QMimeData>
@@ -1487,14 +1487,14 @@ void EmbeddedWorkArea::disable()
 //
 ////////////////////////////////////////////////////////////////////
 
-#ifdef Q_WS_MACX
-class NoTabFrameMacStyle : public QMacStyle {
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
+class NoTabFrameMacStyle : public QProxyStyle {
 public:
        ///
        QRect subElementRect(SubElement element, const QStyleOption * option,
                             const QWidget * widget = 0) const
        {
-               QRect rect = QMacStyle::subElementRect(element, option, widget);
+               QRect rect = QProxyStyle::subElementRect(element, option, 
widget);
                bool noBar = static_cast<QTabWidget const *>(widget)->count() 
<= 1;
 
                // The Qt Mac style puts the contents into a 3 pixel wide box
@@ -1518,7 +1518,7 @@ NoTabFrameMacStyle noTabFrameMacStyle;
 TabWorkArea::TabWorkArea(QWidget * parent)
        : QTabWidget(parent), clicked_tab_(-1)
 {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        setStyle(&noTabFrameMacStyle);
 #endif
 
diff --git a/src/frontends/qt4/LayoutBox.cpp b/src/frontends/qt4/LayoutBox.cpp
index 783dc78..563a8ec 100644
--- a/src/frontends/qt4/LayoutBox.cpp
+++ b/src/frontends/qt4/LayoutBox.cpp
@@ -522,7 +522,7 @@ bool LayoutBox::eventFilter(QObject * o, QEvent * e)
        
 void LayoutBox::setIconSize(QSize size)
 {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        bool small = size.height() < 20;
        setAttribute(Qt::WA_MacSmallSize, small);
        setAttribute(Qt::WA_MacNormalSize, !small);
diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp
index 5a901d8..d957907 100644
--- a/src/frontends/qt4/Menus.cpp
+++ b/src/frontends/qt4/Menus.cpp
@@ -2231,7 +2231,7 @@ bool Menus::searchMenu(FuncRequest const & func,
 void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
 {
        if (initial) {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
                // setup special mac specific menu items, but only do this
                // the first time a QMenuBar is created. Otherwise Qt will
                // create duplicate items in the application menu. It seems
@@ -2282,7 +2282,7 @@ void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, 
bool initial)
                Menu * menu = new Menu(view, m->submenuname(), true);
                menu->setTitle(label(*m));
 
-#if defined(Q_WS_MACX) && (defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 
0x050000))
+#if defined(Q_OS_MACX) && (defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 
0x050000))
                // On Mac OS with QT/cocoa, the menu is not displayed if there 
is no action
                // so we create a temporary one here
                QAction * action = new QAction(menu);
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index 2b62371..f074a4a 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -298,7 +298,7 @@ QStringList texFileList(QString const & filename)
 
 QString const externalLineEnding(docstring const & str)
 {
-#ifdef Q_WS_MACX
+#if (defined(Q_OS_MACX) && QT_VERSION > 0x050000) || defined(Q_WS_MACX)
        // The MAC clipboard uses \r for lineendings, and we use \n
        return toqstr(subst(str, '\n', '\r'));
 #elif defined(Q_WS_WIN)

Reply via email to