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.
6 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
10 * \author Stefan Schimanski
11 * \author Abdelrazak Younes
13 * Full author contact details are available in file CREDITS.
19 #include "GuiCommandBuffer.h"
20 #include "GuiToolbar.h"
21 #include "LyXAction.h"
23 #include "qt_helpers.h"
24 #include "InsertTableWidget.h"
27 #include "BufferParams.h"
28 #include "BufferView.h"
30 #include "FuncRequest.h"
31 #include "FuncStatus.h"
32 #include "IconPalette.h"
36 #include "Paragraph.h"
37 #include "TextClass.h"
38 #include "ToolbarBackend.h"
40 #include "support/debug.h"
41 #include "support/filetools.h"
42 #include "support/gettext.h"
43 #include "support/lstrings.h"
44 #include "support/lyxalgo.h" // sorted
46 #include <QAbstractItemDelegate>
47 #include <QAbstractTextDocumentLayout>
48 #include <QApplication>
50 #include <QFontMetrics>
51 #include <QHeaderView>
52 #include <QItemDelegate>
58 #include <QSortFilterProxyModel>
59 #include <QStandardItem>
60 #include <QStandardItemModel>
61 #include <QTextDocument>
64 #include <QToolButton>
67 #include <boost/assert.hpp>
73 using namespace lyx::support;
75 static void initializeResources()
77 static bool initialized = false;
79 Q_INIT_RESOURCE(Resources);
96 bool operator<(PngMap const & lhs, PngMap const & rhs)
98 return lhs.key < rhs.key;
104 CompareKey(QString const & name) : name_(name) {}
105 bool operator()(PngMap const & other) const { return other.key == name_; }
111 PngMap sorted_png_map[] = {
112 { "Bumpeq", "bumpeq2" },
115 { "Delta", "delta2" },
116 { "Downarrow", "downarrow2" },
117 { "Gamma", "gamma2" },
118 { "Lambda", "lambda2" },
119 { "Leftarrow", "leftarrow2" },
120 { "Leftrightarrow", "leftrightarrow2" },
121 { "Longleftarrow", "longleftarrow2" },
122 { "Longleftrightarrow", "longleftrightarrow2" },
123 { "Longrightarrow", "longrightarrow2" },
124 { "Omega", "omega2" },
128 { "Rightarrow", "rightarrow2" },
129 { "Sigma", "sigma2" },
130 { "Subset", "subset2" },
131 { "Supset", "supset2" },
132 { "Theta", "theta2" },
133 { "Uparrow", "uparrow2" },
134 { "Updownarrow", "updownarrow2" },
135 { "Upsilon", "upsilon2" },
136 { "Vdash", "vdash3" },
138 { "nLeftarrow", "nleftarrow2" },
139 { "nLeftrightarrow", "nleftrightarrow2" },
140 { "nRightarrow", "nrightarrow2" },
141 { "nVDash", "nvdash3" },
142 { "nvDash", "nvdash2" },
143 { "textrm \\AA", "textrm_AA"},
144 { "textrm \\O", "textrm_O"},
145 { "vDash", "vdash2" }
148 size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);
151 QString findPng(QString const & name)
153 PngMap const * const begin = sorted_png_map;
154 PngMap const * const end = begin + nr_sorted_png_map;
155 BOOST_ASSERT(sorted(begin, end));
157 PngMap const * const it = find_if(begin, end, CompareKey(name));
161 png_name = it->value;
164 png_name.replace('_', "underscore");
165 png_name.replace(' ', '_');
167 // This way we can have "math-delim { }" on the toolbar.
168 png_name.replace('(', "lparen");
169 png_name.replace(')', "rparen");
170 png_name.replace('[', "lbracket");
171 png_name.replace(']', "rbracket");
172 png_name.replace('{', "lbrace");
173 png_name.replace('}', "rbrace");
174 png_name.replace('|', "bars");
175 png_name.replace(',', "thinspace");
176 png_name.replace(':', "mediumspace");
177 png_name.replace(';', "thickspace");
178 png_name.replace('!', "negthinspace");
181 LYXERR(Debug::GUI, "findPng(" << fromqstr(name) << ")\n"
182 << "Looking for math PNG called \"" << fromqstr(png_name) << '"');
189 /// return a icon for the given action
190 static QIcon getIcon(FuncRequest const & f, bool unknown)
192 initializeResources();
198 case LFUN_MATH_INSERT:
199 if (!f.argument().empty()) {
201 name1 = findPng(toqstr(f.argument()).mid(1));
204 case LFUN_MATH_DELIM:
205 case LFUN_MATH_BIGDELIM:
207 name1 = findPng(toqstr(f.argument()));
211 name1 = toqstr(f.argument());
214 name2 = toqstr(lyxaction.getActionName(f.action));
217 if (!f.argument().empty()) {
218 name1 = name2 + ' ' + toqstr(f.argument());
219 name1.replace(' ', '_');
223 string fullname = libFileSearch("images/" + path, name1, "png").absFilename();
224 if (pm.load(toqstr(fullname)))
227 fullname = libFileSearch("images/" + path, name2, "png").absFilename();
228 if (pm.load(toqstr(fullname)))
231 if (pm.load(":/images/" + path + name1 + ".png"))
234 if (pm.load(":/images/" + path + name2 + ".png"))
237 LYXERR(Debug::GUI, "Cannot find icon for command \""
238 << lyxaction.getActionName(f.action)
239 << '(' << to_utf8(f.argument()) << ")\"");
241 pm.load(":/images/unknown.png");
247 /////////////////////////////////////////////////////////////////////
251 /////////////////////////////////////////////////////////////////////
253 class LayoutItemDelegate : public QItemDelegate {
256 explicit LayoutItemDelegate(QObject * parent = 0)
257 : QItemDelegate(parent)
261 void paint(QPainter * painter, QStyleOptionViewItem const & option,
262 QModelIndex const & index) const
264 QStyleOptionViewItem opt = option;
266 // default background
267 painter->fillRect(opt.rect, opt.palette.color(QPalette::Base));
270 if (lyxrc.group_layouts) {
271 QSortFilterProxyModel const * model
272 = static_cast<QSortFilterProxyModel const *>(index.model());
274 QString stdCat = category(*model->sourceModel(), 0);
275 QString cat = category(*index.model(), index.row());
277 // not the standard layout and not the same as in the previous line?
279 && (index.row() == 0 || cat != category(*index.model(), index.row() - 1))) {
282 // draw unselected background
283 QStyle::State state = opt.state;
284 opt.state = opt.state & ~QStyle::State_Selected;
285 drawBackground(painter, opt, index);
288 // draw category header
289 drawCategoryHeader(painter, opt,
290 category(*index.model(), index.row()));
292 // move rect down below header
293 opt.rect.setTop(opt.rect.top() + headerHeight(opt));
299 QItemDelegate::paint(painter, opt, index);
303 void drawDisplay(QPainter * painter, QStyleOptionViewItem const & opt,
304 const QRect & /*rect*/, const QString & text ) const
306 QString utext = underlineFilter(text);
308 // Draw the rich text.
310 QColor col = opt.palette.text().color();
311 if (opt.state & QStyle::State_Selected)
312 col = opt.palette.highlightedText().color();
313 QAbstractTextDocumentLayout::PaintContext context;
314 context.palette.setColor(QPalette::Text, col);
317 doc.setDefaultFont(opt.font);
320 QTextFrameFormat fmt = doc.rootFrame()->frameFormat();
322 doc.rootFrame()->setFrameFormat(fmt);
324 painter->translate(opt.rect.x() + 5,
325 opt.rect.y() + (opt.rect.height() - opt.fontMetrics.height()) / 2);
326 doc.documentLayout()->draw(painter, context);
331 QSize sizeHint(QStyleOptionViewItem const & opt,
332 QModelIndex const & index) const
334 GuiLayoutBox * combo = static_cast<GuiLayoutBox *>(parent());
335 QSortFilterProxyModel const * model
336 = static_cast<QSortFilterProxyModel const *>(index.model());
337 QSize size = QItemDelegate::sizeHint(opt, index);
339 /// QComboBox uses the first row height to estimate the
340 /// complete popup height during QComboBox::showPopup().
341 /// To avoid scrolling we have to sneak in space for the headers.
342 /// So we tweak this value accordingly. It's not nice, but the
343 /// only possible way it seems.
344 if (lyxrc.group_layouts && index.row() == 0 && combo->inShowPopup_) {
345 int itemHeight = size.height();
347 // we have to show \c cats many headers:
348 unsigned cats = combo->visibleCategories_;
350 // and we have \c n items to distribute the needed space over
351 unsigned n = combo->model()->rowCount();
353 // so the needed average height (rounded upwards) is:
354 size.setHeight((headerHeight(opt) * cats + itemHeight * n + n - 1) / n);
358 // Add space for the category headers here?
359 // Not for the standard layout though.
360 QString stdCat = category(*model->sourceModel(), 0);
361 QString cat = category(*index.model(), index.row());
362 if (lyxrc.group_layouts && stdCat != cat
363 && (index.row() == 0 || cat != category(*index.model(), index.row() - 1))) {
364 size.setHeight(size.height() + headerHeight(opt));
372 QString category(QAbstractItemModel const & model, int row) const
374 return model.data(model.index(row, 2), Qt::DisplayRole).toString();
378 int headerHeight(QStyleOptionViewItem const & opt) const
380 return opt.fontMetrics.height() * 8 / 10;
383 void drawCategoryHeader(QPainter * painter, QStyleOptionViewItem const & opt,
384 QString const & category) const
386 // slightly blended color
387 QColor lcol = opt.palette.text().color();
389 painter->setPen(lcol);
391 // set 80% scaled, bold font
392 QFont font = opt.font;
394 font.setWeight(QFont::Black);
395 font.setPointSize(opt.font.pointSize() * 8 / 10);
396 painter->setFont(font);
398 // draw the centered text
399 QFontMetrics fm(font);
400 int w = fm.width(category);
401 int x = opt.rect.x() + (opt.rect.width() - w) / 2;
402 int y = opt.rect.y() + fm.ascent();
405 painter->drawText(x, y, category);
407 // the vertical position of the line: middle of lower case chars
408 int ymid = y - 1 - fm.xHeight() / 2; // -1 for the baseline
410 // draw the horizontal line
411 if (!category.isEmpty()) {
412 painter->drawLine(opt.rect.x(), ymid, left - 1, ymid);
413 painter->drawLine(right + 1, ymid, opt.rect.right(), ymid);
415 painter->drawLine(opt.rect.x(), ymid, opt.rect.right(), ymid);
420 QString underlineFilter(QString const & s) const
423 GuiLayoutBox * p = static_cast<GuiLayoutBox *>(parent());
424 QString const & f = p->filter();
428 // step through data item and put "(x)" for every matching character
432 for (int i = 0; i < f.length(); ++i) {
433 int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
434 BOOST_ASSERT(p != -1);
435 if (lastp == p - 1 && lastp != -1) {
436 // remove ")" and append "x)"
437 r = r.left(r.length() - 4) + s[p] + "</u>";
440 r += s.mid(lastp + 1, p - lastp - 1);
441 r += QString("<u>") + s[p] + "</u>";
445 r += s.mid(lastp + 1);
451 class GuiLayoutFilterModel : public QSortFilterProxyModel {
454 GuiLayoutFilterModel(QObject * parent = 0)
455 : QSortFilterProxyModel(parent)
459 void triggerLayoutChange()
461 layoutAboutToBeChanged();
467 GuiLayoutBox::GuiLayoutBox(GuiToolbar * bar, GuiView & owner)
468 : owner_(owner), bar_(bar), lastSel_(-1),
469 layoutItemDelegate_(new LayoutItemDelegate(this)),
470 visibleCategories_(0), inShowPopup_(false)
472 setSizeAdjustPolicy(QComboBox::AdjustToContents);
473 setFocusPolicy(Qt::ClickFocus);
474 setMinimumWidth(sizeHint().width());
475 setMaxVisibleItems(100);
477 // set the layout model with two columns
478 // 1st: translated layout names
479 // 2nd: raw layout names
480 model_ = new QStandardItemModel(0, 2, this);
481 filterModel_ = new GuiLayoutFilterModel(this);
482 filterModel_->setSourceModel(model_);
483 setModel(filterModel_);
485 // for the filtering we have to intercept characters
486 view()->installEventFilter(this);
487 view()->setItemDelegateForColumn(0, layoutItemDelegate_);
489 QObject::connect(this, SIGNAL(activated(int)),
490 this, SLOT(selected(int)));
491 QObject::connect(bar_, SIGNAL(iconSizeChanged(QSize)),
492 this, SLOT(setIconSize(QSize)));
494 owner_.setLayoutDialog(this);
495 updateContents(true);
499 void GuiLayoutBox::setFilter(QString const & s)
501 bool enabled = view()->updatesEnabled();
502 view()->setUpdatesEnabled(false);
504 // remember old selection
505 int sel = currentIndex();
507 lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
510 filterModel_->setFilterRegExp(charFilterRegExp(filter_));
513 // restore old selection
514 if (lastSel_ != -1) {
515 QModelIndex i = filterModel_->mapFromSource(model_->index(lastSel_, 0));
517 setCurrentIndex(i.row());
520 // Workaround to resize to content size
521 // FIXME: There must be a better way. The QComboBox::AdjustToContents)
523 if (view()->isVisible()) {
524 // call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
525 // the hack in the item delegate to make space for the headers.
526 // We do not call our implementation of showPopup because that
527 // would reset the filter again. This is only needed if the user clicks
529 BOOST_ASSERT(!inShowPopup_);
531 QComboBox::showPopup();
532 inShowPopup_ = false;
534 // The item delegate hack is off again. So trigger a relayout of the popup.
535 filterModel_->triggerLayoutChange();
538 owner_.message(_("Filtering layouts with \"" + fromqstr(s) + "\". "
539 "Press ESC to remove filter."));
541 owner_.message(_("Enter characters to filter the layout list."));
544 view()->setUpdatesEnabled(enabled);
548 void GuiLayoutBox::countCategories()
550 int n = filterModel_->rowCount();
551 visibleCategories_ = 0;
552 if (n == 0 || !lyxrc.group_layouts)
555 // skip the "Standard" category
556 QString prevCat = model_->index(0, 2).data().toString();
559 for (int i = 0; i < n; ++i) {
560 QString cat = filterModel_->index(i, 2).data().toString();
562 ++visibleCategories_;
568 QString GuiLayoutBox::charFilterRegExp(QString const & filter)
571 for (int i = 0; i < filter.length(); ++i) {
574 re += ".*[" + QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
576 re += ".*" + QRegExp::escape(c);
582 void GuiLayoutBox::resetFilter()
584 setFilter(QString());
588 void GuiLayoutBox::showPopup()
590 owner_.message(_("Enter characters to filter the layout list."));
592 bool enabled = view()->updatesEnabled();
593 view()->setUpdatesEnabled(false);
597 // call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
598 // the hack in the item delegate to make space for the headers.
599 BOOST_ASSERT(!inShowPopup_);
601 QComboBox::showPopup();
602 inShowPopup_ = false;
604 // The item delegate hack is off again. So trigger a relayout of the popup.
605 filterModel_->triggerLayoutChange();
607 view()->setUpdatesEnabled(enabled);
611 bool GuiLayoutBox::eventFilter(QObject * o, QEvent * e)
613 if (e->type() != QEvent::KeyPress)
614 return QComboBox::eventFilter(o, e);
616 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
617 bool modified = (ke->modifiers() == Qt::ControlModifier)
618 || (ke->modifiers() == Qt::AltModifier)
619 || (ke->modifiers() == Qt::MetaModifier);
623 if (!modified && !filter_.isEmpty()) {
628 case Qt::Key_Backspace:
630 // cut off one character
631 setFilter(filter_.left(filter_.length() - 1));
635 if (modified || ke->text().isEmpty())
637 // find chars for the filter string
639 for (int i = 0; i < ke->text().length(); ++i) {
640 QChar c = ke->text()[i];
641 if (c.isLetterOrNumber()
644 || c.category() == QChar::Separator_Space) {
649 // append new chars to the filter string
650 setFilter(filter_ + s);
656 return QComboBox::eventFilter(o, e);
660 void GuiLayoutBox::setIconSize(QSize size)
662 bool small = size.height() < 20;
663 setAttribute(Qt::WA_MacSmallSize, small);
664 setAttribute(Qt::WA_MacNormalSize, !small);
668 void GuiLayoutBox::set(docstring const & layout)
675 QString const & name = toqstr((*text_class_)[layout].name());
676 if (name == currentText())
679 QList<QStandardItem *> r = model_->findItems(name, Qt::MatchExactly, 1);
681 lyxerr << "Trying to select non existent layout type "
682 << fromqstr(name) << endl;
686 setCurrentIndex(filterModel_->mapFromSource(r.first()->index()).row());
690 void GuiLayoutBox::addItemSort(docstring const & item, docstring const & category,
691 bool sorted, bool sortedByCat)
693 QString qitem = toqstr(item);
694 QString titem = toqstr(translateIfPossible(item));
695 QString qcat = toqstr(translateIfPossible(category));
697 QList<QStandardItem *> row;
698 row.append(new QStandardItem(titem));
699 row.append(new QStandardItem(qitem));
700 row.append(new QStandardItem(qcat));
702 // the first entry is easy
703 int const end = model_->rowCount();
705 model_->appendRow(row);
712 while (i < end && model_->item(i, 2)->text() != qcat)
716 // skip the Standard layout
720 // the simple unsorted case
723 // jump to the end of the category group
724 while (i < end && model_->item(i, 2)->text() == qcat)
726 model_->insertRow(i, row);
728 model_->appendRow(row);
732 // find row to insert the item, after the separator if it exists
734 // find alphabetic position
736 && model_->item(i, 0)->text().compare(titem) < 0
737 && (!sortedByCat || model_->item(i, 2)->text() == qcat))
741 model_->insertRow(i, row);
745 void GuiLayoutBox::updateContents(bool reset)
749 Buffer const * buffer = owner_.buffer();
758 // we'll only update the layout list if the text class has changed
759 // or we've moved from one inset to another
760 DocumentClass const * text_class = &buffer->params().documentClass();
761 Inset const * inset =
762 owner_.view()->cursor().innerParagraph().inInset();
763 if (!reset && text_class_ == text_class && inset_ == inset) {
764 set(owner_.view()->cursor().innerParagraph().layout().name());
769 text_class_ = text_class;
772 DocumentClass::const_iterator lit = text_class_->begin();
773 DocumentClass::const_iterator len = text_class_->end();
774 for (; lit != len; ++lit) {
775 docstring const & name = lit->name();
776 // if this inset requires the empty layout, we skip the default
778 if (name == text_class_->defaultLayoutName() && inset &&
779 (inset->forceEmptyLayout() || inset->useEmptyLayout()))
781 // if it doesn't require the empty layout, we skip it
782 if (name == text_class_->emptyLayoutName() && inset &&
783 !inset->forceEmptyLayout() && !inset->useEmptyLayout())
785 addItemSort(name, lit->category(), lyxrc.sort_layouts, lyxrc.group_layouts);
788 set(owner_.view()->cursor().innerParagraph().layout().name());
791 // needed to recalculate size hint
793 setMinimumWidth(sizeHint().width());
794 setEnabled(!buffer->isReadonly());
799 void GuiLayoutBox::selected(int index)
802 QModelIndex mindex = filterModel_->mapToSource(filterModel_->index(index, 1));
803 docstring const layoutName =
804 qstring_to_ucs4(model_->itemFromIndex(mindex)->text());
809 updateContents(false);
814 // find corresponding text class
815 if (text_class_->hasLayout(layoutName)) {
816 FuncRequest const func(LFUN_LAYOUT, layoutName, FuncRequest::TOOLBAR);
817 theLyXFunc().setLyXView(&owner_);
819 updateContents(false);
823 lyxerr << "ERROR (layoutSelected): layout not found!" << endl;
828 /////////////////////////////////////////////////////////////////////
832 /////////////////////////////////////////////////////////////////////
835 GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
836 : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner),
837 layout_(0), command_buffer_(0)
839 // give visual separation between adjacent toolbars
842 // TODO: save toolbar position
845 ToolbarInfo::item_iterator it = tbinfo.items.begin();
846 ToolbarInfo::item_iterator end = tbinfo.items.end();
847 for (; it != end; ++it)
852 Action * GuiToolbar::addItem(ToolbarItem const & item)
854 Action * act = new Action(&owner_, getIcon(item.func_, false),
855 toqstr(item.label_), item.func_, toqstr(item.label_), this);
856 actions_.append(act);
862 class PaletteButton : public QToolButton
866 ToolbarItem const & tbitem_;
869 PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
870 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
872 QString const label = qt_(to_ascii(tbitem_.label_));
876 connect(bar_, SIGNAL(iconSizeChanged(QSize)),
877 this, SLOT(setIconSize(QSize)));
879 ToolbarInfo const * tbinfo =
880 toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
882 // use the icon of first action for the toolbar button
883 setIcon(getIcon(tbinfo->items.begin()->func_, true));
886 void mousePressEvent(QMouseEvent * e)
889 QToolButton::mousePressEvent(e);
895 ToolbarInfo const * tbinfo =
896 toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
898 lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
901 IconPalette * panel = new IconPalette(this);
902 QString const label = qt_(to_ascii(tbitem_.label_));
903 panel->setWindowTitle(label);
904 connect(this, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
905 connect(panel, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
906 ToolbarInfo::item_iterator it = tbinfo->items.begin();
907 ToolbarInfo::item_iterator const end = tbinfo->items.end();
908 for (; it != end; ++it)
909 if (!getStatus(it->func_).unknown())
910 panel->addButton(bar_->addItem(*it));
912 QToolButton::mousePressEvent(e);
916 class MenuButton : public QToolButton
920 ToolbarItem const & tbitem_;
923 MenuButton(GuiToolbar * bar, ToolbarItem const & item)
924 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
926 setPopupMode(QToolButton::InstantPopup);
927 QString const label = qt_(to_ascii(tbitem_.label_));
931 setIcon(QPixmap(":images/math/" + toqstr(tbitem_.name_) + ".png"));
932 connect(bar, SIGNAL(iconSizeChanged(QSize)),
933 this, SLOT(setIconSize(QSize)));
936 void mousePressEvent(QMouseEvent * e)
939 QToolButton::mousePressEvent(e);
945 QString const label = qt_(to_ascii(tbitem_.label_));
946 ButtonMenu * m = new ButtonMenu(label, this);
947 m->setWindowTitle(label);
948 m->setTearOffEnabled(true);
949 connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
950 ToolbarInfo const * tbinfo =
951 toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
953 lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
956 ToolbarInfo::item_iterator it = tbinfo->items.begin();
957 ToolbarInfo::item_iterator const end = tbinfo->items.end();
958 for (; it != end; ++it)
959 if (!getStatus(it->func_).unknown())
960 m->add(bar_->addItem(*it));
963 QToolButton::mousePressEvent(e);
970 void GuiToolbar::add(ToolbarItem const & item)
972 switch (item.type_) {
973 case ToolbarItem::SEPARATOR:
976 case ToolbarItem::LAYOUTS:
977 layout_ = new GuiLayoutBox(this, owner_);
980 case ToolbarItem::MINIBUFFER:
981 command_buffer_ = new GuiCommandBuffer(&owner_);
982 addWidget(command_buffer_);
983 /// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
984 //setHorizontalStretchable(true);
986 case ToolbarItem::TABLEINSERT: {
987 QToolButton * tb = new QToolButton;
988 tb->setCheckable(true);
989 tb->setIcon(getIcon(FuncRequest(LFUN_TABULAR_INSERT), true));
990 QString const label = qt_(to_ascii(item.label_));
991 tb->setToolTip(label);
992 tb->setStatusTip(label);
994 InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
995 connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
996 connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
997 connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
1001 case ToolbarItem::ICONPALETTE:
1002 addWidget(new PaletteButton(this, item));
1005 case ToolbarItem::POPUPMENU: {
1006 addWidget(new MenuButton(this, item));
1009 case ToolbarItem::COMMAND: {
1010 if (!getStatus(item.func_).unknown())
1011 addAction(addItem(item));
1020 void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
1022 // if tbinfo.state == auto *do not* set on/off
1023 if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
1024 if (GuiToolbar::isVisible())
1025 tbinfo.state = ToolbarSection::ToolbarInfo::ON;
1027 tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
1030 // no need to save it here.
1031 Qt::ToolBarArea loc = owner_.toolBarArea(this);
1033 if (loc == Qt::TopToolBarArea)
1034 tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
1035 else if (loc == Qt::BottomToolBarArea)
1036 tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
1037 else if (loc == Qt::RightToolBarArea)
1038 tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
1039 else if (loc == Qt::LeftToolBarArea)
1040 tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
1042 tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
1044 // save toolbar position. They are not used to restore toolbar position
1045 // now because move(x,y) does not work for toolbar.
1046 tbinfo.posx = pos().x();
1047 tbinfo.posy = pos().y();
1051 void GuiToolbar::updateContents()
1053 // update visible toolbars only
1056 // This is a speed bottleneck because this is called on every keypress
1057 // and update calls getStatus, which copies the cursor at least two times
1058 for (int i = 0; i < actions_.size(); ++i)
1059 actions_[i]->update();
1062 layout_->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
1069 } // namespace frontend
1072 #include "GuiToolbar_moc.cpp"