From e2f864efe447c0d71eeaefaaeb4d51b8316f3fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ram=C3=B6ller?= Date: Thu, 24 Nov 2016 14:10:03 +0200 Subject: [PATCH] Lock toolbars (#10283) - LFUNs to (un)lock toolbars positions (both individually and all at once) - corresponding menu entry to "Lock Toolbars" menu. --- lib/ui/stdcontext.inc | 2 ++ lib/ui/stdmenus.inc | 2 ++ src/FuncCode.h | 1 + src/LyXAction.cpp | 12 +++++++ src/frontends/qt4/GuiToolbar.cpp | 29 +++++++++++++-- src/frontends/qt4/GuiToolbar.h | 3 ++ src/frontends/qt4/GuiView.cpp | 62 ++++++++++++++++++++++++++++++++ src/frontends/qt4/GuiView.h | 5 +++ 8 files changed, 114 insertions(+), 2 deletions(-) diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 89cf287088..54fbc8d57f 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -673,6 +673,8 @@ Menuset Menu "context-toolbars" Toolbars Separator + Item "Lock All Toolbars|L" "toolbar-movable *" + Separator Item "Small-sized Icons" "icon-size small" Item "Normal-sized Icons" "icon-size normal" Item "Big-sized Icons" "icon-size big" diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index a392ba5048..e8d2a29fa7 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -353,6 +353,8 @@ Menuset Menu "toolbars" Toolbars Separator + Item "Lock All Toolbars|L" "toolbar-movable *" + Separator Item "Small-sized Icons" "icon-size small" Item "Normal-sized Icons" "icon-size normal" Item "Big-sized Icons" "icon-size big" diff --git a/src/FuncCode.h b/src/FuncCode.h index 9561cbc6d2..c8a46ce54a 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -472,6 +472,7 @@ enum FuncCode // 365 LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR,// gm, 20170302 LFUN_BUFFER_ZOOM, // daniel, 20161028 + LFUN_TOOLBAR_MOVABLE, // daniel, 20160712 LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index d3c1895694..c068db9bea 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3747,6 +3747,18 @@ void LyXAction::init() */ { 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 + * \li Params: : *|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 * \li Action: Toggles visibility of a given toolbar between on/off/auto. diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index 36a7326a5e..1c38a18cab 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -61,8 +61,6 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner) connect(&owner, SIGNAL(iconSizeChanged(QSize)), this, SLOT(setIconSize(QSize))); - // Toolbar dragging is allowed. - setMovable(true); // This is used by QMainWindow::restoreState for proper main window state // restauration. setObjectName(toqstr(tbinfo.name)); @@ -357,6 +355,7 @@ void GuiToolbar::saveSession() const { QSettings settings; settings.setValue(sessionKey() + "/visibility", visibility_); + settings.setValue(sessionKey() + "/movability", isMovable()); } @@ -373,6 +372,9 @@ void GuiToolbar::restoreSession() guiApp->toolbars().defaultVisibility(fromqstr(objectName())); } setVisibility(visibility); + + int movability = settings.value(sessionKey() + "/movability", true).toBool(); + setMovable(movability); } @@ -408,6 +410,29 @@ void GuiToolbar::toggle() 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 lyx diff --git a/src/frontends/qt4/GuiToolbar.h b/src/frontends/qt4/GuiToolbar.h index caad355bd8..43f6188748 100644 --- a/src/frontends/qt4/GuiToolbar.h +++ b/src/frontends/qt4/GuiToolbar.h @@ -97,6 +97,9 @@ public: /// void toggle(); + /// toggles movability + void movable(bool silent = false); + /// GuiCommandBuffer * commandBuffer() { return command_buffer_; } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index f01b94c919..030898bd3c 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -793,6 +793,9 @@ bool GuiView::restoreLayout() initToolbar(cit->name); } + // update lock (all) toolbars positions + updateLockToolbars(); + updateDialogs(); 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() { ToolbarMap::iterator it = d.toolbars_.begin(); @@ -876,6 +890,8 @@ void GuiView::initToolbar(string const & name) if (visibility & Toolbars::ON) tb->setVisible(true); + + tb->setMovable(true); } @@ -1895,6 +1911,23 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) 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: flag.setOnOff(d.iconSize(cmd.argument()) == iconSize()); break; @@ -3815,6 +3848,35 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) 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: { QSize size = d.iconSize(cmd.argument()); setIconSize(size); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 4b0429c29b..297de89719 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -210,6 +210,9 @@ public: /// Current ratio between physical pixels and device-independent pixels double pixelRatio() const; + // movability flag of all toolbars + bool toolbarsMovable; + Q_SIGNALS: void closing(int); void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset); @@ -357,6 +360,8 @@ private: void initToolbars(); /// void initToolbar(std::string const & name); + /// Update lock (all) toolbars position + void updateLockToolbars(); /// bool lfunUiToggle(std::string const & ui_component); ///