]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToolbar.cpp
* fix sorting of layout names
[lyx.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                 return QComboBox::eventFilter(o, e);
354
355         QKeyEvent * ke = static_cast<QKeyEvent*>(e);
356         bool modified = (ke->modifiers() == Qt::ControlModifier)
357                 || (ke->modifiers() == Qt::AltModifier)
358                 || (ke->modifiers() == Qt::MetaModifier);
359         
360         switch (ke->key()) {
361         case Qt::Key_Escape:
362                 if (!modified && !filter_.isEmpty()) {
363                         resetFilter();
364                         return true;
365                 }
366                 break;
367         case Qt::Key_Backspace:
368                 if (!modified) {
369                         // cut off one character
370                         setFilter(filter_.left(filter_.length() - 1));
371                 }
372                 break;
373         default:
374                 if (modified || ke->text().isEmpty())
375                         break;
376                 // find chars for the filter string
377                 QString s;
378                 for (int i = 0; i < ke->text().length(); ++i) {
379                         QChar c = ke->text()[i];
380                         if (c.isLetterOrNumber()
381                             || c.isSymbol()
382                             || c.isPunct()
383                             || c.category() == QChar::Separator_Space) {
384                                 s += c;
385                         }
386                 }
387                 if (!s.isEmpty()) {
388                         // append new chars to the filter string
389                         setFilter(filter_ + s);
390                         return true;
391                 }
392                 break;
393         }
394
395         return QComboBox::eventFilter(o, e);
396 }
397
398
399 void GuiLayoutBox::set(docstring const & layout)
400 {
401         resetFilter();
402         
403         if (!text_class_)
404                 return;
405
406         QString const & name = toqstr((*text_class_)[layout]->name());
407         if (name == currentText())
408                 return;
409
410         QList<QStandardItem *> r = model_->findItems(name, Qt::MatchExactly, 1);
411         if (r.empty()) {
412                 lyxerr << "Trying to select non existent layout type "
413                         << fromqstr(name) << endl;
414                 return;
415         }
416
417         setCurrentIndex(filterModel_->mapFromSource(r.first()->index()).row());
418 }
419
420
421 void GuiLayoutBox::addItemSort(docstring const & item, bool sorted)
422 {
423         QString qitem = toqstr(item);
424         QString titem = toqstr(translateIfPossible(item));
425
426         QList<QStandardItem *> row;
427         row.append(new QStandardItem(titem));
428         row.append(new QStandardItem(qitem));
429
430         // the simple unsorted case
431         int const end = model_->rowCount();
432         if (!sorted || end < 2 || qitem[0].category() != QChar::Letter_Uppercase) {
433                 model_->appendRow(row);
434                 return;
435         }
436
437         // find row to insert the item
438         int i = 1; // skip the Standard layout
439         QString is = model_->item(i, 1)->text();
440         while (is.compare(titem) < 0) {
441                 // e.g. --Separator--
442                 if (is[0].category() != QChar::Letter_Uppercase)
443                         break;
444                 ++i;
445                 if (i == end)
446                         break;
447                 is = model_->item(i, 1)->text();
448         }
449
450         model_->insertRow(i, row);
451 }
452
453
454 void GuiLayoutBox::updateContents(bool reset)
455 {
456         resetFilter();
457         
458         Buffer const * buffer = owner_.buffer();
459         if (!buffer) {
460                 model_->clear();
461                 setEnabled(false);
462                 text_class_ = 0;
463                 inset_ = 0;
464                 return;
465         }
466
467         // we'll only update the layout list if the text class has changed
468         // or we've moved from one inset to another
469         DocumentClass const * text_class = &buffer->params().documentClass();
470         Inset const * inset = 
471         owner_.view()->cursor().innerParagraph().inInset();
472         if (!reset && text_class_ == text_class && inset_ == inset) {
473                 set(owner_.view()->cursor().innerParagraph().layout()->name());
474                 return;
475         }
476
477         inset_ = inset;
478         text_class_ = text_class;
479
480         model_->clear();
481         for (size_t i = 0; i != text_class_->layoutCount(); ++i) {
482                 Layout const & lt = *text_class_->layout(i);
483                 docstring const & name = lt.name();
484                 // if this inset requires the empty layout, we skip the default
485                 // layout
486                 if (name == text_class_->defaultLayoutName() && inset &&
487                     (inset->forceEmptyLayout() || inset->useEmptyLayout()))
488                         continue;
489                 // if it doesn't require the empty layout, we skip it
490                 if (name == text_class_->emptyLayoutName() && inset &&
491                     !inset->forceEmptyLayout() && !inset->useEmptyLayout())
492                         continue;
493                 addItemSort(name, lyxrc.sort_layouts);
494         }
495
496         set(owner_.view()->cursor().innerParagraph().layout()->name());
497
498         // needed to recalculate size hint
499         hide();
500         setMinimumWidth(sizeHint().width());
501         setEnabled(!buffer->isReadonly());
502         show();
503 }
504
505
506 void GuiLayoutBox::selected(int index)
507 {
508         // get selection
509         QModelIndex mindex = filterModel_->mapToSource(filterModel_->index(index, 1));
510         docstring const name = qstring_to_ucs4(model_->itemFromIndex(mindex)->text());
511
512         owner_.setFocus();
513
514         if (!text_class_) {
515                 updateContents(false);
516                 resetFilter();
517                 return;
518         }
519
520         // find corresponding text class
521         for (size_t i = 0; i != text_class_->layoutCount(); ++i) {
522                 docstring const & itname = text_class_->layout(i)->name();
523                 if (itname == name) {
524                         FuncRequest const func(LFUN_LAYOUT, itname,
525                                                FuncRequest::TOOLBAR);
526                         theLyXFunc().setLyXView(&owner_);
527                         lyx::dispatch(func);
528                         updateContents(false);
529                         resetFilter();
530                         return;
531                 }
532         }
533         lyxerr << "ERROR (layoutSelected): layout not found!" << endl;
534 }
535
536
537
538 /////////////////////////////////////////////////////////////////////
539 //
540 // GuiToolbar
541 //
542 /////////////////////////////////////////////////////////////////////
543
544
545 GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
546         : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner),
547           layout_(0), command_buffer_(0)
548 {
549         // give visual separation between adjacent toolbars
550         addSeparator();
551
552         // TODO: save toolbar position
553         setMovable(true);
554
555         ToolbarInfo::item_iterator it = tbinfo.items.begin();
556         ToolbarInfo::item_iterator end = tbinfo.items.end();
557         for (; it != end; ++it)
558                 add(*it);
559 }
560
561
562 Action * GuiToolbar::addItem(ToolbarItem const & item)
563 {
564         Action * act = new Action(owner_,
565                 getIcon(item.func_, false),
566           toqstr(item.label_), item.func_, toqstr(item.label_));
567         actions_.append(act);
568         return act;
569 }
570
571 namespace {
572
573 class PaletteButton : public QToolButton
574 {
575 private:
576         GuiToolbar * bar_;
577         ToolbarItem const & tbitem_;
578         bool initialized_;
579 public:
580         PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
581                 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
582         {
583                 QString const label = qt_(to_ascii(tbitem_.label_));
584                 setToolTip(label);
585                 setStatusTip(label);
586                 setText(label);
587                 connect(bar_, SIGNAL(iconSizeChanged(QSize)),
588                         this, SLOT(setIconSize(QSize)));
589                 setCheckable(true);
590                 ToolbarInfo const * tbinfo = 
591                         toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
592                 if (tbinfo)
593                         // use the icon of first action for the toolbar button
594                         setIcon(getIcon(tbinfo->items.begin()->func_, true));
595         }
596
597         void mousePressEvent(QMouseEvent * e)
598         {
599                 if (initialized_) {
600                         QToolButton::mousePressEvent(e);
601                         return;
602                 }
603
604                 initialized_ = true;
605
606                 ToolbarInfo const * tbinfo = 
607                         toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
608                 if (!tbinfo) {
609                         lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
610                         return;
611                 }
612                 IconPalette * panel = new IconPalette(this);
613                 QString const label = qt_(to_ascii(tbitem_.label_));
614                 panel->setWindowTitle(label);
615                 connect(this, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
616                 connect(panel, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
617                 ToolbarInfo::item_iterator it = tbinfo->items.begin();
618                 ToolbarInfo::item_iterator const end = tbinfo->items.end();
619                 for (; it != end; ++it)
620                         if (!getStatus(it->func_).unknown())
621                                 panel->addButton(bar_->addItem(*it));
622
623                 QToolButton::mousePressEvent(e);
624         }
625 };
626
627 class MenuButton : public QToolButton
628 {
629 private:
630         GuiToolbar * bar_;
631         ToolbarItem const & tbitem_;
632         bool initialized_;
633 public:
634         MenuButton(GuiToolbar * bar, ToolbarItem const & item)
635                 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
636         {
637                 setPopupMode(QToolButton::InstantPopup);
638                 QString const label = qt_(to_ascii(tbitem_.label_));
639                 setToolTip(label);
640                 setStatusTip(label);
641                 setText(label);
642                 setIcon(QPixmap(":images/math/" + toqstr(tbitem_.name_) + ".png"));
643                 connect(bar, SIGNAL(iconSizeChanged(QSize)),
644                         this, SLOT(setIconSize(QSize)));
645         }
646
647         void mousePressEvent(QMouseEvent * e)
648         {
649                 if (initialized_) {
650                         QToolButton::mousePressEvent(e);
651                         return;
652                 }
653
654                 initialized_ = true;
655
656                 QString const label = qt_(to_ascii(tbitem_.label_));
657                 ButtonMenu * m = new ButtonMenu(label, this);
658                 m->setWindowTitle(label);
659                 m->setTearOffEnabled(true);
660                 connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
661                 ToolbarInfo const * tbinfo = 
662                         toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
663                 if (!tbinfo) {
664                         lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
665                         return;
666                 }
667                 ToolbarInfo::item_iterator it = tbinfo->items.begin();
668                 ToolbarInfo::item_iterator const end = tbinfo->items.end();
669                 for (; it != end; ++it)
670                         if (!getStatus(it->func_).unknown())
671                                 m->add(bar_->addItem(*it));
672                 setMenu(m);
673
674                 QToolButton::mousePressEvent(e);
675         }
676 };
677
678 }
679
680
681 void GuiToolbar::add(ToolbarItem const & item)
682 {
683         switch (item.type_) {
684         case ToolbarItem::SEPARATOR:
685                 addSeparator();
686                 break;
687         case ToolbarItem::LAYOUTS:
688                 layout_ = new GuiLayoutBox(owner_);
689                 addWidget(layout_);
690                 break;
691         case ToolbarItem::MINIBUFFER:
692                 command_buffer_ = new GuiCommandBuffer(&owner_);
693                 addWidget(command_buffer_);
694                 /// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
695                 //setHorizontalStretchable(true);
696                 break;
697         case ToolbarItem::TABLEINSERT: {
698                 QToolButton * tb = new QToolButton;
699                 tb->setCheckable(true);
700                 tb->setIcon(getIcon(FuncRequest(LFUN_TABULAR_INSERT), true));
701                 QString const label = qt_(to_ascii(item.label_));
702                 tb->setToolTip(label);
703                 tb->setStatusTip(label);
704                 tb->setText(label);
705                 InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
706                 connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
707                 connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
708                 connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
709                 addWidget(tb);
710                 break;
711                 }
712         case ToolbarItem::ICONPALETTE:
713                 addWidget(new PaletteButton(this, item));
714                 break;
715
716         case ToolbarItem::POPUPMENU: {
717                 addWidget(new MenuButton(this, item));
718                 break;
719                 }
720         case ToolbarItem::COMMAND: {
721                 if (!getStatus(item.func_).unknown())
722                         addAction(addItem(item));
723                 break;
724                 }
725         default:
726                 break;
727         }
728 }
729
730
731 void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
732 {
733         // if tbinfo.state == auto *do not* set on/off
734         if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
735                 if (GuiToolbar::isVisible())
736                         tbinfo.state = ToolbarSection::ToolbarInfo::ON;
737                 else
738                         tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
739         }
740         //
741         // no need to save it here.
742         Qt::ToolBarArea loc = owner_.toolBarArea(this);
743
744         if (loc == Qt::TopToolBarArea)
745                 tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
746         else if (loc == Qt::BottomToolBarArea)
747                 tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
748         else if (loc == Qt::RightToolBarArea)
749                 tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
750         else if (loc == Qt::LeftToolBarArea)
751                 tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
752         else
753                 tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
754
755         // save toolbar position. They are not used to restore toolbar position
756         // now because move(x,y) does not work for toolbar.
757         tbinfo.posx = pos().x();
758         tbinfo.posy = pos().y();
759 }
760
761
762 void GuiToolbar::updateContents()
763 {
764         // update visible toolbars only
765         if (!isVisible())
766                 return;
767         // This is a speed bottleneck because this is called on every keypress
768         // and update calls getStatus, which copies the cursor at least two times
769         for (int i = 0; i < actions_.size(); ++i)
770                 actions_[i]->update();
771
772         if (layout_)
773                 layout_->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
774
775         // emit signal
776         updated();
777 }
778
779
780 } // namespace frontend
781 } // namespace lyx
782
783 #include "GuiToolbar_moc.cpp"