]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiToolbar.cpp
* custom keyboard search/filter which shows only those layouts whose
[features.git] / src / frontends / qt4 / GuiToolbar.cpp
1 /**
2  * \file qt4/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 Abdelrazak Younes
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #include <config.h>
16
17 #include "GuiView.h"
18 #include "GuiCommandBuffer.h"
19 #include "GuiToolbar.h"
20 #include "LyXAction.h"
21 #include "Action.h"
22 #include "qt_helpers.h"
23 #include "InsertTableWidget.h"
24
25 #include "Buffer.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
28 #include "Cursor.h"
29 #include "FuncRequest.h"
30 #include "FuncStatus.h"
31 #include "IconPalette.h"
32 #include "Layout.h"
33 #include "LyXFunc.h"
34 #include "LyXRC.h"
35 #include "Paragraph.h"
36 #include "TextClass.h"
37 #include "ToolbarBackend.h"
38
39 #include "support/debug.h"
40 #include "support/filetools.h"
41 #include "support/gettext.h"
42 #include "support/lstrings.h"
43 #include "support/lyxalgo.h" // sorted
44
45 #include <QComboBox>
46 #include <QHeaderView>
47 #include <QKeyEvent>
48 #include <QList>
49 #include <QPixmap>
50 #include <QSortFilterProxyModel>
51 #include <QStandardItem>
52 #include <QStandardItemModel>
53 #include <QToolBar>
54 #include <QToolButton>
55 #include <QVariant>
56
57 #include <boost/assert.hpp>
58
59 using namespace std;
60 using namespace lyx::support;
61
62 static void initializeResources()
63 {
64         static bool initialized = false;
65         if (!initialized) {
66                 Q_INIT_RESOURCE(Resources); 
67                 initialized = true;
68         }
69 }
70
71
72 namespace lyx {
73 namespace frontend {
74
75 namespace {
76
77 struct PngMap {
78         char const * key;
79         char const * value;
80 };
81
82
83 bool operator<(PngMap const & lhs, PngMap const & rhs)
84 {
85                 return strcmp(lhs.key, rhs.key) < 0;
86 }
87
88
89 class CompareKey {
90 public:
91         CompareKey(string const & name) : name_(name) {}
92         bool operator()(PngMap const & other) const { return other.key == name_; }
93 private:
94         string const name_;
95 };
96
97
98 PngMap sorted_png_map[] = {
99         { "Bumpeq", "bumpeq2" },
100         { "Cap", "cap2" },
101         { "Cup", "cup2" },
102         { "Delta", "delta2" },
103         { "Downarrow", "downarrow2" },
104         { "Gamma", "gamma2" },
105         { "Lambda", "lambda2" },
106         { "Leftarrow", "leftarrow2" },
107         { "Leftrightarrow", "leftrightarrow2" },
108         { "Longleftarrow", "longleftarrow2" },
109         { "Longleftrightarrow", "longleftrightarrow2" },
110         { "Longrightarrow", "longrightarrow2" },
111         { "Omega", "omega2" },
112         { "Phi", "phi2" },
113         { "Pi", "pi2" },
114         { "Psi", "psi2" },
115         { "Rightarrow", "rightarrow2" },
116         { "Sigma", "sigma2" },
117         { "Subset", "subset2" },
118         { "Supset", "supset2" },
119         { "Theta", "theta2" },
120         { "Uparrow", "uparrow2" },
121         { "Updownarrow", "updownarrow2" },
122         { "Upsilon", "upsilon2" },
123         { "Vdash", "vdash3" },
124         { "Xi", "xi2" },
125         { "nLeftarrow", "nleftarrow2" },
126         { "nLeftrightarrow", "nleftrightarrow2" },
127         { "nRightarrow", "nrightarrow2" },
128         { "nVDash", "nvdash3" },
129         { "nvDash", "nvdash2" },
130         { "textrm \\AA", "textrm_AA"},
131         { "textrm \\O", "textrm_O"},
132         { "vDash", "vdash2" }
133 };
134
135 size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);
136
137
138 string const find_png(string const & name)
139 {
140         PngMap const * const begin = sorted_png_map;
141         PngMap const * const end = begin + nr_sorted_png_map;
142         BOOST_ASSERT(sorted(begin, end));
143
144         PngMap const * const it = find_if(begin, end, CompareKey(name));
145
146         string png_name;
147         if (it != end)
148                 png_name = it->value;
149         else {
150                 png_name = subst(name, "_", "underscore");
151                 png_name = subst(png_name, ' ', '_');
152
153                 // This way we can have "math-delim { }" on the toolbar.
154                 png_name = subst(png_name, "(", "lparen");
155                 png_name = subst(png_name, ")", "rparen");
156                 png_name = subst(png_name, "[", "lbracket");
157                 png_name = subst(png_name, "]", "rbracket");
158                 png_name = subst(png_name, "{", "lbrace");
159                 png_name = subst(png_name, "}", "rbrace");
160                 png_name = subst(png_name, "|", "bars");
161                 png_name = subst(png_name, ",", "thinspace");
162                 png_name = subst(png_name, ":", "mediumspace");
163                 png_name = subst(png_name, ";", "thickspace");
164                 png_name = subst(png_name, "!", "negthinspace");
165         }
166
167         LYXERR(Debug::GUI, "find_png(" << name << ")\n"
168                 << "Looking for math PNG called \"" << png_name << '"');
169         return png_name;
170 }
171
172 } // namespace anon
173
174
175 /// return a icon for the given action
176 static QIcon getIcon(FuncRequest const & f, bool unknown)
177 {
178         initializeResources();
179         QPixmap pm;
180         string name1;
181         string name2;
182         string path;
183         string fullname;
184
185         switch (f.action) {
186         case LFUN_MATH_INSERT:
187                 if (!f.argument().empty()) {
188                         path = "math/";
189                         name1 = find_png(to_utf8(f.argument()).substr(1));
190                 }
191                 break;
192         case LFUN_MATH_DELIM:
193         case LFUN_MATH_BIGDELIM:
194                 path = "math/";
195                 name1 = find_png(to_utf8(f.argument()));
196                 break;
197         case LFUN_CALL:
198                 path = "commands/";
199                 name1 = to_utf8(f.argument());
200                 break;
201         default:
202                 name2 = lyxaction.getActionName(f.action);
203                 name1 = name2;
204
205                 if (!f.argument().empty())
206                         name1 = subst(name2 + ' ' + to_utf8(f.argument()), ' ', '_');
207         }
208
209         fullname = libFileSearch("images/" + path, name1, "png").absFilename();
210         if (pm.load(toqstr(fullname)))
211                 return pm;
212
213         fullname = libFileSearch("images/" + path, name2, "png").absFilename();
214         if (pm.load(toqstr(fullname)))
215                 return pm;
216
217         if (pm.load(":/images/" + toqstr(path + name1) + ".png"))
218                 return pm;
219
220         if (pm.load(":/images/" + toqstr(path + name2) + ".png"))
221                 return pm;
222
223         LYXERR(Debug::GUI, "Cannot find icon for command \""
224                            << lyxaction.getActionName(f.action)
225                            << '(' << to_utf8(f.argument()) << ")\"");
226         if (unknown)
227                 pm.load(":/images/unknown.png");
228
229         return pm;
230 }
231
232
233 /////////////////////////////////////////////////////////////////////
234 //
235 // GuiLayoutBox
236 //
237 /////////////////////////////////////////////////////////////////////
238
239 class GuiFilterProxyModel : public QSortFilterProxyModel
240 {
241 public:
242         ///
243         GuiFilterProxyModel(QObject * parent)
244         : QSortFilterProxyModel(parent) {}
245         
246         ///
247         QVariant data(const QModelIndex & index, int role) const
248         {
249                 GuiLayoutBox * p = static_cast<GuiLayoutBox *>(parent());
250                 QString const & f = p->filter();
251
252                 if (!f.isEmpty() && index.isValid() && role == Qt::DisplayRole) {
253                         // step through data item and put "(x)" for every matching character
254                         QString s = QSortFilterProxyModel::data(index, role).toString();
255                         QString r;
256                         int lastp = -1;
257                         p->filter();
258                         for (int i = 0; i < f.length(); ++i) {
259                                 int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
260                                 BOOST_ASSERT(p != -1);
261                                 if (lastp == p - 1 && lastp != -1) {
262                                         // remove ")" and append "x)"
263                                         r = r.left(r.length() - 1) + s[p] + ")";
264                                 } else {
265                                         // append "(x)"
266                                         r += s.mid(lastp + 1, p - lastp - 1);
267                                         r += "(" + s[p] + ")";
268                                 }
269                                 lastp = p;
270                         }
271                         r += s.mid(lastp + 1);
272                         return r;
273                 }
274                 
275                 return QSortFilterProxyModel::data(index, role);
276         }
277         
278         ///
279         void setCharFilter(QString const & f)
280         {
281                 setFilterRegExp(charFilterRegExp(f));
282                 reset();
283         }
284
285 private:
286         ///
287         QString charFilterRegExp(QString const & filter)
288         {
289                 QString re;
290                 for (int i = 0; i < filter.length(); ++i)
291                         re += ".*" + QRegExp::escape(filter[i]);
292                 return re;
293         }
294 };
295
296
297 GuiLayoutBox::GuiLayoutBox(GuiView & owner)
298         : owner_(owner)
299 {
300         setSizeAdjustPolicy(QComboBox::AdjustToContents);
301         setFocusPolicy(Qt::ClickFocus);
302         setMinimumWidth(sizeHint().width());
303         setMaxVisibleItems(100);
304
305         // set the layout model with two columns
306         // 1st: translated layout names
307         // 2nd: raw layout names
308         model_ = new QStandardItemModel(0, 2, this);
309         filterModel_ = new GuiFilterProxyModel(this);
310         filterModel_->setSourceModel(model_);
311         filterModel_->setDynamicSortFilter(true);
312         filterModel_->setFilterCaseSensitivity(Qt::CaseInsensitive);
313         setModel(filterModel_);
314
315         // for the filtering we have to intercept characters
316         view()->installEventFilter(this);
317         
318         QObject::connect(this, SIGNAL(activated(int)),
319                          this, SLOT(selected(int)));
320         owner_.setLayoutDialog(this);
321         updateContents(true);
322 }
323
324
325 void GuiLayoutBox::setFilter(QString const & s)
326 {
327         // remember old selection
328         int sel = currentIndex();
329         if (sel != -1)
330                 lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
331
332         filter_ = s;
333         filterModel_->setCharFilter(s);
334         
335         // restore old selection
336         if (lastSel_ != -1) {
337                 QModelIndex i = filterModel_->mapFromSource(model_->index(lastSel_, 0));
338                 if (i.isValid())
339                         setCurrentIndex(i.row());
340         }
341 }
342
343
344 void GuiLayoutBox::resetFilter()
345 {
346         setFilter(QString());
347 }
348
349
350 bool GuiLayoutBox::eventFilter(QObject *o, QEvent *e)
351 {
352         if (e->type() == QEvent::KeyPress) {
353                 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
354                 bool modified = (ke->modifiers() == Qt::ControlModifier)
355                         || (ke->modifiers() == Qt::AltModifier)
356                         || (ke->modifiers() == Qt::MetaModifier);
357                 
358                 switch (ke->key()) {
359                 case Qt::Key_Escape:
360                         if (!modified && !filter_.isEmpty()) {
361                                 resetFilter();
362                                 return true;
363                         }
364                         break;
365                 case Qt::Key_Backspace:
366                         if (!modified) {
367                                 // cut off one character
368                                 setFilter(filter_.left(filter_.length() - 1));
369                         }
370                         break;
371                 default:
372                         if (modified || ke->text().isEmpty())
373                                 break;
374                         // find chars for the filter string
375                         QString s;
376                         for (int i = 0; i < ke->text().length(); ++i) {
377                                 QChar c = ke->text()[i];
378                                 if (c.isLetterOrNumber()
379                                     || c.isSymbol()
380                                     || c.isPunct()
381                                     || c.category() == QChar::Separator_Space) {
382                                         s += c;
383                                 }
384                         }
385                         if (!s.isEmpty()) {
386                                 // append new chars to the filter string
387                                 setFilter(filter_ + s);
388                                 return true;
389                         }
390                         break;
391                 }
392         }
393         return QComboBox::eventFilter(o, e);
394 }
395
396
397 void GuiLayoutBox::set(docstring const & layout)
398 {
399         resetFilter();
400         
401         if (!text_class_)
402                 return;
403
404         QString const & name = toqstr((*text_class_)[layout]->name());
405         if (name == currentText())
406                 return;
407
408         QList<QStandardItem *> r = model_->findItems(name, Qt::MatchExactly, 1);
409         if (r.empty()) {
410                 lyxerr << "Trying to select non existent layout type "
411                         << fromqstr(name) << endl;
412                 return;
413         }
414
415         setCurrentIndex(filterModel_->mapFromSource(r.first()->index()).row());
416 }
417
418
419 void GuiLayoutBox::addItemSort(docstring const & item, bool sorted)
420 {
421         QString qitem = toqstr(item);
422         QList<QStandardItem *> row;
423         row.append(new QStandardItem(toqstr(translateIfPossible(item))));
424         row.append(new QStandardItem(qitem));
425
426         // the simple unsorted case
427         int const end = model_->rowCount();
428         if (!sorted || end < 2 || qitem[0].category() != QChar::Letter_Uppercase) {
429                 model_->appendRow(row);
430                 return;
431         }
432
433         // find row to insert the item
434         int i = 1; // skip the Standard layout
435         QString is = model_->item(i, 1)->text();
436         while (is.compare(qitem) < 0) {
437                 // e.g. --Separator--
438                 if (is[0].category() != QChar::Letter_Uppercase)
439                         break;
440                 ++i;
441                 if (i == end)
442                         break;
443                 QString is = model_->item(i, 1)->text();
444         }
445
446         model_->insertRow(i, row);
447 }
448
449
450 void GuiLayoutBox::updateContents(bool reset)
451 {
452         resetFilter();
453         
454         Buffer const * buffer = owner_.buffer();
455         if (!buffer) {
456                 model_->clear();
457                 setEnabled(false);
458                 text_class_ = 0;
459                 inset_ = 0;
460                 return;
461         }
462
463         // we'll only update the layout list if the text class has changed
464         // or we've moved from one inset to another
465         DocumentClass const * text_class = &buffer->params().documentClass();
466         Inset const * inset = 
467         owner_.view()->cursor().innerParagraph().inInset();
468         if (!reset && text_class_ == text_class && inset_ == inset) {
469                 set(owner_.view()->cursor().innerParagraph().layout()->name());
470                 return;
471         }
472
473         inset_ = inset;
474         text_class_ = text_class;
475
476         model_->clear();
477         for (size_t i = 0; i != text_class_->layoutCount(); ++i) {
478                 Layout const & lt = *text_class_->layout(i);
479                 docstring const & name = lt.name();
480                 // if this inset requires the empty layout, we skip the default
481                 // layout
482                 if (name == text_class_->defaultLayoutName() && inset &&
483                     (inset->forceEmptyLayout() || inset->useEmptyLayout()))
484                         continue;
485                 // if it doesn't require the empty layout, we skip it
486                 if (name == text_class_->emptyLayoutName() && inset &&
487                     !inset->forceEmptyLayout() && !inset->useEmptyLayout())
488                         continue;
489                 addItemSort(name, lyxrc.sort_layouts);
490         }
491
492         set(owner_.view()->cursor().innerParagraph().layout()->name());
493
494         // needed to recalculate size hint
495         hide();
496         setMinimumWidth(sizeHint().width());
497         setEnabled(!buffer->isReadonly());
498         show();
499 }
500
501
502 void GuiLayoutBox::selected(int index)
503 {
504         // get selection
505         QModelIndex mindex = filterModel_->mapToSource(filterModel_->index(index, 1));
506         docstring const name = qstring_to_ucs4(model_->itemFromIndex(mindex)->text());
507
508         owner_.setFocus();
509
510         if (!text_class_) {
511                 updateContents(false);
512                 resetFilter();
513                 return;
514         }
515
516         // find corresponding text class
517         for (size_t i = 0; i != text_class_->layoutCount(); ++i) {
518                 docstring const & itname = text_class_->layout(i)->name();
519                 if (itname == name) {
520                         FuncRequest const func(LFUN_LAYOUT, itname,
521                                                FuncRequest::TOOLBAR);
522                         theLyXFunc().setLyXView(&owner_);
523                         lyx::dispatch(func);
524                         updateContents(false);
525                         resetFilter();
526                         return;
527                 }
528         }
529         lyxerr << "ERROR (layoutSelected): layout not found!" << endl;
530 }
531
532
533
534 /////////////////////////////////////////////////////////////////////
535 //
536 // GuiToolbar
537 //
538 /////////////////////////////////////////////////////////////////////
539
540
541 GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
542         : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner),
543           layout_(0), command_buffer_(0)
544 {
545         // give visual separation between adjacent toolbars
546         addSeparator();
547
548         // TODO: save toolbar position
549         setMovable(true);
550
551         ToolbarInfo::item_iterator it = tbinfo.items.begin();
552         ToolbarInfo::item_iterator end = tbinfo.items.end();
553         for (; it != end; ++it)
554                 add(*it);
555 }
556
557
558 Action * GuiToolbar::addItem(ToolbarItem const & item)
559 {
560         Action * act = new Action(owner_,
561                 getIcon(item.func_, false),
562           toqstr(item.label_), item.func_, toqstr(item.label_));
563         actions_.append(act);
564         return act;
565 }
566
567 namespace {
568
569 class PaletteButton : public QToolButton
570 {
571 private:
572         GuiToolbar * bar_;
573         ToolbarItem const & tbitem_;
574         bool initialized_;
575 public:
576         PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
577                 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
578         {
579                 QString const label = qt_(to_ascii(tbitem_.label_));
580                 setToolTip(label);
581                 setStatusTip(label);
582                 setText(label);
583                 connect(bar_, SIGNAL(iconSizeChanged(QSize)),
584                         this, SLOT(setIconSize(QSize)));
585                 setCheckable(true);
586                 ToolbarInfo const * tbinfo = 
587                         toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
588                 if (tbinfo)
589                         // use the icon of first action for the toolbar button
590                         setIcon(getIcon(tbinfo->items.begin()->func_, true));
591         }
592
593         void mousePressEvent(QMouseEvent * e)
594         {
595                 if (initialized_) {
596                         QToolButton::mousePressEvent(e);
597                         return;
598                 }
599
600                 initialized_ = true;
601
602                 ToolbarInfo const * tbinfo = 
603                         toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
604                 if (!tbinfo) {
605                         lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
606                         return;
607                 }
608                 IconPalette * panel = new IconPalette(this);
609                 QString const label = qt_(to_ascii(tbitem_.label_));
610                 panel->setWindowTitle(label);
611                 connect(this, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
612                 connect(panel, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
613                 ToolbarInfo::item_iterator it = tbinfo->items.begin();
614                 ToolbarInfo::item_iterator const end = tbinfo->items.end();
615                 for (; it != end; ++it)
616                         if (!getStatus(it->func_).unknown())
617                                 panel->addButton(bar_->addItem(*it));
618
619                 QToolButton::mousePressEvent(e);
620         }
621 };
622
623 class MenuButton : public QToolButton
624 {
625 private:
626         GuiToolbar * bar_;
627         ToolbarItem const & tbitem_;
628         bool initialized_;
629 public:
630         MenuButton(GuiToolbar * bar, ToolbarItem const & item)
631                 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
632         {
633                 setPopupMode(QToolButton::InstantPopup);
634                 QString const label = qt_(to_ascii(tbitem_.label_));
635                 setToolTip(label);
636                 setStatusTip(label);
637                 setText(label);
638                 setIcon(QPixmap(":images/math/" + toqstr(tbitem_.name_) + ".png"));
639                 connect(bar, SIGNAL(iconSizeChanged(QSize)),
640                         this, SLOT(setIconSize(QSize)));
641         }
642
643         void mousePressEvent(QMouseEvent * e)
644         {
645                 if (initialized_) {
646                         QToolButton::mousePressEvent(e);
647                         return;
648                 }
649
650                 initialized_ = true;
651
652                 QString const label = qt_(to_ascii(tbitem_.label_));
653                 ButtonMenu * m = new ButtonMenu(label, this);
654                 m->setWindowTitle(label);
655                 m->setTearOffEnabled(true);
656                 connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
657                 ToolbarInfo const * tbinfo = 
658                         toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
659                 if (!tbinfo) {
660                         lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
661                         return;
662                 }
663                 ToolbarInfo::item_iterator it = tbinfo->items.begin();
664                 ToolbarInfo::item_iterator const end = tbinfo->items.end();
665                 for (; it != end; ++it)
666                         if (!getStatus(it->func_).unknown())
667                                 m->add(bar_->addItem(*it));
668                 setMenu(m);
669
670                 QToolButton::mousePressEvent(e);
671         }
672 };
673
674 }
675
676
677 void GuiToolbar::add(ToolbarItem const & item)
678 {
679         switch (item.type_) {
680         case ToolbarItem::SEPARATOR:
681                 addSeparator();
682                 break;
683         case ToolbarItem::LAYOUTS:
684                 layout_ = new GuiLayoutBox(owner_);
685                 addWidget(layout_);
686                 break;
687         case ToolbarItem::MINIBUFFER:
688                 command_buffer_ = new GuiCommandBuffer(&owner_);
689                 addWidget(command_buffer_);
690                 /// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
691                 //setHorizontalStretchable(true);
692                 break;
693         case ToolbarItem::TABLEINSERT: {
694                 QToolButton * tb = new QToolButton;
695                 tb->setCheckable(true);
696                 tb->setIcon(getIcon(FuncRequest(LFUN_TABULAR_INSERT), true));
697                 QString const label = qt_(to_ascii(item.label_));
698                 tb->setToolTip(label);
699                 tb->setStatusTip(label);
700                 tb->setText(label);
701                 InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
702                 connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
703                 connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
704                 connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
705                 addWidget(tb);
706                 break;
707                 }
708         case ToolbarItem::ICONPALETTE:
709                 addWidget(new PaletteButton(this, item));
710                 break;
711
712         case ToolbarItem::POPUPMENU: {
713                 addWidget(new MenuButton(this, item));
714                 break;
715                 }
716         case ToolbarItem::COMMAND: {
717                 if (!getStatus(item.func_).unknown())
718                         addAction(addItem(item));
719                 break;
720                 }
721         default:
722                 break;
723         }
724 }
725
726
727 void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
728 {
729         // if tbinfo.state == auto *do not* set on/off
730         if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
731                 if (GuiToolbar::isVisible())
732                         tbinfo.state = ToolbarSection::ToolbarInfo::ON;
733                 else
734                         tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
735         }
736         //
737         // no need to save it here.
738         Qt::ToolBarArea loc = owner_.toolBarArea(this);
739
740         if (loc == Qt::TopToolBarArea)
741                 tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
742         else if (loc == Qt::BottomToolBarArea)
743                 tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
744         else if (loc == Qt::RightToolBarArea)
745                 tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
746         else if (loc == Qt::LeftToolBarArea)
747                 tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
748         else
749                 tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
750
751         // save toolbar position. They are not used to restore toolbar position
752         // now because move(x,y) does not work for toolbar.
753         tbinfo.posx = pos().x();
754         tbinfo.posy = pos().y();
755 }
756
757
758 void GuiToolbar::updateContents()
759 {
760         // update visible toolbars only
761         if (!isVisible())
762                 return;
763         // This is a speed bottleneck because this is called on every keypress
764         // and update calls getStatus, which copies the cursor at least two times
765         for (int i = 0; i < actions_.size(); ++i)
766                 actions_[i]->update();
767
768         if (layout_)
769                 layout_->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
770
771         // emit signal
772         updated();
773 }
774
775
776 } // namespace frontend
777 } // namespace lyx
778
779 #include "GuiToolbar_moc.cpp"