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
|
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"
|
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>
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-07-21 23:08:30 +00:00
|
|
|
|
class QLComboBox : public QComboBox {
|
|
|
|
|
public:
|
|
|
|
|
QLComboBox(QWidget * parent) : QComboBox(parent) {}
|
|
|
|
|
void popup() { QComboBox::popup(); }
|
|
|
|
|
};
|
|
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
QLToolbar::QLToolbar(LyXView * o)
|
2002-09-24 13:57:09 +00:00
|
|
|
|
: owner_(static_cast<QtView *>(o)),
|
2003-07-25 18:10:34 +00:00
|
|
|
|
combo_(0)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
|
|
|
|
proxy_.reset(new ToolbarProxy(*this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::displayToolbar(ToolbarBackend::Toolbar const & tb, bool show)
|
2003-04-10 14:08:06 +00:00
|
|
|
|
{
|
|
|
|
|
QToolBar * qtb = toolbars_[tb.name];
|
|
|
|
|
if (show) {
|
|
|
|
|
qtb->show();
|
|
|
|
|
} else {
|
|
|
|
|
qtb->hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::update()
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
|
|
|
|
ButtonMap::const_iterator p = map_.begin();
|
|
|
|
|
ButtonMap::const_iterator end = map_.end();
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
for (; p != end; ++p) {
|
|
|
|
|
QToolButton * button = p->first;
|
|
|
|
|
int action = p->second;
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
|
|
|
|
FuncStatus const status =
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner_->getLyXFunc().getStatus(action);
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
button->setToggleButton(true);
|
|
|
|
|
button->setOn(status.onoff(true));
|
|
|
|
|
button->setEnabled(!status.disabled());
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-24 15:53:55 +00:00
|
|
|
|
bool const enable = !owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled();
|
|
|
|
|
|
|
|
|
|
// Workaround for Qt bug where setEnabled(true) closes
|
|
|
|
|
// the popup
|
|
|
|
|
if (combo_ && enable != combo_->isEnabled())
|
|
|
|
|
combo_->setEnabled(enable);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::button_selected(QToolButton * button)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
|
|
|
|
ButtonMap::const_iterator cit = map_.find(button);
|
|
|
|
|
|
|
|
|
|
if (cit == map_.end()) {
|
|
|
|
|
lyxerr << "non existent tool button selected !" << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner_->getLyXFunc().dispatch(cit->second, true);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
}
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::changed_layout(string const & sel)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2002-08-29 14:43:01 +00:00
|
|
|
|
owner_->centralWidget()->setFocus();
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
LyXTextClass const & tc =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
owner_->buffer()->params().getLyXTextClass();
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
LyXTextClass::const_iterator end = tc.end();
|
|
|
|
|
for (LyXTextClass::const_iterator cit = tc.begin();
|
|
|
|
|
cit != end; ++cit) {
|
2002-12-17 20:37:13 +00:00
|
|
|
|
// Yes, the _() is correct
|
2002-07-11 01:01:38 +00:00
|
|
|
|
if (_((*cit)->name()) == sel) {
|
2002-09-17 12:29:40 +00:00
|
|
|
|
owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-25 18:10:34 +00:00
|
|
|
|
lyxerr << "ERROR (QLToolbar::layoutSelected): layout not found!"
|
2002-06-19 03:38:44 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
}
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::setLayout(string const & layout)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2003-04-02 18:08:05 +00:00
|
|
|
|
if (!combo_)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
LyXTextClass const & tc =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
owner_->buffer()->params().getLyXTextClass();
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::updateLayoutList()
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2003-04-02 18:08:05 +00:00
|
|
|
|
if (!combo_)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
LyXTextClass const & tc =
|
2003-09-09 09:47:59 +00:00
|
|
|
|
owner_->buffer()->params().getLyXTextClass();
|
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
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
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())
|
2002-12-17 20:37:13 +00:00
|
|
|
|
combo_->insertItem(qt_((*cit)->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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::clearLayoutList()
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2003-04-02 18:08:05 +00:00
|
|
|
|
if (!combo_)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-08-02 12:23:24 +00:00
|
|
|
|
Toolbar::clearLayoutList();
|
2002-06-19 03:38:44 +00:00
|
|
|
|
combo_->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::openLayoutList()
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2003-04-02 18:08:05 +00:00
|
|
|
|
if (!combo_)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
combo_->popup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-15 01:06:13 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
QMainWindow::ToolBarDock getPosition(ToolbarBackend::Flags const & flags)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::add(ToolbarBackend::Toolbar const & tb)
|
2002-06-19 03:38:44 +00:00
|
|
|
|
{
|
2003-04-15 01:06:13 +00:00
|
|
|
|
QToolBar * qtb = new QToolBar(qt_(tb.name), owner_, getPosition(tb.flags));
|
|
|
|
|
// give visual separation between adjacent toolbars
|
|
|
|
|
qtb->addSeparator();
|
2003-04-09 19:53:10 +00:00
|
|
|
|
|
|
|
|
|
ToolbarBackend::item_iterator it = tb.items.begin();
|
|
|
|
|
ToolbarBackend::item_iterator end = tb.items.end();
|
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
add(qtb, it->first, it->second);
|
|
|
|
|
|
2003-04-10 14:08:06 +00:00
|
|
|
|
toolbars_[tb.name] = qtb;
|
2003-04-15 01:06:13 +00:00
|
|
|
|
displayToolbar(tb, tb.flags & ToolbarBackend::ON);
|
2003-04-10 14:08:06 +00:00
|
|
|
|
|
2003-04-09 19:53:10 +00:00
|
|
|
|
}
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2003-04-09 19:53:10 +00:00
|
|
|
|
|
2003-07-25 18:10:34 +00:00
|
|
|
|
void QLToolbar::add(QToolBar * tb, int action, string const & tooltip)
|
2003-04-09 19:53:10 +00:00
|
|
|
|
{
|
2002-06-19 03:38:44 +00:00
|
|
|
|
switch (action) {
|
2003-04-02 18:08:05 +00:00
|
|
|
|
case ToolbarBackend::SEPARATOR:
|
2003-04-09 19:53:10 +00:00
|
|
|
|
tb->addSeparator();
|
2002-06-19 03:38:44 +00:00
|
|
|
|
break;
|
2003-04-02 18:08:05 +00:00
|
|
|
|
case ToolbarBackend::LAYOUTS: {
|
2003-04-09 19:53:10 +00:00
|
|
|
|
combo_ = new QLComboBox(tb);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
QSizePolicy p(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
|
combo_->setSizePolicy(p);
|
2002-07-25 04:41:11 +00:00
|
|
|
|
combo_->setFocusPolicy(QWidget::ClickFocus);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
combo_->setMinimumWidth(combo_->sizeHint().width());
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
|
QObject::connect(combo_, SIGNAL(activated(const QString &)),
|
|
|
|
|
proxy_.get(), SLOT(layout_selected(const QString &)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-04-15 01:06:13 +00:00
|
|
|
|
case ToolbarBackend::MINIBUFFER:
|
|
|
|
|
owner_->addCommandBuffer(tb);
|
|
|
|
|
tb->setHorizontalStretchable(true);
|
|
|
|
|
break;
|
2002-07-13 01:42:15 +00:00
|
|
|
|
default: {
|
2003-06-23 13:18:56 +00:00
|
|
|
|
if (owner_->getLyXFunc().getStatus(action).unknown())
|
|
|
|
|
break;
|
2003-04-08 19:17:00 +00:00
|
|
|
|
QPixmap p = QPixmap(toolbarbackend.getIcon(action).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), "",
|
2003-04-09 19:53:10 +00:00
|
|
|
|
proxy_.get(), SLOT(button_selected()), tb);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
2003-04-09 19:53:10 +00:00
|
|
|
|
map_[button] = action;
|
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
|
|
|
|
}
|