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 class QLComboBox : public QComboBox {
89 QLComboBox(QWidget * parent) : QComboBox(parent) {}
90 void popup() { QComboBox::popup(); }
94 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs &, int, int)
95 : owner_(static_cast<QtView *>(o)),
98 proxy_.reset(new ToolbarProxy(*this));
102 Toolbar::Pimpl::~Pimpl()
107 void Toolbar::Pimpl::update()
109 ButtonMap::const_iterator p = map_.begin();
110 ButtonMap::const_iterator end = map_.end();
112 for (; p != end; ++p) {
113 QToolButton * button = p->first;
114 int action = p->second;
116 FuncStatus const status =
117 owner_->getLyXFunc()->getStatus(action);
119 button->setToggleButton(true);
120 button->setOn(status.onoff(true));
121 button->setEnabled(!status.disabled());
125 combo_->setEnabled(!owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled());
129 void Toolbar::Pimpl::button_selected(QToolButton * button)
131 ButtonMap::const_iterator cit = map_.find(button);
133 if (cit == map_.end()) {
134 lyxerr << "non existent tool button selected !" << endl;
138 owner_->getLyXFunc()->dispatch(cit->second, true);
142 void Toolbar::Pimpl::changed_layout(string const & sel)
144 LyXTextClass const & tc =
145 owner_->buffer()->params.getLyXTextClass();
147 LyXTextClass::const_iterator end = tc.end();
148 for (LyXTextClass::const_iterator cit = tc.begin();
150 if (_((*cit)->name()) == sel) {
151 owner_->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
155 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
160 void Toolbar::Pimpl::setLayout(string const & layout)
162 LyXTextClass const & tc =
163 owner_->buffer()->params.getLyXTextClass();
165 string const & name = _(tc[layout]->name());
169 for (i = 0; i < combo_->count(); ++i) {
170 if (name == combo_->text(i).latin1())
174 if (i == combo_->count()) {
175 lyxerr << "Trying to select non existent layout type "
180 combo_->setCurrentItem(i);
184 void Toolbar::Pimpl::updateLayoutList(bool force)
186 // if we don't need an update, don't ...
187 if (combo_->count() && !force)
190 LyXTextClass const & tc =
191 owner_->buffer()->params.getLyXTextClass();
193 combo_->setUpdatesEnabled(false);
197 LyXTextClass::const_iterator cit = tc.begin();
198 LyXTextClass::const_iterator end = tc.end();
199 for (; cit != end; ++cit) {
200 // ignore obsolete entries
201 if ((*cit)->obsoleted_by().empty())
202 combo_->insertItem(_((*cit)->name()).c_str());
205 // needed to recalculate size hint
207 combo_->setMinimumWidth(combo_->sizeHint().width());
210 combo_->setUpdatesEnabled(true);
215 void Toolbar::Pimpl::clearLayoutList()
221 void Toolbar::Pimpl::openLayoutList()
227 void Toolbar::Pimpl::add(int action)
229 if (!toolbars_.size()) {
230 toolbars_.push_back(new QToolBar(owner_));
234 case ToolbarDefaults::SEPARATOR:
235 toolbars_.back()->addSeparator();
237 case ToolbarDefaults::NEWLINE:
238 toolbars_.push_back(new QToolBar(owner_));
240 case ToolbarDefaults::LAYOUTS: {
241 combo_ = new QLComboBox(toolbars_.back());
242 QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
243 combo_->setSizePolicy(p);
244 combo_->setFocusPolicy(QWidget::ClickFocus);
245 combo_->setMinimumWidth(combo_->sizeHint().width());
247 QObject::connect(combo_, SIGNAL(activated(const QString &)),
248 proxy_.get(), SLOT(layout_selected(const QString &)));
253 new QToolButton(getIconPixmap(action),
254 _(lyxaction.helpText(action)).c_str(), "",
255 proxy_.get(), SLOT(button_selected()), toolbars_.back());