work on piece selection and position
This commit is contained in:
parent
c4dbea1d56
commit
e2b816f192
|
@ -189,6 +189,11 @@ VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece)
|
|||
|
||||
// TODO : set all the information we need for the piece!
|
||||
|
||||
//
|
||||
connect(piece, &VPuzzlePiece::SelectionChanged, this, &PuzzleMainWindow::on_PieceSelectionChanged);
|
||||
connect(piece, &VPuzzlePiece::PositionChanged, this, &PuzzleMainWindow::on_PiecePositionChanged);
|
||||
|
||||
|
||||
return piece;
|
||||
}
|
||||
|
||||
|
@ -228,9 +233,9 @@ void PuzzleMainWindow::InitPropertyTabCurrentPiece()
|
|||
|
||||
// ------------------------------ placement -----------------------------------
|
||||
connect(ui->doubleSpinBoxCurrentPieceBoxPositionX, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
||||
&PuzzleMainWindow::on_CurrentPiecePositionChanged);
|
||||
&PuzzleMainWindow::on_CurrentPiecePositionEdited);
|
||||
connect(ui->doubleSpinBoxCurrentPieceBoxPositionY, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
||||
&PuzzleMainWindow::on_CurrentPiecePositionChanged);
|
||||
&PuzzleMainWindow::on_CurrentPiecePositionEdited);
|
||||
}
|
||||
|
||||
|
||||
|
@ -310,9 +315,6 @@ void PuzzleMainWindow::InitPieceCarrousel()
|
|||
|
||||
connect(ui->dockWidgetPieceCarrousel, QOverload<Qt::DockWidgetArea>::of(&QDockWidget::dockLocationChanged), this,
|
||||
&PuzzleMainWindow::on_PieceCarrouselLocationChanged);
|
||||
|
||||
connect(m_pieceCarrousel, QOverload<VPuzzlePiece*>::of(&VPieceCarrousel::pieceClicked), this,
|
||||
&PuzzleMainWindow::on_PieceSelected);
|
||||
}
|
||||
|
||||
|
||||
|
@ -335,31 +337,34 @@ void PuzzleMainWindow::SetPropertiesData()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
|
||||
{
|
||||
if(m_selectedPiece == nullptr)
|
||||
{
|
||||
if(false) // check for multiple piece selection
|
||||
{
|
||||
// TODO in the future
|
||||
}
|
||||
else
|
||||
if(m_selectedPieces.count() == 0)
|
||||
{
|
||||
// TODO : update current piece data to show a "no current piece selected"
|
||||
ui->containerCurrentPieceNoData->setVisible(true);
|
||||
ui->containerCurrentPieceData->setVisible(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(m_selectedPieces.count() == 1)
|
||||
{
|
||||
VPuzzlePiece *selectedPiece = m_selectedPieces.first();
|
||||
|
||||
ui->containerCurrentPieceNoData->setVisible(false);
|
||||
ui->containerCurrentPieceData->setVisible(true);
|
||||
|
||||
// set the value to the current piece
|
||||
ui->lineEditCurrentPieceName->setText(m_selectedPiece->GetName());
|
||||
ui->lineEditCurrentPieceName->setText(selectedPiece->GetName());
|
||||
|
||||
ui->checkBoxCurrentPieceShowSeamline->setChecked(m_selectedPiece->GetShowSeamLine());
|
||||
ui->checkBoxCurrentPieceMirrorPiece->setChecked(m_selectedPiece->GetPieceMirrored());
|
||||
ui->checkBoxCurrentPieceShowSeamline->setChecked(selectedPiece->GetShowSeamLine());
|
||||
ui->checkBoxCurrentPieceMirrorPiece->setChecked(selectedPiece->GetPieceMirrored());
|
||||
|
||||
// TODO:rotation and placement;
|
||||
QPointF pos = selectedPiece->GetPosition();
|
||||
SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit()));
|
||||
SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit()));
|
||||
|
||||
// TODO: rotation
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO in the future
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -790,18 +795,18 @@ void PuzzleMainWindow::on_pushButtonLayoutExport_clicked()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleMainWindow::on_checkBoxCurrentPieceShowSeamline_toggled(bool checked)
|
||||
{
|
||||
if(m_selectedPiece != nullptr)
|
||||
if(m_selectedPieces.count() == 1)
|
||||
{
|
||||
m_selectedPiece->SetShowSeamLine(checked);
|
||||
m_selectedPieces.first()->SetShowSeamLine(checked);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleMainWindow::on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked)
|
||||
{
|
||||
if(m_selectedPiece != nullptr)
|
||||
if(m_selectedPieces.count() == 1)
|
||||
{
|
||||
m_selectedPiece->SetPieceMirrored(checked);
|
||||
m_selectedPieces.first()->SetPieceMirrored(checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -821,16 +826,22 @@ void PuzzleMainWindow::on_doubleSpinBoxCurrentPieceAngle_valueChanged(double val
|
|||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleMainWindow::on_CurrentPiecePositionChanged()
|
||||
void PuzzleMainWindow::on_CurrentPiecePositionEdited()
|
||||
{
|
||||
// just for test purpuses, to be removed:
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("TODO PuzzleMainWindow::CurrentPiecePositionChanged");
|
||||
int ret = msgBox.exec();
|
||||
// ui->doubleSpinBoxCurrentPieceBoxPositionX->blockSignals(true);
|
||||
// ui->doubleSpinBoxCurrentPieceBoxPositionY->blockSignals(true);
|
||||
|
||||
Q_UNUSED(ret);
|
||||
if(m_selectedPieces.count() == 1)
|
||||
{
|
||||
VPuzzlePiece *piece = m_selectedPieces.first();
|
||||
QPointF pos(UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionX->value(), m_layout->GetUnit(), Unit::Px),
|
||||
UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionY->value(), m_layout->GetUnit(), Unit::Px));
|
||||
piece->SetPosition(pos);
|
||||
}
|
||||
|
||||
// ui->doubleSpinBoxCurrentPieceBoxPositionX->blockSignals(false);
|
||||
// ui->doubleSpinBoxCurrentPieceBoxPositionY->blockSignals(false);
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -851,17 +862,35 @@ void PuzzleMainWindow::on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleMainWindow::on_PieceSelected(VPuzzlePiece* piece)
|
||||
void PuzzleMainWindow::on_PieceSelectionChanged()
|
||||
{
|
||||
m_selectedPiece = piece;
|
||||
// for now we have only single selection
|
||||
// FIXME / TODO : To be updated when we support multiple selection.
|
||||
|
||||
// update the state of the piece carrousel
|
||||
m_pieceCarrousel->SelectPiece(piece);
|
||||
|
||||
// update the Layout
|
||||
|
||||
// TODO
|
||||
for (auto piece : m_selectedPieces)
|
||||
{
|
||||
if(piece->GetIsSelected())
|
||||
{
|
||||
piece->SetIsSelected(false);
|
||||
}
|
||||
}
|
||||
m_selectedPieces = m_layout->GetSelectedPieces();
|
||||
|
||||
// update the property of the piece currently selected
|
||||
SetPropertyTabCurrentPieceData();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleMainWindow::on_PiecePositionChanged()
|
||||
{
|
||||
|
||||
if(m_selectedPieces.count() == 1)
|
||||
{
|
||||
VPuzzlePiece *piece = m_selectedPieces.first();
|
||||
QPointF pos = piece->GetPosition();
|
||||
|
||||
SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, UnitConvertor(pos.x(), Unit::Px, m_layout->GetUnit()));
|
||||
SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionY, UnitConvertor(pos.y(), Unit::Px, m_layout->GetUnit()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ private:
|
|||
VPuzzleCommandLinePtr m_cmd;
|
||||
|
||||
VPuzzleLayout *m_layout{nullptr};
|
||||
VPuzzlePiece *m_selectedPiece{nullptr};
|
||||
QList<VPuzzlePiece *>m_selectedPieces{QList<VPuzzlePiece *>()};
|
||||
|
||||
/**
|
||||
* @brief CreatePiece creates a piece from the given VLayoutPiece data
|
||||
|
@ -354,7 +354,7 @@ private slots:
|
|||
* @brief on_CurrentPiecePositionChanged When the positionX or the positionY
|
||||
* is changed in the current piece tab
|
||||
*/
|
||||
void on_CurrentPiecePositionChanged();
|
||||
void on_CurrentPiecePositionEdited();
|
||||
|
||||
/**
|
||||
* @brief PieceCarrouselLocationChanged When the piece carrousel's location
|
||||
|
@ -364,10 +364,14 @@ private slots:
|
|||
void on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area);
|
||||
|
||||
/**
|
||||
* @brief on_PieceSelected When a piece has been selected
|
||||
* @param piece the piece that was selected
|
||||
* @brief on_PieceSelectionChanged When the piece selection has changed
|
||||
*/
|
||||
void on_PieceSelected(VPuzzlePiece* piece);
|
||||
void on_PieceSelectionChanged();
|
||||
|
||||
/**
|
||||
* @brief on_PiecePositionChanged When the current piece position has changed
|
||||
*/
|
||||
void on_PiecePositionChanged();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
#include "vpiececarrousel.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "../vmisc/backport/qoverload.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
#include <QScrollBar>
|
||||
|
||||
Q_LOGGING_CATEGORY(pCarrousel, "p.carrousel")
|
||||
|
||||
|
@ -118,10 +118,6 @@ void VPieceCarrousel::Refresh()
|
|||
VPieceCarrouselLayer *carrouselLayer = new VPieceCarrouselLayer(layer, this);
|
||||
m_carrouselLayers.append(carrouselLayer);
|
||||
m_layersContainer->layout()->addWidget(carrouselLayer);
|
||||
|
||||
connect(carrouselLayer, QOverload<VPieceCarrouselPiece*>::of(&VPieceCarrouselLayer::pieceClicked), this,
|
||||
&VPieceCarrousel::on_PieceClicked);
|
||||
|
||||
}
|
||||
|
||||
on_ActiveLayerChanged(0);
|
||||
|
@ -160,20 +156,6 @@ void VPieceCarrousel::Clear()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPieceCarrousel::SelectPiece(VPuzzlePiece* piece)
|
||||
{
|
||||
for (auto layer : m_carrouselLayers)
|
||||
{
|
||||
QList<VPieceCarrouselPiece*> carrouselPieces = layer->GetCarrouselPieces();
|
||||
for (auto carrouselPiece : carrouselPieces)
|
||||
{
|
||||
carrouselPiece->SetIsSelected(carrouselPiece->GetPiece() == piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPieceCarrousel::on_ActiveLayerChanged(int index)
|
||||
{
|
||||
|
@ -239,11 +221,3 @@ void VPieceCarrousel::RefreshOrientation()
|
|||
// FIXME: find a nicer way than putting directly the 120 width of the piece
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPieceCarrousel::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece)
|
||||
{
|
||||
emit pieceClicked(carrouselPiece->GetPiece());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -78,13 +78,6 @@ public:
|
|||
void SelectPiece(VPuzzlePiece* piece);
|
||||
|
||||
|
||||
signals:
|
||||
void pieceClicked(VPuzzlePiece* piece);
|
||||
|
||||
public slots:
|
||||
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
|
||||
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPieceCarrousel)
|
||||
|
||||
|
|
|
@ -89,10 +89,6 @@ void VPieceCarrouselLayer::Refresh()
|
|||
setVisible(true);
|
||||
carrouselPiece->CleanPreview();
|
||||
setVisible(false);
|
||||
|
||||
connect(carrouselPiece, QOverload<VPieceCarrouselPiece*>::of(&VPieceCarrouselPiece::clicked), this,
|
||||
&VPieceCarrouselLayer::on_PieceClicked);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,8 +98,3 @@ QList<VPieceCarrouselPiece*> VPieceCarrouselLayer::GetCarrouselPieces()
|
|||
return m_carrouselPieces;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPieceCarrouselLayer::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece)
|
||||
{
|
||||
emit pieceClicked(carrouselPiece);
|
||||
}
|
||||
|
|
|
@ -45,12 +45,6 @@ public:
|
|||
|
||||
QList<VPieceCarrouselPiece*> GetCarrouselPieces();
|
||||
|
||||
signals:
|
||||
void pieceClicked(VPieceCarrouselPiece* carrouselPiece);
|
||||
|
||||
public slots:
|
||||
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPieceCarrouselLayer)
|
||||
|
||||
|
|
|
@ -92,6 +92,11 @@ void VPieceCarrouselPiece::Init()
|
|||
pieceLayout->addWidget(m_piecePreview);
|
||||
pieceLayout->addWidget(m_label);
|
||||
|
||||
|
||||
// connect the signals
|
||||
connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPieceCarrouselPiece::on_PieceSelectionChanged);
|
||||
|
||||
|
||||
// then refresh the data
|
||||
Refresh();
|
||||
}
|
||||
|
@ -142,11 +147,9 @@ VPuzzlePiece * VPieceCarrouselPiece::GetPiece()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPieceCarrouselPiece::SetIsSelected(bool value)
|
||||
void VPieceCarrouselPiece::on_PieceSelectionChanged()
|
||||
{
|
||||
m_isSelected = value;
|
||||
|
||||
if(value)
|
||||
if(m_piece->GetIsSelected())
|
||||
{
|
||||
setStyleSheet("background-color:white; border: 2px solid red;");
|
||||
}
|
||||
|
@ -156,11 +159,7 @@ void VPieceCarrouselPiece::SetIsSelected(bool value)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VPieceCarrouselPiece::GetIsSelected()
|
||||
{
|
||||
return m_isSelected;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -170,9 +169,9 @@ void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event)
|
|||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
if(!m_isSelected)
|
||||
if(!m_piece->GetIsSelected())
|
||||
{
|
||||
emit clicked(this);
|
||||
m_piece->SetIsSelected(true);
|
||||
}
|
||||
m_dragStart = event->pos();
|
||||
}
|
||||
|
|
|
@ -58,22 +58,8 @@ public:
|
|||
*/
|
||||
VPuzzlePiece * GetPiece();
|
||||
|
||||
/**
|
||||
* @brief SetSelected sets the selected state to the given value
|
||||
* @param value the new selected state
|
||||
*/
|
||||
void SetIsSelected(bool value);
|
||||
|
||||
/**
|
||||
* @brief GetSelected Returns wether the piece is selected or not
|
||||
* @return true if the piece is selected
|
||||
*/
|
||||
bool GetIsSelected();
|
||||
|
||||
signals:
|
||||
void clicked(VPieceCarrouselPiece* m_piece);
|
||||
|
||||
public slots:
|
||||
void on_PieceSelectionChanged();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
@ -87,8 +73,6 @@ private:
|
|||
QLabel *m_label{nullptr};
|
||||
VPieceCarrouselPiecePreview *m_piecePreview{nullptr};
|
||||
|
||||
bool m_isSelected = false;
|
||||
|
||||
QPoint m_dragStart;
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -33,11 +33,16 @@
|
|||
#include <QPainter>
|
||||
#include <QCursor>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
#include "vpuzzlepiece.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece")
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPuzzleGraphicsPiece::VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *parent) :
|
||||
QGraphicsItem(parent),
|
||||
QGraphicsObject(parent),
|
||||
m_piece(piece),
|
||||
m_cuttingLine(QPainterPath()),
|
||||
m_seamLine(QPainterPath())
|
||||
|
@ -55,7 +60,7 @@ VPuzzleGraphicsPiece::~VPuzzleGraphicsPiece()
|
|||
void VPuzzleGraphicsPiece::Init()
|
||||
{
|
||||
// set some infos
|
||||
setFlags(ItemIsSelectable | ItemIsMovable);
|
||||
setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
|
||||
setCursor(QCursor(Qt::OpenHandCursor));
|
||||
|
||||
//setAcceptHoverEvents(true); // maybe we can do some stuff with this
|
||||
|
@ -76,7 +81,9 @@ void VPuzzleGraphicsPiece::Init()
|
|||
|
||||
// TODO : initialises the other elements like grain line, labels, passmarks etc.
|
||||
|
||||
|
||||
// Initialises the connectors
|
||||
connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPuzzleGraphicsPiece::on_PieceSelectionChanged);
|
||||
connect(m_piece, &VPuzzlePiece::PositionChanged, this, &VPuzzleGraphicsPiece::on_PiecePositionChanged);
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,8 +113,14 @@ QPainterPath VPuzzleGraphicsPiece::shape() const
|
|||
void VPuzzleGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(option);
|
||||
|
||||
QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
||||
if(isSelected())
|
||||
{
|
||||
pen.setColor(Qt::red);
|
||||
}
|
||||
|
||||
QBrush noBrush(Qt::NoBrush);
|
||||
|
||||
painter->setPen(pen);
|
||||
|
@ -136,6 +149,8 @@ void VPuzzleGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
return;
|
||||
}
|
||||
|
||||
setSelected(true);
|
||||
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
}
|
||||
|
||||
|
@ -155,4 +170,38 @@ void VPuzzleGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPuzzleGraphicsPiece::on_PieceSelectionChanged()
|
||||
{
|
||||
setSelected(m_piece->GetIsSelected());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPuzzleGraphicsPiece::on_PiecePositionChanged()
|
||||
{
|
||||
setPos(m_piece->GetPosition());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QVariant VPuzzleGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (scene()) {
|
||||
if(change == ItemPositionHasChanged)
|
||||
{
|
||||
blockSignals(true);
|
||||
m_piece->SetPosition(pos());
|
||||
blockSignals(false);
|
||||
}
|
||||
|
||||
if(change == ItemSelectedHasChanged)
|
||||
{
|
||||
if(m_piece->GetIsSelected() != isSelected())
|
||||
{
|
||||
m_piece->SetIsSelected(isSelected());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QGraphicsObject::itemChange(change, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,15 +31,27 @@
|
|||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
#include "vpuzzlepiece.h"
|
||||
class VPuzzlePiece;
|
||||
|
||||
class VPuzzleGraphicsPiece : public QGraphicsItem
|
||||
class VPuzzleGraphicsPiece : public QGraphicsObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *parent = nullptr);
|
||||
~VPuzzleGraphicsPiece();
|
||||
void Init();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief on_PieceSelectionChanged When the piece selection was changed
|
||||
*/
|
||||
void on_PieceSelectionChanged();
|
||||
|
||||
/**
|
||||
* @brief on_PiecePositionChanged When the piece position was changed
|
||||
*/
|
||||
void on_PiecePositionChanged();
|
||||
|
||||
protected:
|
||||
QRectF boundingRect() const override;
|
||||
QPainterPath shape() const override;
|
||||
|
@ -48,6 +60,7 @@ protected:
|
|||
void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPuzzleGraphicsPiece)
|
||||
|
@ -55,7 +68,6 @@ private:
|
|||
|
||||
QPainterPath m_cuttingLine;
|
||||
QPainterPath m_seamLine;
|
||||
|
||||
};
|
||||
|
||||
#endif // VPUZZLEGRAPHICSPIECE_H
|
||||
|
|
|
@ -75,6 +75,29 @@ QList<VPuzzleLayer *> VPuzzleLayout::GetLayers()
|
|||
return m_layers;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QList<VPuzzlePiece *> VPuzzleLayout::GetSelectedPieces()
|
||||
{
|
||||
QList<VPuzzlePiece *> result = QList<VPuzzlePiece *>();
|
||||
|
||||
QList<VPuzzleLayer *> layers = m_layers;
|
||||
layers.prepend(m_unplacedPiecesLayer);
|
||||
|
||||
for (auto layer : layers)
|
||||
{
|
||||
for (auto piece : layer->GetPieces())
|
||||
{
|
||||
if(piece->GetIsSelected())
|
||||
{
|
||||
result.append(piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPuzzleLayout::SetUnit(Unit unit)
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "def.h"
|
||||
|
||||
class VPuzzleLayer;
|
||||
class VPuzzlePiece;
|
||||
|
||||
// is this the right place for the definition?
|
||||
enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2};
|
||||
|
@ -51,7 +52,22 @@ public:
|
|||
VPuzzleLayer* AddLayer(VPuzzleLayer *layer);
|
||||
QList<VPuzzleLayer *> GetLayers();
|
||||
|
||||
/**
|
||||
* @brief GetSelectedPieces Returns the list of the selected pieces
|
||||
* @return the selected pieces
|
||||
*/
|
||||
QList<VPuzzlePiece *> GetSelectedPieces();
|
||||
|
||||
/**
|
||||
* @brief SetUnit Sets the unit of the layout to the given unit
|
||||
* @param unit the new unit
|
||||
*/
|
||||
void SetUnit(Unit unit);
|
||||
|
||||
/**
|
||||
* @brief GetUnit Returns the current unit of the layout
|
||||
* @return the unit
|
||||
*/
|
||||
Unit GetUnit() const;
|
||||
|
||||
/**
|
||||
|
@ -133,7 +149,16 @@ public:
|
|||
*/
|
||||
QMarginsF GetLayoutMarginsConverted() const;
|
||||
|
||||
/**
|
||||
* @brief SetFollowGrainline Sets the type of grainline for the pieces to follow
|
||||
* @param state the type of grainline
|
||||
*/
|
||||
void SetFollowGrainline(FollowGrainline state);
|
||||
|
||||
/**
|
||||
* @brief GetFollowGrainline Returns if the layout's pieces follow a grainline or not
|
||||
* @return wether the pieces follow a grainline and if so, which grainline
|
||||
*/
|
||||
FollowGrainline GetFollowGrainline() const;
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,8 @@ Q_LOGGING_CATEGORY(pMainGraphicsView, "p.mainGraphicsView")
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPuzzleMainGraphicsView::VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget *parent) :
|
||||
QGraphicsView(parent)
|
||||
QGraphicsView(parent),
|
||||
m_graphicsPieces(QList<VPuzzleGraphicsPiece*>())
|
||||
{
|
||||
m_scene = new VPuzzleMainGraphicsScene(this);
|
||||
setScene(m_scene);
|
||||
|
@ -123,9 +124,22 @@ void VPuzzleMainGraphicsView::dropEvent(QDropEvent *event)
|
|||
QPointF scenePos = mapToScene(point);
|
||||
// todo take the position into account
|
||||
|
||||
VPuzzleGraphicsPiece *item = new VPuzzleGraphicsPiece(piece);
|
||||
item->setPos(scenePos);
|
||||
m_scene->addItem(item);
|
||||
AddPiece(piece, scenePos);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPuzzleMainGraphicsView::AddPiece(VPuzzlePiece *piece, QPointF pos)
|
||||
{
|
||||
VPuzzleGraphicsPiece *item = new VPuzzleGraphicsPiece(piece);
|
||||
m_scene->addItem(item);
|
||||
item->setSelected(true);
|
||||
item->setPos(pos);
|
||||
|
||||
item->blockSignals(true);
|
||||
piece->SetPosition(pos);
|
||||
item->blockSignals(false);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
*/
|
||||
void RefreshLayout();
|
||||
|
||||
void AddPiece(VPuzzlePiece *piece, QPointF pos);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
|
@ -60,8 +62,11 @@ protected:
|
|||
private:
|
||||
Q_DISABLE_COPY(VPuzzleMainGraphicsView)
|
||||
|
||||
VPuzzleGraphicsLayout *m_graphicsLayout{nullptr};
|
||||
VPuzzleMainGraphicsScene *m_scene{nullptr};
|
||||
|
||||
VPuzzleGraphicsLayout *m_graphicsLayout{nullptr};
|
||||
QList<VPuzzleGraphicsPiece*> m_graphicsPieces;
|
||||
|
||||
};
|
||||
|
||||
#endif // VPUZZLEMAINGRAPHICVIEW_H
|
||||
|
|
|
@ -101,6 +101,8 @@ bool VPuzzlePiece::GetShowSeamLine()
|
|||
void VPuzzlePiece::SetShowSeamLine(bool value)
|
||||
{
|
||||
m_showSeamline = value;
|
||||
|
||||
emit PropertiesChanged();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -113,5 +115,53 @@ bool VPuzzlePiece::GetPieceMirrored()
|
|||
void VPuzzlePiece::SetPieceMirrored(bool value)
|
||||
{
|
||||
m_mirrorPiece = value;
|
||||
|
||||
emit PropertiesChanged();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPuzzlePiece::SetPosition(QPointF point)
|
||||
{
|
||||
m_transform.translate(point.x() - m_transform.dx(), point.y() - m_transform.dy());
|
||||
|
||||
emit PositionChanged();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPointF VPuzzlePiece::GetPosition()
|
||||
{
|
||||
return QPointF(m_transform.dx(), m_transform.dy());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPuzzlePiece::SetRotation(qreal angle)
|
||||
{
|
||||
Q_UNUSED(angle);
|
||||
//TODO
|
||||
|
||||
emit RotationChanged();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VPuzzlePiece::GetRotation()
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPuzzlePiece::SetIsSelected(bool value)
|
||||
{
|
||||
m_isSelected = value;
|
||||
|
||||
emit SelectionChanged();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VPuzzlePiece::GetIsSelected()
|
||||
{
|
||||
return m_isSelected;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -31,9 +31,11 @@
|
|||
#include <QUuid>
|
||||
#include <QVector>
|
||||
#include <QPoint>
|
||||
#include <QTransform>
|
||||
|
||||
class VPuzzlePiece
|
||||
class VPuzzlePiece : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VPuzzlePiece();
|
||||
~VPuzzlePiece();
|
||||
|
@ -109,14 +111,84 @@ public:
|
|||
*/
|
||||
void SetPieceMirrored(bool value);
|
||||
|
||||
/**
|
||||
* @brief SetPosition Sets the position of the piece, in relation to the origin of the scene
|
||||
* @param point the point where to set the piece
|
||||
*/
|
||||
void SetPosition(QPointF point);
|
||||
|
||||
/**
|
||||
* @brief GetPosition Returns the position of the piece
|
||||
* @return the position of the piece
|
||||
*/
|
||||
QPointF GetPosition();
|
||||
|
||||
/**
|
||||
* @brief SetRotation Sets the rotation of the piece to the given angle.
|
||||
* @param angle the angle of the rotation
|
||||
*/
|
||||
void SetRotation(qreal angle);
|
||||
|
||||
/**
|
||||
* @brief GetRotation Returns the angle of rotation
|
||||
* @return the angle of rotation
|
||||
*/
|
||||
qreal GetRotation();
|
||||
|
||||
/**
|
||||
* @brief SetIsSelected Sets wether the piece is selected
|
||||
* @param value true if the piece is selected
|
||||
*/
|
||||
void SetIsSelected(bool value);
|
||||
|
||||
/**
|
||||
* @brief GetIsSelected Returns wether the piece is selected
|
||||
* @return true if the piece is selected
|
||||
*/
|
||||
bool GetIsSelected();
|
||||
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief SelectionChanged emited when the selection of the piece was
|
||||
* changed through the SetIsSelected function
|
||||
*/
|
||||
void SelectionChanged();
|
||||
|
||||
/**
|
||||
* @brief PositionChanged emited when the position of the piece was
|
||||
* changed through the SetPosition function
|
||||
*/
|
||||
void PositionChanged();
|
||||
|
||||
/**
|
||||
* @brief RotationChanged emited when the position of the piece was
|
||||
* changed through the function SetRotation
|
||||
*/
|
||||
void RotationChanged();
|
||||
|
||||
/**
|
||||
* @brief PropertiesChanged emited when of the properties showSemaline
|
||||
* or mirrorpiece where changed.
|
||||
*/
|
||||
void PropertiesChanged();
|
||||
|
||||
/**
|
||||
* @brief LayerChanged emited when the piece's layer was changed.
|
||||
*/
|
||||
void LayerChanged();
|
||||
|
||||
private:
|
||||
QUuid m_uuid{QUuid()};
|
||||
QString m_name{QString()};
|
||||
QVector<QPointF> m_cuttingLine{QVector<QPointF>()};
|
||||
QVector<QPointF> m_seamLine{QVector<QPointF>()};
|
||||
|
||||
QTransform m_transform{QTransform()};
|
||||
|
||||
bool m_showSeamline{true};
|
||||
bool m_mirrorPiece{false};
|
||||
bool m_isSelected{false};
|
||||
};
|
||||
|
||||
#endif // VPUZZLEPIECE_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user