ui: graph zoom buttons
Added simple zoom buttons to graph
This commit is contained in:
@@ -103,6 +103,26 @@ void QtGraphicsView::ensureVisibleAnimated(const QRectF& rect, int xmargin, int
|
||||
move->start();
|
||||
}
|
||||
|
||||
void QtGraphicsView::setMouseWheelCallback(const std::function<void(QWheelEvent*)>& callback)
|
||||
{
|
||||
m_mouseWheelCallback = callback;
|
||||
}
|
||||
|
||||
void QtGraphicsView::updateZoom(float delta)
|
||||
{
|
||||
float factor = 1.0f + 0.001f * delta;
|
||||
|
||||
if (factor <= 0.0f)
|
||||
{
|
||||
factor = 0.000001;
|
||||
}
|
||||
|
||||
double newZoom = m_zoomFactor * factor;
|
||||
m_zoomFactor = qBound(0.1, newZoom, 100.0);
|
||||
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
void QtGraphicsView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && !itemAt(event->pos()))
|
||||
@@ -193,20 +213,7 @@ void QtGraphicsView::keyReleaseEvent(QKeyEvent* event)
|
||||
|
||||
void QtGraphicsView::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
bool zoomDefault = ApplicationSettings::getInstance()->getControlsGraphZoomOnMouseWheel();
|
||||
bool shiftPressed = event->modifiers() == Qt::ShiftModifier;
|
||||
|
||||
if (zoomDefault != shiftPressed)
|
||||
{
|
||||
if (event->delta() != 0.0f)
|
||||
{
|
||||
updateZoom(event->delta());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QGraphicsView::wheelEvent(event);
|
||||
}
|
||||
m_mouseWheelCallback(event);
|
||||
}
|
||||
|
||||
void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event)
|
||||
@@ -381,18 +388,3 @@ void QtGraphicsView::updateTransform()
|
||||
float zoomFactor = m_appZoomFactor * m_zoomFactor;
|
||||
setTransform(QTransform(zoomFactor, 0, 0, zoomFactor, 0, 0));
|
||||
}
|
||||
|
||||
void QtGraphicsView::updateZoom(float delta)
|
||||
{
|
||||
float factor = 1.0f + 0.001 * delta;
|
||||
|
||||
if (factor <= 0.0f)
|
||||
{
|
||||
factor = 0.000001;
|
||||
}
|
||||
|
||||
double newZoom = m_zoomFactor * factor;
|
||||
m_zoomFactor = qBound(0.1, newZoom, 100.0);
|
||||
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <functional>
|
||||
|
||||
class QTimer;
|
||||
class QtGraphNode;
|
||||
|
||||
@@ -25,6 +27,9 @@ public:
|
||||
|
||||
void ensureVisibleAnimated(const QRectF& rect, int xmargin = 50, int ymargin = 50);
|
||||
|
||||
void setMouseWheelCallback(const std::function<void(QWheelEvent*)>& callback);
|
||||
void updateZoom(float delta);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
@@ -50,7 +55,6 @@ private:
|
||||
bool moves() const;
|
||||
|
||||
void updateTransform();
|
||||
void updateZoom(float delta);
|
||||
|
||||
QPoint m_last;
|
||||
|
||||
@@ -70,6 +74,8 @@ private:
|
||||
|
||||
QAction* m_exportGraphAction;
|
||||
QAction* m_copyNodeNameAction;
|
||||
|
||||
std::function<void(QWheelEvent*)> m_mouseWheelCallback;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPHICS_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user