]> git.lyx.org Git - features.git/commitdiff
Add the icon-size to the toolbar menu
authorDaniel Ramöller <d.lyx@web.de>
Sun, 9 Oct 2016 07:15:20 +0000 (09:15 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Nov 2016 09:00:52 +0000 (10:00 +0100)
- Adds LFUNs for setting the icon size
- Adds icons sizes to the Toolbars menu
- Uses the Toolbars menu as application context menu
- The context menu can now be user defined in stdcontext.inc

Fixes ticket #10428.

lib/ui/stdcontext.inc
lib/ui/stdmenus.inc
src/FuncCode.h
src/LyXAction.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h

index fded25a41d117ba64a0bc874d4a068d473c420de..abba2650318ca494c8eff93c2869d8ef8c61d840 100644 (file)
@@ -659,4 +659,17 @@ Menuset
                Item "Settings...|S" "inset-settings"
        End
 
+#
+# Toolbar context menu
+#
+       Menu "context-toolbars"
+               Toolbars
+               Separator
+               Item "Small-sized Icons" "icon-size 16"
+               Item "Normal-sized Icons" "icon-size 20"
+               Item "Big-sized Icons" "icon-size 26"
+               Item "Huge-sized Icons" "icon-size 32"
+               Item "Giant-sized Icons" "icon-size 48"
+       End
+
 End
index 87c78edf43075af9c9c9afbd5aeeecac553060cd..06614c89970e2ba6a5e2d9259718b115cf63a5aa 100644 (file)
@@ -350,6 +350,12 @@ Menuset
 
        Menu "toolbars"
                Toolbars
+               Separator
+               Item "Small-sized Icons" "icon-size 16"
+               Item "Normal-sized Icons" "icon-size 20"
+               Item "Big-sized Icons" "icon-size 26"
+               Item "Huge-sized Icons" "icon-size 32"
+               Item "Giant-sized Icons" "icon-size 48"
        End
 #
 # INSERT MENU
index c84f35238cc0cdd9391e56978467dd50957b3612..ad9cb56f34447703a9a3258779f36de7c1589de2 100644 (file)
@@ -467,6 +467,7 @@ enum FuncCode
        LFUN_TABULAR_FEATURE,           // gm, 20151210
        LFUN_BRANCH_INVERT,             // rgheck, 20160712
        LFUN_LYX_ACTIVATE,              // skostysh, 20160804
+       LFUN_ICON_SIZE,                 // daniel, 20160712
        LFUN_LASTACTION                 // end of the table
 };
 
index 6674fec18b681ecbe39f440e5c0800726e20b9aa..cf113184f39df7fbf93cfc4a5ca1450211418837 100644 (file)
@@ -2745,6 +2745,15 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_TOOLBAR_TOGGLE, "toolbar-toggle", NoBuffer, Buffer },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_ICON_SIZE
+ * \li Action: Sets icon size of toolbars.
+ * \li Syntax: icon-size [<SIZE>]
+ * \li Params: <SIZE> : the icon size in px, the default is 20 (normalIconSize).
+ * \li Origin: 11 July 2016
+ * \endvar
+ */
+               { LFUN_ICON_SIZE, "icon-size", NoBuffer, Buffer },
 /*!
  * \var lyx::FuncCode lyx::LFUN_MENU_OPEN
  * \li Action: Opens the menu given by its name.
index 70aa5883bb2c9f22f8dc4369a23887f95310aa5c..432da37d533600d094af9aeab794c810d254787a 100644 (file)
@@ -327,62 +327,6 @@ public:
                delete stack_widget_;
        }
 
-       QMenu * toolBarPopup(GuiView * parent)
-       {
-               // FIXME: translation
-               QMenu * menu = new QMenu(parent);
-               QActionGroup * iconSizeGroup = new QActionGroup(parent);
-
-               QAction * smallIcons = new QAction(iconSizeGroup);
-               smallIcons->setText(qt_("Small-sized icons"));
-               smallIcons->setCheckable(true);
-               QObject::connect(smallIcons, SIGNAL(triggered()),
-                       parent, SLOT(smallSizedIcons()));
-               menu->addAction(smallIcons);
-
-               QAction * normalIcons = new QAction(iconSizeGroup);
-               normalIcons->setText(qt_("Normal-sized icons"));
-               normalIcons->setCheckable(true);
-               QObject::connect(normalIcons, SIGNAL(triggered()),
-                       parent, SLOT(normalSizedIcons()));
-               menu->addAction(normalIcons);
-
-               QAction * bigIcons = new QAction(iconSizeGroup);
-               bigIcons->setText(qt_("Big-sized icons"));
-               bigIcons->setCheckable(true);
-               QObject::connect(bigIcons, SIGNAL(triggered()),
-                       parent, SLOT(bigSizedIcons()));
-               menu->addAction(bigIcons);
-
-               QAction * hugeIcons = new QAction(iconSizeGroup);
-               hugeIcons->setText(qt_("Huge-sized icons"));
-               hugeIcons->setCheckable(true);
-               QObject::connect(hugeIcons, SIGNAL(triggered()),
-                       parent, SLOT(hugeSizedIcons()));
-               menu->addAction(hugeIcons);
-
-               QAction * giantIcons = new QAction(iconSizeGroup);
-               giantIcons->setText(qt_("Giant-sized icons"));
-               giantIcons->setCheckable(true);
-               QObject::connect(giantIcons, SIGNAL(triggered()),
-                       parent, SLOT(giantSizedIcons()));
-               menu->addAction(giantIcons);
-
-               unsigned int cur = parent->iconSize().width();
-               if ( cur == parent->d.smallIconSize)
-                       smallIcons->setChecked(true);
-               else if (cur == parent->d.normalIconSize)
-                       normalIcons->setChecked(true);
-               else if (cur == parent->d.bigIconSize)
-                       bigIcons->setChecked(true);
-               else if (cur == parent->d.hugeIconSize)
-                       hugeIcons->setChecked(true);
-               else if (cur == parent->d.giantIconSize)
-                       giantIcons->setChecked(true);
-
-               return menu;
-       }
-
        void setBackground()
        {
                stack_widget_->setCurrentWidget(bg_widget_);
@@ -516,7 +460,7 @@ GuiView::GuiView(int id)
                this, SLOT(onBufferViewChanged()));
 
        // GuiToolbars *must* be initialised before the menu bar.
-       normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge
+       setIconSize(QSize(d.normalIconSize, d.normalIconSize)); // at least on Mac the default is 32 otherwise, which is huge
        constructToolbars();
 
        // set ourself as the current view. This is needed for the menu bar
@@ -608,6 +552,11 @@ GuiView::GuiView(int id)
        connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
                SLOT(doShowDialog(QString const &, QString const &, Inset *)));
 
+       // set custom application bars context menu, e.g. tool bar and menu bar
+       setContextMenuPolicy(Qt::CustomContextMenu);
+       connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
+               SLOT(toolBarPopup(const QPoint &)));
+
        // Forbid too small unresizable window because it can happen
        // with some window manager under X11.
        setMinimumSize(300, 200);
@@ -748,14 +697,6 @@ bool GuiView::restoreLayout()
        //code below is skipped when when ~/.config/LyX is (re)created
        QSize icon_size = settings.value(icon_key).toSize();
        // Check whether session size changed.
-       if (icon_size.width() != int(d.smallIconSize) &&
-           icon_size.width() != int(d.normalIconSize) &&
-           icon_size.width() != int(d.bigIconSize) &&
-           icon_size.width() != int(d.hugeIconSize) &&
-           icon_size.width() != int(d.giantIconSize)) {
-               icon_size.setWidth(d.normalIconSize);
-               icon_size.setHeight(d.normalIconSize);
-       }
        setIconSize(icon_size);
 
 #if defined(Q_WS_X11) || defined(QPA_XCB)
@@ -921,12 +862,6 @@ void GuiView::focusInEvent(QFocusEvent * e)
 }
 
 
-QMenu * GuiView::createPopupMenu()
-{
-       return d.toolBarPopup(this);
-}
-
-
 void GuiView::showEvent(QShowEvent * e)
 {
        LYXERR(Debug::GUI, "Passed Geometry "
@@ -1114,36 +1049,6 @@ void GuiView::updateStatusBarMessage(QString const & str)
 }
 
 
-void GuiView::smallSizedIcons()
-{
-       setIconSize(QSize(d.smallIconSize, d.smallIconSize));
-}
-
-
-void GuiView::normalSizedIcons()
-{
-       setIconSize(QSize(d.normalIconSize, d.normalIconSize));
-}
-
-
-void GuiView::bigSizedIcons()
-{
-       setIconSize(QSize(d.bigIconSize, d.bigIconSize));
-}
-
-
-void GuiView::hugeSizedIcons()
-{
-       setIconSize(QSize(d.hugeIconSize, d.hugeIconSize));
-}
-
-
-void GuiView::giantSizedIcons()
-{
-       setIconSize(QSize(d.giantIconSize, d.giantIconSize));
-}
-
-
 void GuiView::clearMessage()
 {
        // FIXME: This code was introduced in r19643 to fix bug #4123. However,
@@ -1923,6 +1828,12 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                break;
        }
 
+       case LFUN_ICON_SIZE: {
+               int const size = cmd.argument().empty() ? d.normalIconSize : convert<int>(cmd.argument());
+               flag.setOnOff(QSize(size, size) == iconSize());
+               break;
+       }
+
        case LFUN_DROP_LAYOUTS_CHOICE:
                enable = buf != 0;
                break;
@@ -3404,6 +3315,14 @@ bool GuiView::goToFileRow(string const & argument)
 }
 
 
+void GuiView::toolBarPopup(const QPoint & pos)
+{
+       QMenu * menu = new QMenu;
+       menu = guiApp->menus().menu(toqstr("context-toolbars"), * this);
+       menu->exec(QCursor::pos());
+}
+
+
 template<class T>
 Buffer::ExportStatus GuiView::GuiViewPrivate::runAndDestroy(const T& func, Buffer const * orig, Buffer * clone, string const & format)
 {
@@ -3809,6 +3728,24 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        break;
                }
 
+               case LFUN_ICON_SIZE: {
+                       int const size = cmd.argument().empty() ? d.normalIconSize : convert<int>(cmd.argument());
+                       setIconSize(QSize(size, size));
+                       if (size == d.smallIconSize)
+                               dr.setMessage("Icon size set to small");
+                       else if (size == d.normalIconSize)
+                               dr.setMessage("Icon size set to normal");
+                       else if (size == d.bigIconSize)
+                               dr.setMessage("Icon size set to big");
+                       else if (size == d.hugeIconSize)
+                               dr.setMessage("Icon size set to huge");
+                       else if (size == d.giantIconSize)
+                               dr.setMessage("Icon size set to giant");
+                       else
+                               dr.setMessage(bformat(_("Icon size set to %1$d"), size));
+                       break;
+               }
+
                case LFUN_DIALOG_UPDATE: {
                        string const name = to_utf8(cmd.argument());
                        if (name == "prefs" || name == "document")
index 4bc8b187a571e3500ed8a3d2b5f61bfeb41d2b96..a864f4b52a157bf4207b2bd8a071d5a88ceedbe1 100644 (file)
@@ -146,7 +146,6 @@ public:
        /// updates the possible layouts selectable
        void updateLayoutList();
        void updateToolbars();
-       QMenu * createPopupMenu();
 
        ///
        LayoutBox * getLayoutDialog() const;
@@ -237,13 +236,6 @@ private Q_SLOTS:
        ///
        void on_lastWorkAreaRemoved();
 
-       /// slots to change the icon size
-       void smallSizedIcons();
-       void normalSizedIcons();
-       void bigSizedIcons();
-       void hugeSizedIcons();
-       void giantSizedIcons();
-
        /// For completion of autosave or export threads.
        void processingThreadStarted();
        void processingThreadFinished();
@@ -257,6 +249,9 @@ private Q_SLOTS:
        void updateStatusBarMessage(QString const & str);
        void clearMessageText();
 
+       ///
+       void toolBarPopup(const QPoint &pos);
+
 private:
        /// Open given child document in current buffer directory.
        void openChildDocument(std::string const & filename);