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 "support/assert.h"
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 // this must be sorted alphabetically
112 // Upper case comes before lower case
113 PngMap sorted_png_map[] = {
114 { "Bumpeq", "bumpeq2" },
117 { "Delta", "delta2" },
118 { "Downarrow", "downarrow2" },
119 { "Gamma", "gamma2" },
120 { "Lambda", "lambda2" },
121 { "Leftarrow", "leftarrow2" },
122 { "Leftrightarrow", "leftrightarrow2" },
123 { "Longleftarrow", "longleftarrow2" },
124 { "Longleftrightarrow", "longleftrightarrow2" },
125 { "Longrightarrow", "longrightarrow2" },
126 { "Omega", "omega2" },
130 { "Rightarrow", "rightarrow2" },
131 { "Sigma", "sigma2" },
132 { "Subset", "subset2" },
133 { "Supset", "supset2" },
134 { "Theta", "theta2" },
135 { "Uparrow", "uparrow2" },
136 { "Updownarrow", "updownarrow2" },
137 { "Upsilon", "upsilon2" },
138 { "Vdash", "vdash3" },
141 { "nLeftarrow", "nleftarrow2" },
142 { "nLeftrightarrow", "nleftrightarrow2" },
143 { "nRightarrow", "nrightarrow2" },
144 { "nVDash", "nvdash3" },
145 { "nvDash", "nvdash2" },
146 { "textrm \\AA", "textrm_AA"},
147 { "textrm \\O", "textrm_O"},
148 { "vDash", "vdash2" }
151 size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);
154 QString findPng(QString const & name)
156 PngMap const * const begin = sorted_png_map;
157 PngMap const * const end = begin + nr_sorted_png_map;
158 LASSERT(sorted(begin, end), /**/);
160 PngMap const * const it = find_if(begin, end, CompareKey(name));
164 png_name = it->value;
167 png_name.replace('_', "underscore");
168 png_name.replace(' ', '_');
170 // This way we can have "math-delim { }" on the toolbar.
171 png_name.replace('(', "lparen");
172 png_name.replace(')', "rparen");
173 png_name.replace('[', "lbracket");
174 png_name.replace(']', "rbracket");
175 png_name.replace('{', "lbrace");
176 png_name.replace('}', "rbrace");
177 png_name.replace('|', "bars");
178 png_name.replace(',', "thinspace");
179 png_name.replace(':', "mediumspace");
180 png_name.replace(';', "thickspace");
181 png_name.replace('!', "negthinspace");
184 LYXERR(Debug::GUI, "findPng(" << name << ")\n"
185 << "Looking for math PNG called \"" << png_name << '"');
192 /// return a icon for the given action
193 static QIcon getIcon(FuncRequest const & f, bool unknown)
195 initializeResources();
201 case LFUN_MATH_INSERT:
202 if (!f.argument().empty()) {
204 name1 = findPng(toqstr(f.argument()).mid(1));
207 case LFUN_MATH_DELIM:
208 case LFUN_MATH_BIGDELIM:
210 name1 = findPng(toqstr(f.argument()));
214 name1 = toqstr(f.argument());
217 name2 = toqstr(lyxaction.getActionName(f.action));
220 if (!f.argument().empty()) {
221 name1 = name2 + ' ' + toqstr(f.argument());
222 name1.replace(' ', '_');
226 string fullname = libFileSearch("images/" + path, name1, "png").absFilename();
227 if (pm.load(toqstr(fullname)))
230 fullname = libFileSearch("images/" + path, name2, "png").absFilename();
231 if (pm.load(toqstr(fullname)))
234 if (pm.load(":/images/" + path + name1 + ".png"))
237 if (pm.load(":/images/" + path + name2 + ".png"))
240 LYXERR(Debug::GUI, "Cannot find icon for command \""
241 << lyxaction.getActionName(f.action)
242 << '(' << to_utf8(f.argument()) << ")\"");
244 pm.load(":/images/unknown.png");
250 /////////////////////////////////////////////////////////////////////
254 /////////////////////////////////////////////////////////////////////
256 class LayoutItemDelegate : public QItemDelegate {
259 explicit LayoutItemDelegate(QObject * parent = 0)
260 : QItemDelegate(parent)
264 void paint(QPainter * painter, QStyleOptionViewItem const & option,
265 QModelIndex const & index) const
267 QStyleOptionViewItem opt = option;
269 // default background
270 painter->fillRect(opt.rect, opt.palette.color(QPalette::Base));
273 if (lyxrc.group_layouts) {
274 QSortFilterProxyModel const * model
275 = static_cast<QSortFilterProxyModel const *>(index.model());
277 QString stdCat = category(*model->sourceModel(), 0);
278 QString cat = category(*index.model(), index.row());
280 // not the standard layout and not the same as in the previous line?
282 && (index.row() == 0 || cat != category(*index.model(), index.row() - 1))) {
285 // draw unselected background
286 QStyle::State state = opt.state;
287 opt.state = opt.state & ~QStyle::State_Selected;
288 drawBackground(painter, opt, index);
291 // draw category header
292 drawCategoryHeader(painter, opt,
293 category(*index.model(), index.row()));
295 // move rect down below header
296 opt.rect.setTop(opt.rect.top() + headerHeight(opt));
302 QItemDelegate::paint(painter, opt, index);
306 void drawDisplay(QPainter * painter, QStyleOptionViewItem const & opt,
307 const QRect & /*rect*/, const QString & text ) const
309 QString utext = underlineFilter(text);
311 // Draw the rich text.
313 QColor col = opt.palette.text().color();
314 if (opt.state & QStyle::State_Selected)
315 col = opt.palette.highlightedText().color();
316 QAbstractTextDocumentLayout::PaintContext context;
317 context.palette.setColor(QPalette::Text, col);
320 doc.setDefaultFont(opt.font);
323 QTextFrameFormat fmt = doc.rootFrame()->frameFormat();
325 doc.rootFrame()->setFrameFormat(fmt);
327 painter->translate(opt.rect.x() + 5,
328 opt.rect.y() + (opt.rect.height() - opt.fontMetrics.height()) / 2);
329 doc.documentLayout()->draw(painter, context);
334 QSize sizeHint(QStyleOptionViewItem const & opt,
335 QModelIndex const & index) const
337 GuiLayoutBox * combo = static_cast<GuiLayoutBox *>(parent());
338 QSortFilterProxyModel const * model
339 = static_cast<QSortFilterProxyModel const *>(index.model());
340 QSize size = QItemDelegate::sizeHint(opt, index);
342 /// QComboBox uses the first row height to estimate the
343 /// complete popup height during QComboBox::showPopup().
344 /// To avoid scrolling we have to sneak in space for the headers.
345 /// So we tweak this value accordingly. It's not nice, but the
346 /// only possible way it seems.
347 if (lyxrc.group_layouts && index.row() == 0 && combo->inShowPopup_) {
348 int itemHeight = size.height();
350 // we have to show \c cats many headers:
351 unsigned cats = combo->visibleCategories_;
353 // and we have \c n items to distribute the needed space over
354 unsigned n = combo->model()->rowCount();
356 // so the needed average height (rounded upwards) is:
357 size.setHeight((headerHeight(opt) * cats + itemHeight * n + n - 1) / n);
361 // Add space for the category headers here?
362 // Not for the standard layout though.
363 QString stdCat = category(*model->sourceModel(), 0);
364 QString cat = category(*index.model(), index.row());
365 if (lyxrc.group_layouts && stdCat != cat
366 && (index.row() == 0 || cat != category(*index.model(), index.row() - 1))) {
367 size.setHeight(size.height() + headerHeight(opt));
375 QString category(QAbstractItemModel const & model, int row) const
377 return model.data(model.index(row, 2), Qt::DisplayRole).toString();
381 int headerHeight(QStyleOptionViewItem const & opt) const
383 return opt.fontMetrics.height() * 8 / 10;
386 void drawCategoryHeader(QPainter * painter, QStyleOptionViewItem const & opt,
387 QString const & category) const
389 // slightly blended color
390 QColor lcol = opt.palette.text().color();
392 painter->setPen(lcol);
394 // set 80% scaled, bold font
395 QFont font = opt.font;
397 font.setWeight(QFont::Black);
398 font.setPointSize(opt.font.pointSize() * 8 / 10);
399 painter->setFont(font);
401 // draw the centered text
402 QFontMetrics fm(font);
403 int w = fm.width(category);
404 int x = opt.rect.x() + (opt.rect.width() - w) / 2;
405 int y = opt.rect.y() + fm.ascent();
408 painter->drawText(x, y, category);
410 // the vertical position of the line: middle of lower case chars
411 int ymid = y - 1 - fm.xHeight() / 2; // -1 for the baseline
413 // draw the horizontal line
414 if (!category.isEmpty()) {
415 painter->drawLine(opt.rect.x(), ymid, left - 1, ymid);
416 painter->drawLine(right + 1, ymid, opt.rect.right(), ymid);
418 painter->drawLine(opt.rect.x(), ymid, opt.rect.right(), ymid);
423 QString underlineFilter(QString const & s) const
426 GuiLayoutBox * p = static_cast<GuiLayoutBox *>(parent());
427 QString const & f = p->filter();
431 // step through data item and put "(x)" for every matching character
435 for (int i = 0; i < f.length(); ++i) {
436 int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
437 LASSERT(p != -1, /**/);
438 if (lastp == p - 1 && lastp != -1) {
439 // remove ")" and append "x)"
440 r = r.left(r.length() - 4) + s[p] + "</u>";
443 r += s.mid(lastp + 1, p - lastp - 1);
444 r += QString("<u>") + s[p] + "</u>";
448 r += s.mid(lastp + 1);
454 class GuiLayoutFilterModel : public QSortFilterProxyModel {
457 GuiLayoutFilterModel(QObject * parent = 0)
458 : QSortFilterProxyModel(parent)
462 void triggerLayoutChange()
464 layoutAboutToBeChanged();
470 GuiLayoutBox::GuiLayoutBox(GuiToolbar * bar, GuiView & owner)
471 : owner_(owner), bar_(bar), lastSel_(-1),
472 layoutItemDelegate_(new LayoutItemDelegate(this)),
473 visibleCategories_(0), inShowPopup_(false)
475 setSizeAdjustPolicy(QComboBox::AdjustToContents);
476 setFocusPolicy(Qt::ClickFocus);
477 setMinimumWidth(sizeHint().width());
478 setMaxVisibleItems(100);
480 // set the layout model with two columns
481 // 1st: translated layout names
482 // 2nd: raw layout names
483 model_ = new QStandardItemModel(0, 2, this);
484 filterModel_ = new GuiLayoutFilterModel(this);
485 filterModel_->setSourceModel(model_);
486 setModel(filterModel_);
488 // for the filtering we have to intercept characters
489 view()->installEventFilter(this);
490 view()->setItemDelegateForColumn(0, layoutItemDelegate_);
492 QObject::connect(this, SIGNAL(activated(int)),
493 this, SLOT(selected(int)));
494 QObject::connect(bar_, SIGNAL(iconSizeChanged(QSize)),
495 this, SLOT(setIconSize(QSize)));
497 owner_.setLayoutDialog(this);
498 updateContents(true);
502 void GuiLayoutBox::setFilter(QString const & s)
504 bool enabled = view()->updatesEnabled();
505 view()->setUpdatesEnabled(false);
507 // remember old selection
508 int sel = currentIndex();
510 lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
513 filterModel_->setFilterRegExp(charFilterRegExp(filter_));
516 // restore old selection
517 if (lastSel_ != -1) {
518 QModelIndex i = filterModel_->mapFromSource(model_->index(lastSel_, 0));
520 setCurrentIndex(i.row());
523 // Workaround to resize to content size
524 // FIXME: There must be a better way. The QComboBox::AdjustToContents)
526 if (view()->isVisible()) {
527 // call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
528 // the hack in the item delegate to make space for the headers.
529 // We do not call our implementation of showPopup because that
530 // would reset the filter again. This is only needed if the user clicks
532 LASSERT(!inShowPopup_, /**/);
534 QComboBox::showPopup();
535 inShowPopup_ = false;
537 // The item delegate hack is off again. So trigger a relayout of the popup.
538 filterModel_->triggerLayoutChange();
541 owner_.message(_("Filtering layouts with \"" + fromqstr(s) + "\". "
542 "Press ESC to remove filter."));
544 owner_.message(_("Enter characters to filter the layout list."));
547 view()->setUpdatesEnabled(enabled);
551 void GuiLayoutBox::countCategories()
553 int n = filterModel_->rowCount();
554 visibleCategories_ = 0;
555 if (n == 0 || !lyxrc.group_layouts)
558 // skip the "Standard" category
559 QString prevCat = model_->index(0, 2).data().toString();
562 for (int i = 0; i < n; ++i) {
563 QString cat = filterModel_->index(i, 2).data().toString();
565 ++visibleCategories_;
571 QString GuiLayoutBox::charFilterRegExp(QString const & filter)
574 for (int i = 0; i < filter.length(); ++i) {
577 re += ".*[" + QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
579 re += ".*" + QRegExp::escape(c);
585 void GuiLayoutBox::resetFilter()
587 setFilter(QString());
591 void GuiLayoutBox::showPopup()
593 owner_.message(_("Enter characters to filter the layout list."));
595 bool enabled = view()->updatesEnabled();
596 view()->setUpdatesEnabled(false);
600 // call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
601 // the hack in the item delegate to make space for the headers.
602 LASSERT(!inShowPopup_, /**/);
604 QComboBox::showPopup();
605 inShowPopup_ = false;
607 // The item delegate hack is off again. So trigger a relayout of the popup.
608 filterModel_->triggerLayoutChange();
610 view()->setUpdatesEnabled(enabled);
614 bool GuiLayoutBox::eventFilter(QObject * o, QEvent * e)
616 if (e->type() != QEvent::KeyPress)
617 return QComboBox::eventFilter(o, e);
619 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
620 bool modified = (ke->modifiers() == Qt::ControlModifier)
621 || (ke->modifiers() == Qt::AltModifier)
622 || (ke->modifiers() == Qt::MetaModifier);
626 if (!modified && !filter_.isEmpty()) {
631 case Qt::Key_Backspace:
633 // cut off one character
634 setFilter(filter_.left(filter_.length() - 1));
638 if (modified || ke->text().isEmpty())
640 // find chars for the filter string
642 for (int i = 0; i < ke->text().length(); ++i) {
643 QChar c = ke->text()[i];
644 if (c.isLetterOrNumber()
647 || c.category() == QChar::Separator_Space) {
652 // append new chars to the filter string
653 setFilter(filter_ + s);
659 return QComboBox::eventFilter(o, e);
663 void GuiLayoutBox::setIconSize(QSize size)
666 bool small = size.height() < 20;
667 setAttribute(Qt::WA_MacSmallSize, small);
668 setAttribute(Qt::WA_MacNormalSize, !small);
673 void GuiLayoutBox::set(docstring const & layout)
680 QString const & name = toqstr((*text_class_)[layout].name());
681 if (name == currentText())
684 QList<QStandardItem *> r = model_->findItems(name, Qt::MatchExactly, 1);
686 LYXERR0("Trying to select non existent layout type " << name);
690 setCurrentIndex(filterModel_->mapFromSource(r.first()->index()).row());
694 void GuiLayoutBox::addItemSort(docstring const & item, docstring const & category,
695 bool sorted, bool sortedByCat)
697 QString qitem = toqstr(item);
698 QString titem = toqstr(translateIfPossible(item));
699 QString qcat = toqstr(translateIfPossible(category));
701 QList<QStandardItem *> row;
702 row.append(new QStandardItem(titem));
703 row.append(new QStandardItem(qitem));
704 row.append(new QStandardItem(qcat));
706 // the first entry is easy
707 int const end = model_->rowCount();
709 model_->appendRow(row);
716 while (i < end && model_->item(i, 2)->text() != qcat)
720 // skip the Standard layout
724 // the simple unsorted case
727 // jump to the end of the category group
728 while (i < end && model_->item(i, 2)->text() == qcat)
730 model_->insertRow(i, row);
732 model_->appendRow(row);
736 // find row to insert the item, after the separator if it exists
738 // find alphabetic position
740 && model_->item(i, 0)->text().compare(titem) < 0
741 && (!sortedByCat || model_->item(i, 2)->text() == qcat))
745 model_->insertRow(i, row);
749 void GuiLayoutBox::updateContents(bool reset)
753 Buffer const * buffer = owner_.buffer();
762 // we'll only update the layout list if the text class has changed
763 // or we've moved from one inset to another
764 DocumentClass const * text_class = &buffer->params().documentClass();
765 Inset const * inset =
766 owner_.view()->cursor().innerParagraph().inInset();
767 if (!reset && text_class_ == text_class && inset_ == inset) {
768 set(owner_.view()->cursor().innerParagraph().layout().name());
773 text_class_ = text_class;
776 DocumentClass::const_iterator lit = text_class_->begin();
777 DocumentClass::const_iterator len = text_class_->end();
779 for (; lit != len; ++lit) {
780 docstring const & name = lit->name();
781 bool const useEmpty = inset_->forceEmptyLayout() || inset_->useEmptyLayout();
782 // if this inset requires the empty layout, we skip the default
784 if (name == text_class_->defaultLayoutName() && inset_ && useEmpty)
786 // if it doesn't require the empty layout, we skip it
787 if (name == text_class_->emptyLayoutName() && inset_ && !useEmpty)
789 addItemSort(name, lit->category(), lyxrc.sort_layouts, lyxrc.group_layouts);
792 set(owner_.view()->cursor().innerParagraph().layout().name());
795 // needed to recalculate size hint
797 setMinimumWidth(sizeHint().width());
798 setEnabled(!buffer->isReadonly());
803 void GuiLayoutBox::selected(int index)
806 QModelIndex mindex = filterModel_->mapToSource(filterModel_->index(index, 1));
807 docstring const layoutName =
808 qstring_to_ucs4(model_->itemFromIndex(mindex)->text());
813 updateContents(false);
818 // find corresponding text class
819 if (text_class_->hasLayout(layoutName)) {
820 FuncRequest const func(LFUN_LAYOUT, layoutName, FuncRequest::TOOLBAR);
821 theLyXFunc().setLyXView(&owner_);
823 updateContents(false);
827 lyxerr << "ERROR (layoutSelected): layout not found!" << endl;
832 /////////////////////////////////////////////////////////////////////
836 /////////////////////////////////////////////////////////////////////
839 GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
840 : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner),
841 layout_(0), command_buffer_(0)
843 // give visual separation between adjacent toolbars
846 // TODO: save toolbar position
849 ToolbarInfo::item_iterator it = tbinfo.items.begin();
850 ToolbarInfo::item_iterator end = tbinfo.items.end();
851 for (; it != end; ++it)
856 Action * GuiToolbar::addItem(ToolbarItem const & item)
858 Action * act = new Action(&owner_, getIcon(item.func_, false),
859 toqstr(item.label_), item.func_, toqstr(item.label_), this);
860 actions_.append(act);
866 class PaletteButton : public QToolButton
870 ToolbarItem const & tbitem_;
873 PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
874 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
876 QString const label = qt_(to_ascii(tbitem_.label_));
880 connect(bar_, SIGNAL(iconSizeChanged(QSize)),
881 this, SLOT(setIconSize(QSize)));
883 ToolbarInfo const * tbinfo =
884 toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
886 // use the icon of first action for the toolbar button
887 setIcon(getIcon(tbinfo->items.begin()->func_, true));
890 void mousePressEvent(QMouseEvent * e)
893 QToolButton::mousePressEvent(e);
899 ToolbarInfo const * tbinfo =
900 toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
902 lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
905 IconPalette * panel = new IconPalette(this);
906 QString const label = qt_(to_ascii(tbitem_.label_));
907 panel->setWindowTitle(label);
908 connect(this, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
909 connect(panel, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
910 ToolbarInfo::item_iterator it = tbinfo->items.begin();
911 ToolbarInfo::item_iterator const end = tbinfo->items.end();
912 for (; it != end; ++it)
913 if (!getStatus(it->func_).unknown())
914 panel->addButton(bar_->addItem(*it));
916 QToolButton::mousePressEvent(e);
920 class MenuButton : public QToolButton
924 ToolbarItem const & tbitem_;
927 MenuButton(GuiToolbar * bar, ToolbarItem const & item)
928 : QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
930 setPopupMode(QToolButton::InstantPopup);
931 QString const label = qt_(to_ascii(tbitem_.label_));
935 setIcon(QPixmap(":images/math/" + toqstr(tbitem_.name_) + ".png"));
936 connect(bar, SIGNAL(iconSizeChanged(QSize)),
937 this, SLOT(setIconSize(QSize)));
940 void mousePressEvent(QMouseEvent * e)
943 QToolButton::mousePressEvent(e);
949 QString const label = qt_(to_ascii(tbitem_.label_));
950 ButtonMenu * m = new ButtonMenu(label, this);
951 m->setWindowTitle(label);
952 m->setTearOffEnabled(true);
953 connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
954 ToolbarInfo const * tbinfo =
955 toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
957 lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
960 ToolbarInfo::item_iterator it = tbinfo->items.begin();
961 ToolbarInfo::item_iterator const end = tbinfo->items.end();
962 for (; it != end; ++it)
963 if (!getStatus(it->func_).unknown())
964 m->add(bar_->addItem(*it));
967 QToolButton::mousePressEvent(e);
974 void GuiToolbar::add(ToolbarItem const & item)
976 switch (item.type_) {
977 case ToolbarItem::SEPARATOR:
980 case ToolbarItem::LAYOUTS:
981 layout_ = new GuiLayoutBox(this, owner_);
984 case ToolbarItem::MINIBUFFER:
985 command_buffer_ = new GuiCommandBuffer(&owner_);
986 addWidget(command_buffer_);
987 /// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
988 //setHorizontalStretchable(true);
990 case ToolbarItem::TABLEINSERT: {
991 QToolButton * tb = new QToolButton;
992 tb->setCheckable(true);
993 tb->setIcon(getIcon(FuncRequest(LFUN_TABULAR_INSERT), true));
994 QString const label = qt_(to_ascii(item.label_));
995 tb->setToolTip(label);
996 tb->setStatusTip(label);
998 InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
999 connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
1000 connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
1001 connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
1005 case ToolbarItem::ICONPALETTE:
1006 addWidget(new PaletteButton(this, item));
1009 case ToolbarItem::POPUPMENU: {
1010 addWidget(new MenuButton(this, item));
1013 case ToolbarItem::COMMAND: {
1014 if (!getStatus(item.func_).unknown())
1015 addAction(addItem(item));
1024 void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
1026 // if tbinfo.state == auto *do not* set on/off
1027 if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
1028 if (GuiToolbar::isVisible())
1029 tbinfo.state = ToolbarSection::ToolbarInfo::ON;
1031 tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
1034 // no need to save it here.
1035 Qt::ToolBarArea loc = owner_.toolBarArea(this);
1037 if (loc == Qt::TopToolBarArea)
1038 tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
1039 else if (loc == Qt::BottomToolBarArea)
1040 tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
1041 else if (loc == Qt::RightToolBarArea)
1042 tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
1043 else if (loc == Qt::LeftToolBarArea)
1044 tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
1046 tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
1048 // save toolbar position. They are not used to restore toolbar position
1049 // now because move(x,y) does not work for toolbar.
1050 tbinfo.posx = pos().x();
1051 tbinfo.posy = pos().y();
1055 void GuiToolbar::updateContents()
1057 // update visible toolbars only
1060 // This is a speed bottleneck because this is called on every keypress
1061 // and update calls getStatus, which copies the cursor at least two times
1062 for (int i = 0; i < actions_.size(); ++i)
1063 actions_[i]->update();
1066 layout_->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
1073 } // namespace frontend
1076 #include "GuiToolbar_moc.cpp"