2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
2006-04-24 13:25:50 +00:00
|
|
|
|
* \file qt4/QLToolbar.C
|
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>
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferparams.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
#include "GuiView.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "QLToolbar.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"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
LyXTextClass const & getTextClass(LyXView const & lv)
|
|
|
|
|
{
|
|
|
|
|
return lv.buffer()->params().getLyXTextClass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 09:33:01 +00:00
|
|
|
|
QLayoutBox::QLayoutBox(QToolBar * toolbar, GuiView & owner)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
: owner_(owner)
|
|
|
|
|
{
|
|
|
|
|
combo_ = new QComboBox;
|
2006-03-16 11:23:23 +00:00
|
|
|
|
combo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
combo_->setFocusPolicy(Qt::ClickFocus);
|
|
|
|
|
combo_->setMinimumWidth(combo_->sizeHint().width());
|
2006-03-25 21:26:09 +00:00
|
|
|
|
combo_->setMaxVisibleItems(100);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
QObject::connect(combo_, SIGNAL(activated(const QString &)),
|
|
|
|
|
this, SLOT(selected(const QString &)));
|
|
|
|
|
|
|
|
|
|
toolbar->addWidget(combo_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLayoutBox::set(string const & layout)
|
|
|
|
|
{
|
|
|
|
|
LyXTextClass const & tc = getTextClass(owner_);
|
|
|
|
|
|
|
|
|
|
QString const & name = qt_(tc[layout]->name());
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (; i < combo_->count(); ++i) {
|
2006-06-04 20:49:09 +00:00
|
|
|
|
if (name == combo_->itemText(i))
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == combo_->count()) {
|
|
|
|
|
lyxerr << "Trying to select non existent layout type "
|
|
|
|
|
<< fromqstr(name) << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-04 20:49:09 +00:00
|
|
|
|
combo_->setCurrentIndex(i);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLayoutBox::update()
|
|
|
|
|
{
|
|
|
|
|
LyXTextClass const & tc = getTextClass(owner_);
|
|
|
|
|
|
|
|
|
|
combo_->setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
|
|
combo_->clear();
|
|
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator it = tc.begin();
|
|
|
|
|
LyXTextClass::const_iterator const end = tc.end();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
// ignore obsolete entries
|
|
|
|
|
if ((*it)->obsoleted_by().empty())
|
2006-06-04 20:49:09 +00:00
|
|
|
|
combo_->addItem(qt_((*it)->name()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// needed to recalculate size hint
|
|
|
|
|
combo_->hide();
|
|
|
|
|
combo_->setMinimumWidth(combo_->sizeHint().width());
|
|
|
|
|
combo_->show();
|
|
|
|
|
|
|
|
|
|
combo_->setUpdatesEnabled(true);
|
|
|
|
|
combo_->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLayoutBox::clear()
|
|
|
|
|
{
|
|
|
|
|
combo_->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLayoutBox::open()
|
|
|
|
|
{
|
2006-06-04 20:49:09 +00:00
|
|
|
|
combo_->showPopup();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLayoutBox::setEnabled(bool enable)
|
|
|
|
|
{
|
|
|
|
|
// Workaround for Qt bug where setEnabled(true) closes
|
|
|
|
|
// the popup
|
|
|
|
|
if (enable != combo_->isEnabled())
|
|
|
|
|
combo_->setEnabled(enable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLayoutBox::selected(const QString & str)
|
|
|
|
|
{
|
|
|
|
|
string const sel = fromqstr(str);
|
|
|
|
|
|
|
|
|
|
owner_.centralWidget()->setFocus();
|
|
|
|
|
|
|
|
|
|
layoutSelected(owner_, sel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
QLToolbar::QLToolbar(ToolbarBackend::Toolbar const & tbb, GuiView & owner)
|
2006-09-13 17:04:42 +00:00
|
|
|
|
: QToolBar(qt_(tbb.gui_name), &owner), owner_(owner)
|
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
|
|
|
|
|
|
|
|
|
ToolbarBackend::item_iterator it = tbb.items.begin();
|
|
|
|
|
ToolbarBackend::item_iterator end = tbb.items.end();
|
|
|
|
|
for (; it != end; ++it)
|
2006-10-18 20:51:16 +00:00
|
|
|
|
add(it->first, it->second);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-09 12:30:55 +00:00
|
|
|
|
void QLToolbar::add(FuncRequest const & func, docstring const & tooltip)
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
switch (func.action) {
|
|
|
|
|
case ToolbarBackend::SEPARATOR:
|
2006-09-10 11:03:21 +00:00
|
|
|
|
addSeparator();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case ToolbarBackend::LAYOUTS:
|
2006-09-10 11:03:21 +00:00
|
|
|
|
layout_.reset(new QLayoutBox(this, owner_));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case ToolbarBackend::MINIBUFFER:
|
2006-09-10 11:03:21 +00:00
|
|
|
|
owner_.addCommandBuffer(this);
|
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;
|
2006-05-31 12:53:05 +00:00
|
|
|
|
case LFUN_TABULAR_INSERT: {
|
|
|
|
|
QToolButton * tb = new QToolButton;
|
|
|
|
|
tb->setCheckable(true);
|
|
|
|
|
tb->setIcon(QPixmap(toqstr(toolbarbackend.getIcon(func))));
|
|
|
|
|
tb->setToolTip(toqstr(tooltip));
|
|
|
|
|
tb->setFocusPolicy(Qt::NoFocus);
|
2006-06-01 20:34:22 +00:00
|
|
|
|
InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
|
2006-05-31 12:53:05 +00:00
|
|
|
|
connect(tb, SIGNAL(toggled(bool)), iv, SLOT(show(bool)));
|
|
|
|
|
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;
|
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
default: {
|
2006-10-11 17:24:46 +00:00
|
|
|
|
if (lyx::getStatus(func).unknown())
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2006-10-09 12:30:55 +00:00
|
|
|
|
Action * action = new Action(owner_, toolbarbackend.getIcon(func), lyx::docstring(), func, tooltip);
|
2006-09-10 11:03:21 +00:00
|
|
|
|
addAction(action);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
ActionVector.push_back(action);
|
|
|
|
|
break;
|
2006-05-31 12:53:05 +00:00
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLToolbar::hide(bool)
|
|
|
|
|
{
|
2006-09-10 11:03:21 +00:00
|
|
|
|
QToolBar::hide();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLToolbar::show(bool)
|
|
|
|
|
{
|
2006-09-10 11:03:21 +00:00
|
|
|
|
QToolBar::show();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-02 16:01:36 +00:00
|
|
|
|
void QLToolbar::saveInfo(ToolbarSection::ToolbarInfo & info)
|
|
|
|
|
{
|
|
|
|
|
// if info.state == auto *do not* set on/off
|
|
|
|
|
if (info.state != ToolbarSection::ToolbarInfo::AUTO) {
|
|
|
|
|
if (QLToolbar::isVisible())
|
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::ON;
|
|
|
|
|
else
|
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::OFF;
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
// no need to save it here.
|
|
|
|
|
Qt::ToolBarArea loc = owner_.toolBarArea(this);
|
|
|
|
|
|
|
|
|
|
if (loc == Qt::TopToolBarArea)
|
|
|
|
|
info.location = ToolbarSection::ToolbarInfo::TOP;
|
|
|
|
|
else if (loc == Qt::BottomToolBarArea)
|
|
|
|
|
info.location = ToolbarSection::ToolbarInfo::BOTTOM;
|
|
|
|
|
else if (loc == Qt::RightToolBarArea)
|
|
|
|
|
info.location = ToolbarSection::ToolbarInfo::RIGHT;
|
|
|
|
|
else if (loc == Qt::LeftToolBarArea)
|
|
|
|
|
info.location = ToolbarSection::ToolbarInfo::LEFT;
|
|
|
|
|
else
|
|
|
|
|
info.location = ToolbarSection::ToolbarInfo::NOTSET;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
void QLToolbar::update()
|
|
|
|
|
{
|
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
|
2006-03-05 17:24:44 +00:00
|
|
|
|
for (size_t i=0; i<ActionVector.size(); ++i)
|
|
|
|
|
ActionVector[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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
|
|
|
|
|
#include "QLToolbar_moc.cpp"
|