2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
|
* \file qt4/GuiToolbar.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "gettext.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
|
#include "IconPalette.h"
|
2007-09-29 20:02:32 +00:00
|
|
|
|
#include "Layout.h"
|
2007-09-19 22:37:22 +00:00
|
|
|
|
#include "LyXFunc.h"
|
|
|
|
|
#include "ToolbarBackend.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
#include "GuiView.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiCommandBuffer.h"
|
|
|
|
|
#include "GuiToolbar.h"
|
2007-04-19 19:43:15 +00:00
|
|
|
|
#include "LyXAction.h"
|
2006-06-17 09:14:58 +00:00
|
|
|
|
#include "Action.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "qt_helpers.h"
|
2006-05-31 12:53:05 +00:00
|
|
|
|
#include "InsertTableWidget.h"
|
2007-09-19 22:37:22 +00:00
|
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/lstrings.h"
|
2007-10-03 22:28:53 +00:00
|
|
|
|
#include "support/lyxalgo.h" // sorted
|
2007-09-19 22:37:22 +00:00
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2007-04-19 19:43:15 +00:00
|
|
|
|
|
2007-04-19 20:29:27 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
using std::endl;
|
2007-10-03 22:28:53 +00:00
|
|
|
|
|
2007-04-19 20:29:27 +00:00
|
|
|
|
using support::FileName;
|
|
|
|
|
using support::libFileSearch;
|
|
|
|
|
using support::subst;
|
2007-10-03 22:28:53 +00:00
|
|
|
|
using support::compare;
|
|
|
|
|
|
2007-04-19 20:29:27 +00:00
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
namespace frontend {
|
|
|
|
|
|
2007-08-30 20:09:12 +00:00
|
|
|
|
static TextClass const & textClass(LyXView const & lv)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-08-30 20:14:33 +00:00
|
|
|
|
return lv.buffer()->params().getTextClass();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-28 22:53:00 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// GuiLayoutBox
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2007-10-01 21:26:25 +00:00
|
|
|
|
GuiLayoutBox::GuiLayoutBox(GuiViewBase & owner)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
: owner_(owner)
|
|
|
|
|
{
|
2007-10-01 21:26:25 +00:00
|
|
|
|
setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
|
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
|
|
|
setMinimumWidth(sizeHint().width());
|
|
|
|
|
setMaxVisibleItems(100);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-10-01 21:26:25 +00:00
|
|
|
|
QObject::connect(this, SIGNAL(activated(QString)),
|
2007-09-28 22:53:00 +00:00
|
|
|
|
this, SLOT(selected(QString)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiLayoutBox::set(docstring const & layout)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-08-30 20:09:12 +00:00
|
|
|
|
TextClass const & tc = textClass(owner_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-07-11 13:39:08 +00:00
|
|
|
|
QString const & name = toqstr(translateIfPossible(tc[layout]->name()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
int i = 0;
|
2007-10-01 21:26:25 +00:00
|
|
|
|
for (; i < count(); ++i) {
|
|
|
|
|
if (name == itemText(i))
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-01 21:26:25 +00:00
|
|
|
|
if (i == count()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
|
lyxerr << "Trying to select non existent layout type "
|
|
|
|
|
<< fromqstr(name) << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-01 21:26:25 +00:00
|
|
|
|
setCurrentIndex(i);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-01 20:45:50 +00:00
|
|
|
|
void GuiLayoutBox::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-08-30 20:09:12 +00:00
|
|
|
|
TextClass const & tc = textClass(owner_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-10-01 21:26:25 +00:00
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-04-29 19:53:54 +00:00
|
|
|
|
TextClass::const_iterator it = tc.begin();
|
|
|
|
|
TextClass::const_iterator const end = tc.end();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
// ignore obsolete entries
|
|
|
|
|
if ((*it)->obsoleted_by().empty())
|
2007-10-01 21:26:25 +00:00
|
|
|
|
addItem(toqstr(translateIfPossible((*it)->name())));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// needed to recalculate size hint
|
2007-10-01 21:26:25 +00:00
|
|
|
|
hide();
|
|
|
|
|
setMinimumWidth(sizeHint().width());
|
|
|
|
|
show();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-10-01 21:26:25 +00:00
|
|
|
|
setUpdatesEnabled(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-01 20:45:50 +00:00
|
|
|
|
|
2007-10-01 21:08:07 +00:00
|
|
|
|
void GuiLayoutBox::selected(const QString & str)
|
2007-10-01 20:45:50 +00:00
|
|
|
|
{
|
2007-10-01 21:08:07 +00:00
|
|
|
|
owner_.setFocus();
|
|
|
|
|
TextClass const & tc = owner_.buffer()->params().getTextClass();
|
|
|
|
|
docstring const name = qstring_to_ucs4(str);
|
2007-10-01 20:45:50 +00:00
|
|
|
|
TextClass::const_iterator it = tc.begin();
|
|
|
|
|
TextClass::const_iterator const end = tc.end();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
docstring const & itname = (*it)->name();
|
|
|
|
|
if (translateIfPossible(itname) == name) {
|
|
|
|
|
FuncRequest const func(LFUN_LAYOUT, itname,
|
|
|
|
|
FuncRequest::TOOLBAR);
|
2007-10-01 21:08:07 +00:00
|
|
|
|
owner_.dispatch(func);
|
2007-10-01 20:45:50 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lyxerr << "ERROR (layoutSelected): layout not found!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-09-28 22:53:00 +00:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// GuiToolbar
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiViewBase & owner)
|
2007-09-28 22:53:00 +00:00
|
|
|
|
: QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner),
|
|
|
|
|
layout_(0), command_buffer_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
// give visual separation between adjacent toolbars
|
2006-09-10 11:03:21 +00:00
|
|
|
|
addSeparator();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-10-31 14:39:16 +00:00
|
|
|
|
// TODO: save toolbar position
|
|
|
|
|
setMovable(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
ToolbarInfo::item_iterator it = tbinfo.items.begin();
|
|
|
|
|
ToolbarInfo::item_iterator end = tbinfo.items.end();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
for (; it != end; ++it)
|
2007-04-19 19:43:15 +00:00
|
|
|
|
add(*it);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-28 22:53:00 +00:00
|
|
|
|
Action * GuiToolbar::addItem(ToolbarItem const & item)
|
|
|
|
|
{
|
2007-09-28 23:14:33 +00:00
|
|
|
|
Action * act = new Action(owner_,
|
|
|
|
|
getIcon(item.func_, false).c_str(),
|
|
|
|
|
toqstr(item.label_), item.func_, toqstr(item.label_));
|
2007-09-28 22:53:00 +00:00
|
|
|
|
actions_.append(act);
|
|
|
|
|
return act;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiToolbar::add(ToolbarItem const & item)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-04-19 19:43:15 +00:00
|
|
|
|
switch (item.type_) {
|
|
|
|
|
case ToolbarItem::SEPARATOR:
|
2006-09-10 11:03:21 +00:00
|
|
|
|
addSeparator();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
2007-04-19 19:43:15 +00:00
|
|
|
|
case ToolbarItem::LAYOUTS:
|
2007-10-01 21:26:25 +00:00
|
|
|
|
layout_ = new GuiLayoutBox(owner_);
|
|
|
|
|
addWidget(layout_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
2007-04-19 19:43:15 +00:00
|
|
|
|
case ToolbarItem::MINIBUFFER:
|
2007-08-31 05:53:55 +00:00
|
|
|
|
command_buffer_ = new GuiCommandBuffer(&owner_);
|
2007-08-24 07:13:07 +00:00
|
|
|
|
addWidget(command_buffer_);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
/// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
|
2006-09-10 11:03:21 +00:00
|
|
|
|
//setHorizontalStretchable(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
2007-04-19 19:43:15 +00:00
|
|
|
|
case ToolbarItem::TABLEINSERT: {
|
2006-05-31 12:53:05 +00:00
|
|
|
|
QToolButton * tb = new QToolButton;
|
|
|
|
|
tb->setCheckable(true);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
tb->setIcon(QPixmap(toqstr(getIcon(FuncRequest(LFUN_TABULAR_INSERT)))));
|
2007-04-22 10:05:17 +00:00
|
|
|
|
tb->setToolTip(qt_(to_ascii(item.label_)));
|
|
|
|
|
tb->setStatusTip(qt_(to_ascii(item.label_)));
|
2007-05-06 07:26:51 +00:00
|
|
|
|
tb->setText(qt_(to_ascii(item.label_)));
|
2006-06-01 20:34:22 +00:00
|
|
|
|
InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
|
2007-01-17 13:06:16 +00:00
|
|
|
|
connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
|
2006-05-31 12:53:05 +00:00
|
|
|
|
connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
|
|
|
|
|
connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
|
2006-09-10 11:03:21 +00:00
|
|
|
|
addWidget(tb);
|
2006-05-31 12:53:05 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-04-19 20:29:27 +00:00
|
|
|
|
case ToolbarItem::ICONPALETTE: {
|
|
|
|
|
QToolButton * tb = new QToolButton(this);
|
2007-04-22 10:05:17 +00:00
|
|
|
|
tb->setToolTip(qt_(to_ascii(item.label_)));
|
|
|
|
|
tb->setStatusTip(qt_(to_ascii(item.label_)));
|
|
|
|
|
tb->setText(qt_(to_ascii(item.label_)));
|
2007-09-28 22:53:00 +00:00
|
|
|
|
connect(this, SIGNAL(iconSizeChanged(QSize)),
|
|
|
|
|
tb, SLOT(setIconSize(QSize)));
|
2007-04-19 22:01:28 +00:00
|
|
|
|
IconPalette * panel = new IconPalette(tb);
|
2007-06-21 16:14:52 +00:00
|
|
|
|
panel->setWindowTitle(qt_(to_ascii(item.label_)));
|
2007-04-19 20:29:27 +00:00
|
|
|
|
connect(this, SIGNAL(updated()), panel, SLOT(updateParent()));
|
2007-07-09 20:33:32 +00:00
|
|
|
|
ToolbarInfo const * tbinfo = toolbarbackend.getDefinedToolbarInfo(item.name_);
|
|
|
|
|
if (!tbinfo) {
|
|
|
|
|
lyxerr << "Unknown toolbar " << item.name_ << endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ToolbarInfo::item_iterator it = tbinfo->items.begin();
|
|
|
|
|
ToolbarInfo::item_iterator const end = tbinfo->items.end();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
for (; it != end; ++it)
|
2007-04-25 16:39:21 +00:00
|
|
|
|
if (!getStatus(it->func_).unknown()) {
|
2007-09-28 22:53:00 +00:00
|
|
|
|
panel->addButton(addItem(*it));
|
2007-04-19 20:29:27 +00:00
|
|
|
|
// use the icon of first action for the toolbar button
|
2007-07-09 20:33:32 +00:00
|
|
|
|
if (it == tbinfo->items.begin())
|
2007-04-19 20:29:27 +00:00
|
|
|
|
tb->setIcon(QPixmap(getIcon(it->func_).c_str()));
|
|
|
|
|
}
|
2007-06-17 17:55:36 +00:00
|
|
|
|
tb->setCheckable(true);
|
2007-04-19 20:29:27 +00:00
|
|
|
|
connect(tb, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
|
|
|
|
|
connect(panel, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
|
|
|
|
|
addWidget(tb);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ToolbarItem::POPUPMENU: {
|
|
|
|
|
QToolButton * tb = new QToolButton;
|
|
|
|
|
tb->setPopupMode(QToolButton::InstantPopup);
|
2007-04-22 10:05:17 +00:00
|
|
|
|
tb->setToolTip(qt_(to_ascii(item.label_)));
|
|
|
|
|
tb->setStatusTip(qt_(to_ascii(item.label_)));
|
|
|
|
|
tb->setText(qt_(to_ascii(item.label_)));
|
2007-08-30 20:09:12 +00:00
|
|
|
|
FileName icon_path = libFileSearch("images/math", item.name_, "png");
|
2007-04-19 20:29:27 +00:00
|
|
|
|
tb->setIcon(QIcon(toqstr(icon_path.absFilename())));
|
2007-09-28 22:53:00 +00:00
|
|
|
|
connect(this, SIGNAL(iconSizeChanged(QSize)),
|
|
|
|
|
tb, SLOT(setIconSize(QSize)));
|
2007-04-19 20:29:27 +00:00
|
|
|
|
|
2007-04-22 10:05:17 +00:00
|
|
|
|
ButtonMenu * m = new ButtonMenu(qt_(to_ascii(item.label_)), tb);
|
2007-06-17 17:55:36 +00:00
|
|
|
|
m->setWindowTitle(qt_(to_ascii(item.label_)));
|
|
|
|
|
m->setTearOffEnabled(true);
|
2007-04-19 20:29:27 +00:00
|
|
|
|
connect(this, SIGNAL(updated()), m, SLOT(updateParent()));
|
2007-07-09 20:33:32 +00:00
|
|
|
|
ToolbarInfo const * tbinfo = toolbarbackend.getDefinedToolbarInfo(item.name_);
|
|
|
|
|
if (!tbinfo) {
|
|
|
|
|
lyxerr << "Unknown toolbar " << item.name_ << endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ToolbarInfo::item_iterator it = tbinfo->items.begin();
|
|
|
|
|
ToolbarInfo::item_iterator const end = tbinfo->items.end();
|
2007-04-19 20:29:27 +00:00
|
|
|
|
for (; it != end; ++it)
|
2007-09-28 22:53:00 +00:00
|
|
|
|
if (!getStatus(it->func_).unknown())
|
|
|
|
|
m->add(addItem(*it));
|
2007-04-19 20:29:27 +00:00
|
|
|
|
tb->setMenu(m);
|
|
|
|
|
addWidget(tb);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ToolbarItem::COMMAND: {
|
2007-09-28 22:53:00 +00:00
|
|
|
|
if (!getStatus(item.func_).unknown())
|
|
|
|
|
addAction(addItem(item));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
2006-05-31 12:53:05 +00:00
|
|
|
|
}
|
2007-04-19 20:29:27 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
{
|
2007-04-21 17:38:43 +00:00
|
|
|
|
// if tbinfo.state == auto *do not* set on/off
|
|
|
|
|
if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
|
2007-08-31 05:53:55 +00:00
|
|
|
|
if (GuiToolbar::isVisible())
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.state = ToolbarSection::ToolbarInfo::ON;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
else
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
//
|
2006-11-02 16:01:36 +00:00
|
|
|
|
// no need to save it here.
|
|
|
|
|
Qt::ToolBarArea loc = owner_.toolBarArea(this);
|
|
|
|
|
|
|
|
|
|
if (loc == Qt::TopToolBarArea)
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
else if (loc == Qt::BottomToolBarArea)
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
else if (loc == Qt::RightToolBarArea)
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
else if (loc == Qt::LeftToolBarArea)
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
else
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
|
|
|
|
// save toolbar position. They are not used to restore toolbar position
|
2007-01-27 20:54:17 +00:00
|
|
|
|
// now because move(x,y) does not work for toolbar.
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.posx = pos().x();
|
|
|
|
|
tbinfo.posy = pos().y();
|
2006-11-02 16:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-01 20:45:50 +00:00
|
|
|
|
void GuiToolbar::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-10-01 09:19:09 +00:00
|
|
|
|
// update visible toolbars only
|
|
|
|
|
if (!isVisible())
|
|
|
|
|
return;
|
2006-10-20 19:40:02 +00:00
|
|
|
|
// This is a speed bottleneck because this is called on every keypress
|
|
|
|
|
// and update calls getStatus, which copies the cursor at least two times
|
2007-09-28 22:53:00 +00:00
|
|
|
|
for (int i = 0; i < actions_.size(); ++i)
|
2007-09-28 21:41:56 +00:00
|
|
|
|
actions_[i]->update();
|
2006-05-31 12:53:05 +00:00
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
|
updated();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-03 22:28:53 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct PngMap {
|
|
|
|
|
char const * key;
|
|
|
|
|
char const * value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(PngMap const & lhs, PngMap const & rhs)
|
|
|
|
|
{
|
|
|
|
|
return compare(lhs.key, rhs.key) < 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompareKey {
|
|
|
|
|
public:
|
|
|
|
|
CompareKey(string const & name) : name_(name) {}
|
|
|
|
|
bool operator()(PngMap const & other) const { return other.key == name_; }
|
|
|
|
|
private:
|
|
|
|
|
string const name_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PngMap sorted_png_map[] = {
|
|
|
|
|
{ "Bumpeq", "bumpeq2" },
|
|
|
|
|
{ "Cap", "cap2" },
|
|
|
|
|
{ "Cup", "cup2" },
|
|
|
|
|
{ "Delta", "delta2" },
|
|
|
|
|
{ "Downarrow", "downarrow2" },
|
|
|
|
|
{ "Gamma", "gamma2" },
|
|
|
|
|
{ "Lambda", "lambda2" },
|
|
|
|
|
{ "Leftarrow", "leftarrow2" },
|
|
|
|
|
{ "Leftrightarrow", "leftrightarrow2" },
|
|
|
|
|
{ "Longleftarrow", "longleftarrow2" },
|
|
|
|
|
{ "Longleftrightarrow", "longleftrightarrow2" },
|
|
|
|
|
{ "Longrightarrow", "longrightarrow2" },
|
|
|
|
|
{ "Omega", "omega2" },
|
|
|
|
|
{ "Phi", "phi2" },
|
|
|
|
|
{ "Pi", "pi2" },
|
|
|
|
|
{ "Psi", "psi2" },
|
|
|
|
|
{ "Rightarrow", "rightarrow2" },
|
|
|
|
|
{ "Sigma", "sigma2" },
|
|
|
|
|
{ "Subset", "subset2" },
|
|
|
|
|
{ "Supset", "supset2" },
|
|
|
|
|
{ "Theta", "theta2" },
|
|
|
|
|
{ "Uparrow", "uparrow2" },
|
|
|
|
|
{ "Updownarrow", "updownarrow2" },
|
|
|
|
|
{ "Upsilon", "upsilon2" },
|
|
|
|
|
{ "Vdash", "vdash3" },
|
|
|
|
|
{ "Xi", "xi2" },
|
|
|
|
|
{ "nLeftarrow", "nleftarrow2" },
|
|
|
|
|
{ "nLeftrightarrow", "nleftrightarrow2" },
|
|
|
|
|
{ "nRightarrow", "nrightarrow2" },
|
|
|
|
|
{ "nVDash", "nvdash3" },
|
|
|
|
|
{ "nvDash", "nvdash2" },
|
|
|
|
|
{ "textrm \\AA", "textrm_AA"},
|
|
|
|
|
{ "textrm \\O", "textrm_Oe"},
|
|
|
|
|
{ "vDash", "vdash2" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const find_png(string const & name)
|
2007-04-19 19:43:15 +00:00
|
|
|
|
{
|
2007-10-03 22:28:53 +00:00
|
|
|
|
PngMap const * const begin = sorted_png_map;
|
|
|
|
|
PngMap const * const end = begin + nr_sorted_png_map;
|
|
|
|
|
BOOST_ASSERT(sorted(begin, end));
|
|
|
|
|
|
|
|
|
|
PngMap const * const it = std::find_if(begin, end, CompareKey(name));
|
|
|
|
|
|
|
|
|
|
string png_name;
|
|
|
|
|
if (it != end)
|
|
|
|
|
png_name = it->value;
|
|
|
|
|
else {
|
|
|
|
|
png_name = subst(name, "_", "underscore");
|
|
|
|
|
png_name = subst(png_name, ' ', '_');
|
|
|
|
|
|
|
|
|
|
// This way we can have "math-delim { }" on the toolbar.
|
|
|
|
|
png_name = subst(png_name, "(", "lparen");
|
|
|
|
|
png_name = subst(png_name, ")", "rparen");
|
|
|
|
|
png_name = subst(png_name, "[", "lbracket");
|
|
|
|
|
png_name = subst(png_name, "]", "rbracket");
|
|
|
|
|
png_name = subst(png_name, "{", "lbrace");
|
|
|
|
|
png_name = subst(png_name, "}", "rbrace");
|
|
|
|
|
png_name = subst(png_name, "|", "bars");
|
|
|
|
|
png_name = subst(png_name, ",", "thinspace");
|
|
|
|
|
png_name = subst(png_name, ":", "mediumspace");
|
|
|
|
|
png_name = subst(png_name, ";", "thickspace");
|
|
|
|
|
png_name = subst(png_name, "!", "negthinspace");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LYXERR(Debug::GUI) << "find_png(" << name << ")\n"
|
|
|
|
|
<< "Looking for math PNG called \""
|
|
|
|
|
<< png_name << '"' << std::endl;
|
|
|
|
|
|
|
|
|
|
return libFileSearch("images/math/", png_name, "png").absFilename();
|
|
|
|
|
}
|
2007-04-19 19:43:15 +00:00
|
|
|
|
|
2007-10-03 22:28:53 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const getIcon(FuncRequest const & f, bool unknown)
|
|
|
|
|
{
|
2007-04-19 19:43:15 +00:00
|
|
|
|
string fullname;
|
|
|
|
|
|
|
|
|
|
switch (f.action) {
|
|
|
|
|
case LFUN_MATH_INSERT:
|
|
|
|
|
if (!f.argument().empty())
|
2007-08-30 20:09:12 +00:00
|
|
|
|
fullname = find_png(to_utf8(f.argument()).substr(1));
|
2007-04-19 19:43:15 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
|
case LFUN_MATH_BIGDELIM:
|
2007-08-30 20:09:12 +00:00
|
|
|
|
fullname = find_png(to_utf8(f.argument()));
|
2007-04-19 19:43:15 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
string const name = lyxaction.getActionName(f.action);
|
2007-08-30 20:09:12 +00:00
|
|
|
|
string png_name = name;
|
2007-04-19 19:43:15 +00:00
|
|
|
|
|
|
|
|
|
if (!f.argument().empty())
|
2007-08-30 20:09:12 +00:00
|
|
|
|
png_name = subst(name + ' ' + to_utf8(f.argument()), ' ', '_');
|
2007-04-19 19:43:15 +00:00
|
|
|
|
|
2007-08-30 20:09:12 +00:00
|
|
|
|
fullname = libFileSearch("images", png_name, "png").absFilename();
|
2007-04-19 19:43:15 +00:00
|
|
|
|
|
|
|
|
|
if (fullname.empty()) {
|
|
|
|
|
// try without the argument
|
2007-08-30 20:09:12 +00:00
|
|
|
|
fullname = libFileSearch("images", name, "png").absFilename();
|
2007-04-19 19:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fullname.empty()) {
|
|
|
|
|
LYXERR(Debug::GUI) << "Full icon name is `"
|
|
|
|
|
<< fullname << '\'' << endl;
|
|
|
|
|
return fullname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LYXERR(Debug::GUI) << "Cannot find icon for command \""
|
|
|
|
|
<< lyxaction.getActionName(f.action)
|
|
|
|
|
<< '(' << to_utf8(f.argument()) << ")\"" << endl;
|
2007-04-19 20:29:27 +00:00
|
|
|
|
if (unknown)
|
2007-08-30 20:09:12 +00:00
|
|
|
|
return libFileSearch("images", "unknown", "png").absFilename();
|
2007-04-19 20:29:27 +00:00
|
|
|
|
else
|
|
|
|
|
return string();
|
2007-04-19 19:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiToolbar_moc.cpp"
|