2002-06-19 03:38:44 +00:00
|
|
|
|
/**
|
2003-07-25 18:10:34 +00:00
|
|
|
|
* \file qt2/QLToolbar.C
|
2002-09-24 13:57:09 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-19 03:38:44 +00:00
|
|
|
|
*
|
2002-09-24 13:57:09 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
2003-07-25 18:10:34 +00:00
|
|
|
|
* \author Jean-Marc Lasgouttes
|
2004-04-29 09:54:59 +00:00
|
|
|
|
* \author Angus Leeming
|
2002-09-24 13:57:09 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-19 03:38:44 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferparams.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
#include "debug.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "funcrequest.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "lyxfunc.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2002-11-26 01:52:51 +00:00
|
|
|
|
#include "QtView.h"
|
2003-07-25 18:10:34 +00:00
|
|
|
|
#include "QLToolbar.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
|
#include "qt_helpers.h"
|
2002-11-26 01:52:51 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
#include <qcombobox.h>
|
2003-09-08 16:23:31 +00:00
|
|
|
|
#include <qtoolbar.h>
|
2004-04-29 09:54:59 +00:00
|
|
|
|
#include <qtoolbutton.h>
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
namespace {
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
LyXTextClass const & getTextClass(LyXView const & lv)
|
2003-04-10 14:08:06 +00:00
|
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
|
return lv.buffer()->params().getLyXTextClass();
|
2003-04-10 14:08:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
QMainWindow::ToolBarDock getPosition(ToolbarBackend::Flags const & flags)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
|
if (flags & ToolbarBackend::TOP)
|
|
|
|
|
return QMainWindow::Top;
|
|
|
|
|
if (flags & ToolbarBackend::BOTTOM)
|
|
|
|
|
return QMainWindow::Bottom;
|
|
|
|
|
if (flags & ToolbarBackend::LEFT)
|
|
|
|
|
return QMainWindow::Left;
|
|
|
|
|
if (flags & ToolbarBackend::RIGHT)
|
|
|
|
|
return QMainWindow::Right;
|
|
|
|
|
return QMainWindow::Top;
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
} // namespace anon
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
QLayoutBox::QLayoutBox(QWidget * parent, QtView & owner)
|
|
|
|
|
: combo_(new QComboBox(parent)),
|
|
|
|
|
owner_(owner)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
|
QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
|
combo_->setSizePolicy(p);
|
|
|
|
|
combo_->setFocusPolicy(QWidget::ClickFocus);
|
|
|
|
|
combo_->setMinimumWidth(combo_->sizeHint().width());
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
QObject::connect(combo_, SIGNAL(activated(const QString &)),
|
|
|
|
|
this, SLOT(selected(const QString &)));
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
void QLayoutBox::set(string const & layout)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
|
LyXTextClass const & tc = getTextClass(owner_);
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
|
QString const & name = qt_(tc[layout]->name());
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
for (; i < combo_->count(); ++i) {
|
2002-12-17 20:37:13 +00:00
|
|
|
|
if (name == combo_->text(i))
|
2002-06-19 03:38:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == combo_->count()) {
|
|
|
|
|
lyxerr << "Trying to select non existent layout type "
|
2002-12-17 20:37:13 +00:00
|
|
|
|
<< fromqstr(name) << endl;
|
2002-06-19 03:38:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
combo_->setCurrentItem(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
void QLayoutBox::update()
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
|
LyXTextClass const & tc = getTextClass(owner_);
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
|
|
|
|
combo_->setUpdatesEnabled(false);
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
combo_->clear();
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
LyXTextClass::const_iterator it = tc.begin();
|
|
|
|
|
LyXTextClass::const_iterator const end = tc.end();
|
|
|
|
|
for (; it != end; ++it) {
|
2002-06-19 03:38:44 +00:00
|
|
|
|
// ignore obsolete entries
|
2004-04-29 09:54:59 +00:00
|
|
|
|
if ((*it)->obsoleted_by().empty())
|
|
|
|
|
combo_->insertItem(qt_((*it)->name()));
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
void QLayoutBox::clear()
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
|
|
|
|
combo_->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
void QLayoutBox::open()
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
|
|
|
|
combo_->popup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
void QLayoutBox::setEnabled(bool enable)
|
|
|
|
|
{
|
|
|
|
|
// Workaround for Qt bug where setEnabled(true) closes
|
|
|
|
|
// the popup
|
|
|
|
|
if (enable != combo_->isEnabled())
|
|
|
|
|
combo_->setEnabled(enable);
|
|
|
|
|
}
|
2003-04-15 01:06:13 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
|
|
void QLayoutBox::selected(const QString & str)
|
2003-04-15 01:06:13 +00:00
|
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
|
string const sel = fromqstr(str);
|
|
|
|
|
|
|
|
|
|
owner_.centralWidget()->setFocus();
|
|
|
|
|
|
|
|
|
|
LyXTextClass const & tc = getTextClass(owner_);
|
|
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator it = tc.begin();
|
|
|
|
|
LyXTextClass::const_iterator const end = tc.end();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
string const & name = (*it)->name();
|
|
|
|
|
// Yes, the _() is correct
|
|
|
|
|
if (_(name) == sel) {
|
|
|
|
|
owner_.getLyXFunc()
|
|
|
|
|
.dispatch(FuncRequest(LFUN_LAYOUT, name),
|
|
|
|
|
true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lyxerr << "ERROR (QLayoutBox::selected): layout not found!" << endl;
|
2003-04-15 01:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2003-04-15 01:06:13 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const & tbb,
|
|
|
|
|
LyXView & owner)
|
|
|
|
|
{
|
2004-05-19 15:11:37 +00:00
|
|
|
|
using lyx::frontend::QLToolbar;
|
2004-04-29 09:54:59 +00:00
|
|
|
|
return Toolbars::ToolbarPtr(new QLToolbar(tbb, owner));
|
|
|
|
|
}
|
2003-04-15 01:06:13 +00:00
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
|
|
QLToolbar::QLToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
|
|
|
|
|
: owner_(dynamic_cast<QtView &>(owner)),
|
|
|
|
|
toolbar_(new QToolBar(qt_(tbb.gui_name), &owner_,
|
|
|
|
|
getPosition(tbb.flags)))
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2003-04-15 01:06:13 +00:00
|
|
|
|
// give visual separation between adjacent toolbars
|
2004-04-29 09:54:59 +00:00
|
|
|
|
toolbar_->addSeparator();
|
2003-04-09 19:53:10 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
ToolbarBackend::item_iterator it = tbb.items.begin();
|
|
|
|
|
ToolbarBackend::item_iterator end = tbb.items.end();
|
2003-04-09 19:53:10 +00:00
|
|
|
|
for (; it != end; ++it)
|
2004-04-29 09:54:59 +00:00
|
|
|
|
add(it->first, it->second);
|
2003-04-09 19:53:10 +00:00
|
|
|
|
}
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2003-04-09 19:53:10 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
void QLToolbar::add(FuncRequest const & func, string const & tooltip)
|
2003-04-09 19:53:10 +00:00
|
|
|
|
{
|
2003-09-21 18:57:15 +00:00
|
|
|
|
switch (func.action) {
|
2003-04-02 18:08:05 +00:00
|
|
|
|
case ToolbarBackend::SEPARATOR:
|
2004-04-29 09:54:59 +00:00
|
|
|
|
toolbar_->addSeparator();
|
2002-06-19 03:38:44 +00:00
|
|
|
|
break;
|
2004-04-29 09:54:59 +00:00
|
|
|
|
case ToolbarBackend::LAYOUTS:
|
|
|
|
|
layout_.reset(new QLayoutBox(toolbar_, owner_));
|
2002-06-19 03:38:44 +00:00
|
|
|
|
break;
|
2003-04-15 01:06:13 +00:00
|
|
|
|
case ToolbarBackend::MINIBUFFER:
|
2004-04-29 09:54:59 +00:00
|
|
|
|
owner_.addCommandBuffer(toolbar_);
|
|
|
|
|
toolbar_->setHorizontalStretchable(true);
|
2003-04-15 01:06:13 +00:00
|
|
|
|
break;
|
2002-07-13 01:42:15 +00:00
|
|
|
|
default: {
|
2004-04-29 09:54:59 +00:00
|
|
|
|
if (owner_.getLyXFunc().getStatus(func).unknown())
|
2003-06-23 13:18:56 +00:00
|
|
|
|
break;
|
2003-09-21 18:57:15 +00:00
|
|
|
|
QPixmap p = QPixmap(toolbarbackend.getIcon(func).c_str());
|
2003-04-09 19:53:10 +00:00
|
|
|
|
QToolButton * button =
|
2003-04-08 19:17:00 +00:00
|
|
|
|
new QToolButton(p, toqstr(tooltip), "",
|
2004-04-29 09:54:59 +00:00
|
|
|
|
this, SLOT(clicked()), toolbar_);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
|
map_[button] = func;
|
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
|
|
|
|
}
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLToolbar::hide(bool)
|
|
|
|
|
{
|
|
|
|
|
toolbar_->hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLToolbar::show(bool)
|
|
|
|
|
{
|
|
|
|
|
toolbar_->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLToolbar::update()
|
|
|
|
|
{
|
|
|
|
|
ButtonMap::const_iterator p = map_.begin();
|
|
|
|
|
ButtonMap::const_iterator end = map_.end();
|
|
|
|
|
|
|
|
|
|
for (; p != end; ++p) {
|
|
|
|
|
QToolButton * button = p->first;
|
|
|
|
|
FuncRequest const & func = p->second;
|
|
|
|
|
|
|
|
|
|
FuncStatus const status =
|
|
|
|
|
owner_.getLyXFunc().getStatus(func);
|
|
|
|
|
|
|
|
|
|
button->setToggleButton(true);
|
|
|
|
|
button->setOn(status.onoff(true));
|
|
|
|
|
button->setEnabled(status.enabled());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QLToolbar::clicked()
|
|
|
|
|
{
|
|
|
|
|
QToolButton const * const_button =
|
|
|
|
|
static_cast<QToolButton const *>(sender());
|
|
|
|
|
QToolButton * button =
|
|
|
|
|
const_cast<QToolButton *>(const_button);
|
|
|
|
|
|
|
|
|
|
ButtonMap::const_iterator it = map_.find(button);
|
|
|
|
|
|
|
|
|
|
if (it != map_.end())
|
|
|
|
|
owner_.getLyXFunc().dispatch(it->second, true);
|
|
|
|
|
else
|
|
|
|
|
lyxerr << "non existent tool button selected !" << endl;
|
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|