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"
|
2007-11-20 22:03:56 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "Cursor.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/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"
|
2007-11-20 22:03:56 +00:00
|
|
|
|
#include "Paragraph.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
|
#include "TextClass.h"
|
2007-09-19 22:37:22 +00:00
|
|
|
|
#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-11-10 00:21:42 +00:00
|
|
|
|
#include "LyXRC.h"
|
2007-09-19 22:37:22 +00:00
|
|
|
|
|
2007-10-20 23:08:02 +00:00
|
|
|
|
#include "support/filetools.h"
|
2007-04-19 19:43:15 +00:00
|
|
|
|
#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>
|
|
|
|
|
|
2007-11-02 19:59:08 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
|
using namespace lyx::support;
|
2007-10-17 18:28:45 +00:00
|
|
|
|
|
|
|
|
|
static void initializeResources()
|
|
|
|
|
{
|
|
|
|
|
static bool initialized = false;
|
|
|
|
|
if (!initialized) {
|
2007-10-19 18:45:09 +00:00
|
|
|
|
Q_INIT_RESOURCE(Resources);
|
2007-10-17 18:28:45 +00:00
|
|
|
|
initialized = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
namespace lyx {
|
2007-10-17 18:28:45 +00:00
|
|
|
|
namespace frontend {
|
2007-04-19 19:43:15 +00:00
|
|
|
|
|
2007-10-15 22:43:55 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct PngMap {
|
|
|
|
|
char const * key;
|
|
|
|
|
char const * value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(PngMap const & lhs, PngMap const & rhs)
|
|
|
|
|
{
|
2007-12-12 22:43:37 +00:00
|
|
|
|
return strcmp(lhs.key, rhs.key) < 0;
|
2007-10-15 22:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"},
|
2007-12-25 09:14:00 +00:00
|
|
|
|
{ "textrm \\O", "textrm_O"},
|
2007-10-15 22:43:55 +00:00
|
|
|
|
{ "vDash", "vdash2" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const find_png(string const & name)
|
|
|
|
|
{
|
|
|
|
|
PngMap const * const begin = sorted_png_map;
|
|
|
|
|
PngMap const * const end = begin + nr_sorted_png_map;
|
|
|
|
|
BOOST_ASSERT(sorted(begin, end));
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
PngMap const * const it = find_if(begin, end, CompareKey(name));
|
2007-10-15 22:43:55 +00:00
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GUI, "find_png(" << name << ")\n"
|
|
|
|
|
<< "Looking for math PNG called \"" << png_name << '"');
|
2007-10-17 18:28:45 +00:00
|
|
|
|
return png_name;
|
2007-10-15 22:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// return a icon for the given action
|
|
|
|
|
static QIcon getIcon(FuncRequest const & f, bool unknown)
|
|
|
|
|
{
|
2007-10-17 18:28:45 +00:00
|
|
|
|
initializeResources();
|
|
|
|
|
QPixmap pm;
|
|
|
|
|
string name1;
|
|
|
|
|
string name2;
|
2007-10-20 23:08:02 +00:00
|
|
|
|
string path;
|
|
|
|
|
string fullname;
|
2007-10-15 22:43:55 +00:00
|
|
|
|
|
|
|
|
|
switch (f.action) {
|
|
|
|
|
case LFUN_MATH_INSERT:
|
2007-10-20 23:08:02 +00:00
|
|
|
|
if (!f.argument().empty()) {
|
|
|
|
|
path = "math/";
|
|
|
|
|
name1 = find_png(to_utf8(f.argument()).substr(1));
|
|
|
|
|
}
|
2007-10-15 22:43:55 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
|
case LFUN_MATH_BIGDELIM:
|
2007-10-20 23:08:02 +00:00
|
|
|
|
path = "math/";
|
|
|
|
|
name1 = find_png(to_utf8(f.argument()));
|
2007-10-15 22:43:55 +00:00
|
|
|
|
break;
|
2007-10-20 23:27:03 +00:00
|
|
|
|
case LFUN_CALL:
|
|
|
|
|
path = "commands/";
|
|
|
|
|
name1 = to_utf8(f.argument());
|
|
|
|
|
break;
|
2007-10-15 22:43:55 +00:00
|
|
|
|
default:
|
2007-10-17 18:28:45 +00:00
|
|
|
|
name2 = lyxaction.getActionName(f.action);
|
|
|
|
|
name1 = name2;
|
2007-10-15 22:43:55 +00:00
|
|
|
|
|
|
|
|
|
if (!f.argument().empty())
|
2007-10-17 18:28:45 +00:00
|
|
|
|
name1 = subst(name2 + ' ' + to_utf8(f.argument()), ' ', '_');
|
2007-10-15 22:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-20 23:08:02 +00:00
|
|
|
|
fullname = libFileSearch("images/" + path, name1, "png").absFilename();
|
|
|
|
|
if (pm.load(toqstr(fullname)))
|
|
|
|
|
return pm;
|
|
|
|
|
|
|
|
|
|
fullname = libFileSearch("images/" + path, name2, "png").absFilename();
|
|
|
|
|
if (pm.load(toqstr(fullname)))
|
|
|
|
|
return pm;
|
|
|
|
|
|
|
|
|
|
if (pm.load(":/images/" + toqstr(path + name1) + ".png"))
|
2007-10-17 18:28:45 +00:00
|
|
|
|
return pm;
|
|
|
|
|
|
2007-10-20 23:08:02 +00:00
|
|
|
|
if (pm.load(":/images/" + toqstr(path + name2) + ".png"))
|
2007-10-17 18:28:45 +00:00
|
|
|
|
return pm;
|
2007-10-15 22:43:55 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GUI, "Cannot find icon for command \""
|
2007-10-15 22:43:55 +00:00
|
|
|
|
<< lyxaction.getActionName(f.action)
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< '(' << to_utf8(f.argument()) << ")\"");
|
2007-10-15 22:43:55 +00:00
|
|
|
|
if (unknown)
|
2007-10-17 18:28:45 +00:00
|
|
|
|
pm.load(":/images/unknown.png");
|
|
|
|
|
|
|
|
|
|
return pm;
|
2007-10-15 22:43:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-28 22:53:00 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// GuiLayoutBox
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
GuiLayoutBox::GuiLayoutBox(GuiView & 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)));
|
2007-11-20 22:03:56 +00:00
|
|
|
|
owner_.setLayoutDialog(this);
|
2007-11-20 22:29:17 +00:00
|
|
|
|
updateContents(true);
|
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-11-20 22:03:56 +00:00
|
|
|
|
if (!text_class_)
|
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-11-20 22:03:56 +00:00
|
|
|
|
QString const & name = toqstr(translateIfPossible(
|
|
|
|
|
(*text_class_)[layout]->name()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-11-20 22:03:56 +00:00
|
|
|
|
if (name == currentText())
|
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-11-20 22:03:56 +00:00
|
|
|
|
int i = findText(name);
|
|
|
|
|
if (i == -1) {
|
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-11-10 00:21:42 +00:00
|
|
|
|
void GuiLayoutBox::addItemSort(QString const & item, bool sorted)
|
|
|
|
|
{
|
|
|
|
|
int const end = count();
|
|
|
|
|
if (!sorted || end < 2 || item[0].category() != QChar::Letter_Uppercase) {
|
|
|
|
|
addItem(item);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Let the default one be at the beginning
|
|
|
|
|
int i = 1;
|
|
|
|
|
for (setCurrentIndex(i); currentText() < item;) {
|
|
|
|
|
// e.g. --Separator--
|
|
|
|
|
if (currentText()[0].category() != QChar::Letter_Uppercase)
|
|
|
|
|
break;
|
|
|
|
|
if (++i == end)
|
|
|
|
|
break;
|
|
|
|
|
setCurrentIndex(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertItem(i, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-20 22:03:56 +00:00
|
|
|
|
void GuiLayoutBox::updateContents(bool reset)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-11-20 22:03:56 +00:00
|
|
|
|
Buffer const * buffer = owner_.buffer();
|
|
|
|
|
if (!buffer) {
|
|
|
|
|
clear();
|
|
|
|
|
setEnabled(false);
|
|
|
|
|
text_class_ = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setEnabled(true);
|
|
|
|
|
TextClass const * text_class = &buffer->params().getTextClass();
|
|
|
|
|
if (!reset && text_class_ == text_class) {
|
|
|
|
|
set(owner_.view()->cursor().innerParagraph().layout()->name());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text_class_ = text_class;
|
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-11-20 22:03:56 +00:00
|
|
|
|
TextClass::const_iterator it = text_class_->begin();
|
|
|
|
|
TextClass::const_iterator const end = text_class_->end();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
// ignore obsolete entries
|
2007-11-10 00:21:42 +00:00
|
|
|
|
addItemSort(toqstr(translateIfPossible((*it)->name())), lyxrc.sort_layouts);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-10 00:21:42 +00:00
|
|
|
|
setCurrentIndex(0);
|
|
|
|
|
|
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());
|
2007-11-20 22:03:56 +00:00
|
|
|
|
set(owner_.view()->cursor().innerParagraph().layout()->name());
|
2007-10-01 21:26:25 +00:00
|
|
|
|
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();
|
2007-11-20 22:03:56 +00:00
|
|
|
|
updateContents(false);
|
|
|
|
|
if (!text_class_)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-10-01 21:08:07 +00:00
|
|
|
|
docstring const name = qstring_to_ucs4(str);
|
2007-11-20 22:03:56 +00:00
|
|
|
|
TextClass::const_iterator it = text_class_->begin();
|
|
|
|
|
TextClass::const_iterator const end = text_class_->end();
|
2007-10-01 20:45:50 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
docstring const & itname = (*it)->name();
|
|
|
|
|
if (translateIfPossible(itname) == name) {
|
|
|
|
|
FuncRequest const func(LFUN_LAYOUT, itname,
|
|
|
|
|
FuncRequest::TOOLBAR);
|
2007-11-26 22:45:17 +00:00
|
|
|
|
theLyXFunc().setLyXView(&owner_);
|
|
|
|
|
lyx::dispatch(func);
|
2007-10-01 20:45:50 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-17 18:28:45 +00:00
|
|
|
|
lyxerr << "ERROR (layoutSelected): layout not found!" << endl;
|
2007-10-01 20:45:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-09-28 22:53:00 +00:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// GuiToolbar
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
|
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & 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_,
|
2007-10-15 22:43:55 +00:00
|
|
|
|
getIcon(item.func_, false),
|
2007-09-28 23:14:33 +00:00
|
|
|
|
toqstr(item.label_), item.func_, toqstr(item.label_));
|
2007-09-28 22:53:00 +00:00
|
|
|
|
actions_.append(act);
|
|
|
|
|
return act;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-16 18:27:24 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class PaletteButton : public QToolButton
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
GuiToolbar * bar_;
|
|
|
|
|
ToolbarItem const & tbitem_;
|
|
|
|
|
bool initialized_;
|
|
|
|
|
public:
|
|
|
|
|
PaletteButton(GuiToolbar * bar, ToolbarItem const & item)
|
|
|
|
|
: QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
|
|
|
|
|
{
|
2008-01-17 08:32:48 +00:00
|
|
|
|
QString label = qt_(to_ascii(tbitem_.label_));
|
|
|
|
|
setToolTip(label);
|
|
|
|
|
setStatusTip(label);
|
|
|
|
|
setText(label);
|
2008-01-16 18:27:24 +00:00
|
|
|
|
connect(bar_, SIGNAL(iconSizeChanged(QSize)),
|
|
|
|
|
this, SLOT(setIconSize(QSize)));
|
|
|
|
|
setCheckable(true);
|
2008-01-16 20:36:45 +00:00
|
|
|
|
ToolbarInfo const * tbinfo =
|
|
|
|
|
toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
|
|
|
|
|
if (tbinfo)
|
|
|
|
|
// use the icon of first action for the toolbar button
|
|
|
|
|
setIcon(getIcon(tbinfo->items.begin()->func_, true));
|
2008-01-16 18:27:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-16 20:36:45 +00:00
|
|
|
|
void mousePressEvent(QMouseEvent * e)
|
2008-01-16 18:27:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (initialized_) {
|
2008-01-16 20:36:45 +00:00
|
|
|
|
QToolButton::mousePressEvent(e);
|
2008-01-16 18:27:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initialized_ = true;
|
|
|
|
|
|
|
|
|
|
ToolbarInfo const * tbinfo =
|
|
|
|
|
toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
|
|
|
|
|
if (!tbinfo) {
|
|
|
|
|
lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-01-17 08:42:28 +00:00
|
|
|
|
IconPalette * panel = new IconPalette(this);
|
|
|
|
|
QString label = qt_(to_ascii(tbitem_.label_));
|
|
|
|
|
panel->setWindowTitle(label);
|
|
|
|
|
connect(this, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
|
|
|
|
|
connect(panel, SIGNAL(visible(bool)), this, SLOT(setChecked(bool)));
|
2008-01-16 18:27:24 +00:00
|
|
|
|
ToolbarInfo::item_iterator it = tbinfo->items.begin();
|
|
|
|
|
ToolbarInfo::item_iterator const end = tbinfo->items.end();
|
2008-01-16 20:36:45 +00:00
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
if (!getStatus(it->func_).unknown())
|
2008-01-17 08:42:28 +00:00
|
|
|
|
panel->addButton(bar_->addItem(*it));
|
2008-01-16 20:36:45 +00:00
|
|
|
|
|
|
|
|
|
QToolButton::mousePressEvent(e);
|
2008-01-16 18:27:24 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-01-17 08:20:22 +00:00
|
|
|
|
class MenuButton : public QToolButton
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
GuiToolbar * bar_;
|
|
|
|
|
ToolbarItem const & tbitem_;
|
|
|
|
|
bool initialized_;
|
|
|
|
|
public:
|
|
|
|
|
MenuButton(GuiToolbar * bar, ToolbarItem const & item)
|
|
|
|
|
: QToolButton(bar), bar_(bar), tbitem_(item), initialized_(false)
|
|
|
|
|
{
|
|
|
|
|
setPopupMode(QToolButton::InstantPopup);
|
2008-01-17 08:32:48 +00:00
|
|
|
|
QString label = qt_(to_ascii(tbitem_.label_));
|
|
|
|
|
setToolTip(label);
|
|
|
|
|
setStatusTip(label);
|
|
|
|
|
setText(label);
|
2008-01-17 08:20:22 +00:00
|
|
|
|
setIcon(QPixmap(":images/math/" + toqstr(tbitem_.name_) + ".png"));
|
|
|
|
|
connect(bar, SIGNAL(iconSizeChanged(QSize)),
|
|
|
|
|
this, SLOT(setIconSize(QSize)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent * e)
|
|
|
|
|
{
|
|
|
|
|
if (initialized_) {
|
|
|
|
|
QToolButton::mousePressEvent(e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initialized_ = true;
|
|
|
|
|
|
2008-01-17 08:32:48 +00:00
|
|
|
|
QString label = qt_(to_ascii(tbitem_.label_));
|
|
|
|
|
ButtonMenu * m = new ButtonMenu(label, this);
|
|
|
|
|
m->setWindowTitle(label);
|
2008-01-17 08:20:22 +00:00
|
|
|
|
m->setTearOffEnabled(true);
|
|
|
|
|
connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
|
|
|
|
|
ToolbarInfo const * tbinfo =
|
|
|
|
|
toolbarbackend.getDefinedToolbarInfo(tbitem_.name_);
|
|
|
|
|
if (!tbinfo) {
|
|
|
|
|
lyxerr << "Unknown toolbar " << tbitem_.name_ << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ToolbarInfo::item_iterator it = tbinfo->items.begin();
|
|
|
|
|
ToolbarInfo::item_iterator const end = tbinfo->items.end();
|
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
if (!getStatus(it->func_).unknown())
|
|
|
|
|
m->add(bar_->addItem(*it));
|
|
|
|
|
setMenu(m);
|
|
|
|
|
|
|
|
|
|
QToolButton::mousePressEvent(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-01-16 18:27:24 +00:00
|
|
|
|
}
|
2007-09-28 22:53:00 +00:00
|
|
|
|
|
2008-01-17 08:32:48 +00:00
|
|
|
|
|
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-10-15 22:43:55 +00:00
|
|
|
|
tb->setIcon(getIcon(FuncRequest(LFUN_TABULAR_INSERT), true));
|
2008-01-17 08:32:48 +00:00
|
|
|
|
QString label = qt_(to_ascii(item.label_));
|
|
|
|
|
tb->setToolTip(label);
|
|
|
|
|
tb->setStatusTip(label);
|
|
|
|
|
tb->setText(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;
|
|
|
|
|
}
|
2008-01-16 18:27:24 +00:00
|
|
|
|
case ToolbarItem::ICONPALETTE:
|
|
|
|
|
addWidget(new PaletteButton(this, item));
|
2007-04-19 20:29:27 +00:00
|
|
|
|
break;
|
2008-01-16 18:27:24 +00:00
|
|
|
|
|
2007-04-19 20:29:27 +00:00
|
|
|
|
case ToolbarItem::POPUPMENU: {
|
2008-01-17 08:20:22 +00:00
|
|
|
|
addWidget(new MenuButton(this, item));
|
2007-04-19 20:29:27 +00:00
|
|
|
|
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
|
|
|
|
|
2007-11-20 22:03:56 +00:00
|
|
|
|
if (layout_)
|
|
|
|
|
layout_->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiToolbar_moc.cpp"
|