Lock toolbars (#10283)

- LFUNs to (un)lock toolbars positions (both individually and all at once)

- corresponding menu entry to "Lock Toolbars" menu.
This commit is contained in:
Daniel Ramöller 2016-11-24 14:10:03 +02:00 committed by Guillaume MM
parent 1fb6a0ac3e
commit e2f864efe4
8 changed files with 114 additions and 2 deletions

View File

@ -673,6 +673,8 @@ Menuset
Menu "context-toolbars" Menu "context-toolbars"
Toolbars Toolbars
Separator Separator
Item "Lock All Toolbars|L" "toolbar-movable *"
Separator
Item "Small-sized Icons" "icon-size small" Item "Small-sized Icons" "icon-size small"
Item "Normal-sized Icons" "icon-size normal" Item "Normal-sized Icons" "icon-size normal"
Item "Big-sized Icons" "icon-size big" Item "Big-sized Icons" "icon-size big"

View File

@ -353,6 +353,8 @@ Menuset
Menu "toolbars" Menu "toolbars"
Toolbars Toolbars
Separator Separator
Item "Lock All Toolbars|L" "toolbar-movable *"
Separator
Item "Small-sized Icons" "icon-size small" Item "Small-sized Icons" "icon-size small"
Item "Normal-sized Icons" "icon-size normal" Item "Normal-sized Icons" "icon-size normal"
Item "Big-sized Icons" "icon-size big" Item "Big-sized Icons" "icon-size big"

View File

@ -472,6 +472,7 @@ enum FuncCode
// 365 // 365
LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR,// gm, 20170302 LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR,// gm, 20170302
LFUN_BUFFER_ZOOM, // daniel, 20161028 LFUN_BUFFER_ZOOM, // daniel, 20161028
LFUN_TOOLBAR_MOVABLE, // daniel, 20160712
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };

View File

@ -3747,6 +3747,18 @@ void LyXAction::init()
*/ */
{ LFUN_THESAURUS_ENTRY, "thesaurus-entry", ReadOnly, Edit }, { LFUN_THESAURUS_ENTRY, "thesaurus-entry", ReadOnly, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_TOOLBAR_MOVABLE
* \li Action: Toggles movability of a given toolbar between true/false.
* \li Syntax: toolbar-movable <NAME>
* \li Params: <NAME>: *|standard|extra|table|math|mathmacrotemplate|\n
minibuffer|review|view/update|math_panels|vcs|
view-others|update-others
* \li Origin: daniel, 12 July 2016
* \endvar
*/
{ LFUN_TOOLBAR_MOVABLE, "toolbar-movable", NoBuffer, Buffer },
/*! /*!
* \var lyx::FuncCode lyx::LFUN_TOOLBAR_TOGGLE * \var lyx::FuncCode lyx::LFUN_TOOLBAR_TOGGLE
* \li Action: Toggles visibility of a given toolbar between on/off/auto. * \li Action: Toggles visibility of a given toolbar between on/off/auto.

View File

@ -61,8 +61,6 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
connect(&owner, SIGNAL(iconSizeChanged(QSize)), this, connect(&owner, SIGNAL(iconSizeChanged(QSize)), this,
SLOT(setIconSize(QSize))); SLOT(setIconSize(QSize)));
// Toolbar dragging is allowed.
setMovable(true);
// This is used by QMainWindow::restoreState for proper main window state // This is used by QMainWindow::restoreState for proper main window state
// restauration. // restauration.
setObjectName(toqstr(tbinfo.name)); setObjectName(toqstr(tbinfo.name));
@ -357,6 +355,7 @@ void GuiToolbar::saveSession() const
{ {
QSettings settings; QSettings settings;
settings.setValue(sessionKey() + "/visibility", visibility_); settings.setValue(sessionKey() + "/visibility", visibility_);
settings.setValue(sessionKey() + "/movability", isMovable());
} }
@ -373,6 +372,9 @@ void GuiToolbar::restoreSession()
guiApp->toolbars().defaultVisibility(fromqstr(objectName())); guiApp->toolbars().defaultVisibility(fromqstr(objectName()));
} }
setVisibility(visibility); setVisibility(visibility);
int movability = settings.value(sessionKey() + "/movability", true).toBool();
setMovable(movability);
} }
@ -408,6 +410,29 @@ void GuiToolbar::toggle()
qstring_to_ucs4(windowTitle()), state)); qstring_to_ucs4(windowTitle()), state));
} }
void GuiToolbar::movable(bool silent)
{
// toggle movability
setMovable(!isMovable());
// manual repaint avoids bug in qt that the drag handle is not removed
// properly, e.g. in Windows
if (isVisible())
repaint();
// silence for toggling of many toolbars for performance
if (!silent) {
docstring state;
if (isMovable()) {
state = _("movable");
} else {
state = _("immovable");
}
owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
qstring_to_ucs4(windowTitle()), state));
}
}
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -97,6 +97,9 @@ public:
/// ///
void toggle(); void toggle();
/// toggles movability
void movable(bool silent = false);
/// ///
GuiCommandBuffer * commandBuffer() { return command_buffer_; } GuiCommandBuffer * commandBuffer() { return command_buffer_; }

View File

@ -793,6 +793,9 @@ bool GuiView::restoreLayout()
initToolbar(cit->name); initToolbar(cit->name);
} }
// update lock (all) toolbars positions
updateLockToolbars();
updateDialogs(); updateDialogs();
return true; return true;
} }
@ -809,6 +812,17 @@ GuiToolbar * GuiView::toolbar(string const & name)
} }
void GuiView::updateLockToolbars()
{
toolbarsMovable = false;
for (ToolbarInfo const & info : guiApp->toolbars()) {
GuiToolbar * tb = toolbar(info.name);
if (tb && tb->isMovable())
toolbarsMovable = true;
}
}
void GuiView::constructToolbars() void GuiView::constructToolbars()
{ {
ToolbarMap::iterator it = d.toolbars_.begin(); ToolbarMap::iterator it = d.toolbars_.begin();
@ -876,6 +890,8 @@ void GuiView::initToolbar(string const & name)
if (visibility & Toolbars::ON) if (visibility & Toolbars::ON)
tb->setVisible(true); tb->setVisible(true);
tb->setMovable(true);
} }
@ -1895,6 +1911,23 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
break; break;
} }
case LFUN_TOOLBAR_MOVABLE: {
string const name = cmd.getArg(0);
// use negation since locked == !movable
if (name == "*") {
// toolbar name * locks all toolbars
flag.setOnOff(!toolbarsMovable);
} else if (GuiToolbar * t = toolbar(name)) {
flag.setOnOff(!(t->isMovable()));
} else {
enable = false;
docstring const msg =
bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
flag.message(msg);
}
break;
}
case LFUN_ICON_SIZE: case LFUN_ICON_SIZE:
flag.setOnOff(d.iconSize(cmd.argument()) == iconSize()); flag.setOnOff(d.iconSize(cmd.argument()) == iconSize());
break; break;
@ -3815,6 +3848,35 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break; break;
} }
case LFUN_TOOLBAR_MOVABLE: {
string const name = cmd.getArg(0);
if (name == "*") {
// toggle (all) toolbars movablility
toolbarsMovable = !toolbarsMovable;
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
Toolbars::Infos::iterator end = guiApp->toolbars().end();
for (; cit != end; ++cit) {
GuiToolbar * tb = toolbar(cit->name);
if (tb && tb->isMovable() != toolbarsMovable) {
// toggle toolbar movablity if it does not fit lock (all) toolbars positions state
// silent = true, since status bar notifications are slow
tb->movable(true);
}
}
if (toolbarsMovable) {
dr.setMessage(_("All toolbars unlocked."));
} else {
dr.setMessage(_("All toolbars locked."));
}
} else if (GuiToolbar * t = toolbar(name)) {
// toggle current toolbar movablity
t->movable();
// update lock (all) toolbars positions
updateLockToolbars();
}
break;
}
case LFUN_ICON_SIZE: { case LFUN_ICON_SIZE: {
QSize size = d.iconSize(cmd.argument()); QSize size = d.iconSize(cmd.argument());
setIconSize(size); setIconSize(size);

View File

@ -210,6 +210,9 @@ public:
/// Current ratio between physical pixels and device-independent pixels /// Current ratio between physical pixels and device-independent pixels
double pixelRatio() const; double pixelRatio() const;
// movability flag of all toolbars
bool toolbarsMovable;
Q_SIGNALS: Q_SIGNALS:
void closing(int); void closing(int);
void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset); void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
@ -357,6 +360,8 @@ private:
void initToolbars(); void initToolbars();
/// ///
void initToolbar(std::string const & name); void initToolbar(std::string const & name);
/// Update lock (all) toolbars position
void updateLockToolbars();
/// ///
bool lfunUiToggle(std::string const & ui_component); bool lfunUiToggle(std::string const & ui_component);
/// ///