namespace lyx {
namespace frontend {
+QIcon DynamicMenuButton::icon_textstyle_apply_;
+QIcon DynamicMenuButton::icon_undo_;
+QIcon DynamicMenuButton::icon_paste_;
+
+
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
: QToolBar(toqstr(tbinfo.gui_name), &owner), visibility_(0),
- owner_(owner), command_buffer_(0), tbinfo_(tbinfo), filled_(false),
+ owner_(owner), command_buffer_(nullptr), tbinfo_(tbinfo), filled_(false),
restored_(false)
{
setIconSize(owner.iconSize());
}
+void GuiToolbar::refill()
+{
+ filled_ = false;
+ clear();
+ fill();
+}
+
+
void GuiToolbar::showEvent(QShowEvent * ev)
{
fill();
}
-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));
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);
}
bool enabled = false;
QList<QAction *> acts = menu()->actions();
- for (int i = 0; i < acts.size(); ++i)
- if (acts[i]->isEnabled()) {
+ for (auto const & act : acts)
+ if (act->isEnabled()) {
enabled = true;
break;
}
Private(Private const &);
void operator=(Private const &);
public:
- Private() : inset_(0) {}
+ Private() : inset_(nullptr) {}
///
DocumentClassConstPtr text_class_;
///
}
+void DynamicMenuButton::resetIconCache()
+{
+ icon_textstyle_apply_ = getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false);
+ icon_undo_ = getIcon(FuncRequest(LFUN_UNDO), false);
+ icon_paste_ = getIcon(FuncRequest(LFUN_PASTE), false);
+}
+
+
void DynamicMenuButton::updateTriggered()
{
QMenu * m = menu();
m->clear();
setPopupMode(QToolButton::MenuButtonPopup);
if (!bv) {
- QToolButton::setIcon(getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false));
+ QToolButton::setIcon(icon_textstyle_apply_);
setEnabled(false);
return;
}
}
// Add item to reset to defaults
Action * reset_act = new Action(FuncRequest(LFUN_FONT_DEFAULT, FuncRequest::TOOLBAR),
- getIcon(FuncRequest(LFUN_UNDO), false),
+ icon_undo_,
qt_("&Reset to default"),
qt_("Reset all font settings to their defaults"), this);
m->addAction(reset_act);
if (default_act)
QToolButton::setDefaultAction(default_act);
- QToolButton::setIcon(getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false));
+ QToolButton::setIcon(icon_textstyle_apply_);
setEnabled(lyx::getStatus(FuncRequest(LFUN_TEXTSTYLE_APPLY)).enabled()
|| lyx::getStatus(FuncRequest(LFUN_FONT_DEFAULT)).enabled());
} else if (menutype == "paste") {
m->clear();
setPopupMode(QToolButton::MenuButtonPopup);
Action * default_action = new Action(FuncRequest(LFUN_PASTE),
- getIcon(FuncRequest(LFUN_PASTE), false),
+ icon_paste_,
qt_("Paste"), qt_("Paste"), this);
if (!bv) {
setEnabled(false);
QMenu * m = menu();
m->clear();
string const & menutype = tbitem_.name;
- InsetLayout::InsetLyXType ftype;
+ InsetLyXType ftype;
if (menutype == "dynamic-custom-insets")
- ftype = InsetLayout::CUSTOM;
+ ftype = InsetLyXType::CUSTOM;
else if (menutype == "dynamic-char-styles")
- ftype = InsetLayout::CHARSTYLE;
+ ftype = InsetLyXType::CHARSTYLE;
else {
// this should have been taken care of earlier
LASSERT(false, return);
// This is a speed bottleneck because this is called on every keypress
// and update calls getStatus, which copies the cursor at least two times
- for (int i = 0; i < actions_.size(); ++i)
- actions_[i]->update();
+ for (auto const & action : actions_)
+ action->update();
LayoutBox * layout = owner_.getLayoutDialog();
if (layout)
}
-bool GuiToolbar::isVisibiltyOn() const
+bool GuiToolbar::isVisibilityOn() const
{
return visibility_ & Toolbars::ON;
}
-void GuiToolbar::toggle()
+void GuiToolbar::setState(string const state)
{
- docstring state;
- if (visibility_ & Toolbars::ALLOWAUTO) {
- if (!(visibility_ & Toolbars::AUTO)) {
+ docstring newstate;
+ if (state == "auto") {
+ if (visibility_ & Toolbars::ALLOWAUTO) {
visibility_ |= Toolbars::AUTO;
hide();
- state = _("auto");
- } else {
- visibility_ &= ~Toolbars::AUTO;
- if (isVisible()) {
- hide();
- state = _("off");
- } else {
- show();
- state = _("on");
- }
- }
+ newstate = _("auto");
+ } else
+ owner_.message(bformat(_("Toolbar \"%1$s\" does not support state \"auto\""),
+ qstring_to_ucs4(windowTitle())));
} else {
- if (isVisible()) {
+ if (visibility_ & Toolbars::AUTO)
+ visibility_ &= ~Toolbars::AUTO;
+ if (state == "off") {
hide();
- state = _("off");
- } else {
+ newstate = _("off");
+ } else if (state == "on") {
show();
- state = _("on");
+ newstate = _("on");
}
}
owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
- qstring_to_ucs4(windowTitle()), state));
+ qstring_to_ucs4(windowTitle()), newstate));
+}
+
+
+void GuiToolbar::toggle()
+{
+ if (visibility_ & Toolbars::ALLOWAUTO) {
+ if (!(visibility_ & Toolbars::AUTO) && !isVisibilityOn()) {
+ setState("auto");
+ } else {
+ if (isVisibilityOn())
+ setState("off");
+ else
+ setState("on");
+ }
+ } else {
+ if (isVisible())
+ setState("off");
+ else
+ setState("on");
+ }
}
void GuiToolbar::movable(bool silent)