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 QPixmap getIconPixmap(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;
63 return QPixmap(fullname.c_str());
66 if (act == LFUN_INSERT_MATH && !arg.empty()) {
68 char const ** pixmap =
69 get_pixmap_from_symbol(arg.c_str(), 30, 30);
71 lyxerr[Debug::GUI] << "Using mathed-provided icon"
73 return QPixmap(pixmap);
78 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
79 fullname = LibFileSearch("images", "unknown", "xpm");
80 if (!fullname.empty()) {
81 lyxerr[Debug::GUI] << "Using default `unknown' icon"
84 return QPixmap(fullname.c_str());
90 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs &, int, int)
91 : owner_(static_cast<QtView *>(o)),
94 proxy_.reset(new ToolbarProxy(*this));
98 Toolbar::Pimpl::~Pimpl()
103 void Toolbar::Pimpl::update()
105 ButtonMap::const_iterator p = map_.begin();
106 ButtonMap::const_iterator end = map_.end();
108 for (; p != end; ++p) {
109 QToolButton * button = p->first;
110 int action = p->second;
112 FuncStatus const status =
113 owner_->getLyXFunc()->getStatus(action);
115 button->setToggleButton(true);
116 button->setOn(status.onoff(true));
117 button->setEnabled(!status.disabled());
121 combo_->setEnabled(!owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled());
125 void Toolbar::Pimpl::button_selected(QToolButton * button)
127 ButtonMap::const_iterator cit = map_.find(button);
129 if (cit == map_.end()) {
130 lyxerr << "non existent tool button selected !" << endl;
134 owner_->getLyXFunc()->verboseDispatch(cit->second, true);
138 void Toolbar::Pimpl::changed_layout(string const & sel)
140 LyXTextClass const & tc =
141 textclasslist[owner_->buffer()->params.textclass];
143 LyXTextClass::const_iterator end = tc.end();
144 for (LyXTextClass::const_iterator cit = tc.begin();
146 if (_((*cit)->name()) == sel) {
147 owner_->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
151 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
156 void Toolbar::Pimpl::setLayout(string const & layout)
158 LyXTextClass const & tc =
159 textclasslist[owner_->buffer()->params.textclass];
161 string const & name = _(tc[layout]->name());
165 for (i = 0; i < combo_->count(); ++i) {
166 if (name == combo_->text(i).latin1())
170 if (i == combo_->count()) {
171 lyxerr << "Trying to select non existent layout type "
176 combo_->setCurrentItem(i);
180 void Toolbar::Pimpl::updateLayoutList(bool force)
182 // if we don't need an update, don't ...
183 if (combo_->count() && !force)
186 LyXTextClass const & tc =
187 textclasslist[owner_->buffer()->params.textclass];
189 combo_->setUpdatesEnabled(false);
193 LyXTextClass::const_iterator cit = tc.begin();
194 LyXTextClass::const_iterator end = tc.end();
195 for (; cit != end; ++cit) {
196 // ignore obsolete entries
197 if ((*cit)->obsoleted_by().empty())
198 combo_->insertItem(_((*cit)->name()).c_str());
201 // needed to recalculate size hint
203 combo_->setMinimumWidth(combo_->sizeHint().width());
206 combo_->setUpdatesEnabled(true);
211 void Toolbar::Pimpl::clearLayoutList()
217 void Toolbar::Pimpl::openLayoutList()
219 #if 0 // popup() is protected
225 void Toolbar::Pimpl::set(bool)
231 void Toolbar::Pimpl::add(int action, bool)
233 if (!toolbars_.size()) {
234 toolbars_.push_back(new QToolBar(owner_));
238 case ToolbarDefaults::SEPARATOR:
239 toolbars_.back()->addSeparator();
241 case ToolbarDefaults::NEWLINE:
242 toolbars_.push_back(new QToolBar(owner_));
244 case ToolbarDefaults::LAYOUTS: {
245 combo_ = new QComboBox(toolbars_.back());
246 QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
247 combo_->setSizePolicy(p);
248 combo_->setFocusPolicy(QWidget::TabFocus);
249 combo_->setMinimumWidth(combo_->sizeHint().width());
251 QObject::connect(combo_, SIGNAL(activated(const QString &)),
252 proxy_.get(), SLOT(layout_selected(const QString &)));
256 char const * tooltip = _(lyxaction.helpText(action)).c_str();
259 new QToolButton(getIconPixmap(action),
261 proxy_.get(), SLOT(button_selected()), toolbars_.back());
265 QToolTip::add(tb, tooltip);
272 void Toolbar::Pimpl::push(int)
275 lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
276 << nth << '\'' << endl;
278 if (nth <= 0 || nth >= int(toollist.size())) {
279 // item nth not found...
283 fl_trigger_object(toollist[nth - 1].icon);