]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/GuiView.cpp
Use real minus char
[features.git] / src / frontends / qt / GuiView.cpp
index 7a6a9dbe51121e8fdc374efcc16d3f92cb0b138f..3fafd20e87980eb2242ffc8f5e2023f2b3e7feea 100644 (file)
 #include <QPoint>
 #include <QSettings>
 #include <QShowEvent>
+#include <QSlider>
 #include <QSplitter>
 #include <QStackedWidget>
 #include <QStatusBar>
@@ -602,6 +603,11 @@ GuiView::GuiView(int id)
        // (such as "source" and "messages")
        setDockOptions(QMainWindow::ForceTabbedDocks);
 
+#ifdef Q_OS_MAC
+       // use document mode tabs on docks
+       setDocumentMode(true);
+#endif
+
        // For Drag&Drop.
        setAcceptDrops(true);
 
@@ -622,6 +628,62 @@ GuiView::GuiView(int id)
        connect(busylabel, SIGNAL(clicked()), this, SLOT(checkCancelBackground()));
 
        QFontMetrics const fm(statusBar()->fontMetrics());
+
+       zoom_slider_ = new QSlider(Qt::Horizontal, statusBar());
+       // Small size slider for macOS to prevent the status bar from enlarging
+       zoom_slider_->setAttribute(Qt::WA_MacSmallSize);
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+       zoom_slider_->setFixedWidth(fm.horizontalAdvance('x') * 15);
+#else
+       zoom_slider_->setFixedWidth(fm.width('x') * 15);
+#endif
+       // Make the defaultZoom center
+       zoom_slider_->setRange(10, (lyxrc.defaultZoom * 2) - 10);
+       // Initialize proper zoom value
+       QSettings settings;
+       zoom_ratio_ = settings.value("zoom_ratio", 1.0).toDouble();
+       // Actual zoom value: default zoom + fractional offset
+       int zoom = (int)(lyxrc.defaultZoom * zoom_ratio_);
+       if (zoom < static_cast<int>(zoom_min_))
+               zoom = zoom_min_;
+       zoom_slider_->setValue(zoom);
+       zoom_slider_->setToolTip(qt_("Workarea zoom level. Drag, use Ctrl-+/- or Shift-Mousewheel to adjust."));
+       zoom_slider_->setTickPosition(QSlider::TicksBelow);
+       zoom_slider_->setTickInterval(lyxrc.defaultZoom - 10);
+
+       // Buttons to change zoom stepwise
+       zoom_in_ = new QPushButton(statusBar());
+       zoom_in_->setText("+");
+       zoom_in_->setFlat(true);
+       zoom_in_->setFixedSize(QSize(fm.height(), fm.height()));
+       zoom_out_ = new QPushButton(statusBar());
+       zoom_out_->setText(QString(0x2212));
+       zoom_out_->setFixedSize(QSize(fm.height(), fm.height()));
+       zoom_out_->setFlat(true);
+
+       statusBar()->addPermanentWidget(zoom_out_);
+       zoom_out_->setEnabled(currentBufferView());
+       statusBar()->addPermanentWidget(zoom_slider_);
+       zoom_slider_->setEnabled(currentBufferView());
+       zoom_out_->setEnabled(currentBufferView());
+       statusBar()->addPermanentWidget(zoom_in_);
+
+       connect(zoom_slider_, SIGNAL(sliderMoved(int)), this, SLOT(zoomSliderMoved(int)));
+       connect(zoom_slider_, SIGNAL(valueChanged(int)), this, SLOT(zoomValueChanged(int)));
+       connect(this, SIGNAL(currentZoomChanged(int)), zoom_slider_, SLOT(setValue(int)));
+       connect(zoom_in_, SIGNAL(clicked()), this, SLOT(zoomInPressed()));
+       connect(zoom_out_, SIGNAL(clicked()), this, SLOT(zoomOutPressed()));
+
+       zoom_value_ = new QLabel(statusBar());
+       zoom_value_->setText(toqstr(bformat(_("[[ZOOM]]%1$d%"), zoom)));
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+       zoom_value_->setMinimumWidth(fm.horizontalAdvance("000%"));
+#else
+       zoom_value_->setMinimumWidth(fm.width("000%"));
+#endif
+       statusBar()->addPermanentWidget(zoom_value_);
+       zoom_value_->setEnabled(currentBufferView());
+
        int const iconheight = max(int(d.normalIconSize), fm.height());
        QSize const iconsize(iconheight, iconheight);
 
@@ -688,7 +750,6 @@ GuiView::GuiView(int id)
        initToolbars();
 
        // clear session data if any.
-       QSettings settings;
        settings.remove("views");
 }
 
@@ -722,6 +783,38 @@ void GuiView::checkCancelBackground()
 }
 
 
+void GuiView::zoomSliderMoved(int value)
+{
+       DispatchResult dr;
+       dispatch(FuncRequest(LFUN_BUFFER_ZOOM, convert<string>(value)), dr);
+       currentWorkArea()->scheduleRedraw(true);
+       zoom_value_->setText(toqstr(bformat(_("[[ZOOM]]%1$d%"), value)));
+}
+
+
+void GuiView::zoomValueChanged(int value)
+{
+       if (value != lyxrc.currentZoom)
+               zoomSliderMoved(value);
+}
+
+
+void GuiView::zoomInPressed()
+{
+       DispatchResult dr;
+       dispatch(FuncRequest(LFUN_BUFFER_ZOOM_IN), dr);
+       currentWorkArea()->scheduleRedraw(true);
+}
+
+
+void GuiView::zoomOutPressed()
+{
+       DispatchResult dr;
+       dispatch(FuncRequest(LFUN_BUFFER_ZOOM_OUT), dr);
+       currentWorkArea()->scheduleRedraw(true);
+}
+
+
 QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
 {
        QVector<GuiWorkArea*> areas;
@@ -840,6 +933,14 @@ void GuiView::saveUISettings() const
 }
 
 
+void GuiView::setCurrentZoom(const int v)
+{
+       lyxrc.currentZoom = v;
+       zoom_value_->setText(toqstr(bformat(_("[[ZOOM]]%1$d%"), v)));
+       Q_EMIT currentZoomChanged(v);
+}
+
+
 bool GuiView::restoreLayout()
 {
        QSettings settings;
@@ -848,7 +949,7 @@ bool GuiView::restoreLayout()
        int zoom = (int)(lyxrc.defaultZoom * zoom_ratio_);
        if (zoom < static_cast<int>(zoom_min_))
                zoom = zoom_min_;
-       lyxrc.currentZoom = zoom;
+       setCurrentZoom(zoom);
        devel_mode_ = settings.value("devel_mode", devel_mode_).toBool();
        settings.beginGroup("views");
        settings.beginGroup(QString::number(id_));
@@ -1299,6 +1400,10 @@ void GuiView::onBufferViewChanged()
        // Buffer-dependent dialogs must be updated. This is done here because
        // some dialogs require buffer()->text.
        updateDialogs();
+       zoom_slider_->setEnabled(currentBufferView());
+       zoom_value_->setEnabled(currentBufferView());
+       zoom_in_->setEnabled(currentBufferView());
+       zoom_out_->setEnabled(currentBufferView());
 }
 
 
@@ -1465,6 +1570,12 @@ bool GuiView::event(QEvent * e)
                return QMainWindow::event(e);
        }
 
+       case QEvent::ApplicationPaletteChange: {
+               // runtime switch from/to dark mode
+               refillToolbars();
+               return QMainWindow::event(e);
+       }
+
        default:
                return QMainWindow::event(e);
        }
@@ -1734,6 +1845,13 @@ void GuiView::updateToolbars()
 }
 
 
+void GuiView::refillToolbars()
+{
+       for (auto const & tb_p : d.toolbars_)
+               tb_p.second->refill();
+}
+
+
 void GuiView::setBuffer(Buffer * newBuffer, bool switch_to)
 {
        LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << endl);
@@ -4547,7 +4665,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        if (zoom < static_cast<int>(zoom_min_))
                                zoom = zoom_min_;
 
-                       lyxrc.currentZoom = zoom;
+                       setCurrentZoom(zoom);
 
                        dr.setMessage(bformat(_("Zoom level is now %1$d% (default value: %2$d%)"),
                                              lyxrc.currentZoom, lyxrc.defaultZoom));
@@ -4893,7 +5011,8 @@ void GuiView::doShowDialog(QString const & qname, QString const & qdata,
                                // activateWindow is needed for floating dockviews
                                dialog->asQWidget()->raise();
                                dialog->asQWidget()->activateWindow();
-                               dialog->asQWidget()->setFocus();
+                               if (dialog->wantInitialFocus())
+                                       dialog->asQWidget()->setFocus();
                        }
                }
        }