Refactoring.
Code style.
This commit is contained in:
parent
a7b0ed1171
commit
46241e8e85
|
@ -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<VCommonSettings *>(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<VCommonSettings *>(VAbstractApplication::VApp()->Settings())->GetScrollingAcceleration();
|
||||
scheduledScrollings *= VAbstractApplication::VApp()->Settings()->GetScrollingAcceleration();
|
||||
|
||||
return scheduledScrollings;
|
||||
}
|
||||
|
@ -138,15 +137,7 @@ auto PrioritizeItems(const QList<QGraphicsItem *> &list) -> QList<QGraphicsItem
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
GraphicsViewZoom::GraphicsViewZoom(QGraphicsView *view)
|
||||
: QObject(view),
|
||||
_view(view),
|
||||
_modifiers(Qt::ControlModifier),
|
||||
_zoom_factor_base(1.0015),
|
||||
target_scene_pos(),
|
||||
target_viewport_pos(),
|
||||
verticalScrollAnim(),
|
||||
_numScheduledVerticalScrollings(0),
|
||||
horizontalScrollAnim(),
|
||||
_numScheduledHorizontalScrollings(0)
|
||||
_view(view)
|
||||
{
|
||||
_view->viewport()->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<VCommonSettings *>(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<QMouseEvent *>(event);
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
|
||||
auto *mouse_event = static_cast<QMouseEvent *>(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<QWheelEvent *>(event))
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
|
||||
if (auto *wheel_event = static_cast<QWheelEvent *>(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<QGestureEvent *>(event));
|
||||
}
|
||||
|
||||
|
@ -403,7 +395,7 @@ auto GraphicsViewZoom::GestureEvent(QGestureEvent *event) -> bool
|
|||
{
|
||||
if (QGesture *pinch = event->gesture(Qt::PinchGesture))
|
||||
{
|
||||
PinchTriggered(static_cast<QPinchGesture *>(pinch));
|
||||
PinchTriggered(static_cast<QPinchGesture *>(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<VCommonSettings *>(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<VMainGraphicsScene *>(scene());
|
||||
auto *currentScene = qobject_cast<VMainGraphicsScene *>(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<VMainGraphicsScene *>(item->scene());
|
||||
auto *currentScene = qobject_cast<VMainGraphicsScene *>(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<QOpenGLWidget *>(this->viewport());
|
||||
if (viewport)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto *viewport = qobject_cast<QOpenGLWidget *>(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<VMainGraphicsScene *>(sc);
|
||||
auto *currentScene = qobject_cast<VMainGraphicsScene *>(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())};
|
||||
}
|
||||
|
|
|
@ -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<QTimeLine> verticalScrollAnim;
|
||||
Qt::KeyboardModifiers _modifiers{Qt::ControlModifier};
|
||||
double _zoom_factor_base{1.0015};
|
||||
QPointF target_scene_pos{};
|
||||
QPointF target_viewport_pos{};
|
||||
QPointer<QTimeLine> verticalScrollAnim{};
|
||||
/** @brief _numScheduledVerticalScrollings keep number scheduled vertical scrollings. */
|
||||
qreal _numScheduledVerticalScrollings;
|
||||
QPointer<QTimeLine> horizontalScrollAnim;
|
||||
qreal _numScheduledVerticalScrollings{0};
|
||||
QPointer<QTimeLine> 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user