From 54b0ca5ee54bc91af376b738b3d39fc8b4cbf1f4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 11 Sep 2021 14:01:29 +0300 Subject: [PATCH] Fix redrawing VPGraphicsSheet. --- src/app/puzzle/layout/vpsheet.cpp | 29 ++++++++++++++++++++++++ src/app/puzzle/layout/vpsheet.h | 2 ++ src/app/puzzle/scene/vpgraphicssheet.cpp | 13 +++++++---- src/app/puzzle/scene/vpgraphicssheet.h | 3 ++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/app/puzzle/layout/vpsheet.cpp b/src/app/puzzle/layout/vpsheet.cpp index 968215fbc..e369c6df2 100644 --- a/src/app/puzzle/layout/vpsheet.cpp +++ b/src/app/puzzle/layout/vpsheet.cpp @@ -280,6 +280,15 @@ void VPSheetSceneData::ClearTilesScheme() RefreshLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPSheetSceneData::RefreshSheetSize() +{ + if (m_graphicsSheet != nullptr) + { + m_graphicsSheet->RefreshBoundingRect(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece) { @@ -707,6 +716,11 @@ void VPSheet::SetSheetSize(qreal width, qreal height) { m_size.setWidth(width); m_size.setHeight(height); + + if (m_sceneData != nullptr) + { + m_sceneData->RefreshSheetSize(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -715,12 +729,22 @@ void VPSheet::SetSheetSizeConverted(qreal width, qreal height) Unit unit = SheetUnits(); m_size.setWidth(UnitConvertor(width, unit, Unit::Px)); m_size.setHeight(UnitConvertor(height, unit, Unit::Px)); + + if (m_sceneData != nullptr) + { + m_sceneData->RefreshSheetSize(); + } } //--------------------------------------------------------------------------------------------------------------------- void VPSheet::SetSheetSize(const QSizeF &size) { m_size = size; + + if (m_sceneData != nullptr) + { + m_sceneData->RefreshSheetSize(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -729,6 +753,11 @@ void VPSheet::SetSheetSizeConverted(const QSizeF &size) Unit unit = SheetUnits(); m_size = QSizeF(UnitConvertor(size.width(), unit, Unit::Px), UnitConvertor(size.height(), unit, Unit::Px)); + + if (m_sceneData != nullptr) + { + m_sceneData->RefreshSheetSize(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/layout/vpsheet.h b/src/app/puzzle/layout/vpsheet.h index e42082968..fc9c758a8 100644 --- a/src/app/puzzle/layout/vpsheet.h +++ b/src/app/puzzle/layout/vpsheet.h @@ -87,6 +87,8 @@ public: void PrepareTilesScheme(); void ClearTilesScheme(); + void RefreshSheetSize(); + private: Q_DISABLE_COPY(VPSheetSceneData) diff --git a/src/app/puzzle/scene/vpgraphicssheet.cpp b/src/app/puzzle/scene/vpgraphicssheet.cpp index 3335369e2..51519e7f2 100644 --- a/src/app/puzzle/scene/vpgraphicssheet.cpp +++ b/src/app/puzzle/scene/vpgraphicssheet.cpp @@ -35,8 +35,7 @@ //--------------------------------------------------------------------------------------------------------------------- VPGraphicsSheet::VPGraphicsSheet(const VPLayoutPtr &layout, QGraphicsItem *parent): QGraphicsItem(parent), - m_layout(layout), - m_boundingRect(GetSheetRect()) + m_layout(layout) {} //--------------------------------------------------------------------------------------------------------------------- @@ -98,8 +97,6 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o } } } - - m_boundingRect = sheetRect; } //--------------------------------------------------------------------------------------------------------------------- @@ -148,8 +145,14 @@ void VPGraphicsSheet::SetShowBorder(bool value) m_showBorder = value; } +//--------------------------------------------------------------------------------------------------------------------- +void VPGraphicsSheet::RefreshBoundingRect() +{ + prepareGeometryChange(); +} + //--------------------------------------------------------------------------------------------------------------------- auto VPGraphicsSheet::boundingRect() const -> QRectF { - return m_boundingRect; + return GetSheetRect(); } diff --git a/src/app/puzzle/scene/vpgraphicssheet.h b/src/app/puzzle/scene/vpgraphicssheet.h index cfd10fefb..7510f53ad 100644 --- a/src/app/puzzle/scene/vpgraphicssheet.h +++ b/src/app/puzzle/scene/vpgraphicssheet.h @@ -60,11 +60,12 @@ public: */ void SetShowBorder(bool value); + void RefreshBoundingRect(); + private: Q_DISABLE_COPY(VPGraphicsSheet) VPLayoutWeakPtr m_layout{}; - QRectF m_boundingRect; bool m_showMargin{true}; bool m_showBorder{true};