Refactoring VPuzzleGraphicsLayout

This commit is contained in:
Ronan Le Tiec 2020-05-23 14:48:31 +02:00
parent 9e532edc1a
commit e43f970ea8
8 changed files with 31 additions and 31 deletions

View File

@ -11,8 +11,8 @@ SOURCES += \
$$PWD/vpcarrouselpiecepreview.cpp \
$$PWD/vpcommandline.cpp \
$$PWD/vpcommands.cpp \
$$PWD/vpgraphicssheet.cpp \
$$PWD/vpmainwindow.cpp \
$$PWD/vpuzzlegraphicslayout.cpp \
$$PWD/vpuzzlegraphicspiece.cpp \
$$PWD/vpuzzlelayout.cpp \
$$PWD/vpuzzlelayer.cpp \
@ -35,9 +35,9 @@ HEADERS += \
$$PWD/vpcarrouselpiecepreview.h \
$$PWD/vpcommandline.h \
$$PWD/vpcommands.h \
$$PWD/vpgraphicssheet.h \
$$PWD/vpmainwindow.h \
$$PWD/vpstable.h \
$$PWD/vpuzzlegraphicslayout.h \
$$PWD/vpuzzlegraphicspiece.h \
$$PWD/vpuzzlelayout.h \
$$PWD/vpuzzlelayer.h \

View File

@ -256,7 +256,7 @@ void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
QVariant data = QVariant::fromValue(layer);
moveToLayer->setData(data);
connect(moveToLayer, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToLayer);
connect(moveToLayer, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
}
}
@ -266,14 +266,14 @@ void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
QAction *removeAction = contextMenu.addAction(tr("Remove from Layout"));
QVariant data = QVariant::fromValue(m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer());
removeAction->setData(data);
connect(removeAction, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToLayer);
connect(removeAction, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
}
contextMenu.exec(event->globalPos());
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPiece::on_ActionPieceMovedToLayer()
void VPCarrouselPiece::on_ActionPieceMovedToPieceList()
{
QAction *act = qobject_cast<QAction *>(sender());
QVariant v = act->data();

View File

@ -1,6 +1,6 @@
/************************************************************************
**
** @file vpuzzlegraphicslayout.cpp
** @file vpgraphicssheet.cpp
** @author Ronan Le Tiec
** @date 3 5, 2020
**
@ -26,10 +26,10 @@
**
*************************************************************************/
#include "vpuzzlegraphicslayout.h"
#include "vpgraphicssheet.h"
//---------------------------------------------------------------------------------------------------------------------
VPuzzleGraphicsLayout::VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent):
VPGraphicsSheet::VPGraphicsSheet(VPuzzleLayout *layout, QGraphicsItem *parent):
QGraphicsItem(parent),
m_layout(layout),
m_boundingRect(GetLayoutRect())
@ -38,13 +38,13 @@ VPuzzleGraphicsLayout::VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsIte
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleGraphicsLayout::~VPuzzleGraphicsLayout()
VPGraphicsSheet::~VPGraphicsSheet()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsLayout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
@ -66,14 +66,14 @@ void VPuzzleGraphicsLayout::paint(QPainter *painter, const QStyleOptionGraphicsI
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VPuzzleGraphicsLayout::GetLayoutRect() const
QRectF VPGraphicsSheet::GetLayoutRect() const
{
QRectF rect = QRectF(QPointF(0,0), m_layout->GetLayoutSize());
return rect;
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VPuzzleGraphicsLayout::GetMarginsRect() const
QRectF VPGraphicsSheet::GetMarginsRect() const
{
QMarginsF margins = m_layout->GetLayoutMargins();
QSizeF size = m_layout->GetLayoutSize();
@ -86,7 +86,7 @@ QRectF VPuzzleGraphicsLayout::GetMarginsRect() const
//---------------------------------------------------------------------------------------------------------------------
QRectF VPuzzleGraphicsLayout::boundingRect() const
QRectF VPGraphicsSheet::boundingRect() const
{
return m_boundingRect;
}

View File

@ -1,6 +1,6 @@
/************************************************************************
**
** @file vpuzzlegraphicslayout.h
** @file vpgraphicssheet.h
** @author Ronan Le Tiec
** @date 3 5, 2020
**
@ -26,19 +26,19 @@
**
*************************************************************************/
#ifndef VPUZZLEGRAPHICSLAYOUT_H
#define VPUZZLEGRAPHICSLAYOUT_H
#ifndef VPGRAPHICSSHEET_H
#define VPGRAPHICSSHEET_H
#include <QGraphicsItem>
#include <QPainter>
#include "vpuzzlelayout.h"
class VPuzzleGraphicsLayout : public QGraphicsItem
class VPGraphicsSheet : public QGraphicsItem
{
public:
explicit VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent = nullptr);
~VPuzzleGraphicsLayout();
explicit VPGraphicsSheet(VPuzzleLayout *layout, QGraphicsItem *parent = nullptr);
~VPGraphicsSheet();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) override;
@ -49,10 +49,10 @@ public:
private:
Q_DISABLE_COPY(VPuzzleGraphicsLayout)
Q_DISABLE_COPY(VPGraphicsSheet)
VPuzzleLayout *m_layout{nullptr};
QRectF m_boundingRect;
};
#endif // VPUZZLEGRAPHICSLAYOUT_H
#endif // VPGRAPHICSSHEET_H

View File

@ -52,7 +52,7 @@ Q_LOGGING_CATEGORY(pWindow, "p.window")
QT_WARNING_POP
//---------------------------------------------------------------------------------------------------------------------
VPMainWindow::VPMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *parent) :
VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::VPMainWindow),
m_cmd(cmd)

View File

@ -38,7 +38,7 @@
#include "vpuzzlelayout.h"
#include "vpuzzlepiece.h"
#include "../vlayout/vlayoutpiece.h"
#include "vpuzzlecommandline.h"
#include "vpcommandline.h"
namespace Ui
{
@ -50,7 +50,7 @@ class VPMainWindow : public QMainWindow
Q_OBJECT
public:
explicit VPMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *parent = nullptr);
explicit VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent = nullptr);
virtual ~VPMainWindow();
/**
@ -93,7 +93,7 @@ private:
VPCarrousel *m_carrousel{nullptr};
VPuzzleMainGraphicsView *m_graphicsView{nullptr};
VPuzzleCommandLinePtr m_cmd;
VPCommandLinePtr m_cmd;
VPuzzleLayout *m_layout{nullptr};
QList<VPuzzlePiece *>m_selectedPieces{QList<VPuzzlePiece *>()};

View File

@ -49,9 +49,9 @@ VPuzzleMainGraphicsView::VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget
m_scene = new VMainGraphicsScene(this);
setScene(m_scene);
m_graphicsLayout = new VPuzzleGraphicsLayout(layout);
m_graphicsLayout->setPos(0, 0);
m_scene->addItem(m_graphicsLayout);
m_graphicsSheet = new VPGraphicsSheet(layout);
m_graphicsSheet->setPos(0, 0);
m_scene->addItem(m_graphicsSheet);
setAcceptDrops(true);
@ -66,7 +66,7 @@ void VPuzzleMainGraphicsView::RefreshLayout()
{
// FIXME: Is that the way to go?
m_graphicsLayout->update();
m_graphicsSheet->update();
m_scene->update();
}

View File

@ -29,7 +29,7 @@
#ifndef VPUZZLEMAINGRAPHICSVIEW_H
#define VPUZZLEMAINGRAPHICSVIEW_H
#include "vpuzzlegraphicslayout.h"
#include "vpgraphicssheet.h"
#include "vpuzzlegraphicspiece.h"
#include "../vwidgets/vmaingraphicsview.h"
@ -76,7 +76,7 @@ private:
VMainGraphicsScene *m_scene{nullptr};
VPuzzleGraphicsLayout *m_graphicsLayout{nullptr};
VPGraphicsSheet *m_graphicsSheet{nullptr};
VPuzzleLayout *m_layout{nullptr};
QList<VPuzzleGraphicsPiece*> m_graphicsPieces{};