mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
* src/frontends/qt4/QLMenubar.C (macxMenuBarInit): use the new support
Qt 4.2 for Mac menus (no merging is done for qt < 4.2 now). * src/frontends/qt4/Action.C (Action): initialize menu role to NoRole for qt >= 4.2. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17373 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
49b2b166b7
commit
fa637e5377
@ -43,6 +43,10 @@ Action::Action(GuiView & lyxView, docstring const & text,
|
|||||||
FuncRequest const & func, docstring const & tooltip)
|
FuncRequest const & func, docstring const & tooltip)
|
||||||
: QAction(&lyxView), func_(func), lyxView_(lyxView)
|
: QAction(&lyxView), func_(func), lyxView_(lyxView)
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION >= 0x040200
|
||||||
|
// only Qt/Mac handles that
|
||||||
|
setMenuRole(NoRole);
|
||||||
|
#endif
|
||||||
setText(toqstr(text));
|
setText(toqstr(text));
|
||||||
setToolTip(toqstr(tooltip));
|
setToolTip(toqstr(tooltip));
|
||||||
setStatusTip(toqstr(tooltip));
|
setStatusTip(toqstr(tooltip));
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include <QMenuBar>
|
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
|
#include <QMenuBar>
|
||||||
|
|
||||||
using std::pair;
|
using std::pair;
|
||||||
using std::string;
|
using std::string;
|
||||||
@ -160,10 +160,7 @@ QMenuBar * QLMenubar::menuBar() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_WS_MACX
|
#ifdef Q_WS_MACX
|
||||||
# define MERGE_MAC_MENUS
|
|
||||||
# ifndef MERGE_MAC_MENUS
|
|
||||||
extern void qt_mac_set_menubar_merge(bool b);
|
extern void qt_mac_set_menubar_merge(bool b);
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void QLMenubar::macxMenuBarInit()
|
void QLMenubar::macxMenuBarInit()
|
||||||
@ -171,35 +168,67 @@ void QLMenubar::macxMenuBarInit()
|
|||||||
#ifdef Q_WS_MACX
|
#ifdef Q_WS_MACX
|
||||||
mac_menubar_.reset(new QMenuBar);
|
mac_menubar_.reset(new QMenuBar);
|
||||||
|
|
||||||
# ifdef MERGE_MAC_MENUS
|
# if QT_VERSION >= 0x040200
|
||||||
/* The qt/mac menu code has a very silly hack that moves some
|
/* Since Qt 4.2, the qt/mac menu code has special code for
|
||||||
menu entries that it recognizes by name (e.g.
|
specifying the role of a menu entry. However, it does not
|
||||||
"Preferences...") to the "LyX" menu. This feature can only
|
work very well with our scheme of creating menus on demand,
|
||||||
work if the menu entries are always available. Since we
|
and therefore we need to put these entries in a special
|
||||||
build menus on demand, we add the entries to a dummy menu
|
invisible menu. (JMarc)
|
||||||
(JMarc)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* The entries of our special mac menu. If we add support for
|
||||||
|
* special entries in MenuBackend, we could imagine something
|
||||||
|
* like
|
||||||
|
* SpecialItem About " "About LyX" "dialog-show aboutlyx"
|
||||||
|
* and therefore avoid hardcoding. I am not sure it is worth
|
||||||
|
* the hassle, though. (JMarc)
|
||||||
|
*/
|
||||||
|
struct MacMenuEntry {
|
||||||
|
kb_action action;
|
||||||
|
char const * arg;
|
||||||
|
char const * label;
|
||||||
|
QAction::MenuRole role;
|
||||||
|
};
|
||||||
|
|
||||||
|
MacMenuEntry entries[] = {
|
||||||
|
{LFUN_DIALOG_SHOW, "aboutlyx", "About LyX",
|
||||||
|
QAction::AboutRole},
|
||||||
|
{LFUN_DIALOG_SHOW, "prefs", "Preferences",
|
||||||
|
QAction::PreferencesRole},
|
||||||
|
{LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
|
||||||
|
};
|
||||||
|
const size_t num_entries = sizeof(entries) / sizeof(MacMenuEntry);
|
||||||
|
|
||||||
|
// the special menu for MenuBackend.
|
||||||
Menu special;
|
Menu special;
|
||||||
special.add(MenuItem(MenuItem::Command,
|
for (size_t i = 0 ; i < num_entries ; ++i) {
|
||||||
qstring_to_ucs4(QMenuBar::tr("About")),
|
FuncRequest const func(entries[i].action,
|
||||||
FuncRequest(LFUN_DIALOG_SHOW, "aboutlyx")));
|
from_utf8(entries[i].arg));
|
||||||
special.add(MenuItem(MenuItem::Command,
|
special.add(MenuItem(MenuItem::Command,
|
||||||
qstring_to_ucs4(QMenuBar::tr("Preferences")),
|
from_utf8(entries[i].label),
|
||||||
FuncRequest(LFUN_DIALOG_SHOW, "prefs")));
|
func));
|
||||||
special.add(MenuItem(MenuItem::Command,
|
}
|
||||||
qstring_to_ucs4(QMenuBar::tr("Quit")),
|
|
||||||
FuncRequest(LFUN_LYX_QUIT)));
|
|
||||||
menubackend_.specialMenu(special);
|
menubackend_.specialMenu(special);
|
||||||
|
|
||||||
QMenu * qMenu = owner_->menuBar()->addMenu("special");
|
// add the entries to a QMenu that will eventually be empty
|
||||||
|
// and therefore invisible.
|
||||||
|
QMenu * qMenu = owner_->menuBar()->addMenu("special");
|
||||||
|
|
||||||
|
// we do not use 'special' because it is a temporary variable,
|
||||||
|
// whereas MenuBackend::specialMenu points to a persistent
|
||||||
|
// copy.
|
||||||
|
Menu::const_iterator cit = menubackend_.specialMenu().begin();
|
||||||
Menu::const_iterator end = menubackend_.specialMenu().end();
|
Menu::const_iterator end = menubackend_.specialMenu().end();
|
||||||
for (Menu::const_iterator cit = menubackend_.specialMenu().begin();
|
for (size_t i = 0 ; cit != end ; ++cit, ++i) {
|
||||||
cit != end ; ++cit)
|
Action * action = new Action(*owner_, cit->label(),
|
||||||
qMenu->addAction(new Action(*owner_, cit->label(), cit->func()));
|
cit->func());
|
||||||
|
action->setMenuRole(entries[i].role);
|
||||||
|
qMenu->addAction(action);
|
||||||
|
|
||||||
|
}
|
||||||
# else
|
# else
|
||||||
qt_mac_set_menubar_merge(false);
|
qt_mac_set_menubar_merge(false);
|
||||||
# endif // MERGE_MAC_MENUS
|
# endif // QT_VERSION >= 0x040200
|
||||||
#endif // Q_WS_MACX
|
#endif // Q_WS_MACX
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user