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