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

Fixes ticket #10428.
This commit is contained in:
Daniel Ramöller 2016-10-09 09:15:20 +02:00 committed by Jean-Marc Lasgouttes
parent e5386ce473
commit e91572a00b
6 changed files with 70 additions and 109 deletions

View 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

View 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

View 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
};

View 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.

View 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")

View 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);