/**
- * \file Toolbar_pimpl.C
- * See the file COPYING.
+ * \file qt2/Toolbar_pimpl.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Lars Gullik Bjønnes, larsbj@lyx.org
- * \uathor John Levon <moz@compsoc.man.ac.uk>
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "FuncStatus.h"
#include "BufferView.h"
#include "buffer.h"
-#include "lyxtextclasslist.h"
#include "LyXAction.h"
-#include "MathsSymbols.h"
#include "gettext.h"
-#include "Tooltips.h"
#include "support/LAssert.h"
#include "support/filetools.h"
-#include "support/lstrings.h"
+#include "support/lstrings.h"
+
+#include "ControlMath.h"
+
+#include <boost/tuple/tuple.hpp>
#include "QtView.h"
-
#include "Toolbar_pimpl.h"
-
+
#include <qtoolbar.h>
#include <qcombobox.h>
#include <qtooltip.h>
#include <qsizepolicy.h>
-
-using std::endl;
-extern LyXAction lyxaction;
+using std::endl;
namespace {
-
-string const getPixmap(int action)
+
+QPixmap getIconPixmap(int action)
{
- string arg;
- string xpm_name;
+ FuncRequest f = lyxaction.retrieveActionArg(action);
- const kb_action act = lyxaction.retrieveActionArg(action, arg);
- string const name = lyxaction.getActionName(act);
- if (!arg.empty())
- xpm_name = subst(name + ' ' + arg, ' ','_');
- else
- xpm_name = name;
+ string fullname;
- string fullname = LibFileSearch("images", xpm_name, "xpm");
+ if (f.action == LFUN_INSERT_MATH && !f.argument.empty()) {
+ fullname = find_xpm(f.argument.substr(1));
+ } else {
+ string const name = lyxaction.getActionName(f.action);
+ string xpm_name(name);
- if (!fullname.empty()) {
- lyxerr[Debug::GUI] << "Full icon name is `"
- << fullname << "'" << endl;
- return fullname;
+ if (!f.argument.empty())
+ xpm_name = subst(name + ' ' + f.argument, ' ','_');
+
+ fullname = LibFileSearch("images", xpm_name, "xpm");
}
-#if 0 // FIXME
- if (act == LFUN_INSERT_MATH && !arg.empty()) {
- char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
- buttonwidth,
- height);
- if (pixmap) {
- lyxerr[Debug::GUI] << "Using mathed-provided icon"
- << endl;
- fl_set_pixmapbutton_data(obj,
- const_cast<char **>(pixmap));
- return;
- }
+
+ if (!fullname.empty()) {
+ lyxerr[Debug::GUI] << "Full icon name is `"
+ << fullname << '\'' << endl;
+ return QPixmap(fullname.c_str());
}
-#endif
-
- lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
+
+ lyxerr << "Unable to find icon `" << fullname << '\'' << endl;
fullname = LibFileSearch("images", "unknown", "xpm");
if (!fullname.empty()) {
- lyxerr[Debug::GUI] << "Using default `unknown' icon"
- << endl;
+ lyxerr[Debug::GUI] << "Using default `unknown' icon"
+ << endl;
}
- return fullname;
+ return QPixmap(fullname.c_str());
}
} // namespace anon
-
-Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs &, int, int)
- : owner_(static_cast<QtView *>(o)),
- combo_(0)
-{
- proxy_.reset(new ToolbarProxy(*this));
-}
-
-Toolbar::Pimpl::~Pimpl()
-{
-}
+class QLComboBox : public QComboBox {
+public:
+ QLComboBox(QWidget * parent) : QComboBox(parent) {}
+ void popup() { QComboBox::popup(); }
+};
-void Toolbar::Pimpl::activate()
+Toolbar::Pimpl::Pimpl(LyXView * o, int, int)
+ : owner_(static_cast<QtView *>(o)),
+ combo_(0)
{
- // FIXME
+ proxy_.reset(new ToolbarProxy(*this));
}
-void Toolbar::Pimpl::deactivate()
+Toolbar::Pimpl::~Pimpl()
{
- // FIXME
}
{
ButtonMap::const_iterator p = map_.begin();
ButtonMap::const_iterator end = map_.end();
-
+
for (; p != end; ++p) {
QToolButton * button = p->first;
int action = p->second;
-
- FuncStatus const status =
- owner_->getLyXFunc()->getStatus(action);
-
+
+ FuncStatus const status =
+ owner_->getLyXFunc().getStatus(action);
+
button->setToggleButton(true);
button->setOn(status.onoff(true));
button->setEnabled(!status.disabled());
}
if (combo_)
- combo_->setEnabled(!owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled());
+ combo_->setEnabled(!owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled());
}
return;
}
- owner_->getLyXFunc()->verboseDispatch(cit->second, true);
+ owner_->getLyXFunc().dispatch(cit->second, true);
}
-
+
void Toolbar::Pimpl::changed_layout(string const & sel)
{
+ owner_->centralWidget()->setFocus();
+
LyXTextClass const & tc =
- textclasslist[owner_->buffer()->params.textclass];
-
+ owner_->buffer()->params.getLyXTextClass();
+
LyXTextClass::const_iterator end = tc.end();
for (LyXTextClass::const_iterator cit = tc.begin();
cit != end; ++cit) {
if (_((*cit)->name()) == sel) {
- owner_->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
+ owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
return;
}
}
lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
<< endl;
}
-
+
void Toolbar::Pimpl::setLayout(string const & layout)
{
LyXTextClass const & tc =
- textclasslist[owner_->buffer()->params.textclass];
-
+ owner_->buffer()->params.getLyXTextClass();
+
string const & name = _(tc[layout]->name());
-
- int i;
-
- for (i = 0; i < combo_->count(); ++i) {
+
+ int i = 0;
+ for (; i < combo_->count(); ++i) {
if (name == combo_->text(i).latin1())
break;
}
void Toolbar::Pimpl::updateLayoutList(bool force)
{
- // if we don't need an update, don't ...
+ // if we don't need an update, don't ...
if (combo_->count() && !force)
return;
-
+
LyXTextClass const & tc =
- textclasslist[owner_->buffer()->params.textclass];
-
- combo_->setUpdatesEnabled(false);
-
+ owner_->buffer()->params.getLyXTextClass();
+
+ combo_->setUpdatesEnabled(false);
+
combo_->clear();
-
+
LyXTextClass::const_iterator cit = tc.begin();
LyXTextClass::const_iterator end = tc.end();
for (; cit != end; ++cit) {
void Toolbar::Pimpl::openLayoutList()
{
-#if 0 // popup() is protected
combo_->popup();
-#endif
}
-void Toolbar::Pimpl::set(bool)
-{
-// FIXME: ???
-}
-
-
-void Toolbar::Pimpl::add(int action, bool)
+void Toolbar::Pimpl::add(int action)
{
if (!toolbars_.size()) {
toolbars_.push_back(new QToolBar(owner_));
}
-
+
switch (action) {
case ToolbarDefaults::SEPARATOR:
toolbars_.back()->addSeparator();
toolbars_.push_back(new QToolBar(owner_));
break;
case ToolbarDefaults::LAYOUTS: {
- combo_ = new QComboBox(toolbars_.back());
+ combo_ = new QLComboBox(toolbars_.back());
QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
combo_->setSizePolicy(p);
- combo_->setFocusPolicy(QWidget::TabFocus);
+ combo_->setFocusPolicy(QWidget::ClickFocus);
combo_->setMinimumWidth(combo_->sizeHint().width());
-
+
QObject::connect(combo_, SIGNAL(activated(const QString &)),
proxy_.get(), SLOT(layout_selected(const QString &)));
break;
}
- default:
- QToolButton * tb =
- new QToolButton(QPixmap(getPixmap(action).c_str()),
- "FIXME", "FIXME",
+ default: {
+ QToolButton * tb =
+ new QToolButton(getIconPixmap(action),
+ _(lyxaction.helpText(action)).c_str(), "",
proxy_.get(), SLOT(button_selected()), toolbars_.back());
map_[tb] = action;
-
- QToolTip::add(tb, _(lyxaction.helpText(action)).c_str());
break;
}
-}
-
-
-void Toolbar::Pimpl::push(int)
-{
-#if 0
- lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
- << nth << '\'' << endl;
-
- if (nth <= 0 || nth >= int(toollist.size())) {
- // item nth not found...
- return;
}
-
- fl_trigger_object(toollist[nth - 1].icon);
-#endif
}