Refactoring VPieceCarrouselPiece

This commit is contained in:
Ronan Le Tiec 2020-05-23 14:36:35 +02:00
parent 8ca77baef0
commit 510d1bd931
5 changed files with 37 additions and 37 deletions

View File

@ -6,6 +6,7 @@ SOURCES += \
$$PWD/main.cpp \ $$PWD/main.cpp \
$$PWD/vpapplication.cpp \ $$PWD/vpapplication.cpp \
$$PWD/vpcarrousel.cpp \ $$PWD/vpcarrousel.cpp \
$$PWD/vpcarrouselpiece.cpp \
$$PWD/vpcarrouselpiecelist.cpp \ $$PWD/vpcarrouselpiecelist.cpp \
$$PWD/vpcommands.cpp \ $$PWD/vpcommands.cpp \
$$PWD/vpiececarrouselpiecepreview.cpp \ $$PWD/vpiececarrouselpiecepreview.cpp \
@ -21,8 +22,7 @@ SOURCES += \
$$PWD/vpuzzlesettings.cpp \ $$PWD/vpuzzlesettings.cpp \
$$PWD/xml/vplayoutfilereader.cpp \ $$PWD/xml/vplayoutfilereader.cpp \
$$PWD/xml/vplayoutfilewriter.cpp \ $$PWD/xml/vplayoutfilewriter.cpp \
$$PWD/xml/vplayoutliterals.cpp \ $$PWD/xml/vplayoutliterals.cpp
$$PWD/vpiececarrouselpiece.cpp
*msvc*:SOURCES += *msvc*:SOURCES +=
@ -30,6 +30,7 @@ HEADERS += \
$$PWD/dialogs/vpdialogabout.h \ $$PWD/dialogs/vpdialogabout.h \
$$PWD/vpapplication.h \ $$PWD/vpapplication.h \
$$PWD/vpcarrousel.h \ $$PWD/vpcarrousel.h \
$$PWD/vpcarrouselpiece.h \
$$PWD/vpcarrouselpiecelist.h \ $$PWD/vpcarrouselpiecelist.h \
$$PWD/vpcommands.h \ $$PWD/vpcommands.h \
$$PWD/vpiececarrouselpiecepreview.h \ $$PWD/vpiececarrouselpiecepreview.h \
@ -46,8 +47,7 @@ HEADERS += \
$$PWD/vpuzzlesettings.h \ $$PWD/vpuzzlesettings.h \
$$PWD/xml/vplayoutfilereader.h \ $$PWD/xml/vplayoutfilereader.h \
$$PWD/xml/vplayoutfilewriter.h \ $$PWD/xml/vplayoutfilewriter.h \
$$PWD/xml/vplayoutliterals.h \ $$PWD/xml/vplayoutliterals.h
$$PWD/vpiececarrouselpiece.h
FORMS += \ FORMS += \
$$PWD/dialogs/vpdialogabout.ui \ $$PWD/dialogs/vpdialogabout.ui \

View File

@ -1,6 +1,6 @@
/************************************************************************ /************************************************************************
** **
** @file vpiececarrouselpiece.cpp ** @file vpcarrouselpiece.cpp
** @author Ronan Le Tiec ** @author Ronan Le Tiec
** @date 25 4, 2020 ** @date 25 4, 2020
** **
@ -26,7 +26,7 @@
** **
*************************************************************************/ *************************************************************************/
#include "vpiececarrouselpiece.h" #include "vpcarrouselpiece.h"
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -47,7 +47,7 @@ Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselLayer) : VPCarrouselPiece::VPCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselLayer) :
m_piece(piece), m_piece(piece),
m_carrouselLayer(carrouselLayer), m_carrouselLayer(carrouselLayer),
m_dragStart(QPoint()) m_dragStart(QPoint())
@ -57,13 +57,13 @@ VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPiece
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiece::~VPieceCarrouselPiece() VPCarrouselPiece::~VPCarrouselPiece()
{ {
delete m_piecePreview; delete m_piecePreview;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::Init() void VPCarrouselPiece::Init()
{ {
// Define the structure // Define the structure
setFixedSize(124,128); setFixedSize(124,128);
@ -98,20 +98,20 @@ void VPieceCarrouselPiece::Init()
// connect the signals // connect the signals
connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPieceCarrouselPiece::on_PieceSelectionChanged); connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPCarrouselPiece::on_PieceSelectionChanged);
// then refresh the data // then refresh the data
Refresh(); Refresh();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::CleanPreview() void VPCarrouselPiece::CleanPreview()
{ {
m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio); m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::Refresh() void VPCarrouselPiece::Refresh()
{ {
// update the graphic view / the scene // update the graphic view / the scene
@ -147,13 +147,13 @@ void VPieceCarrouselPiece::Refresh()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzlePiece * VPieceCarrouselPiece::GetPiece() VPuzzlePiece * VPCarrouselPiece::GetPiece()
{ {
return m_piece; return m_piece;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::on_PieceSelectionChanged() void VPCarrouselPiece::on_PieceSelectionChanged()
{ {
if(m_piece->GetIsSelected()) if(m_piece->GetIsSelected())
{ {
@ -166,7 +166,7 @@ void VPieceCarrouselPiece::on_PieceSelectionChanged()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event) void VPCarrouselPiece::mousePressEvent(QMouseEvent *event)
{ {
qCDebug(pCarrouselPiece, "mouse pressed"); qCDebug(pCarrouselPiece, "mouse pressed");
@ -189,7 +189,7 @@ void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::mouseMoveEvent(QMouseEvent *event) void VPCarrouselPiece::mouseMoveEvent(QMouseEvent *event)
{ {
if (!(event->buttons() & Qt::LeftButton)) if (!(event->buttons() & Qt::LeftButton))
{ {
@ -235,7 +235,7 @@ void VPieceCarrouselPiece::mouseMoveEvent(QMouseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::contextMenuEvent(QContextMenuEvent *event) void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
{ {
QMenu contextMenu; QMenu contextMenu;
@ -256,7 +256,7 @@ void VPieceCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
QVariant data = QVariant::fromValue(layer); QVariant data = QVariant::fromValue(layer);
moveToLayer->setData(data); moveToLayer->setData(data);
connect(moveToLayer, &QAction::triggered, this, &VPieceCarrouselPiece::on_ActionPieceMovedToLayer); connect(moveToLayer, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToLayer);
} }
} }
@ -266,14 +266,14 @@ void VPieceCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
QAction *removeAction = contextMenu.addAction(tr("Remove from Layout")); QAction *removeAction = contextMenu.addAction(tr("Remove from Layout"));
QVariant data = QVariant::fromValue(m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer()); QVariant data = QVariant::fromValue(m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer());
removeAction->setData(data); removeAction->setData(data);
connect(removeAction, &QAction::triggered, this, &VPieceCarrouselPiece::on_ActionPieceMovedToLayer); connect(removeAction, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToLayer);
} }
contextMenu.exec(event->globalPos()); contextMenu.exec(event->globalPos());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::on_ActionPieceMovedToLayer() void VPCarrouselPiece::on_ActionPieceMovedToLayer()
{ {
QAction *act = qobject_cast<QAction *>(sender()); QAction *act = qobject_cast<QAction *>(sender());
QVariant v = act->data(); QVariant v = act->data();

View File

@ -1,6 +1,6 @@
/************************************************************************ /************************************************************************
** **
** @file vpiececarrouselpiece.h ** @file vpcarrouselpiece.h
** @author Ronan Le Tiec ** @author Ronan Le Tiec
** @date 25 4, 2020 ** @date 25 4, 2020
** **
@ -25,8 +25,8 @@
** along with Valentina. If not, see <http://www.gnu.org/licenses/>. ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
** **
*************************************************************************/ *************************************************************************/
#ifndef VPIECECARROUSELPIECE_H #ifndef VPCARROUSELPIECE_H
#define VPIECECARROUSELPIECE_H #define VPCARROUSELPIECE_H
#include <QFrame> #include <QFrame>
#include <QLabel> #include <QLabel>
@ -39,12 +39,12 @@
class VPCarrouselPieceList; class VPCarrouselPieceList;
class VPieceCarrouselPiece : public QFrame class VPCarrouselPiece : public QFrame
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit VPieceCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselLayer); explicit VPCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselLayer);
~VPieceCarrouselPiece(); ~VPCarrouselPiece();
void Init(); void Init();
void Refresh(); void Refresh();
@ -55,7 +55,7 @@ public:
void CleanPreview(); void CleanPreview();
/** /**
* @brief GetLayoutPiece Returns the corresponding layout piece * @brief GetPiece Returns the corresponding layout piece
* @return the corresponding layout piece * @return the corresponding layout piece
*/ */
VPuzzlePiece * GetPiece(); VPuzzlePiece * GetPiece();
@ -78,7 +78,7 @@ private slots:
void on_ActionPieceMovedToLayer(); void on_ActionPieceMovedToLayer();
private: private:
Q_DISABLE_COPY(VPieceCarrouselPiece) Q_DISABLE_COPY(VPCarrouselPiece)
VPuzzlePiece *m_piece; VPuzzlePiece *m_piece;
@ -93,4 +93,4 @@ private slots:
}; };
#endif // VPIECECARROUSELPIECE_H #endif // VPCARROUSELPIECE_H

View File

@ -40,7 +40,7 @@ Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer")
VPCarrouselPieceList::VPCarrouselPieceList(VPuzzleLayer *layer, VPCarrousel *carrousel) : VPCarrouselPieceList::VPCarrouselPieceList(VPuzzleLayer *layer, VPCarrousel *carrousel) :
m_layer(layer), m_layer(layer),
m_carrousel(carrousel), m_carrousel(carrousel),
m_carrouselPieces(QList<VPieceCarrouselPiece*>()) m_carrouselPieces(QList<VPCarrouselPiece*>())
{ {
Init(); Init();
} }
@ -85,7 +85,7 @@ void VPCarrouselPieceList::Refresh()
setVisible(true); setVisible(true);
for (auto piece : pieces) for (auto piece : pieces)
{ {
VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece, this); VPCarrouselPiece *carrouselPiece = new VPCarrouselPiece(piece, this);
m_carrouselPieces.append(carrouselPiece); m_carrouselPieces.append(carrouselPiece);
layout()->addWidget(carrouselPiece); layout()->addWidget(carrouselPiece);
carrouselPiece->CleanPreview(); // fitInView only works if the widget is displayed. carrouselPiece->CleanPreview(); // fitInView only works if the widget is displayed.
@ -99,7 +99,7 @@ void VPCarrouselPieceList::Clear()
// Removes and deletes the carrousel pieces from the layer // Removes and deletes the carrousel pieces from the layer
while (!m_carrouselPieces.isEmpty()) while (!m_carrouselPieces.isEmpty())
{ {
VPieceCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast(); VPCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast();
if(carrouselPiece != nullptr) if(carrouselPiece != nullptr)
{ {
@ -111,7 +111,7 @@ void VPCarrouselPieceList::Clear()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QList<VPieceCarrouselPiece*> VPCarrouselPieceList::GetCarrouselPieces() QList<VPCarrouselPiece*> VPCarrouselPieceList::GetCarrouselPieces()
{ {
return m_carrouselPieces; return m_carrouselPieces;
} }

View File

@ -31,7 +31,7 @@
#include <QWidget> #include <QWidget>
#include "vpuzzlelayer.h" #include "vpuzzlelayer.h"
#include "vpiececarrouselpiece.h" #include "vpcarrouselpiece.h"
class VPCarrousel; class VPCarrousel;
@ -46,11 +46,11 @@ public:
void Refresh(); void Refresh();
/** /**
* @brief Clear it clears the carrousel layer from its pieces * @brief Clear it clears the carrousel pieceList from its pieces
*/ */
void Clear(); void Clear();
QList<VPieceCarrouselPiece*> GetCarrouselPieces(); QList<VPCarrouselPiece*> GetCarrouselPieces();
VPCarrousel* GetCarrousel(); VPCarrousel* GetCarrousel();
@ -65,7 +65,7 @@ private:
VPuzzleLayer *m_layer; VPuzzleLayer *m_layer;
VPCarrousel *m_carrousel; VPCarrousel *m_carrousel;
QList<VPieceCarrouselPiece*> m_carrouselPieces; QList<VPCarrouselPiece*> m_carrouselPieces;
private slots: private slots: