2002-06-19 03:38:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file Toolbar_pimpl.C
|
|
|
|
|
* See the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes, larsbj@lyx.org
|
|
|
|
|
* \uathor John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "ToolbarDefaults.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "lyxtextclasslist.h"
|
|
|
|
|
#include "LyXAction.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2002-07-13 01:42:15 +00:00
|
|
|
|
QPixmap getIconPixmap(int action)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
|
|
|
|
string arg;
|
|
|
|
|
string xpm_name;
|
|
|
|
|
|
|
|
|
|
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 = LibFileSearch("images", xpm_name, "xpm");
|
|
|
|
|
|
|
|
|
|
if (!fullname.empty()) {
|
|
|
|
|
lyxerr[Debug::GUI] << "Full icon name is `"
|
|
|
|
|
<< fullname << "'" << endl;
|
2002-07-13 01:42:15 +00:00
|
|
|
|
return QPixmap(fullname.c_str());
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (act == LFUN_INSERT_MATH && !arg.empty()) {
|
2002-07-13 01:42:15 +00:00
|
|
|
|
#if 0 // FIXME: GUII
|
|
|
|
|
char const ** pixmap =
|
|
|
|
|
get_pixmap_from_symbol(arg.c_str(), 30, 30);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
if (pixmap) {
|
|
|
|
|
lyxerr[Debug::GUI] << "Using mathed-provided icon"
|
|
|
|
|
<< endl;
|
2002-07-13 01:42:15 +00:00
|
|
|
|
return QPixmap(pixmap);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2002-07-13 01:42:15 +00:00
|
|
|
|
}
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
|
|
lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
|
|
|
|
|
fullname = LibFileSearch("images", "unknown", "xpm");
|
|
|
|
|
if (!fullname.empty()) {
|
|
|
|
|
lyxerr[Debug::GUI] << "Using default `unknown' icon"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
2002-07-13 01:42:15 +00:00
|
|
|
|
return QPixmap(fullname.c_str());
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2002-07-11 01:01:38 +00:00
|
|
|
|
Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs &, int, int)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
: owner_(static_cast<QtView *>(o)),
|
|
|
|
|
combo_(0)
|
|
|
|
|
{
|
|
|
|
|
proxy_.reset(new ToolbarProxy(*this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Toolbar::Pimpl::~Pimpl()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbar::Pimpl::update()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
button->setToggleButton(true);
|
|
|
|
|
button->setOn(status.onoff(true));
|
|
|
|
|
button->setEnabled(!status.disabled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (combo_)
|
|
|
|
|
combo_->setEnabled(!owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbar::Pimpl::button_selected(QToolButton * button)
|
|
|
|
|
{
|
|
|
|
|
ButtonMap::const_iterator cit = map_.find(button);
|
|
|
|
|
|
|
|
|
|
if (cit == map_.end()) {
|
|
|
|
|
lyxerr << "non existent tool button selected !" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-18 20:15:29 +00:00
|
|
|
|
owner_->getLyXFunc()->dispatch(cit->second, true);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbar::Pimpl::changed_layout(string const & sel)
|
|
|
|
|
{
|
|
|
|
|
LyXTextClass const & tc =
|
|
|
|
|
textclasslist[owner_->buffer()->params.textclass];
|
|
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator end = tc.end();
|
|
|
|
|
for (LyXTextClass::const_iterator cit = tc.begin();
|
|
|
|
|
cit != end; ++cit) {
|
2002-07-11 01:01:38 +00:00
|
|
|
|
if (_((*cit)->name()) == sel) {
|
|
|
|
|
owner_->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
|
2002-06-19 03:38:44 +00:00
|
|
|
|
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];
|
|
|
|
|
|
2002-07-11 01:01:38 +00:00
|
|
|
|
string const & name = _(tc[layout]->name());
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < combo_->count(); ++i) {
|
|
|
|
|
if (name == combo_->text(i).latin1())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == combo_->count()) {
|
|
|
|
|
lyxerr << "Trying to select non existent layout type "
|
|
|
|
|
<< name << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
combo_->setCurrentItem(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbar::Pimpl::updateLayoutList(bool force)
|
|
|
|
|
{
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
combo_->clear();
|
|
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator cit = tc.begin();
|
|
|
|
|
LyXTextClass::const_iterator end = tc.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
|
// ignore obsolete entries
|
2002-07-11 01:01:38 +00:00
|
|
|
|
if ((*cit)->obsoleted_by().empty())
|
|
|
|
|
combo_->insertItem(_((*cit)->name()).c_str());
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// needed to recalculate size hint
|
|
|
|
|
combo_->hide();
|
|
|
|
|
combo_->setMinimumWidth(combo_->sizeHint().width());
|
|
|
|
|
combo_->show();
|
|
|
|
|
|
|
|
|
|
combo_->setUpdatesEnabled(true);
|
|
|
|
|
combo_->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbar::Pimpl::clearLayoutList()
|
|
|
|
|
{
|
|
|
|
|
combo_->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (!toolbars_.size()) {
|
|
|
|
|
toolbars_.push_back(new QToolBar(owner_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
case ToolbarDefaults::SEPARATOR:
|
|
|
|
|
toolbars_.back()->addSeparator();
|
|
|
|
|
break;
|
|
|
|
|
case ToolbarDefaults::NEWLINE:
|
|
|
|
|
toolbars_.push_back(new QToolBar(owner_));
|
|
|
|
|
break;
|
|
|
|
|
case ToolbarDefaults::LAYOUTS: {
|
|
|
|
|
combo_ = new QComboBox(toolbars_.back());
|
|
|
|
|
QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
|
combo_->setSizePolicy(p);
|
|
|
|
|
combo_->setFocusPolicy(QWidget::TabFocus);
|
|
|
|
|
combo_->setMinimumWidth(combo_->sizeHint().width());
|
|
|
|
|
|
|
|
|
|
QObject::connect(combo_, SIGNAL(activated(const QString &)),
|
|
|
|
|
proxy_.get(), SLOT(layout_selected(const QString &)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-07-13 01:42:15 +00:00
|
|
|
|
default: {
|
|
|
|
|
char const * tooltip = _(lyxaction.helpText(action)).c_str();
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
QToolButton * tb =
|
2002-07-13 01:42:15 +00:00
|
|
|
|
new QToolButton(getIconPixmap(action),
|
|
|
|
|
tooltip, tooltip,
|
2002-06-19 03:38:44 +00:00
|
|
|
|
proxy_.get(), SLOT(button_selected()), toolbars_.back());
|
|
|
|
|
|
|
|
|
|
map_[tb] = action;
|
|
|
|
|
|
2002-07-13 01:42:15 +00:00
|
|
|
|
QToolTip::add(tb, tooltip);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-07-13 01:42:15 +00:00
|
|
|
|
}
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|