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());
setIcon(getIcon(*tbinfo->items.begin()->func, true));
}
- void mousePressEvent(QMouseEvent * e)
+ void mousePressEvent(QMouseEvent * e) override
{
if (initialized_) {
QToolButton::mousePressEvent(e);
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_;
///
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)
}
-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) && !isVisibiltyOn()) {
+ setState("auto");
+ } else {
+ if (isVisibiltyOn())
+ setState("off");
+ else
+ setState("on");
+ }
+ } else {
+ if (isVisible())
+ setState("off");
+ else
+ setState("on");
+ }
}
void GuiToolbar::movable(bool silent)