HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
dot_graphics_view.cpp
Go to the documentation of this file.
2 #include "gui/gui_globals.h"
4 #include <qmath.h>
5 #include <QScrollBar>
6 
7 namespace hal {
9  : QGraphicsView(parent), mPanModifier(Qt::KeyboardModifier::ShiftModifier)
10  {
11  setMouseTracking(true);
12  }
13 
15  {
16  qreal scaleFactor = qPow(2.0, event->delta() / 240.0); //How fast we zoom
17  scaleWithinLimits(scaleFactor);
18 
19  }
20 
22  {
23  scaleWithinLimits(1.2);
24  }
25 
27  {
28  scaleWithinLimits(0.8);
29  }
30 
31  void DotGraphicsView::scaleWithinLimits(qreal scaleFactor)
32  {
33  qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
34  if(0.1 < factor && factor < 100) scale(scaleFactor, scaleFactor);
35  }
36 
38  {
39  if ((event->modifiers() == mPanModifier && event->button() == Qt::LeftButton) ||
41  {
42  mMovePosition = event->pos();
43  }
44  }
45 
47  {
48  if (!scene())
49  return;
50 
51  if ((event->buttons().testFlag(Qt::LeftButton) && event->modifiers() == mPanModifier) ||
53  {
55  QScrollBar* vBar = verticalScrollBar();
56  QPoint delta_move = event->pos() - mMovePosition;
57  mMovePosition = event->pos();
58  if (hBar) hBar->setValue(hBar->value() + (isRightToLeft() ? delta_move.x() : -delta_move.x()));
59  if (vBar) vBar->setValue(vBar->value() - delta_move.y());
60  }
61  else
63  }
64 }
void mousePressEvent(QMouseEvent *event) override
DotGraphicsView(QWidget *parent=nullptr)
void mouseMoveEvent(QMouseEvent *event) override
void wheelEvent(QWheelEvent *event) override
static SettingsItemCheckbox * sSettingPanOnMiddleButton
virtual QVariant value() const override
Definition: defines.h:45
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
QScrollBar * horizontalScrollBar() const const
QScrollBar * verticalScrollBar() const const
void setValue(int)
virtual bool event(QEvent *event) override
virtual void mouseMoveEvent(QMouseEvent *event) override
void scale(qreal sx, qreal sy)
QGraphicsScene * scene() const const
QTransform transform() const const
int x() const const
int y() const const
int width() const const
LeftButton
QRect mapRect(const QRect &rectangle) const const
QTransform & scale(qreal sx, qreal sy)
bool toBool() const const
void setMouseTracking(bool enable)