]> git.lyx.org Git - features.git/commitdiff
Add menu to statusbar zoom value
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 11 Mar 2021 17:14:46 +0000 (18:14 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 11 Mar 2021 17:14:46 +0000 (18:14 +0100)
src/frontends/qt/GuiView.cpp
src/frontends/qt/GuiView.h

index 48aa13f7833f0be428dd7ca37d459b004c007df0..ceb3651d9d1da47497006699823708f06274ae6d 100644 (file)
@@ -672,8 +672,12 @@ GuiView::GuiView(int id)
        connect(zoom_in_, SIGNAL(clicked()), this, SLOT(zoomInPressed()));
        connect(zoom_out_, SIGNAL(clicked()), this, SLOT(zoomOutPressed()));
 
-       zoom_value_ = new QLabel(statusBar());
+       zoom_value_ = new QToolButton(statusBar());
        zoom_value_->setText(toqstr(bformat(_("[[ZOOM]]%1$d%"), zoom)));
+       zoom_value_->setToolButtonStyle(Qt::ToolButtonTextOnly);
+       zoom_value_->setAutoRaise(true);
+       zoom_value_->setPopupMode(QToolButton::InstantPopup);
+       zoom_value_->setFixedHeight(fm.height());
 #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
        zoom_value_->setMinimumWidth(fm.horizontalAdvance("000%"));
 #else
@@ -682,6 +686,21 @@ GuiView::GuiView(int id)
        statusBar()->addPermanentWidget(zoom_value_);
        zoom_value_->setEnabled(currentBufferView());
 
+       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);
+       zoom_value_->addAction(act_zoom_default_);
+       zoom_value_->addAction(act_zoom_in_);
+       zoom_value_->addAction(act_zoom_out_);
+       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()));
+
        int const iconheight = max(int(d.normalIconSize), fm.height());
        QSize const iconsize(iconheight, iconheight);
 
@@ -779,6 +798,15 @@ 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;
@@ -792,6 +820,7 @@ void GuiView::zoomValueChanged(int value)
 {
        if (value != lyxrc.currentZoom)
                zoomSliderMoved(value);
+       enableZoomOptions();
 }
 
 
@@ -811,6 +840,13 @@ void GuiView::zoomOutPressed()
 }
 
 
+void GuiView::resetDefaultZoom()
+{
+       zoomValueChanged(lyxrc.defaultZoom);
+       enableZoomOptions();
+}
+
+
 QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
 {
        QVector<GuiWorkArea*> areas;
index 728ed0d0d5324edb727931962b41110c164a59f1..015f8851c79c0df3c840a403c3110d17198b66e9 100644 (file)
@@ -29,6 +29,7 @@ class QPushButton;
 class QLabel;
 class QShowEvent;
 class QSlider;
+class QToolButton;
 
 
 namespace lyx {
@@ -253,6 +254,8 @@ private Q_SLOTS:
        ///
        void zoomOutPressed();
        ///
+       void resetDefaultZoom();
+       ///
        void on_currentWorkAreaChanged(GuiWorkArea *);
        ///
        void onBufferViewChanged();
@@ -476,6 +479,8 @@ private:
        void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
        ///
        void showMessage();
+       ///
+       void enableZoomOptions();
 
        /// This view ID.
        int id_;
@@ -500,13 +505,19 @@ private:
        /// Statusbar widget that shows version control status
        QLabel * version_control_;
        /// Statusbar widget that shows zoom value
-       QLabel * zoom_value_;
+       QToolButton * zoom_value_;
        /// The zoom slider widget
        QSlider * zoom_slider_;
        /// Zoom in ("+") Button
        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_;
 
        /// The rate from which the actual zoom value is calculated
        /// from the default zoom pref