diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index 3dc1a7e67..4924a2851 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -73,7 +73,7 @@ auto ScrollingSteps(QWheelEvent *wheel_event) -> qreal const QPoint numPixels = wheel_event->pixelDelta(); const QPoint numDegrees = wheel_event->angleDelta() / 8; qreal numSteps = 0; - VCommonSettings *settings = qobject_cast(VAbstractApplication::VApp()->Settings()); + VCommonSettings *settings = VAbstractApplication::VApp()->Settings(); if (not numPixels.isNull()) { @@ -108,8 +108,7 @@ auto PrepareScrolling(qreal scheduledScrollings, QWheelEvent *wheel_event) -> qr scheduledScrollings += numSteps; } - scheduledScrollings *= - qobject_cast(VAbstractApplication::VApp()->Settings())->GetScrollingAcceleration(); + scheduledScrollings *= VAbstractApplication::VApp()->Settings()->GetScrollingAcceleration(); return scheduledScrollings; } @@ -138,15 +137,7 @@ auto PrioritizeItems(const QList &list) -> QListviewport()->installEventFilter(this); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -205,13 +196,13 @@ void GraphicsViewZoom::set_zoom_factor_base(double value) //--------------------------------------------------------------------------------------------------------------------- void GraphicsViewZoom::InitScrollingAnimation() { - VCommonSettings *settings = qobject_cast(VAbstractApplication::VApp()->Settings()); - if (not verticalScrollAnim.isNull()) { delete verticalScrollAnim; } + VCommonSettings *settings = VAbstractApplication::VApp()->Settings(); + verticalScrollAnim = new QTimeLine(settings->GetScrollingDuration(), this); verticalScrollAnim->setUpdateInterval(settings->GetScrollingUpdateInterval()); @@ -277,7 +268,8 @@ auto GraphicsViewZoom::eventFilter(QObject *object, QEvent *event) -> bool * This data need for gentle_zoom(). * Almoust the same we do in method GraphicsViewZoom::animFinished. */ - QMouseEvent *mouse_event = static_cast(event); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) + auto *mouse_event = static_cast(event); QPointF delta = target_viewport_pos - mouse_event->pos(); if (qAbs(delta.x()) > 5 || qAbs(delta.y()) > 5) { @@ -286,9 +278,11 @@ auto GraphicsViewZoom::eventFilter(QObject *object, QEvent *event) -> bool } return false; } + if (event->type() == QEvent::Wheel) { - if (QWheelEvent *wheel_event = static_cast(event)) + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) + if (auto *wheel_event = static_cast(event)) { const QPoint numDegrees = wheel_event->angleDelta(); if (numDegrees.x() == 0) @@ -298,31 +292,29 @@ auto GraphicsViewZoom::eventFilter(QObject *object, QEvent *event) -> bool gentle_zoom(qPow(_zoom_factor_base, numDegrees.y())); return true; } - else if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) + + if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { StartHorizontalScrollings(wheel_event); return true; } - else - { - StartVerticalScrollings(wheel_event); - return true; - } - } - else - { - if (QGuiApplication::keyboardModifiers() == _modifiers) - { - return true; // ignore - } - StartHorizontalScrollings(wheel_event); + StartVerticalScrollings(wheel_event); return true; } + + if (QGuiApplication::keyboardModifiers() == _modifiers) + { + return true; // ignore + } + + StartHorizontalScrollings(wheel_event); + return true; } } else if (event->type() == QEvent::Gesture) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) return GestureEvent(static_cast(event)); } @@ -403,7 +395,7 @@ auto GraphicsViewZoom::GestureEvent(QGestureEvent *event) -> bool { if (QGesture *pinch = event->gesture(Qt::PinchGesture)) { - PinchTriggered(static_cast(pinch)); + PinchTriggered(static_cast(pinch)); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) return true; } return false; @@ -428,20 +420,14 @@ const unsigned long VMainGraphicsView::scrollDelay = 160; * @param parent parent object. */ VMainGraphicsView::VMainGraphicsView(QWidget *parent) - : QGraphicsView(parent), - zoom(nullptr), - showToolOptions(true), - isAllowRubberBand(true), - m_ptStartPos(), - m_oldCursor(), - m_currentCursor(Qt::ArrowCursor) + : QGraphicsView(parent) { setAcceptDrops(true); - VCommonSettings *settings = qobject_cast(VAbstractApplication::VApp()->Settings()); + VCommonSettings *settings = VAbstractApplication::VApp()->Settings(); if (settings && settings->IsOpenGLRender()) { - QOpenGLWidget *viewport = new QOpenGLWidget(); + auto *viewport = new QOpenGLWidget(); QSurfaceFormat fmt; fmt.setSamples(settings->GetGraphicalOutput() ? 10 : 0); fmt.setStencilBufferSize(8); @@ -512,7 +498,7 @@ void VMainGraphicsView::ZoomOriginal() //--------------------------------------------------------------------------------------------------------------------- void VMainGraphicsView::ZoomFitBest() { - VMainGraphicsScene *currentScene = qobject_cast(scene()); + auto *currentScene = qobject_cast(scene()); SCASSERT(currentScene) currentScene->SetOriginsVisible(false); const QRectF rect = currentScene->VisibleItemsBoundingRect(); @@ -758,7 +744,7 @@ void VMainGraphicsView::EnsureItemVisibleWithDelay(const QGraphicsItem *item, un else { // Ensure visible only small rect around a cursor - VMainGraphicsScene *currentScene = qobject_cast(item->scene()); + auto *currentScene = qobject_cast(item->scene()); SCASSERT(currentScene); const QPointF cursorPosition = currentScene->getScenePos(); EnsureVisibleWithDelay( @@ -810,15 +796,8 @@ void VMainGraphicsView::SetAntialiasing(bool value) //--------------------------------------------------------------------------------------------------------------------- auto VMainGraphicsView::IsOpenGLRender() const -> bool { - QOpenGLWidget *viewport = qobject_cast(this->viewport()); - if (viewport) - { - return true; - } - else - { - return false; - } + auto *viewport = qobject_cast(this->viewport()); + return viewport != nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -850,7 +829,7 @@ void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QG const QRectF viewRect = SceneVisibleArea(view); // Calculate scene rect - VMainGraphicsScene *currentScene = qobject_cast(sc); + auto *currentScene = qobject_cast(sc); SCASSERT(currentScene) const QRectF itemsRect = currentScene->VisibleItemsBoundingRect(); @@ -881,5 +860,5 @@ auto VMainGraphicsView::SceneVisibleArea(QGraphicsView *view) -> QRectF { SCASSERT(view != nullptr) // to receive the currently visible area, map the widgets bounds to the scene - return QRectF(view->mapToScene(0, 0), view->mapToScene(view->width(), view->height())); + return {view->mapToScene(0, 0), view->mapToScene(view->width(), view->height())}; } diff --git a/src/libs/vwidgets/vmaingraphicsview.h b/src/libs/vwidgets/vmaingraphicsview.h index 29f0b419a..18c146b4e 100644 --- a/src/libs/vwidgets/vmaingraphicsview.h +++ b/src/libs/vwidgets/vmaingraphicsview.h @@ -82,32 +82,34 @@ public: void set_modifiers(Qt::KeyboardModifiers modifiers); void set_zoom_factor_base(double value); void InitScrollingAnimation(); + signals: void zoomed(); + public slots: void VerticalScrollingTime(qreal x); void HorizontalScrollingTime(qreal x); void animFinished(); protected: - virtual auto eventFilter(QObject *object, QEvent *event) -> bool override; + auto eventFilter(QObject *object, QEvent *event) -> bool override; private: // cppcheck-suppress unknownMacro Q_DISABLE_COPY_MOVE(GraphicsViewZoom) // NOLINT QGraphicsView *_view; - Qt::KeyboardModifiers _modifiers; - double _zoom_factor_base; - QPointF target_scene_pos; - QPointF target_viewport_pos; - QPointer verticalScrollAnim; + Qt::KeyboardModifiers _modifiers{Qt::ControlModifier}; + double _zoom_factor_base{1.0015}; + QPointF target_scene_pos{}; + QPointF target_viewport_pos{}; + QPointer verticalScrollAnim{}; /** @brief _numScheduledVerticalScrollings keep number scheduled vertical scrollings. */ - qreal _numScheduledVerticalScrollings; - QPointer horizontalScrollAnim; + qreal _numScheduledVerticalScrollings{0}; + QPointer horizontalScrollAnim{}; /** @brief _numScheduledHorizontalScrollings keep number scheduled horizontal scrollings. */ - qreal _numScheduledHorizontalScrollings; + qreal _numScheduledHorizontalScrollings{0}; - void FictiveSceneRect(QGraphicsScene *sc, QGraphicsView *view); + static void FictiveSceneRect(QGraphicsScene *sc, QGraphicsView *view); void StartVerticalScrollings(QWheelEvent *wheel_event); void StartHorizontalScrollings(QWheelEvent *wheel_event); @@ -157,6 +159,7 @@ signals: void itemClicked(QGraphicsItem *item); void ScaleChanged(qreal scale); void ZoomFitBestCurrent(); + public slots: void Zoom(qreal scale); void ZoomIn(); @@ -176,12 +179,12 @@ protected: private: Q_DISABLE_COPY_MOVE(VMainGraphicsView) // NOLINT - GraphicsViewZoom *zoom; - bool showToolOptions; - bool isAllowRubberBand; - QPoint m_ptStartPos; - QCursor m_oldCursor; - Qt::CursorShape m_currentCursor; + GraphicsViewZoom *zoom{nullptr}; + bool showToolOptions{true}; + bool isAllowRubberBand{true}; + QPoint m_ptStartPos{}; + QCursor m_oldCursor{}; + Qt::CursorShape m_currentCursor{Qt::ArrowCursor}; }; #endif // VMAINGRAPHICSVIEW_H