2 * \file Toolbar_pimpl.C
3 * See the file COPYING.
5 * \author Lars Gullik Bjønnes, larsbj@lyx.org
6 * \uathor John Levon <moz@compsoc.man.ac.uk>
12 #pragma implementation
15 #include "ToolbarDefaults.h"
18 #include "FuncStatus.h"
19 #include "BufferView.h"
21 #include "lyxtextclasslist.h"
22 #include "LyXAction.h"
23 #include "MathsSymbols.h"
27 #include "support/LAssert.h"
28 #include "support/filetools.h"
29 #include "support/lstrings.h"
33 #include "Toolbar_pimpl.h"
36 #include <qcombobox.h>
38 #include <qsizepolicy.h>
42 extern LyXAction lyxaction;
46 string const getPixmap(int action)
51 const kb_action act = lyxaction.retrieveActionArg(action, arg);
52 string const name = lyxaction.getActionName(act);
54 xpm_name = subst(name + ' ' + arg, ' ','_');
58 string fullname = LibFileSearch("images", xpm_name, "xpm");
60 if (!fullname.empty()) {
61 lyxerr[Debug::GUI] << "Full icon name is `"
62 << fullname << "'" << endl;
67 if (act == LFUN_INSERT_MATH && !arg.empty()) {
68 char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
72 lyxerr[Debug::GUI] << "Using mathed-provided icon"
74 fl_set_pixmapbutton_data(obj,
75 const_cast<char **>(pixmap));
81 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
82 fullname = LibFileSearch("images", "unknown", "xpm");
83 if (!fullname.empty()) {
84 lyxerr[Debug::GUI] << "Using default `unknown' icon"
93 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs &, int, int)
94 : owner_(static_cast<QtView *>(o)),
97 proxy_.reset(new ToolbarProxy(*this));
101 Toolbar::Pimpl::~Pimpl()
106 void Toolbar::Pimpl::activate()
112 void Toolbar::Pimpl::deactivate()
118 void Toolbar::Pimpl::update()
120 ButtonMap::const_iterator p = map_.begin();
121 ButtonMap::const_iterator end = map_.end();
123 for (; p != end; ++p) {
124 QToolButton * button = p->first;
125 int action = p->second;
127 FuncStatus const status =
128 owner_->getLyXFunc()->getStatus(action);
130 button->setToggleButton(true);
131 button->setOn(status.onoff(true));
132 button->setEnabled(!status.disabled());
136 combo_->setEnabled(!owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled());
140 void Toolbar::Pimpl::button_selected(QToolButton * button)
142 ButtonMap::const_iterator cit = map_.find(button);
144 if (cit == map_.end()) {
145 lyxerr << "non existent tool button selected !" << endl;
149 owner_->getLyXFunc()->verboseDispatch(cit->second, true);
153 void Toolbar::Pimpl::changed_layout(string const & sel)
155 LyXTextClass const & tc =
156 textclasslist[owner_->buffer()->params.textclass];
158 LyXTextClass::const_iterator end = tc.end();
159 for (LyXTextClass::const_iterator cit = tc.begin();
161 if (_((*cit)->name()) == sel) {
162 owner_->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
166 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
171 void Toolbar::Pimpl::setLayout(string const & layout)
173 LyXTextClass const & tc =
174 textclasslist[owner_->buffer()->params.textclass];
176 string const & name = _(tc[layout]->name());
180 for (i = 0; i < combo_->count(); ++i) {
181 if (name == combo_->text(i).latin1())
185 if (i == combo_->count()) {
186 lyxerr << "Trying to select non existent layout type "
191 combo_->setCurrentItem(i);
195 void Toolbar::Pimpl::updateLayoutList(bool force)
197 // if we don't need an update, don't ...
198 if (combo_->count() && !force)
201 LyXTextClass const & tc =
202 textclasslist[owner_->buffer()->params.textclass];
204 combo_->setUpdatesEnabled(false);
208 LyXTextClass::const_iterator cit = tc.begin();
209 LyXTextClass::const_iterator end = tc.end();
210 for (; cit != end; ++cit) {
211 // ignore obsolete entries
212 if ((*cit)->obsoleted_by().empty())
213 combo_->insertItem(_((*cit)->name()).c_str());
216 // needed to recalculate size hint
218 combo_->setMinimumWidth(combo_->sizeHint().width());
221 combo_->setUpdatesEnabled(true);
226 void Toolbar::Pimpl::clearLayoutList()
232 void Toolbar::Pimpl::openLayoutList()
234 #if 0 // popup() is protected
240 void Toolbar::Pimpl::set(bool)
246 void Toolbar::Pimpl::add(int action, bool)
248 if (!toolbars_.size()) {
249 toolbars_.push_back(new QToolBar(owner_));
253 case ToolbarDefaults::SEPARATOR:
254 toolbars_.back()->addSeparator();
256 case ToolbarDefaults::NEWLINE:
257 toolbars_.push_back(new QToolBar(owner_));
259 case ToolbarDefaults::LAYOUTS: {
260 combo_ = new QComboBox(toolbars_.back());
261 QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
262 combo_->setSizePolicy(p);
263 combo_->setFocusPolicy(QWidget::TabFocus);
264 combo_->setMinimumWidth(combo_->sizeHint().width());
266 QObject::connect(combo_, SIGNAL(activated(const QString &)),
267 proxy_.get(), SLOT(layout_selected(const QString &)));
272 new QToolButton(QPixmap(getPixmap(action).c_str()),
274 proxy_.get(), SLOT(button_selected()), toolbars_.back());
278 QToolTip::add(tb, _(lyxaction.helpText(action)).c_str());
284 void Toolbar::Pimpl::push(int)
287 lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
288 << nth << '\'' << endl;
290 if (nth <= 0 || nth >= int(toollist.size())) {
291 // item nth not found...
295 fl_trigger_object(toollist[nth - 1].icon);