Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Jan 1, 2025
1 parent 68eccfc commit cf4b2b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
44 changes: 21 additions & 23 deletions src/qvgraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void QVGraphicsView::keyPressEvent(QKeyEvent *event)
if (scrollXSmallSteps != 0 || scrollYSmallSteps != 0 || scrollYLargeSteps != 0)
{
const QPoint delta {
(horizontalScrollBar()->singleStep() * scrollXSmallSteps) * (isRightToLeft() ? -1 : 1),
(horizontalScrollBar()->singleStep() * scrollXSmallSteps) * getRtlFlip(),
(verticalScrollBar()->singleStep() * scrollYSmallSteps) + (verticalScrollBar()->pageStep() * scrollYLargeSteps)
};
scrollHelper->move(delta);
Expand Down Expand Up @@ -384,7 +384,7 @@ void QVGraphicsView::executeDragAction(const Qv::ViewportDragAction action, cons
{
if (action == Qv::ViewportDragAction::Pan)
{
scrollHelper->move(QPointF(-delta.x() * (isRightToLeft() ? -1 : 1), -delta.y()));
scrollHelper->move(QPointF(-delta.x() * getRtlFlip(), -delta.y()));
}
else if (action == Qv::ViewportDragAction::MoveWindow)
{
Expand All @@ -403,7 +403,7 @@ void QVGraphicsView::executeDragAction(const Qv::ViewportDragAction action, cons
void QVGraphicsView::executeScrollAction(const Qv::ViewportScrollAction action, const QPoint delta, const QPoint mousePos, const bool hasShiftModifier)
{
const int deltaPerWheelStep = 120;
const int rtlFlip = isRightToLeft() ? -1 : 1;
const int rtlFlip = getRtlFlip();

const auto getUniAxisDelta = [delta, rtlFlip]() {
return
Expand Down Expand Up @@ -612,7 +612,7 @@ void QVGraphicsView::zoomAbsolute(const qreal absoluteLevel, const std::optional
if (pos.has_value())
{
const QPointF move = mapFromScene(scenePos) - pos.value();
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + (move.x() * (isRightToLeft() ? -1 : 1)));
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + (move.x() * getRtlFlip()));
verticalScrollBar()->setValue(verticalScrollBar()->value() + move.y());
lastZoomRoundingError = mapToScene(pos.value()) - scenePos;
constrainBoundsTimer->start();
Expand Down Expand Up @@ -936,7 +936,7 @@ LogicalPixelFitter QVGraphicsView::getPixelFitter() const
void QVGraphicsView::matchContentCenter(const QRect target)
{
const QPointF delta = QRectF(getContentRect()).center() - QRectF(target).center();
scrollHelper->move(QPointF(delta.x() * (isRightToLeft() ? -1 : 1), delta.y()));
scrollHelper->move(QPointF(delta.x() * getRtlFlip(), delta.y()));
}

QRect QVGraphicsView::getContentRect() const
Expand Down Expand Up @@ -965,19 +965,14 @@ QRect QVGraphicsView::getUsableViewportRect(const bool addOverscan) const
return rect;
}

void QVGraphicsView::setTransformScale(qreal value)
void QVGraphicsView::setTransformScale(const qreal value)
{
setTransformWithNormalization(getUnspecializedTransform().scale(value, value));
}

void QVGraphicsView::setTransformWithNormalization(QTransform matrix)
void QVGraphicsView::setTransformWithNormalization(const QTransform &matrix)
{
if (!loadedPixmapItem->pixmap().isNull())
{
matrix = normalizeTransformOrigin(matrix, loadedPixmapItem->boundingRect().size());
}
setTransform(matrix);
qDebug() << getContentRect();
setTransform(normalizeTransformOrigin(matrix, loadedPixmapItem->boundingRect().size()));
}

QTransform QVGraphicsView::getUnspecializedTransform() const
Expand All @@ -993,6 +988,14 @@ QTransform QVGraphicsView::getUnspecializedTransform() const
return { t.m11() < 0 ? -1.0 : 1.0, 0, 0, t.m22() < 0 ? -1.0 : 1.0, 0, 0 };
}

QTransform QVGraphicsView::normalizeTransformOrigin(const QTransform &matrix, const QSizeF &pixmapSize) const
{
const int horizontalFactor = matrix.m11() < 0 ? -1 * getRtlFlip() : matrix.m12() < 0 ? -1 : 0;
const int verticalFactor = matrix.m22() < 0 ? -1 : matrix.m21() < 0 ? -1 * getRtlFlip() : 0;
QTransform t { matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), 0, 0 };
return t.translate(pixmapSize.width() * horizontalFactor, pixmapSize.height() * verticalFactor);
}

qreal QVGraphicsView::getDpiAdjustment() const
{
// Although inverting this potentially introduces a rounding error, it is inevitable. For
Expand Down Expand Up @@ -1024,6 +1027,11 @@ void QVGraphicsView::handleSmoothScalingChange()
removeExpensiveScaling();
}

int QVGraphicsView::getRtlFlip() const
{
return isRightToLeft() ? -1 : 1;
}

void QVGraphicsView::cancelTurboNav()
{
if (!turboNavMode.has_value())
Expand All @@ -1042,16 +1050,6 @@ MainWindow* QVGraphicsView::getMainWindow() const
return qobject_cast<MainWindow*>(window());
}

QTransform QVGraphicsView::normalizeTransformOrigin(QTransform matrix, const QSizeF pixmapSize)
{
const bool isXNegative = matrix.m11() < 0 || matrix.m12() < 0;
const bool isYNegative = matrix.m22() < 0 || matrix.m21() < 0;
return matrix.translate(
isXNegative ? -pixmapSize.width() : 0,
isYNegative ? -pixmapSize.height() : 0
);
}

void QVGraphicsView::settingsUpdated()
{
auto &settingsManager = qvApp->getSettingsManager();
Expand Down
10 changes: 6 additions & 4 deletions src/qvgraphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,26 @@ class QVGraphicsView : public QGraphicsView

QRect getUsableViewportRect(const bool addOverscan = false) const;

void setTransformScale(qreal absoluteScale);
void setTransformScale(const qreal absoluteScale);

void setTransformWithNormalization(QTransform matrix);
void setTransformWithNormalization(const QTransform &matrix);

QTransform getUnspecializedTransform() const;

QTransform normalizeTransformOrigin(const QTransform &matrix, const QSizeF &pixmapSize) const;

qreal getDpiAdjustment() const;

void handleDpiAdjustmentChange();

void handleSmoothScalingChange();

int getRtlFlip() const;

void cancelTurboNav();

MainWindow* getMainWindow() const;

static QTransform normalizeTransformOrigin(QTransform matrix, const QSizeF pixmapSize);

private slots:
void animatedFrameChanged(QRect rect);

Expand Down

0 comments on commit cf4b2b6

Please sign in to comment.