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