mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Use customizable zoom context menu
Based on a proposal by Daniel (#12187)
This commit is contained in:
parent
d29d2f48fd
commit
1bf53d47a5
@ -723,4 +723,13 @@ Menuset
|
||||
Item "Giant-sized Icons" "icon-size giant"
|
||||
End
|
||||
|
||||
#
|
||||
# Zoom context menu
|
||||
#
|
||||
Menu "context-zoom"
|
||||
ZoomOptions
|
||||
Separator
|
||||
Item "Show Zoom Slider|S" "ui-toggle zoomslider"
|
||||
End
|
||||
|
||||
End
|
||||
|
@ -684,28 +684,8 @@ GuiView::GuiView(int id)
|
||||
zoom_value_->setEnabled(currentBufferView());
|
||||
zoom_value_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
ZoomMenu * zoom_menu = new ZoomMenu(statusBar());
|
||||
act_zoom_default_ = new QAction(toqstr(bformat(_("&Reset to default (%1$d%)"),
|
||||
lyxrc.defaultZoom)), this);
|
||||
act_zoom_in_ = new QAction(qt_("Zoom &in"), this);
|
||||
act_zoom_out_ = new QAction(qt_("Zoom &out"), this);
|
||||
act_zoom_show_ = new QAction(qt_("Show zoom slider"), this);
|
||||
act_zoom_show_->setCheckable(true);
|
||||
zoom_menu->addAction(act_zoom_default_);
|
||||
zoom_menu->addAction(act_zoom_in_);
|
||||
zoom_menu->addAction(act_zoom_out_);
|
||||
zoom_menu->addAction(act_zoom_show_);
|
||||
enableZoomOptions();
|
||||
connect(act_zoom_default_, SIGNAL(triggered()),
|
||||
this, SLOT(resetDefaultZoom()));
|
||||
connect(act_zoom_in_, SIGNAL(triggered()),
|
||||
this, SLOT(zoomInPressed()));
|
||||
connect(act_zoom_out_, SIGNAL(triggered()),
|
||||
this, SLOT(zoomOutPressed()));
|
||||
connect(act_zoom_show_, SIGNAL(triggered()),
|
||||
this, SLOT(toogleZoomSlider()));
|
||||
connect(zoom_value_, SIGNAL(customContextMenuRequested(QPoint)),
|
||||
zoom_menu, SLOT(showMenu(QPoint)));
|
||||
this, SLOT(showZoomContextMenu()));
|
||||
|
||||
int const iconheight = max(int(d.normalIconSize), fm.height());
|
||||
QSize const iconsize(iconheight, iconheight);
|
||||
@ -804,15 +784,6 @@ void GuiView::checkCancelBackground()
|
||||
}
|
||||
|
||||
|
||||
void GuiView::enableZoomOptions()
|
||||
{
|
||||
act_zoom_default_->setEnabled(zoom_slider_->value() != lyxrc.defaultZoom);
|
||||
FuncStatus status;
|
||||
act_zoom_in_->setEnabled(getStatus(FuncRequest(LFUN_BUFFER_ZOOM_IN), status));
|
||||
act_zoom_out_->setEnabled(getStatus(FuncRequest(LFUN_BUFFER_ZOOM_OUT), status));
|
||||
}
|
||||
|
||||
|
||||
void GuiView::zoomSliderMoved(int value)
|
||||
{
|
||||
DispatchResult dr;
|
||||
@ -826,7 +797,6 @@ void GuiView::zoomValueChanged(int value)
|
||||
{
|
||||
if (value != lyxrc.currentZoom)
|
||||
zoomSliderMoved(value);
|
||||
enableZoomOptions();
|
||||
}
|
||||
|
||||
|
||||
@ -846,17 +816,12 @@ void GuiView::zoomOutPressed()
|
||||
}
|
||||
|
||||
|
||||
void GuiView::toogleZoomSlider()
|
||||
void GuiView::showZoomContextMenu()
|
||||
{
|
||||
DispatchResult dr;
|
||||
dispatch(FuncRequest(LFUN_UI_TOGGLE, "zoomslider"), dr);
|
||||
}
|
||||
|
||||
|
||||
void GuiView::resetDefaultZoom()
|
||||
{
|
||||
zoomValueChanged(lyxrc.defaultZoom);
|
||||
enableZoomOptions();
|
||||
QMenu * menu = guiApp->menus().menu(toqstr("context-zoom"), * this);
|
||||
if (!menu)
|
||||
return;
|
||||
menu->exec(QCursor::pos());
|
||||
}
|
||||
|
||||
|
||||
@ -1008,7 +973,6 @@ bool GuiView::restoreLayout()
|
||||
|
||||
bool const show_zoom_slider = settings.value("zoom_slider_visible", true).toBool();
|
||||
zoom_slider_->setVisible(show_zoom_slider);
|
||||
act_zoom_show_->setChecked(show_zoom_slider);
|
||||
zoom_in_->setVisible(show_zoom_slider);
|
||||
zoom_out_->setVisible(show_zoom_slider);
|
||||
|
||||
@ -2363,7 +2327,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
||||
case LFUN_UI_TOGGLE:
|
||||
if (cmd.argument() == "zoomslider") {
|
||||
enable = doc_buffer;
|
||||
flag.setOnOff(zoom_slider_->isVisible());
|
||||
// Test to avoid crash if called before zoom_slider_ is initialized
|
||||
// FIXME: can probably be done better
|
||||
if (enable)
|
||||
flag.setOnOff(zoom_slider_->isVisible());
|
||||
} else
|
||||
flag.setOnOff(isFullScreen());
|
||||
break;
|
||||
@ -2482,7 +2449,8 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
||||
bformat(_("Zoom level cannot be less than %1$d%."), zoom_min_);
|
||||
flag.message(msg);
|
||||
enable = false;
|
||||
}
|
||||
} else if (cmd.argument().empty() && lyxrc.currentZoom == lyxrc.defaultZoom)
|
||||
enable = false;
|
||||
else
|
||||
enable = doc_buffer;
|
||||
break;
|
||||
@ -4870,7 +4838,6 @@ bool GuiView::lfunUiToggle(string const & ui_component)
|
||||
zoom_slider_->setVisible(!zoom_slider_->isVisible());
|
||||
zoom_in_->setVisible(zoom_slider_->isVisible());
|
||||
zoom_out_->setVisible(zoom_slider_->isVisible());
|
||||
act_zoom_show_->setChecked(zoom_slider_->isVisible());
|
||||
} else if (ui_component == "frame") {
|
||||
int const l = contentsMargins().left();
|
||||
|
||||
|
@ -253,9 +253,7 @@ private Q_SLOTS:
|
||||
///
|
||||
void zoomOutPressed();
|
||||
///
|
||||
void resetDefaultZoom();
|
||||
///
|
||||
void toogleZoomSlider();
|
||||
void showZoomContextMenu();
|
||||
///
|
||||
void on_currentWorkAreaChanged(GuiWorkArea *);
|
||||
///
|
||||
@ -480,8 +478,6 @@ private:
|
||||
void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
|
||||
///
|
||||
void showMessage();
|
||||
///
|
||||
void enableZoomOptions();
|
||||
|
||||
/// This view ID.
|
||||
int id_;
|
||||
@ -513,14 +509,6 @@ private:
|
||||
QPushButton * zoom_in_;
|
||||
/// Zoom out ("-") Button
|
||||
QPushButton * zoom_out_;
|
||||
/// Set zoom to default
|
||||
QAction * act_zoom_default_;
|
||||
/// Zoom in menu action
|
||||
QAction * act_zoom_in_;
|
||||
/// Zoom out menu action
|
||||
QAction * act_zoom_out_;
|
||||
/// Show zoom slider
|
||||
QAction * act_zoom_show_;
|
||||
|
||||
/// The rate from which the actual zoom value is calculated
|
||||
/// from the default zoom pref
|
||||
@ -546,16 +534,6 @@ public Q_SLOTS:
|
||||
void showMenu(QPoint const &) { exec(QCursor::pos()); }
|
||||
};
|
||||
|
||||
class ZoomMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ZoomMenu(QWidget *) {};
|
||||
|
||||
public Q_SLOTS:
|
||||
void showMenu(QPoint const &) { exec(QCursor::pos()); }
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -197,7 +197,9 @@ public:
|
||||
/** Commands to separate environments (context menu version). */
|
||||
EnvironmentSeparatorsContext,
|
||||
/** This is the list of quotation marks available */
|
||||
SwitchQuotes
|
||||
SwitchQuotes,
|
||||
/** Options in the Zoom menu **/
|
||||
ZoomOptions
|
||||
};
|
||||
|
||||
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
||||
@ -374,6 +376,7 @@ public:
|
||||
void expandCaptions(Buffer const * buf, bool switchcap = false);
|
||||
void expandEnvironmentSeparators(BufferView const *, bool contextmenu = false);
|
||||
void expandQuotes(BufferView const *);
|
||||
void expandZoomOptions(BufferView const *);
|
||||
///
|
||||
ItemList items_;
|
||||
///
|
||||
@ -489,7 +492,8 @@ void MenuDefinition::read(Lexer & lex)
|
||||
md_switchcaptions,
|
||||
md_env_separators,
|
||||
md_env_separatorscontext,
|
||||
md_switchquotes
|
||||
md_switchquotes,
|
||||
md_zoomoptions
|
||||
};
|
||||
|
||||
LexerKeyword menutags[] = {
|
||||
@ -530,7 +534,8 @@ void MenuDefinition::read(Lexer & lex)
|
||||
{ "toc", md_toc },
|
||||
{ "toolbars", md_toolbars },
|
||||
{ "updateformats", md_updateformats },
|
||||
{ "viewformats", md_viewformats }
|
||||
{ "viewformats", md_viewformats },
|
||||
{ "zoomoptions", md_zoomoptions }
|
||||
};
|
||||
|
||||
lex.pushTable(menutags);
|
||||
@ -687,6 +692,10 @@ void MenuDefinition::read(Lexer & lex)
|
||||
add(MenuItem(MenuItem::SwitchQuotes));
|
||||
break;
|
||||
|
||||
case md_zoomoptions:
|
||||
add(MenuItem(MenuItem::ZoomOptions));
|
||||
break;
|
||||
|
||||
case md_optsubmenu:
|
||||
case md_submenu: {
|
||||
lex.next(true);
|
||||
@ -1815,6 +1824,49 @@ void MenuDefinition::expandCaptions(Buffer const * buf, bool switchcap)
|
||||
}
|
||||
|
||||
|
||||
void MenuDefinition::expandZoomOptions(BufferView const * bv)
|
||||
{
|
||||
if (!bv)
|
||||
return;
|
||||
|
||||
add(MenuItem(MenuItem::Command,
|
||||
toqstr(bformat(_("Reset to Default (%1$d%)|R"),
|
||||
lyxrc.defaultZoom)),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM)));
|
||||
add(MenuItem(MenuItem::Separator));
|
||||
add(MenuItem(MenuItem::Command, qt_("Zoom In|I"),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM_IN)));
|
||||
add(MenuItem(MenuItem::Command, qt_("Zoom Out|O"),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM_OUT)));
|
||||
add(MenuItem(MenuItem::Separator));
|
||||
// Offer some fractional values of the default
|
||||
int z = lyxrc.defaultZoom * 1.75;
|
||||
add(MenuItem(MenuItem::Command,
|
||||
toqstr(bformat(_("[[ZOOM]]%1$d%"), z)),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM, convert<string>(z))));
|
||||
z = lyxrc.defaultZoom * 1.5;
|
||||
add(MenuItem(MenuItem::Command,
|
||||
toqstr(bformat(_("[[ZOOM]]%1$d%"), z)),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM, convert<string>(z))));
|
||||
z = lyxrc.defaultZoom * 1.25;
|
||||
add(MenuItem(MenuItem::Command,
|
||||
toqstr(bformat(_("[[ZOOM]]%1$d%"), z)),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM, convert<string>(z))));
|
||||
z = lyxrc.defaultZoom * 0.75;
|
||||
add(MenuItem(MenuItem::Command,
|
||||
toqstr(bformat(_("[[ZOOM]]%1$d%"), z)),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM, convert<string>(z))));
|
||||
z = lyxrc.defaultZoom * 0.5;
|
||||
add(MenuItem(MenuItem::Command,
|
||||
toqstr(bformat(_("[[ZOOM]]%1$d%"), z)),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM, convert<string>(z))));
|
||||
z = lyxrc.defaultZoom * 0.25;
|
||||
add(MenuItem(MenuItem::Command,
|
||||
toqstr(bformat(_("[[ZOOM]]%1$d%"), z)),
|
||||
FuncRequest(LFUN_BUFFER_ZOOM, convert<string>(z))));
|
||||
}
|
||||
|
||||
|
||||
void MenuDefinition::expandQuotes(BufferView const * bv)
|
||||
{
|
||||
if (!bv)
|
||||
@ -2432,6 +2484,10 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
|
||||
tomenu.expandQuotes(bv);
|
||||
break;
|
||||
|
||||
case MenuItem::ZoomOptions:
|
||||
tomenu.expandZoomOptions(bv);
|
||||
break;
|
||||
|
||||
case MenuItem::Submenu: {
|
||||
MenuItem item(*cit);
|
||||
item.setSubmenu(MenuDefinition(cit->submenuname()));
|
||||
|
Loading…
Reference in New Issue
Block a user