From 7823d3b01b1b5a2c9ab639d08cbe2b8097f5e073 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 19 Jul 2022 18:39:04 +0200 Subject: [PATCH] Fix display of bindings for StaticMenuButton This requires to add a parameter to GuiToolbar::addItem so that it is possble to make a difference between toolbar buttons and menu items. The long-term solution is to rely on the menu backend for such things. Fixes bug #12004. --- src/frontends/qt/GuiToolbar.cpp | 16 +++++++++++----- src/frontends/qt/GuiToolbar.h | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/frontends/qt/GuiToolbar.cpp b/src/frontends/qt/GuiToolbar.cpp index bc2613d1a4..51699c98a8 100644 --- a/src/frontends/qt/GuiToolbar.cpp +++ b/src/frontends/qt/GuiToolbar.cpp @@ -142,17 +142,23 @@ void GuiToolbar::setVisibility(int visibility) } -Action * GuiToolbar::addItem(ToolbarItem const & item) +Action * GuiToolbar::addItem(ToolbarItem const & item, bool menu) { QString text = toqstr(item.label); + QString tooltip = text; // Get the keys bound to this action, but keep only the // first one later KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*item.func); - if (!bindings.empty()) - text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]"; + if (!bindings.empty()) { + QString binding = toqstr(bindings.begin()->print(KeySequence::ForGui)); + if (menu) + text += '\t' + binding; + else + tooltip += " [" + binding + "]"; + } Action * act = new Action(item.func, getIcon(*item.func, false), text, - text, this); + tooltip, this); if (item.type == ToolbarItem::BIDICOMMAND) act->setRtlIcon(getIcon(*item.func, false, true)); @@ -277,7 +283,7 @@ void StaticMenuButton::initialize() ToolbarInfo::item_iterator const end = tbinfo->items.end(); for (; it != end; ++it) if (!getStatus(*it->func).unknown()) - m->add(bar_->addItem(*it)); + m->add(bar_->addItem(*it, true)); setMenu(m); } diff --git a/src/frontends/qt/GuiToolbar.h b/src/frontends/qt/GuiToolbar.h index f1cc13a914..6b3581c2d2 100644 --- a/src/frontends/qt/GuiToolbar.h +++ b/src/frontends/qt/GuiToolbar.h @@ -169,8 +169,9 @@ public: /// GuiCommandBuffer * commandBuffer() { return command_buffer_; } - /// - Action * addItem(ToolbarItem const & item); + /// add item to toolbar. + /// \param menu : when true, the item is for a menu entry, not a button. + Action * addItem(ToolbarItem const & item, bool menu = false); /// GuiView const & owner() { return owner_; } -- 2.39.5