Commit e072b082 authored by Nikita Sirgienko's avatar Nikita Sirgienko

[GSoC 2020] Update zoom widget according zoom changing from ZoomIn/ZoomOut actions

parent 86679168
Pipeline #25347 passed with stage
in 31 minutes and 37 seconds
......@@ -23,6 +23,7 @@
#include <config-cantor.h>
#include <array>
#include <cmath>
#include "cantor_part.h"
#include "lib/assistant.h"
......@@ -112,6 +113,7 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
m_panelHandler(new Cantor::PanelPluginHandler(this)),
m_initProgressDlg(nullptr),
m_showProgressDlg(true),
m_currectZoomAction(nullptr),
m_showBackendHelp(nullptr),
m_statusBarBlocked(false),
m_sessionStatusCounter(0)
......@@ -219,6 +221,7 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
KStandardAction::zoomIn(m_worksheetview, SLOT(zoomIn()), collection);
KStandardAction::zoomOut(m_worksheetview, SLOT(zoomOut()), collection);
KStandardAction::actualSize(m_worksheetview, SLOT(actualSize()), collection);
connect(m_worksheetview, &WorksheetView::scaleFactorChanged, this, &CantorPart::updateZoomWidgetValue);
m_evaluate = new QAction(i18n("Evaluate Worksheet"), collection);
collection->addAction(QLatin1String("evaluate_worksheet"), m_evaluate);
......@@ -1040,9 +1043,25 @@ void CantorPart::zoomValueEdited(const QString& text)
{
double zoom = match.captured(1).toDouble() / 100.0;
if (m_worksheetview)
m_worksheetview->setScaleFactor(zoom);
m_worksheetview->setScaleFactor(zoom, false);
}
}
void CantorPart::updateZoomWidgetValue(double zoom)
{
if (m_zoom)
{
double scale = zoom;
scale = round(scale * 100);
const QString& searchText = QString::number((int)scale) + QLatin1String("%");
if (m_currectZoomAction)
m_currectZoomAction->setText(searchText);
else
m_currectZoomAction = m_zoom->addAction(searchText);
m_zoom->setCurrentAction(m_currectZoomAction);
}
}
K_PLUGIN_FACTORY_WITH_JSON(CantorPartFactory, "cantor_part.json", registerPlugin<CantorPart>();)
#include "cantor_part.moc"
......@@ -118,6 +118,7 @@ protected Q_SLOTS:
void evaluateOrInterrupt();
void restartBackend();
void zoomValueEdited(const QString& text);
void updateZoomWidgetValue(double zoom);
void enableTypesetting(bool enable);
void showBackendHelp();
void print();
......@@ -172,6 +173,7 @@ private:
QAction * m_evaluate;
QAction * m_restart;
KSelectAction* m_zoom;
QAction* m_currectZoomAction;
QAction * m_save;
QAction * m_findNext;
QAction * m_findPrev;
......
......@@ -240,11 +240,13 @@ qreal WorksheetView::scaleFactor() const
return m_scale;
}
void WorksheetView::setScaleFactor(qreal zoom)
void WorksheetView::setScaleFactor(qreal zoom, bool emitSignal)
{
scale(1/m_scale * zoom, 1/m_scale * zoom);
m_scale = zoom;
updateSceneSize();
if (emitSignal)
emit scaleFactorChanged(m_scale);
}
void WorksheetView::updateSceneSize()
......@@ -275,6 +277,7 @@ void WorksheetView::zoomIn()
m_scale *= 1.1;
scale(1.1, 1.1);
updateSceneSize();
emit scaleFactorChanged(m_scale);
}
void WorksheetView::zoomOut()
......@@ -282,6 +285,7 @@ void WorksheetView::zoomOut()
m_scale /= 1.1;
scale(1/1.1, 1/1.1);
updateSceneSize();
emit scaleFactorChanged(m_scale);
}
void WorksheetView::actualSize()
......@@ -289,4 +293,5 @@ void WorksheetView::actualSize()
scale (1/m_scale, 1/m_scale);
m_scale = 1.0;
updateSceneSize();
emit scaleFactorChanged(m_scale);
}
......@@ -44,11 +44,12 @@ public:
QPointF sceneCursorPos() const;
QRectF viewRect() const;
qreal scaleFactor() const;
void setScaleFactor(qreal);
void setScaleFactor(qreal scale, bool emitSignal = true);
void updateSceneSize();
Q_SIGNALS:
void viewRectChanged(QRectF rect) const;
void scaleFactorChanged(double scale);
public Q_SLOTS:
void zoomIn();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment