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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author John Levon
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
2008-03-10 13:10:10 +00:00
|
|
|
* \author Stefan Schimanski
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "GuiToolbar.h"
|
2008-05-25 08:30:06 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "Action.h"
|
2008-05-25 08:30:06 +00:00
|
|
|
#include "GuiApplication.h"
|
|
|
|
#include "GuiCommandBuffer.h"
|
|
|
|
#include "GuiView.h"
|
|
|
|
#include "IconPalette.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "InsertTableWidget.h"
|
2009-08-12 21:51:10 +00:00
|
|
|
#include "LayoutBox.h"
|
2008-05-25 08:30:06 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "Toolbars.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "FuncStatus.h"
|
2009-06-08 15:36:32 +00:00
|
|
|
#include "KeyMap.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "LyXRC.h"
|
2013-05-23 02:58:58 +00:00
|
|
|
#include "Session.h"
|
2009-08-09 16:19:43 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2007-04-19 19:43:15 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-09-19 22:37:22 +00:00
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
#include <QSettings>
|
2009-08-12 22:22:26 +00:00
|
|
|
#include <QShowEvent>
|
2008-05-27 11:15:17 +00:00
|
|
|
#include <QString>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QToolBar>
|
|
|
|
#include <QToolButton>
|
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2007-11-02 19:59:08 +00:00
|
|
|
|
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
|
|
|
|
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-11-05 13:52:37 +00:00
|
|
|
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
|
2008-08-15 18:43:46 +00:00
|
|
|
: QToolBar(toqstr(tbinfo.gui_name), &owner), visibility_(0),
|
2013-05-19 20:04:29 +00:00
|
|
|
owner_(owner), command_buffer_(0), tbinfo_(tbinfo), filled_(false),
|
|
|
|
restored_(false)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-06-19 07:40:29 +00:00
|
|
|
setIconSize(owner.iconSize());
|
2008-06-19 06:21:04 +00:00
|
|
|
connect(&owner, SIGNAL(iconSizeChanged(QSize)), this,
|
|
|
|
SLOT(setIconSize(QSize)));
|
|
|
|
|
2008-05-28 10:26:03 +00:00
|
|
|
// Toolbar dragging is allowed.
|
2006-10-31 14:39:16 +00:00
|
|
|
setMovable(true);
|
2008-05-28 10:26:03 +00:00
|
|
|
// This is used by QMainWindow::restoreState for proper main window state
|
|
|
|
// restauration.
|
2008-05-27 11:15:17 +00:00
|
|
|
setObjectName(toqstr(tbinfo.name));
|
|
|
|
restoreSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-19 20:04:29 +00:00
|
|
|
void GuiToolbar::setVisible(bool visible)
|
|
|
|
{
|
|
|
|
// This is a hack to find out which toolbars have been restored by
|
|
|
|
// MainWindow::restoreState and which toolbars should be initialized
|
|
|
|
// by us (i.e., new toolbars)
|
|
|
|
restored_ = true;
|
|
|
|
QToolBar::setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiToolbar::isRestored() const
|
|
|
|
{
|
|
|
|
return restored_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-28 10:26:03 +00:00
|
|
|
void GuiToolbar::fill()
|
|
|
|
{
|
2008-05-28 10:30:25 +00:00
|
|
|
if (filled_)
|
|
|
|
return;
|
2008-05-28 10:26:03 +00:00
|
|
|
ToolbarInfo::item_iterator it = tbinfo_.items.begin();
|
|
|
|
ToolbarInfo::item_iterator end = tbinfo_.items.end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
add(*it);
|
2008-05-28 10:30:25 +00:00
|
|
|
filled_ = true;
|
2008-05-28 10:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToolbar::showEvent(QShowEvent * ev)
|
|
|
|
{
|
|
|
|
fill();
|
|
|
|
ev->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
void GuiToolbar::setVisibility(int visibility)
|
|
|
|
{
|
|
|
|
visibility_ = visibility;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-28 22:53:00 +00:00
|
|
|
Action * GuiToolbar::addItem(ToolbarItem const & item)
|
|
|
|
{
|
2009-06-08 15:36:32 +00:00
|
|
|
QString text = toqstr(item.label_);
|
|
|
|
// Get the keys bound to this action, but keep only the
|
|
|
|
// first one later
|
|
|
|
KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(item.func_);
|
2012-10-21 19:14:16 +00:00
|
|
|
if (!bindings.empty())
|
2009-06-08 15:36:32 +00:00
|
|
|
text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]";
|
|
|
|
|
2013-05-02 17:22:10 +00:00
|
|
|
Action * act = new Action(getIcon(item.func_, false),
|
|
|
|
text, item.func_, text, this);
|
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 09:19:52 +00:00
|
|
|
QString const label = qt_(to_ascii(tbitem_.label_));
|
2008-01-17 08:32:48 +00:00
|
|
|
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-05-27 11:15:17 +00:00
|
|
|
ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
|
2008-01-16 20:36:45 +00:00
|
|
|
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;
|
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
|
2008-01-16 18:27:24 +00:00
|
|
|
if (!tbinfo) {
|
2008-06-05 14:40:41 +00:00
|
|
|
LYXERR0("Unknown toolbar " << tbitem_.name_);
|
2008-01-16 18:27:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-01-17 08:42:28 +00:00
|
|
|
IconPalette * panel = new IconPalette(this);
|
2008-01-17 09:19:52 +00:00
|
|
|
QString const label = qt_(to_ascii(tbitem_.label_));
|
2008-01-17 08:42:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-18 10:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MenuButton::MenuButton(GuiToolbar * bar, ToolbarItem const & item, bool const sticky)
|
2012-09-22 18:51:49 +00:00
|
|
|
: QToolButton(bar), bar_(bar), tbitem_(item)
|
2008-01-17 08:20:22 +00:00
|
|
|
{
|
2009-04-18 10:44:44 +00:00
|
|
|
setPopupMode(QToolButton::InstantPopup);
|
|
|
|
QString const label = qt_(to_ascii(tbitem_.label_));
|
|
|
|
setToolTip(label);
|
|
|
|
setStatusTip(label);
|
|
|
|
setText(label);
|
2009-09-13 18:09:40 +00:00
|
|
|
QString const name = toqstr(tbitem_.name_);
|
2012-08-21 12:56:34 +00:00
|
|
|
QStringList imagedirs;
|
|
|
|
imagedirs << "images/math/" << "images/";
|
2014-10-18 13:50:22 +00:00
|
|
|
for (int i = 0; i < imagedirs.size(); ++i) {
|
2012-08-21 12:56:34 +00:00
|
|
|
QString imagedir = imagedirs.at(i);
|
2015-03-12 23:47:21 +00:00
|
|
|
FileName const fname = imageLibFileSearch(imagedir, name, "svgz,png",
|
2014-10-18 13:50:22 +00:00
|
|
|
theGuiApp()->imageSearchMode());
|
2012-08-21 12:56:34 +00:00
|
|
|
if (fname.exists()) {
|
2015-03-12 23:47:21 +00:00
|
|
|
setIcon(QIcon(getPixmap(imagedir, name, "svgz,png")));
|
2012-08-21 12:56:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-03-25 01:59:34 +00:00
|
|
|
}
|
2009-04-18 10:44:44 +00:00
|
|
|
if (sticky)
|
|
|
|
connect(this, SIGNAL(triggered(QAction *)),
|
|
|
|
this, SLOT(actionTriggered(QAction *)));
|
|
|
|
connect(bar, SIGNAL(iconSizeChanged(QSize)),
|
|
|
|
this, SLOT(setIconSize(QSize)));
|
2012-09-22 18:51:49 +00:00
|
|
|
initialize();
|
2009-04-18 10:44:44 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 08:20:22 +00:00
|
|
|
|
2012-09-22 18:51:49 +00:00
|
|
|
void MenuButton::initialize()
|
|
|
|
{
|
2009-04-18 10:44:44 +00:00
|
|
|
QString const label = qt_(to_ascii(tbitem_.label_));
|
|
|
|
ButtonMenu * m = new ButtonMenu(label, this);
|
|
|
|
m->setWindowTitle(label);
|
|
|
|
m->setTearOffEnabled(true);
|
|
|
|
connect(bar_, SIGNAL(updated()), m, SLOT(updateParent()));
|
2012-03-15 11:55:40 +00:00
|
|
|
connect(bar_, SIGNAL(updated()), this, SLOT(updateTriggered()));
|
2009-04-18 10:44:44 +00:00
|
|
|
ToolbarInfo const * tbinfo = guiApp->toolbars().info(tbitem_.name_);
|
|
|
|
if (!tbinfo) {
|
|
|
|
LYXERR0("Unknown toolbar " << tbitem_.name_);
|
|
|
|
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);
|
|
|
|
}
|
2008-01-17 08:20:22 +00:00
|
|
|
|
|
|
|
|
2009-04-18 10:44:44 +00:00
|
|
|
void MenuButton::actionTriggered(QAction * action)
|
|
|
|
{
|
|
|
|
QToolButton::setDefaultAction(action);
|
|
|
|
setPopupMode(QToolButton::DelayedPopup);
|
2008-01-16 18:27:24 +00:00
|
|
|
}
|
2007-09-28 22:53:00 +00:00
|
|
|
|
2008-01-17 08:32:48 +00:00
|
|
|
|
2012-03-15 11:55:40 +00:00
|
|
|
void MenuButton::updateTriggered()
|
|
|
|
{
|
|
|
|
if (!menu())
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool enabled = false;
|
|
|
|
QList<QAction *> acts = menu()->actions();
|
|
|
|
for (int i = 0; i < acts.size(); ++i)
|
|
|
|
if (acts[i]->isEnabled()) {
|
|
|
|
enabled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Enable the MenuButton if at least one menu item is enabled
|
|
|
|
setEnabled(enabled);
|
|
|
|
// If a disabled item is default, switch to InstantPopup
|
|
|
|
// (this can happen if a user selects e.g. DVI and then
|
|
|
|
// turns non-TeX fonts on)
|
|
|
|
if (defaultAction() && !defaultAction()->isEnabled())
|
|
|
|
setPopupMode(QToolButton::InstantPopup);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2009-08-14 22:58:57 +00:00
|
|
|
case ToolbarItem::LAYOUTS: {
|
|
|
|
LayoutBox * layout = owner_.getLayoutDialog();
|
2009-08-14 22:47:57 +00:00
|
|
|
QObject::connect(this, SIGNAL(iconSizeChanged(QSize)),
|
2009-08-14 22:58:57 +00:00
|
|
|
layout, SLOT(setIconSize(QSize)));
|
|
|
|
QAction * action = addWidget(layout);
|
|
|
|
action->setVisible(true);
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
2009-08-14 22:58:57 +00:00
|
|
|
}
|
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 09:19:52 +00:00
|
|
|
QString const label = qt_(to_ascii(item.label_));
|
2008-01-17 08:32:48 +00:00
|
|
|
tb->setToolTip(label);
|
|
|
|
tb->setStatusTip(label);
|
|
|
|
tb->setText(label);
|
2013-05-02 16:27:32 +00:00
|
|
|
InsertTableWidget * iv = new InsertTableWidget(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: {
|
2009-04-18 10:44:44 +00:00
|
|
|
addWidget(new MenuButton(this, item, false));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ToolbarItem::STICKYPOPUPMENU: {
|
|
|
|
addWidget(new MenuButton(this, item, true));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 13:30:44 +00:00
|
|
|
void GuiToolbar::update(int context)
|
2006-11-02 16:01:36 +00:00
|
|
|
{
|
2015-04-18 17:10:33 +00:00
|
|
|
if (visibility_ & Toolbars::AUTO) {
|
2015-06-18 13:30:44 +00:00
|
|
|
setVisible(visibility_ & context & Toolbars::ALLOWAUTO);
|
2016-08-19 12:53:31 +00:00
|
|
|
if (isVisible() && commandBuffer() && (context & Toolbars::MINIBUFFER_FOCUS))
|
2015-04-18 17:10:33 +00:00
|
|
|
commandBuffer()->setFocus();
|
|
|
|
}
|
2006-11-02 16:01:36 +00:00
|
|
|
|
2007-10-01 09:19:09 +00:00
|
|
|
// update visible toolbars only
|
|
|
|
if (!isVisible())
|
|
|
|
return;
|
2008-05-27 11:15:17 +00:00
|
|
|
|
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
|
|
|
|
2009-08-14 22:58:57 +00:00
|
|
|
LayoutBox * layout = owner_.getLayoutDialog();
|
|
|
|
if (layout)
|
|
|
|
layout->setEnabled(lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
|
2007-11-20 22:03:56 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
QString GuiToolbar::sessionKey() const
|
|
|
|
{
|
2008-09-21 21:28:37 +00:00
|
|
|
return "views/" + QString::number(owner_.id()) + "/" + objectName();
|
2008-05-27 11:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToolbar::saveSession() const
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(sessionKey() + "/visibility", visibility_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToolbar::restoreSession()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2011-01-03 14:39:41 +00:00
|
|
|
int const error_val = -1;
|
|
|
|
int visibility =
|
|
|
|
settings.value(sessionKey() + "/visibility", error_val).toInt();
|
|
|
|
if (visibility == error_val || visibility == 0) {
|
2011-01-03 15:56:27 +00:00
|
|
|
// This should not happen, but in case we use the defaults
|
2012-07-16 21:11:26 +00:00
|
|
|
LYXERR(Debug::GUI, "Session settings could not be found! Defaults are used instead.");
|
2011-01-03 14:39:41 +00:00
|
|
|
visibility =
|
|
|
|
guiApp->toolbars().defaultVisibility(fromqstr(objectName()));
|
|
|
|
}
|
|
|
|
setVisibility(visibility);
|
2008-05-27 11:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToolbar::toggle()
|
|
|
|
{
|
|
|
|
docstring state;
|
2011-01-03 11:42:01 +00:00
|
|
|
if (visibility_ & Toolbars::ALLOWAUTO) {
|
2008-05-27 11:15:17 +00:00
|
|
|
if (!(visibility_ & Toolbars::AUTO)) {
|
|
|
|
visibility_ |= Toolbars::AUTO;
|
|
|
|
hide();
|
|
|
|
state = _("auto");
|
|
|
|
} else {
|
|
|
|
visibility_ &= ~Toolbars::AUTO;
|
|
|
|
if (isVisible()) {
|
|
|
|
hide();
|
|
|
|
state = _("off");
|
|
|
|
} else {
|
|
|
|
show();
|
|
|
|
state = _("on");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isVisible()) {
|
|
|
|
hide();
|
|
|
|
state = _("off");
|
|
|
|
} else {
|
|
|
|
show();
|
|
|
|
state = _("on");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
|
|
|
|
qstring_to_ucs4(windowTitle()), state));
|
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiToolbar.cpp"
|