[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-cvs
Subject:    [LyX/2.2.x] Add the icon-size to the toolbar menu
From:       Jean-Marc Lasgouttes <lasgouttes () lyx ! org>
Date:       2016-11-25 9:41:13
Message-ID: 20161125094113.7FE7D280692 () lyx ! lyx ! org
[Download RAW message or body]

commit 060a9664f77a2fa0a8c456b9dc567a775bba9645
Author: Daniel Ramöller <d.lyx@web.de>
Date:   Sun Oct 9 09:15:20 2016 +0200

    Add the icon-size to the toolbar menu
    
    - 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
    
    When the logical sizes differ and the icon set is changed, the correct
    sizes are established only after a restart.
    
    Fixes ticket #10428.
    
    (cherry picked from commit e91572a00bd61d56b5386519b52d316a32974497)
    (cherry picked from commit 6c92075799ae8d83f4f38e3c169c40da215e03f2)
    (cherry picked from commit 7971dc83efd2a3a2d282af17cded54698340e176)
---
 lib/ui/stdcontext.inc         |   13 +++
 lib/ui/stdmenus.inc           |    6 ++
 src/FuncCode.h                |    1 +
 src/LyXAction.cpp             |   11 +++
 src/frontends/qt4/GuiView.cpp |  187 ++++++++++++++++++-----------------------
 src/frontends/qt4/GuiView.h   |   11 +--
 status.22x                    |    4 +
 7 files changed, 120 insertions(+), 113 deletions(-)

diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index ab71a5b..e587f06 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -658,4 +658,17 @@ Menuset
 		Item "Settings...|S" "inset-settings"
 	End
 
+#
+# Toolbar context menu
+#
+	Menu "context-toolbars"
+		Toolbars
+		Separator
+		Item "Small-sized Icons" "icon-size small"
+		Item "Normal-sized Icons" "icon-size normal"
+		Item "Big-sized Icons" "icon-size big"
+		Item "Huge-sized Icons" "icon-size huge"
+		Item "Giant-sized Icons" "icon-size giant"
+	End
+
 End
diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index 62ed8e2..c48a669 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -350,6 +350,12 @@ Menuset
 
 	Menu "toolbars"
 		Toolbars
+		Separator
+		Item "Small-sized Icons" "icon-size small"
+		Item "Normal-sized Icons" "icon-size normal"
+		Item "Big-sized Icons" "icon-size big"
+		Item "Huge-sized Icons" "icon-size huge"
+		Item "Giant-sized Icons" "icon-size giant"
 	End
 #
 # INSERT MENU
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 40ec9d3..1285b2d 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -465,6 +465,7 @@ enum FuncCode
 	// 340
 	LFUN_BUFFER_MOVE_PREVIOUS,      // skostysh 20150408
 	LFUN_TABULAR_FEATURE,           // gm, 20151210
+	LFUN_ICON_SIZE,                 // daniel, 20160712
 	LFUN_LASTACTION                 // end of the table
 };
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 831c3f6..3ee66db 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -2728,6 +2728,17 @@ void LyXAction::init()
  */
 		{ 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 or one of the logical settings
+                        small|normal|big|huge|giant, the default is normal
+                        (whose size in px is icon set dependent).
+ * \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.
  * \li Syntax: menu-open <NAME>
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 9166f72..38f3433 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -328,62 +328,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_);
@@ -440,6 +384,60 @@ public:
 		processing_thread_watcher_.setFuture(f);
 	}
 
+	QSize iconSize(docstring const & icon_size)
+	{
+		unsigned int size;
+		if (icon_size == "small")
+			size = smallIconSize;
+		else if (icon_size == "normal")
+			size = normalIconSize;
+		else if (icon_size == "big")
+			size = bigIconSize;
+		else if (icon_size == "huge")
+			size = hugeIconSize;
+		else if (icon_size == "giant")
+			size = giantIconSize;
+		else
+			size = icon_size.empty() ? normalIconSize : convert<int>(icon_size);
+
+		if (size < smallIconSize)
+			size = smallIconSize;
+
+		return QSize(size, size);
+	}
+
+	QSize iconSize(QString const & icon_size)
+	{
+		return iconSize(qstring_to_ucs4(icon_size));
+	}
+
+	string & iconSize(QSize const & qsize)
+	{
+		LATTEST(qsize.width() == qsize.height());
+
+		static string icon_size;
+
+		unsigned int size = qsize.width();
+
+		if (size < smallIconSize)
+			size = smallIconSize;
+
+		if (size == smallIconSize)
+			icon_size = "small";
+		else if (size == normalIconSize)
+			icon_size = "normal";
+		else if (size == bigIconSize)
+			icon_size = "big";
+		else if (size == hugeIconSize)
+			icon_size = "huge";
+		else if (size == giantIconSize)
+			icon_size = "giant";
+		else
+			icon_size = convert<string>(size);
+
+		return icon_size;
+	}
+
 public:
 	GuiView * gv_;
 	GuiWorkArea * current_work_area_;
@@ -514,7 +512,7 @@ GuiView::GuiView(int id)
 	  command_execute_(false), minibuffer_focus_(false)
 {
 	// 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
@@ -606,6 +604,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);
@@ -717,7 +720,7 @@ void GuiView::saveLayout() const
 	settings.setValue("geometry", saveGeometry());
 #endif
 	settings.setValue("layout", saveState(0));
-	settings.setValue("icon_size", iconSize());
+	settings.setValue("icon_size", toqstr(d.iconSize(iconSize())));
 }
 
 
@@ -744,17 +747,7 @@ bool GuiView::restoreLayout()
 		return false;
 
 	//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);
+	setIconSize(d.iconSize(settings.value(icon_key).toString()));
 
 #if defined(Q_WS_X11) || defined(QPA_XCB)
 	QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
@@ -919,12 +912,6 @@ void GuiView::focusInEvent(QFocusEvent * e)
 }
 
 
-QMenu * GuiView::createPopupMenu()
-{
-	return d.toolBarPopup(this);
-}
-
-
 void GuiView::showEvent(QShowEvent * e)
 {
 	LYXERR(Debug::GUI, "Passed Geometry "
@@ -1112,36 +1099,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,
@@ -1924,6 +1881,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & \
flag)  break;
 	}
 
+	case LFUN_ICON_SIZE:
+		flag.setOnOff(d.iconSize(cmd.argument()) == iconSize());
+		break;
+
 	case LFUN_DROP_LAYOUTS_CHOICE:
 		enable = buf != 0;
 		break;
@@ -3398,6 +3359,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)  {
@@ -3800,6 +3769,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult \
& dr)  break;
 		}
 
+		case LFUN_ICON_SIZE: {
+			QSize size = d.iconSize(cmd.argument());
+			setIconSize(size);
+			dr.setMessage(bformat(_("Icon size set to %1$dx%2$d."),
+						size.width(), size.height()));
+			break;
+		}
+
 		case LFUN_DIALOG_UPDATE: {
 			string const name = to_utf8(cmd.argument());
 			if (name == "prefs" || name == "document")
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index 3fcfc01..d12dc56 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
@@ -146,7 +146,6 @@ public:
 	/// updates the possible layouts selectable
 	void updateLayoutList();
 	void updateToolbars();
-	QMenu * createPopupMenu();
 
 	///
 	LayoutBox * getLayoutDialog() const;
@@ -233,13 +232,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();
@@ -253,6 +245,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);
diff --git a/status.22x b/status.22x
index 2c52f5c..c257d6a 100644
--- a/status.22x
+++ b/status.22x
@@ -26,6 +26,10 @@ What's new
 - The title bar is now set according to platform UI. Read-only and
   version control are shown by indicators in the status bar.
 
+- The toolbar context menu and the View>Toobars menus are now
+  identical. Both allow to change icon size and to enable individual
+  toolbars.
+
 - The citation dialog has been redesigned, following user suggestions.
 
 - Remember citation style settings both within and between sessions


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic