4 #include <QApplication> 12 viewport()->installEventFilter(
this);
13 setMouseTracking(
true);
20 scale(factor, factor);
22 QPointF delta_viewport_pos =
m_target_viewport_pos - QPointF(viewport()->width() / 2.0, viewport()->height() / 2.0);
24 centerOn(mapToScene(viewport_center.toPoint()));
41 if (event->type() == QEvent::MouseMove) {
42 QMouseEvent* mouse_event =
static_cast<QMouseEvent*
>(event);
44 if (qAbs(delta.x()) > 5 || qAbs(delta.y()) > 5)
49 }
else if (event->type() == QEvent::Wheel) {
50 QWheelEvent* wheel_event =
static_cast<QWheelEvent*
>(event);
51 if (QApplication::keyboardModifiers() ==
m_modifiers) {
52 if (wheel_event->orientation() == Qt::Vertical) {
53 double angle = wheel_event->angleDelta().y();
double m_zoom_factor_base
void set_zoom_factor_base(double value)
bool eventFilter(QObject *object, QEvent *event)
QPointF m_target_scene_pos
void closeEvent(QCloseEvent *event)
QPointF m_target_viewport_pos
void gentle_zoom(double factor)
void set_modifiers(Qt::KeyboardModifiers modifiers)
Qt::KeyboardModifiers m_modifiers