2 * \file qt4/QLToolbar.C
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 Abdelrazak Younes
12 * Full author contact details are available in file CREDITS.
18 #include "bufferparams.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
26 #include "QLToolbar.h"
28 #include "qt_helpers.h"
29 #include "InsertTableWidget.h"
33 #include <QToolButton>
45 LyXTextClass const & getTextClass(LyXView const & lv)
47 return lv.buffer()->params().getLyXTextClass();
54 QLayoutBox::QLayoutBox(QToolBar * toolbar, GuiView & owner)
57 combo_ = new QComboBox;
58 combo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
59 combo_->setFocusPolicy(Qt::ClickFocus);
60 combo_->setMinimumWidth(combo_->sizeHint().width());
61 combo_->setMaxVisibleItems(100);
63 QObject::connect(combo_, SIGNAL(activated(const QString &)),
64 this, SLOT(selected(const QString &)));
66 toolbar->addWidget(combo_);
70 void QLayoutBox::set(string const & layout)
72 LyXTextClass const & tc = getTextClass(owner_);
74 QString const & name = qt_(tc[layout]->name());
77 for (; i < combo_->count(); ++i) {
78 if (name == combo_->itemText(i))
82 if (i == combo_->count()) {
83 lyxerr << "Trying to select non existent layout type "
84 << fromqstr(name) << endl;
88 combo_->setCurrentIndex(i);
92 void QLayoutBox::update()
94 LyXTextClass const & tc = getTextClass(owner_);
96 combo_->setUpdatesEnabled(false);
100 LyXTextClass::const_iterator it = tc.begin();
101 LyXTextClass::const_iterator const end = tc.end();
102 for (; it != end; ++it) {
103 // ignore obsolete entries
104 if ((*it)->obsoleted_by().empty())
105 combo_->addItem(qt_((*it)->name()));
108 // needed to recalculate size hint
110 combo_->setMinimumWidth(combo_->sizeHint().width());
113 combo_->setUpdatesEnabled(true);
118 void QLayoutBox::clear()
124 void QLayoutBox::open()
130 void QLayoutBox::setEnabled(bool enable)
132 // Workaround for Qt bug where setEnabled(true) closes
134 if (enable != combo_->isEnabled())
135 combo_->setEnabled(enable);
139 void QLayoutBox::selected(const QString & str)
141 string const sel = fromqstr(str);
143 owner_.centralWidget()->setFocus();
145 layoutSelected(owner_, sel);
149 QLToolbar::QLToolbar(ToolbarBackend::Toolbar const & tbb, GuiView & owner)
151 QToolBar(qt_(tbb.gui_name), &owner)
153 // give visual separation between adjacent toolbars
156 // allowing the toolbars to tear off is too easily done,
157 // and we don't save their orientation anyway. Disable the handle.
160 ToolbarBackend::item_iterator it = tbb.items.begin();
161 ToolbarBackend::item_iterator end = tbb.items.end();
162 for (; it != end; ++it)
163 add(it->first, it->second);
167 void QLToolbar::add(FuncRequest const & func, string const & tooltip)
169 switch (func.action) {
170 case ToolbarBackend::SEPARATOR:
173 case ToolbarBackend::LAYOUTS:
174 layout_.reset(new QLayoutBox(this, owner_));
176 case ToolbarBackend::MINIBUFFER:
177 owner_.addCommandBuffer(this);
178 /// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
179 //setHorizontalStretchable(true);
181 case LFUN_TABULAR_INSERT: {
182 QToolButton * tb = new QToolButton;
183 tb->setCheckable(true);
184 tb->setIcon(QPixmap(toqstr(toolbarbackend.getIcon(func))));
185 tb->setToolTip(toqstr(tooltip));
186 tb->setFocusPolicy(Qt::NoFocus);
187 InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
188 connect(tb, SIGNAL(toggled(bool)), iv, SLOT(show(bool)));
189 connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
190 connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
195 if (owner_.getLyXFunc().getStatus(func).unknown())
198 Action * action = new Action(owner_, toolbarbackend.getIcon(func), "", func, tooltip);
200 ActionVector.push_back(action);
207 void QLToolbar::hide(bool)
213 void QLToolbar::show(bool)
219 void QLToolbar::update()
221 for (size_t i=0; i<ActionVector.size(); ++i)
222 ActionVector[i]->update();
229 } // namespace frontend
232 #include "QLToolbar_moc.cpp"