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 "LyXAction.h"
24 #include "support/LAssert.h"
25 #include "support/filetools.h"
26 #include "support/lstrings.h"
30 #include "Toolbar_pimpl.h"
33 #include <qcombobox.h>
35 #include <qsizepolicy.h>
39 extern LyXAction lyxaction;
43 QPixmap getIconPixmap(int action)
48 const kb_action act = lyxaction.retrieveActionArg(action, arg);
49 string const name = lyxaction.getActionName(act);
51 xpm_name = subst(name + ' ' + arg, ' ','_');
55 string fullname = LibFileSearch("images", xpm_name, "xpm");
57 if (!fullname.empty()) {
58 lyxerr[Debug::GUI] << "Full icon name is `"
59 << fullname << "'" << endl;
60 return QPixmap(fullname.c_str());
63 if (act == LFUN_INSERT_MATH && !arg.empty()) {
65 char const ** pixmap =
66 get_pixmap_from_symbol(arg.c_str(), 30, 30);
68 lyxerr[Debug::GUI] << "Using mathed-provided icon"
70 return QPixmap(pixmap);
75 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
76 fullname = LibFileSearch("images", "unknown", "xpm");
77 if (!fullname.empty()) {
78 lyxerr[Debug::GUI] << "Using default `unknown' icon"
81 return QPixmap(fullname.c_str());
87 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs &, int, int)
88 : owner_(static_cast<QtView *>(o)),
91 proxy_.reset(new ToolbarProxy(*this));
95 Toolbar::Pimpl::~Pimpl()
100 void Toolbar::Pimpl::update()
102 ButtonMap::const_iterator p = map_.begin();
103 ButtonMap::const_iterator end = map_.end();
105 for (; p != end; ++p) {
106 QToolButton * button = p->first;
107 int action = p->second;
109 FuncStatus const status =
110 owner_->getLyXFunc()->getStatus(action);
112 button->setToggleButton(true);
113 button->setOn(status.onoff(true));
114 button->setEnabled(!status.disabled());
118 combo_->setEnabled(!owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled());
122 void Toolbar::Pimpl::button_selected(QToolButton * button)
124 ButtonMap::const_iterator cit = map_.find(button);
126 if (cit == map_.end()) {
127 lyxerr << "non existent tool button selected !" << endl;
131 owner_->getLyXFunc()->dispatch(cit->second, true);
135 void Toolbar::Pimpl::changed_layout(string const & sel)
137 LyXTextClass const & tc =
138 owner_->buffer()->params.getLyXTextClass();
140 LyXTextClass::const_iterator end = tc.end();
141 for (LyXTextClass::const_iterator cit = tc.begin();
143 if (_((*cit)->name()) == sel) {
144 owner_->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
148 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
153 void Toolbar::Pimpl::setLayout(string const & layout)
155 LyXTextClass const & tc =
156 owner_->buffer()->params.getLyXTextClass();
158 string const & name = _(tc[layout]->name());
162 for (i = 0; i < combo_->count(); ++i) {
163 if (name == combo_->text(i).latin1())
167 if (i == combo_->count()) {
168 lyxerr << "Trying to select non existent layout type "
173 combo_->setCurrentItem(i);
177 void Toolbar::Pimpl::updateLayoutList(bool force)
179 // if we don't need an update, don't ...
180 if (combo_->count() && !force)
183 LyXTextClass const & tc =
184 owner_->buffer()->params.getLyXTextClass();
186 combo_->setUpdatesEnabled(false);
190 LyXTextClass::const_iterator cit = tc.begin();
191 LyXTextClass::const_iterator end = tc.end();
192 for (; cit != end; ++cit) {
193 // ignore obsolete entries
194 if ((*cit)->obsoleted_by().empty())
195 combo_->insertItem(_((*cit)->name()).c_str());
198 // needed to recalculate size hint
200 combo_->setMinimumWidth(combo_->sizeHint().width());
203 combo_->setUpdatesEnabled(true);
208 void Toolbar::Pimpl::clearLayoutList()
214 void Toolbar::Pimpl::openLayoutList()
216 #if 0 // popup() is protected
222 void Toolbar::Pimpl::set(bool)
228 void Toolbar::Pimpl::add(int action, bool)
230 if (!toolbars_.size()) {
231 toolbars_.push_back(new QToolBar(owner_));
235 case ToolbarDefaults::SEPARATOR:
236 toolbars_.back()->addSeparator();
238 case ToolbarDefaults::NEWLINE:
239 toolbars_.push_back(new QToolBar(owner_));
241 case ToolbarDefaults::LAYOUTS: {
242 combo_ = new QComboBox(toolbars_.back());
243 QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
244 combo_->setSizePolicy(p);
245 combo_->setFocusPolicy(QWidget::TabFocus);
246 combo_->setMinimumWidth(combo_->sizeHint().width());
248 QObject::connect(combo_, SIGNAL(activated(const QString &)),
249 proxy_.get(), SLOT(layout_selected(const QString &)));
253 char const * tooltip = _(lyxaction.helpText(action)).c_str();
256 new QToolButton(getIconPixmap(action),
258 proxy_.get(), SLOT(button_selected()), toolbars_.back());
262 QToolTip::add(tb, tooltip);
269 void Toolbar::Pimpl::push(int)
272 lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
273 << nth << '\'' << endl;
275 if (nth <= 0 || nth >= int(toollist.size())) {
276 // item nth not found...
280 fl_trigger_object(toollist[nth - 1].icon);