]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiToolbar.cpp
BiblioInfo: provide macro for ellipses
[lyx.git] / src / frontends / qt / GuiToolbar.cpp
1 /**
2  * \file qt/GuiToolbar.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author John Levon
8  * \author Jean-Marc Lasgouttes
9  * \author Angus Leeming
10  * \author Stefan Schimanski
11  * \author Abdelrazak Younes
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #include <config.h>
17
18 #include "GuiToolbar.h"
19
20 #include "Action.h"
21 #include "Buffer.h"
22 #include "BufferParams.h"
23 #include "BufferView.h"
24 #include "Cursor.h"
25 #include "CutAndPaste.h"
26 #include "FuncRequest.h"
27 #include "FuncStatus.h"
28 #include "GuiApplication.h"
29 #include "GuiCommandBuffer.h"
30 #include "GuiView.h"
31 #include "IconPalette.h"
32 #include "InsertTableWidget.h"
33 #include "KeyMap.h"
34 #include "LayoutBox.h"
35 #include "LyX.h"
36 #include "LyXRC.h"
37 #include "Menus.h"
38 #include "qt_helpers.h"
39 #include "Session.h"
40 #include "Text.h"
41 #include "TextClass.h"
42 #include "Toolbars.h"
43
44 #include "insets/InsetText.h"
45
46 #include "support/convert.h"
47 #include "support/debug.h"
48 #include "support/docstring_list.h"
49 #include "support/gettext.h"
50 #include "support/lstrings.h"
51
52 #include <QSettings>
53 #include <QShowEvent>
54 #include <QString>
55 #include <QToolBar>
56 #include <QToolButton>
57
58 #include "support/lassert.h"
59
60 using namespace std;
61 using namespace lyx::support;
62
63 namespace lyx {
64 namespace frontend {
65
66 QIcon DynamicMenuButton::icon_textstyle_apply_;
67 QIcon DynamicMenuButton::icon_undo_;
68 QIcon DynamicMenuButton::icon_paste_;
69
70
71 GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
72         : QToolBar(toqstr(tbinfo.gui_name), &owner), visibility_(0),
73           owner_(owner), command_buffer_(nullptr), tbinfo_(tbinfo), filled_(false),
74           restored_(false)
75 {
76         setIconSize(owner.iconSize());
77         connect(&owner, SIGNAL(iconSizeChanged(QSize)), this,
78                 SLOT(setIconSize(QSize)));
79         setContextMenuPolicy(Qt::CustomContextMenu);
80         connect(this, SIGNAL(customContextMenuRequested(QPoint)),
81                 SLOT(showContextMenu(QPoint)));
82
83         // This is used by QMainWindow::restoreState for proper main window state
84         // restoration.
85         setObjectName(toqstr(tbinfo.name));
86         restoreSession();
87 }
88
89
90 void GuiToolbar::setVisible(bool visible)
91 {
92         // This is a hack to find out which toolbars have been restored by
93         // MainWindow::restoreState and which toolbars should be initialized
94         // by us (i.e., new toolbars)
95         restored_ = true;
96         // Record the actual visibility in toolbar state visibility_.
97         // This is useful to restore the visibility of toolbars when
98         // returning from full-screen. Therefore the recording is disabled
99         // while LyX is in full-screen state.
100         if (!owner_.isFullScreen()) {
101                 if (visible)
102                         visibility_ |= Toolbars::ON;
103                 else
104                         visibility_ &= ~Toolbars::ON;
105         }
106         QToolBar::setVisible(visible);
107 }
108
109
110 bool GuiToolbar::isRestored() const
111 {
112         return restored_;
113 }
114
115
116 void GuiToolbar::fill()
117 {
118         if (filled_)
119                 return;
120         ToolbarInfo::item_iterator it = tbinfo_.items.begin();
121         ToolbarInfo::item_iterator end = tbinfo_.items.end();
122         for (; it != end; ++it)
123                 add(*it);
124         filled_ = true;
125 }
126
127
128 void GuiToolbar::refill()
129 {
130         filled_ = false;
131         clear();
132         fill();
133 }
134
135
136 void GuiToolbar::showEvent(QShowEvent * ev)
137 {
138         fill();
139         ev->accept();
140 }
141
142
143 void GuiToolbar::setVisibility(int visibility)
144 {
145         visibility_ = visibility;
146 }
147
148
149 void GuiToolbar::showContextMenu(QPoint pos)
150 {
151         QMenu * menu = guiApp->menus().menu(toqstr("context-toolbars"), owner_);
152         menu->exec(mapToGlobal(pos));
153 }
154
155
156 Action * GuiToolbar::addItem(ToolbarItem const & item, bool menu)
157 {
158         QString text = toqstr(item.label);
159         QString tooltip = text;
160         // Get the keys bound to this action, but keep only the
161         // first one later
162         KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*item.func);
163         if (!bindings.empty()) {
164                 QString binding = toqstr(bindings.begin()->print(KeySequence::ForGui));
165                 if (menu)
166                         text += '\t' + binding;
167                 else
168                         tooltip += " [" + binding + "]";
169         }
170
171         Action * act = new Action(item.func, getIcon(*item.func, false), text,
172                                   tooltip, this);
173         if (item.type == ToolbarItem::BIDICOMMAND)
174                 act->setRtlIcon(getIcon(*item.func, false, true));
175
176         actions_.append(act);
177         return act;
178 }
179
180 namespace {
181
182 class PaletteButton : public QToolButton
183 {
184 private:
185         GuiToolbar * bar_;
186         ToolbarItem const & tbitem_;
187         bool initialized_;
188 public:
189         PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
190                 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
191         {
192                 QString const label = qt_(to_ascii(tbitem_.label));
193                 setToolTip(label);
194                 setStatusTip(label);
195                 setText(label);
196                 connect(bar_, SIGNAL(iconSizeChanged(QSize)),
197                         this, SLOT(setIconSize(QSize)));
198                 setCheckable(true);
199                 ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name);
200                 if (tbinfo)
201                         // use the icon of first action for the toolbar button
202                         setIcon(getIcon(*tbinfo->items.begin()->func, true));
203         }
204
205         void mousePressEvent(QMouseEvent * e) override
206         {
207                 if (initialized_) {
208                         QToolButton::mousePressEvent(e);
209                         return;
210                 }
211
212                 initialized_ = true;
213
214                 ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name);
215                 if (!tbinfo) {
216                         LYXERR0("Unknown toolbar " << tbitem_.name);
217                         return;
218                 }
219                 IconPalette * panel = new IconPalette(this);
220                 QString const label = qt_(to_ascii(tbitem_.label));
221                 panel->setWindowTitle(label);
222                 connect(this, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
223                 connect(panel, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
224                 ToolbarInfo::item_iterator it = tbinfo->items.begin();
225                 ToolbarInfo::item_iterator const end = tbinfo->items.end();
226                 for (; it != end; ++it)
227                         if (!getStatus(*it->func).unknown())
228                                 panel->addButton(bar_->addItem(*it));
229
230                 QToolButton::mousePressEvent(e);
231         }
232 };
233
234 } // namespace
235
236
237 MenuButtonBase::MenuButtonBase(GuiToolbar * bar, ToolbarItem const & item)
238         : QToolButton(bar), bar_(bar), tbitem_(item)
239 {
240         setPopupMode(QToolButton::InstantPopup);
241         QString const label = qt_(to_ascii(tbitem_.label));
242         setToolTip(label);
243         setStatusTip(label);
244         setText(label);
245         QString const name = toqstr(tbitem_.name);
246         QStringList imagedirs;
247         imagedirs << "images/math/" << "images/";
248         for (int i = 0; i < imagedirs.size(); ++i) {
249                 QString imagedir = imagedirs.at(i);
250                 FileName const fname = imageLibFileSearch(imagedir, name, "svgz,png",
251                         theGuiApp()->imageSearchMode());
252                 if (fname.exists()) {
253                         setIcon(QIcon(getPixmap(imagedir, name, "svgz,png")));
254                         break;
255                 }
256         }
257 }
258
259
260 void MenuButtonBase::actionTriggered(QAction * action)
261 {
262         QToolButton::setDefaultAction(action);
263         setPopupMode(QToolButton::DelayedPopup);
264 }
265
266
267 StaticMenuButton::StaticMenuButton(
268     GuiToolbar * bar, ToolbarItem const & item, bool const sticky)
269         : MenuButtonBase(bar, item)
270 {
271         if (sticky)
272                 connect(this, SIGNAL(triggered(QAction *)),
273                         this, SLOT(actionTriggered(QAction *)));
274         connect(bar, SIGNAL(iconSizeChanged(QSize)),
275                 this, SLOT(setIconSize(QSize)));
276         initialize();
277 }
278
279
280 void StaticMenuButton::initialize()
281 {
282         QString const label = qt_(to_ascii(tbitem_.label));
283         ButtonMenu * m = new ButtonMenu(label, this);
284         m->setWindowTitle(label);
285         m->setTearOffEnabled(true);
286         connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
287         connect(bar_, SIGNAL(updated()), this, SLOT(updateTriggered()));
288         ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name);
289         if (!tbinfo) {
290                 LYXERR0("Unknown toolbar " << tbitem_.name);
291                 return;
292         }
293         ToolbarInfo::item_iterator it = tbinfo->items.begin();
294         ToolbarInfo::item_iterator const end = tbinfo->items.end();
295         for (; it != end; ++it)
296                 if (!getStatus(*it->func).unknown())
297                         m->add(bar_->addItem(*it, true));
298         setMenu(m);
299 }
300
301
302 void StaticMenuButton::updateTriggered()
303 {
304         if (!menu())
305                 return;
306
307         bool enabled = false;
308         QList<QAction *> acts = menu()->actions();
309         for (auto const & act : acts)
310                 if (act->isEnabled()) {
311                         enabled = true;
312                         break;
313                 }
314         // Enable the MenuButton if at least one menu item is enabled
315         setEnabled(enabled);
316         // If a disabled item is default, switch to InstantPopup
317         // (this can happen if a user selects e.g. DVI and then
318         // turns non-TeX fonts on)
319         if (defaultAction() && !defaultAction()->isEnabled())
320                 setPopupMode(QToolButton::InstantPopup);
321 }
322
323
324 class DynamicMenuButton::Private
325 {
326         /// noncopyable
327         Private(Private const &);
328         void operator=(Private const &);
329 public:
330         Private() : inset_(nullptr) {}
331         ///
332         DocumentClassConstPtr text_class_;
333         ///
334         InsetText const * inset_;
335 };
336
337
338 DynamicMenuButton::DynamicMenuButton(GuiToolbar * bar, ToolbarItem const & item)
339         : MenuButtonBase(bar, item), d(new Private())
340 {
341         initialize();
342 }
343
344
345 DynamicMenuButton::~DynamicMenuButton() 
346
347         delete d;
348 }
349
350
351 void DynamicMenuButton::initialize()
352 {
353         QString const label = qt_(to_ascii(tbitem_.label));
354         ButtonMenu * m = new ButtonMenu(label, this);
355         m->setWindowTitle(label);
356         m->setTearOffEnabled(true);
357         connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
358         connect(bar_, SIGNAL(updated()), this, SLOT(updateTriggered()));
359         connect(bar_, SIGNAL(iconSizeChanged(QSize)),
360                 this, SLOT(setIconSize(QSize)));
361         setMenu(m);
362 }
363
364
365 bool DynamicMenuButton::isMenuType(string const & s)
366 {
367         return s == "dynamic-custom-insets"
368                 || s == "dynamic-char-styles"
369                 || s == "textstyle-apply"
370                 || s == "paste";
371 }
372
373
374 void DynamicMenuButton::resetIconCache()
375 {
376         icon_textstyle_apply_ = getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false);
377         icon_undo_ =  getIcon(FuncRequest(LFUN_UNDO), false);
378         icon_paste_ = getIcon(FuncRequest(LFUN_PASTE), false);
379 }
380
381
382 void DynamicMenuButton::updateTriggered()
383 {
384         QMenu * m = menu();
385         // the menu should exist by this point
386         // if not, we can at least avoid crashing in release mode
387         LASSERT(m, return);
388         GuiView const & owner = bar_->owner();
389         BufferView const * bv = owner.currentBufferView();
390
391         string const & menutype = tbitem_.name;
392         if (menutype == "dynamic-custom-insets" || menutype == "dynamic-char-styles") {
393                 if (!bv) {
394                         m->clear();
395                         setEnabled(false);
396                         setMinimumWidth(sizeHint().width());
397                         d->text_class_.reset();
398                         d->inset_ = nullptr;
399                         return;
400                 }
401                 DocumentClassConstPtr text_class =
402                                 bv->buffer().params().documentClassPtr();
403                 InsetText const * inset = &(bv->cursor().innerText()->inset());
404                 // if the text class has changed, then we need to reload the menu
405                 if (d->text_class_ != text_class) {
406                         d->text_class_ = text_class;
407                         // at the moment, we can just call loadFlexInsets, and it will
408                         // handle both types. if there were more types of menus, then we
409                         // might need to have other options.
410                         loadFlexInsets();
411                 }
412                 // remember where we are
413                 d->inset_ = inset;
414                 // note that enabling here might need to be more subtle if there
415                 // were other kinds of menus.
416                 setEnabled(!bv->buffer().isReadonly()
417                            && !m->isEmpty()
418                            && inset->insetAllowed(FLEX_CODE));
419         } else if (menutype == "textstyle-apply") {
420                 m->clear();
421                 setPopupMode(QToolButton::MenuButtonPopup);
422                 if (!bv) {
423                         QToolButton::setIcon(icon_textstyle_apply_);
424                         setEnabled(false);
425                         return;
426                 }
427                 vector<docstring> ffList = bv->cursor().innerText()->getFreeFonts();
428                 unsigned int i = 0;
429                 Action * default_act = nullptr;
430                 for (auto const & f : ffList) {
431                         FuncRequest func(LFUN_TEXTSTYLE_APPLY, convert<docstring>(i),
432                                          FuncRequest::TOOLBAR);
433                         docstring const lb = char_type('&') + convert<docstring>(i)
434                                 + from_ascii(". ") + f ;
435                         Action * act = new Action(func, QIcon(), toqstr(lb), toqstr(f), this);
436                         m->addAction(act);
437                         // The most recent one is the default
438                         if (i == 0)
439                                 default_act = act;
440                         ++i;
441                 }
442                 // Add items to reset to defaults
443                 Action * reset_act = new Action(FuncRequest(LFUN_FONT_DEFAULT, FuncRequest::TOOLBAR),
444                                                 icon_undo_,
445                                                 qt_("&Reset to default (keep language)"),
446                                                 qt_("Reset all font settings to their defaults but keep language settings"), this);
447                 m->addAction(reset_act);
448                 Action * reset_act_lang = new Action(FuncRequest(LFUN_COMMAND_SEQUENCE, "font-default ; language reset",
449                                                                  FuncRequest::TOOLBAR),
450                                                 icon_undo_,
451                                                 qt_("Reset to default (including &language)"),
452                                                 qt_("Reset all font settings and the language to their defaults"), this);
453                 m->addAction(reset_act_lang);
454                 if (default_act)
455                         QToolButton::setDefaultAction(default_act);
456                 QToolButton::setIcon(icon_textstyle_apply_);
457                 setEnabled(lyx::getStatus(FuncRequest(LFUN_TEXTSTYLE_APPLY)).enabled()
458                            || lyx::getStatus(FuncRequest(LFUN_FONT_DEFAULT)).enabled());
459         } else if (menutype == "paste") {
460                 m->clear();
461                 setPopupMode(QToolButton::MenuButtonPopup);
462                 Action * default_action = new Action(FuncRequest(LFUN_PASTE),
463                                                      icon_paste_,
464                                                      qt_("Paste"), qt_("Paste"), this);
465                 if (!bv) {
466                         setEnabled(false);
467                         QToolButton::setDefaultAction(default_action);
468                         return;
469                 }
470                 docstring_list const sel = cap::availableSelections(&bv->buffer());
471
472                 docstring_list::const_iterator cit = sel.begin();
473                 docstring_list::const_iterator end = sel.end();
474
475                 for (unsigned int index = 0; cit != end; ++cit, ++index) {
476                         docstring const s = *cit;
477                         FuncRequest func(LFUN_PASTE, convert<docstring>(index),
478                                          FuncRequest::TOOLBAR);
479                         docstring const lb = char_type('&') + convert<docstring>(index)
480                                 + from_ascii(". ") + s ;
481                         Action * act = new Action(func, QIcon(), toqstr(lb), toqstr(s), this);
482                         m->addAction(act);
483                 }
484                 QToolButton::setDefaultAction(default_action);
485                 setEnabled(lyx::getStatus(FuncRequest(LFUN_PASTE)).enabled());
486         }
487 }
488
489
490 void DynamicMenuButton::loadFlexInsets()
491 {
492         QMenu * m = menu();
493         m->clear();
494         string const & menutype = tbitem_.name;
495         InsetLyXType ftype;
496         if (menutype == "dynamic-custom-insets")
497                 ftype = InsetLyXType::CUSTOM;
498         else if (menutype == "dynamic-char-styles")
499                 ftype = InsetLyXType::CHARSTYLE;
500         else {
501                 // this should have been taken care of earlier
502                 LASSERT(false, return);
503         }
504
505         TextClass::InsetLayouts const & inset_layouts = 
506                         d->text_class_->insetLayouts();
507         for (auto const & iit : inset_layouts) {
508                 InsetLayout const & il = iit.second;
509                 if (il.lyxtype() != ftype)
510                         continue;
511                 docstring const name = iit.first;
512                 QString const loc_item = toqstr(translateIfPossible(
513                                 prefixIs(name, from_ascii("Flex:")) ? 
514                                 name.substr(5) : name));
515                 FuncRequest func(LFUN_FLEX_INSERT, 
516                                 from_ascii("\"") + name + from_ascii("\""), FuncRequest::TOOLBAR);
517                 Action * act = 
518                                 new Action(func, getIcon(func, false), loc_item, loc_item, this);
519                 m->addAction(act);
520         }
521 }
522
523
524 void GuiToolbar::add(ToolbarItem const & item)
525 {
526         switch (item.type) {
527         case ToolbarItem::SEPARATOR:
528                 addSeparator();
529                 break;
530         case ToolbarItem::LAYOUTS: {
531                 LayoutBox * layout = owner_.getLayoutDialog();
532                 QObject::connect(this, SIGNAL(iconSizeChanged(QSize)),
533                         layout, SLOT(setIconSize(QSize)));
534                 QAction * action = addWidget(layout);
535                 action->setVisible(true);
536                 break;
537         }
538         case ToolbarItem::MINIBUFFER:
539                 command_buffer_ = new GuiCommandBuffer(&owner_);
540                 addWidget(command_buffer_);
541                 /// \todo find a Qt5 equivalent to setHorizontalStretchable(true);
542                 //setHorizontalStretchable(true);
543                 break;
544         case ToolbarItem::TABLEINSERT: {
545                 QToolButton * tb = new QToolButton;
546                 tb->setCheckable(true);
547                 tb->setIcon(getIcon(FuncRequest(LFUN_TABULAR_INSERT), true));
548                 QString const label = qt_(to_ascii(item.label));
549                 tb->setToolTip(label);
550                 tb->setStatusTip(label);
551                 tb->setText(label);
552                 InsertTableWidget * iv = new InsertTableWidget(tb);
553                 connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
554                 connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
555                 connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
556                 addWidget(tb);
557                 break;
558                 }
559         case ToolbarItem::ICONPALETTE:
560                 addWidget(new PaletteButton(this, item));
561                 break;
562         case ToolbarItem::POPUPMENU: {
563                 addWidget(new StaticMenuButton(this, item, false));
564                 break;
565                 }
566         case ToolbarItem::STICKYPOPUPMENU: {
567                 addWidget(new StaticMenuButton(this, item, true));
568                 break;
569                 }
570         case ToolbarItem::DYNAMICMENU: {
571                 // we only handle certain things
572                 if (DynamicMenuButton::isMenuType(item.name))
573                         addWidget(new DynamicMenuButton(this, item));
574                 else
575                         LYXERR0("Unknown dynamic menu type: " << item.name);
576                 break;
577         }
578         case ToolbarItem::BIDICOMMAND: {
579                 if (!getStatus(*item.func).unknown())
580                         addAction(addItem(item));
581                 break;
582                 }
583         case ToolbarItem::COMMAND: {
584                 if (!getStatus(*item.func).unknown())
585                         addAction(addItem(item));
586                 break;
587                 }
588         default:
589                 break;
590         }
591 }
592
593
594 void GuiToolbar::update(int context)
595 {
596         if (visibility_ & Toolbars::AUTO) {
597                 setVisible(visibility_ & context & Toolbars::ALLOWAUTO);
598                 if (isVisible() && commandBuffer() && (context & Toolbars::MINIBUFFER_FOCUS))
599                         commandBuffer()->setFocus();
600         }
601
602         // update visible toolbars only
603         if (!isVisible())
604                 return;
605
606         // This is a speed bottleneck because this is called on every keypress
607         // and update calls getStatus, which copies the cursor at least two times
608         for (auto const & action : actions_)
609                 action->update();
610
611         LayoutBox * layout = owner_.getLayoutDialog();
612         if (layout)
613                 layout->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
614
615         // emit signal
616         updated();
617 }
618
619
620 QString GuiToolbar::sessionKey() const
621 {
622         return "views/" + QString::number(owner_.id()) + "/" + objectName();
623 }
624
625
626 void GuiToolbar::saveSession(QSettings & settings) const
627 {
628         settings.setValue(sessionKey() + "/visibility", visibility_);
629         settings.setValue(sessionKey() + "/movability", isMovable());
630 }
631
632
633 void GuiToolbar::restoreSession()
634 {
635         QSettings settings;
636         int const error_val = -1;
637         int visibility =
638                 settings.value(sessionKey() + "/visibility", error_val).toInt();
639         if (visibility == error_val || visibility == 0) {
640                 // This should not happen, but in case we use the defaults
641                 LYXERR(Debug::GUI, "Session settings could not be found! Defaults are used instead.");
642                 visibility =
643                         guiApp->toolbars().defaultVisibility(fromqstr(objectName()));
644         }
645         setVisibility(visibility);
646
647         int movability = settings.value(sessionKey() + "/movability", true).toBool();
648         setMovable(movability);
649 }
650
651
652 bool GuiToolbar::isVisibilityOn() const
653 {
654         return visibility_ & Toolbars::ON;
655 }
656
657
658 void GuiToolbar::setState(string const state)
659 {
660         docstring newstate;
661         if (state == "auto") {
662                 if (visibility_ & Toolbars::ALLOWAUTO) {
663                         visibility_ |= Toolbars::AUTO;
664                         hide();
665                         newstate = _("auto");
666                 } else
667                         owner_.message(bformat(_("Toolbar \"%1$s\" does not support state \"auto\""),
668                                 qstring_to_ucs4(windowTitle())));
669         } else {
670                 if (visibility_ & Toolbars::AUTO)
671                         visibility_ &= ~Toolbars::AUTO;
672                 if (state == "off") {
673                         hide();
674                         newstate = _("off");
675                 } else if (state == "on") {
676                         show();
677                         newstate = _("on");
678                 }
679         }
680
681         owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
682                 qstring_to_ucs4(windowTitle()), newstate));
683 }
684
685
686 void GuiToolbar::toggle()
687 {
688         if (visibility_ & Toolbars::ALLOWAUTO) {
689                 if (!(visibility_ & Toolbars::AUTO) && !isVisibilityOn()) {
690                         setState("auto");
691                 } else {
692                         if (isVisibilityOn())
693                                 setState("off");
694                         else
695                                 setState("on");
696                 }
697         } else {
698                 if (isVisible())
699                         setState("off");
700                 else
701                         setState("on");
702         }
703 }
704
705 void GuiToolbar::movable(bool silent)
706 {
707         // toggle movability
708         setMovable(!isMovable());
709
710         // manual update avoids bug in qt that the drag handle is not removed
711         // properly, e.g. in Windows
712         Q_EMIT update();
713
714         // silence for toggling of many toolbars for performance
715         if (!silent) {
716                 docstring state;
717                 if (isMovable())
718                         state = _("movable");
719                 else
720                         state = _("immovable");
721                 owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
722                         qstring_to_ucs4(windowTitle()), state));
723         }
724 }
725
726 } // namespace frontend
727 } // namespace lyx
728
729 #include "moc_GuiToolbar.cpp"