improve multiple selection and add grainline to pieces

This commit is contained in:
Ronan Le Tiec 2020-05-06 15:05:01 +02:00
parent e2b816f192
commit d72be9029f
15 changed files with 266 additions and 73 deletions

View File

@ -184,9 +184,17 @@ VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece)
VPuzzlePiece *piece = new VPuzzlePiece();
piece->SetName(rawPiece.GetName());
piece->SetUuid(rawPiece.GetUUID());
piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints());
piece->SetSeamLine(rawPiece.GetMappedContourPoints());
piece->SetIsGrainlineEnabled(rawPiece.IsGrainlineEnabled());
if(rawPiece.IsGrainlineEnabled())
{
piece->SetGrainlineAngle(rawPiece.GrainlineAngle());
piece->SetGrainline(rawPiece.GetGrainline());
}
// TODO : set all the information we need for the piece!
//
@ -339,16 +347,20 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
{
if(m_selectedPieces.count() == 0)
{
// TODO : update current piece data to show a "no current piece selected"
// show the content "no piece selected"
ui->containerCurrentPieceNoData->setVisible(true);
ui->containerCurrentPieceData->setVisible(false);
ui->containerCurrentPieceMultipleData->setVisible(false);
}
else if(m_selectedPieces.count() == 1)
{
VPuzzlePiece *selectedPiece = m_selectedPieces.first();
// show the content "selected piece data"
ui->containerCurrentPieceNoData->setVisible(false);
ui->containerCurrentPieceData->setVisible(true);
ui->containerCurrentPieceMultipleData->setVisible(false);
VPuzzlePiece *selectedPiece = m_selectedPieces.first();
// set the value to the current piece
ui->lineEditCurrentPieceName->setText(selectedPiece->GetName());
@ -364,7 +376,13 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
}
else
{
// TODO in the future
// show the content "multiple pieces selected"
ui->containerCurrentPieceNoData->setVisible(false);
ui->containerCurrentPieceData->setVisible(false);
ui->containerCurrentPieceMultipleData->setVisible(true);
// if needed in the future, we can show some properties that coul be edited for all the pieces
}
}
@ -864,16 +882,6 @@ void PuzzleMainWindow::on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area)
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::on_PieceSelectionChanged()
{
// for now we have only single selection
// FIXME / TODO : To be updated when we support multiple selection.
for (auto piece : m_selectedPieces)
{
if(piece->GetIsSelected())
{
piece->SetIsSelected(false);
}
}
m_selectedPieces = m_layout->GetSelectedPieces();
// update the property of the piece currently selected

View File

@ -228,9 +228,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-542</y>
<width>342</width>
<height>894</height>
<height>1302</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -250,31 +250,6 @@
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="containerCurrentPieceNoData" native="true">
<layout class="QVBoxLayout" name="containerCurrentPieceNoDataLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelCurrentPieceNoPieceSelected">
<property name="minimumSize">
<size>
<width>0</width>
<height>400</height>
</size>
</property>
<property name="text">
<string>No piece selected</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="containerCurrentPieceData" native="true">
<layout class="QVBoxLayout" name="containerCurrentPieceDataLayout">
@ -380,6 +355,9 @@
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceBoxPositionX">
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
</property>
@ -397,6 +375,9 @@
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxCurrentPieceBoxPositionY">
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
</property>
@ -411,6 +392,53 @@
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="containerCurrentPieceNoData" native="true">
<layout class="QVBoxLayout" name="containerCurrentPieceNoDataLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelCurrentPieceNoPieceSelected">
<property name="minimumSize">
<size>
<width>0</width>
<height>400</height>
</size>
</property>
<property name="text">
<string>No piece selected</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="containerCurrentPieceMultipleData" native="true">
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QLabel" name="labelCurrentPieceMultiplePieceSelected">
<property name="minimumSize">
<size>
<width>0</width>
<height>400</height>
</size>
</property>
<property name="text">
<string>Multiple pieces selected</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacerCurrentPiece">
<property name="orientation">

View File

@ -221,3 +221,9 @@ void VPieceCarrousel::RefreshOrientation()
// FIXME: find a nicer way than putting directly the 120 width of the piece
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrousel::ClearSelection()
{
m_layout->ClearSelection();
}

View File

@ -72,10 +72,9 @@ public:
void Clear();
/**
* @brief SelectPiece Updates the carrousel so that the given piece is selected
* @param piece the piece to select
* @brief ClearSelection Clears the selection of the carrousel.
*/
void SelectPiece(VPuzzlePiece* piece);
void ClearSelection();
private:

View File

@ -27,6 +27,8 @@
*************************************************************************/
#include "vpiececarrousellayer.h"
#include "vpiececarrousel.h"
#include <QVBoxLayout>
@ -35,9 +37,9 @@
Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer")
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselLayer::VPieceCarrouselLayer(VPuzzleLayer *layer, QWidget *parent) :
QWidget(parent),
VPieceCarrouselLayer::VPieceCarrouselLayer(VPuzzleLayer *layer, VPieceCarrousel *carrousel) :
m_layer(layer),
m_carrousel(carrousel),
m_carrouselPieces(QList<VPieceCarrouselPiece*>())
{
Init();
@ -80,7 +82,7 @@ void VPieceCarrouselLayer::Refresh()
{
// qCDebug(pCarrouselLayer, "piece name : %s", piece->GetName().toStdString().c_str());
VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece);
VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece, this);
m_carrouselPieces.append(carrouselPiece);
layout()->addWidget(carrouselPiece);
@ -98,3 +100,9 @@ QList<VPieceCarrouselPiece*> VPieceCarrouselLayer::GetCarrouselPieces()
return m_carrouselPieces;
}
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrousel* VPieceCarrouselLayer::GetCarrousel()
{
return m_carrousel;
}

View File

@ -33,11 +33,13 @@
#include "vpuzzlelayer.h"
#include "vpiececarrouselpiece.h"
class VPieceCarrousel;
class VPieceCarrouselLayer : public QWidget
{
Q_OBJECT
public:
explicit VPieceCarrouselLayer(VPuzzleLayer *layer, QWidget *parent = nullptr);
VPieceCarrouselLayer(VPuzzleLayer *layer, VPieceCarrousel *carrousel);
~VPieceCarrouselLayer();
void Init();
@ -45,10 +47,13 @@ public:
QList<VPieceCarrouselPiece*> GetCarrouselPieces();
VPieceCarrousel* GetCarrousel();
private:
Q_DISABLE_COPY(VPieceCarrouselLayer)
VPuzzleLayer *m_layer;
VPieceCarrousel *m_carrousel;
QList<VPieceCarrouselPiece*> m_carrouselPieces;
private slots:

View File

@ -37,6 +37,8 @@
#include <QApplication>
#include "vpuzzlemimedatapiece.h"
#include "vpiececarrousellayer.h"
#include "vpiececarrousel.h"
#include <QLoggingCategory>
@ -44,9 +46,10 @@ Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent) :
QFrame(parent),
m_piece(piece)
VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, VPieceCarrouselLayer *carrouselLayer) :
m_piece(piece),
m_carrouselLayer(carrouselLayer),
m_dragStart(QPoint())
{
Init();
}
@ -169,10 +172,16 @@ void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton)
{
if(!m_piece->GetIsSelected())
if(!(event->modifiers() & Qt::ControlModifier))
{
m_carrouselLayer->GetCarrousel()->ClearSelection();
m_piece->SetIsSelected(true);
}
else
{
m_piece->SetIsSelected(!m_piece->GetIsSelected());
}
m_dragStart = event->pos();
}
}
@ -190,6 +199,11 @@ void VPieceCarrouselPiece::mouseMoveEvent(QMouseEvent *event)
return;
}
// make sure the multiple selection is removed
m_carrouselLayer->GetCarrousel()->ClearSelection();
m_piece->SetIsSelected(true);
// starts the dragging
QDrag *drag = new QDrag(this);
VPuzzleMimeDataPiece *mimeData = new VPuzzleMimeDataPiece();
mimeData->SetPiecePtr(m_piece);

View File

@ -37,11 +37,13 @@
#include "vpiececarrouselpiecepreview.h"
class VPieceCarrouselLayer;
class VPieceCarrouselPiece : public QFrame
{
Q_OBJECT
public:
explicit VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent = nullptr);
explicit VPieceCarrouselPiece(VPuzzlePiece *piece, VPieceCarrouselLayer *carrouselLayer);
~VPieceCarrouselPiece();
void Init();
@ -70,6 +72,9 @@ private:
Q_DISABLE_COPY(VPieceCarrouselPiece)
VPuzzlePiece *m_piece;
VPieceCarrouselLayer *m_carrouselLayer;
QLabel *m_label{nullptr};
VPieceCarrouselPiecePreview *m_piecePreview{nullptr};

View File

@ -45,7 +45,8 @@ VPuzzleGraphicsPiece::VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *p
QGraphicsObject(parent),
m_piece(piece),
m_cuttingLine(QPainterPath()),
m_seamLine(QPainterPath())
m_seamLine(QPainterPath()),
m_grainline(QPainterPath())
{
Init();
}
@ -63,9 +64,6 @@ void VPuzzleGraphicsPiece::Init()
setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
setCursor(QCursor(Qt::OpenHandCursor));
//setAcceptHoverEvents(true); // maybe we can do some stuff with this
// initialises the seam line
QVector<QPointF> seamLinePoints = m_piece->GetSeamLine();
m_seamLine.moveTo(seamLinePoints.first());
@ -78,8 +76,14 @@ void VPuzzleGraphicsPiece::Init()
for (int i = 1; i < cuttingLinepoints.size(); ++i)
m_cuttingLine.lineTo(cuttingLinepoints.at(i));
// initialises the grainline
QVector<QPointF> grainLinepoints = m_piece->GetGrainline();
m_grainline.moveTo(grainLinepoints.first());
for (int i = 1; i < grainLinepoints.size(); ++i)
m_grainline.lineTo(grainLinepoints.at(i));
// TODO : initialises the other elements like grain line, labels, passmarks etc.
// TODO : initialises the other elements labels, passmarks etc.
// Initialises the connectors
connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPuzzleGraphicsPiece::on_PieceSelectionChanged);
@ -126,47 +130,69 @@ void VPuzzleGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsIt
painter->setPen(pen);
painter->setBrush(noBrush);
// paint the cutting line
if(!m_cuttingLine.isEmpty())
{
painter->drawPath(m_cuttingLine);
}
// paint the seam line
if(!m_seamLine.isEmpty())
{
painter->drawPath(m_seamLine);
}
// paint the grainline
if(!m_grainline.isEmpty())
{
painter->drawPath(m_grainline);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
bool selectionState = isSelected();
//perform the default behaviour
QGraphicsItem::mousePressEvent(event);
// change the cursor when clicking left button
if (!(event->buttons() & Qt::LeftButton))
if (event->button() == Qt::LeftButton)
{
return;
setSelected(true);
setCursor(Qt::ClosedHandCursor);
if (event->modifiers() & Qt::ControlModifier)
{
setSelected(!selectionState);
}
else
{
setSelected(true);
}
}
setSelected(true);
setCursor(Qt::ClosedHandCursor);
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
bool selectionState = isSelected();
//perform the default behaviour
QGraphicsItem::mouseReleaseEvent(event);
// change the cursor when clicking left button
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
qCDebug(pGraphicsPiece, "piiiiieeece --- mouse release");
setCursor(Qt::OpenHandCursor);
// change the cursor when clicking left button
if (event->button() == Qt::LeftButton)
{
setCursor(Qt::OpenHandCursor);
qCDebug(pGraphicsPiece, "piiiiieeece --- left button");
setSelected(selectionState);
}
}

View File

@ -68,6 +68,7 @@ private:
QPainterPath m_cuttingLine;
QPainterPath m_seamLine;
QPainterPath m_grainline;
};
#endif // VPUZZLEGRAPHICSPIECE_H

View File

@ -268,3 +268,12 @@ bool VPuzzleLayout::GetStickyEdges() const
{
return m_stickyEdges;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::ClearSelection()
{
for(auto piece : GetSelectedPieces())
{
piece->SetIsSelected(false);
}
}

View File

@ -194,6 +194,12 @@ public:
void SetStickyEdges(bool state);
bool GetStickyEdges() const;
/**
* @brief ClearSelection goes through the layers & pieces and calls
* SetIsSelected(false) for the pieces that were selected.
*/
void ClearSelection();
private:
Q_DISABLE_COPY(VPuzzleLayout)
VPuzzleLayer *m_unplacedPiecesLayer;

View File

@ -142,4 +142,7 @@ void VPuzzleMainGraphicsView::AddPiece(VPuzzlePiece *piece, QPointF pos)
item->blockSignals(true);
piece->SetPosition(pos);
item->blockSignals(false);
}

View File

@ -152,9 +152,11 @@ qreal VPuzzlePiece::GetRotation()
//---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetIsSelected(bool value)
{
m_isSelected = value;
emit SelectionChanged();
if(m_isSelected != value)
{
m_isSelected = value;
emit SelectionChanged();
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -163,5 +165,38 @@ bool VPuzzlePiece::GetIsSelected()
return m_isSelected;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetIsGrainlineEnabled(bool value)
{
m_isGrainlineEnabled = value;
}
//---------------------------------------------------------------------------------------------------------------------
bool VPuzzlePiece::GetIsGrainlineEnabled()
{
return m_isGrainlineEnabled;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetGrainlineAngle(qreal value)
{
m_grainlineAngle = value;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPuzzlePiece::GetGrainlineAngle()
{
return m_grainlineAngle;
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetGrainline(QVector<QPointF> grainline)
{
m_grainline = grainline;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VPuzzlePiece::GetGrainline()
{
return m_grainline;
}

View File

@ -147,6 +147,42 @@ public:
*/
bool GetIsSelected();
/**
* @brief SetIsGrainlineEnabled Wether the piece has a grainline or not
* @param value true or false
*/
void SetIsGrainlineEnabled(bool value);
/**
* @brief GetIsGrainlineEnabled Returns wether the grainline is enabled for this piece
* @return true if enabled
*/
bool GetIsGrainlineEnabled();
/**
* @brief SetGrainlineAngle Sets the angle of the grainline
* @param value
*/
void SetGrainlineAngle(qreal value);
/**
* @brief GetGrainlineAngle Returns the angle of the grainline for this piece
* @return the angle
*/
qreal GetGrainlineAngle();
/**
* @brief SetGrainline Sets the grainline to the given vector of points
* @param grainline the grainline
*/
void SetGrainline(QVector<QPointF> grainline);
/**
* @brief GetGrainline Returns the grainline for this piece
* @return the vector
*/
QVector<QPointF> GetGrainline();
signals:
/**
@ -184,6 +220,10 @@ private:
QVector<QPointF> m_cuttingLine{QVector<QPointF>()};
QVector<QPointF> m_seamLine{QVector<QPointF>()};
QVector<QPointF> m_grainline{QVector<QPointF>()};
bool m_isGrainlineEnabled{false};
qreal m_grainlineAngle{0};
QTransform m_transform{QTransform()};
bool m_showSeamline{true};