Piece carrousel design and piece selection

This commit is contained in:
Ronan Le Tiec 2020-05-01 18:26:02 +02:00
parent 7bca5f41ec
commit f5e325a235
10 changed files with 172 additions and 20 deletions

View File

@ -294,6 +294,9 @@ void PuzzleMainWindow::InitPieceCarrousel()
connect(ui->dockWidgetPieceCarrousel, QOverload<Qt::DockWidgetArea>::of(&QDockWidget::dockLocationChanged), this, connect(ui->dockWidgetPieceCarrousel, QOverload<Qt::DockWidgetArea>::of(&QDockWidget::dockLocationChanged), this,
&PuzzleMainWindow::on_PieceCarrouselLocationChanged); &PuzzleMainWindow::on_PieceCarrouselLocationChanged);
connect(m_pieceCarrousel, QOverload<VPuzzlePiece*>::of(&VPieceCarrousel::pieceClicked), this,
&PuzzleMainWindow::on_PieceSelected);
} }
@ -329,7 +332,10 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
} }
else else
{ {
// TODO set the values of the piece currently selected // set the value to the current piece
ui->lineEditCurrentPieceName->setText(m_selectedPiece->GetName());
// TODO: checkbox show seamline, mirror piece, rotation and placement;
} }
} }
@ -816,3 +822,18 @@ void PuzzleMainWindow::on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void PuzzleMainWindow::on_PieceSelected(VPuzzlePiece* piece)
{
m_selectedPiece = piece;
// update the state of the piece carrousel
m_pieceCarrousel->SelectPiece(piece);
// update the Layout
// TODO
// update the property of the piece currently selected
SetPropertyTabCurrentPieceData();
}

View File

@ -356,6 +356,12 @@ private slots:
*/ */
void on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area); void on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area);
/**
* @brief on_PieceSelected When a been has been selected
* @param piece the piece that was selected
*/
void on_PieceSelected(VPuzzlePiece* piece);
}; };
#endif // PUZZLEMAINWINDOW_H #endif // PUZZLEMAINWINDOW_H

View File

@ -119,6 +119,10 @@ void VPieceCarrousel::Refresh()
VPieceCarrouselLayer *carrouselLayer = new VPieceCarrouselLayer(layer, this); VPieceCarrouselLayer *carrouselLayer = new VPieceCarrouselLayer(layer, this);
m_carrouselLayers.append(carrouselLayer); m_carrouselLayers.append(carrouselLayer);
m_layersContainer->layout()->addWidget(carrouselLayer); m_layersContainer->layout()->addWidget(carrouselLayer);
connect(carrouselLayer, QOverload<VPieceCarrouselPiece*>::of(&VPieceCarrouselLayer::pieceClicked), this,
&VPieceCarrousel::on_PieceClicked);
} }
on_ActiveLayerChanged(0); on_ActiveLayerChanged(0);
@ -155,6 +159,20 @@ 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) void VPieceCarrousel::on_ActiveLayerChanged(int index)
{ {
@ -198,7 +216,7 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// FIXME: find a nicer way than putting directly the 120 height of the piece // FIXME: find a nicer way than putting directly the 120 height of the piece
m_scrollArea->setMinimumHeight(120 + m_scrollArea->horizontalScrollBar()->sizeHint().height()+2); m_scrollArea->setMinimumHeight(128 + m_scrollArea->horizontalScrollBar()->sizeHint().height()+2);
m_scrollArea->setMinimumWidth(0); m_scrollArea->setMinimumWidth(0);
} }
else // Qt::Vertical else // Qt::Vertical
@ -211,10 +229,16 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_scrollArea->setMinimumHeight(0); m_scrollArea->setMinimumHeight(0);
m_scrollArea->setMinimumWidth(120 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2); m_scrollArea->setMinimumWidth(124 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2);
// FIXME: find a nicer way than putting directly the 120 width of the piece // FIXME: find a nicer way than putting directly the 120 width of the piece
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrousel::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece)
{
emit pieceClicked(carrouselPiece->GetPiece());
}

View File

@ -33,6 +33,7 @@
#include <QComboBox> #include <QComboBox>
#include <QScrollArea> #include <QScrollArea>
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include "vpuzzlepiece.h"
#include "vpiececarrousellayer.h" #include "vpiececarrousellayer.h"
class VPieceCarrousel : public QWidget class VPieceCarrousel : public QWidget
@ -59,9 +60,19 @@ public:
*/ */
void Clear(); void Clear();
/**
* @brief SelectPiece Updates the carrousel so that the given piece is selected
* @param piece the piece to select
*/
void SelectPiece(VPuzzlePiece* piece);
signals: signals:
void pieceClicked(VPuzzlePiece* piece);
public slots: public slots:
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
private: private:
Q_DISABLE_COPY(VPieceCarrousel) Q_DISABLE_COPY(VPieceCarrousel)

View File

@ -86,5 +86,21 @@ void VPieceCarrouselLayer::Refresh()
setVisible(true); setVisible(true);
carrouselPiece->CleanPreview(); carrouselPiece->CleanPreview();
setVisible(false); setVisible(false);
connect(carrouselPiece, QOverload<VPieceCarrouselPiece*>::of(&VPieceCarrouselPiece::clicked), this,
&VPieceCarrouselLayer::on_PieceClicked);
} }
} }
//---------------------------------------------------------------------------------------------------------------------
QList<VPieceCarrouselPiece*> VPieceCarrouselLayer::GetCarrouselPieces()
{
return m_carrouselPieces;
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselLayer::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece)
{
emit pieceClicked(carrouselPiece);
}

View File

@ -43,9 +43,13 @@ public:
void Init(); void Init();
void Refresh(); void Refresh();
QList<VPieceCarrouselPiece*> GetCarrouselPieces();
signals: signals:
void pieceClicked(VPieceCarrouselPiece* carrouselPiece);
public slots: public slots:
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
private: private:
Q_DISABLE_COPY(VPieceCarrouselLayer) Q_DISABLE_COPY(VPieceCarrouselLayer)

View File

@ -37,7 +37,7 @@
Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece") Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent) : QWidget(parent), m_piece(piece) VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, QWidget *parent) : QFrame(parent), m_piece(piece)
{ {
Init(); Init();
} }
@ -52,25 +52,31 @@ VPieceCarrouselPiece::~VPieceCarrouselPiece()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::Init() void VPieceCarrouselPiece::Init()
{ {
//m_label->setStyleSheet("background-color:cornflowerblue");
// Define the structure // Define the structure
setFixedSize(120,120); setFixedSize(124,128);
QVBoxLayout *pieceLayout = new QVBoxLayout(); QVBoxLayout *pieceLayout = new QVBoxLayout();
pieceLayout->setMargin(0); pieceLayout->setMargin(0);
pieceLayout->setSpacing(0);
setLayout(pieceLayout); setLayout(pieceLayout);
setStyleSheet("background-color:white; border: 2px solid transparent;");
// define the preview of the piece // define the preview of the piece
m_graphicsView = new QGraphicsView(this); m_graphicsView = new QGraphicsView(this);
// m_graphicsView = new VMainGraphicsView(this);
// --> undefined reference to 'VMainGraphicsView::VMainGraphicView(QWidget*)'
QGraphicsScene *graphicsScene = new QGraphicsScene(this); QGraphicsScene *graphicsScene = new QGraphicsScene(this);
m_graphicsView->setScene(graphicsScene); m_graphicsView->setScene(graphicsScene);
m_graphicsView->setFixedSize(120,100); m_graphicsView->setFixedSize(120,100);
m_graphicsView->setStyleSheet("border: 4px solid transparent;");
// define the label // define the label
m_label = new QLabel(); m_label = new QLabel();
m_label->sizePolicy(); m_label->sizePolicy();
m_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); m_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
m_label->setFixedSize(120,20); m_label->setFixedSize(120,24);
m_label->setStyleSheet("border: 0px;");
pieceLayout->addWidget(m_graphicsView); pieceLayout->addWidget(m_graphicsView);
pieceLayout->addWidget(m_label); pieceLayout->addWidget(m_label);
@ -111,6 +117,46 @@ void VPieceCarrouselPiece::Refresh()
QString clippedText = metrix.elidedText(m_piece->GetName(), Qt::ElideRight, width); QString clippedText = metrix.elidedText(m_piece->GetName(), Qt::ElideRight, width);
m_label->setText(clippedText); m_label->setText(clippedText);
m_label->setToolTip(m_piece->GetName()); setToolTip(m_piece->GetName());
} }
//---------------------------------------------------------------------------------------------------------------------
VPuzzlePiece * VPieceCarrouselPiece::GetPiece()
{
return m_piece;
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::SetIsSelected(bool value)
{
m_isSelected = value;
if(value)
{
setStyleSheet("background-color:white; border: 2px solid red;");
}
else
{
setStyleSheet("background-color:white; border: 2px solid transparent;");
}
}
//---------------------------------------------------------------------------------------------------------------------
bool VPieceCarrouselPiece::GetIsSelected()
{
return m_isSelected;
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
if(!m_isSelected)
{
emit clicked(this);
}
}
}

View File

@ -28,14 +28,15 @@
#ifndef VPIECECARROUSELPIECE_H #ifndef VPIECECARROUSELPIECE_H
#define VPIECECARROUSELPIECE_H #define VPIECECARROUSELPIECE_H
#include <QWidget> #include <QFrame>
#include <QLabel> #include <QLabel>
#include <QGraphicsView> #include <QGraphicsView>
#include <QMouseEvent>
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
class VPieceCarrouselPiece : public QWidget class VPieceCarrouselPiece : public QFrame
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -50,16 +51,40 @@ public:
*/ */
void CleanPreview(); void CleanPreview();
/**
* @brief GetLayoutPiece Returns the corresponding layout piece
* @return the corresponding layout piece
*/
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: signals:
void clicked(VPieceCarrouselPiece* m_piece);
public slots: public slots:
protected:
void mousePressEvent(QMouseEvent *event) override;
private: private:
Q_DISABLE_COPY(VPieceCarrouselPiece) Q_DISABLE_COPY(VPieceCarrouselPiece)
VPuzzlePiece *m_piece; VPuzzlePiece *m_piece;
QLabel *m_label; QLabel *m_label{nullptr};
QGraphicsView *m_graphicsView; QGraphicsView *m_graphicsView{nullptr};
bool m_isSelected = false;
private slots: private slots:

View File

@ -58,7 +58,6 @@ public:
/** /**
* @brief SetUuid Sets the uuid of the piece to the given value * @brief SetUuid Sets the uuid of the piece to the given value
* @return the uuid of the piece
*/ */
void SetUuid(const QUuid &uuid); void SetUuid(const QUuid &uuid);

View File

@ -62,7 +62,7 @@ bool VPuzzleLayoutFileReader::ReadFile(VPuzzleLayout *layout, QFile *file)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout) void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout)
{ {
Q_ASSERT(isStartElement() && name() == ML::TagLayout); SCASSERT(isStartElement() && name() == ML::TagLayout);
while (readNextStartElement()) while (readNextStartElement())
{ {
@ -84,7 +84,7 @@ void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout) void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout)
{ {
Q_ASSERT(isStartElement() && name() == ML::TagProperties); SCASSERT(isStartElement() && name() == ML::TagProperties);
while (readNextStartElement()) while (readNextStartElement())
{ {
@ -162,7 +162,7 @@ void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout)
{ {
Q_UNUSED(layout); // to be removed when used Q_UNUSED(layout); // to be removed when used
Q_ASSERT(isStartElement() && name() == ML::TagTiles); SCASSERT(isStartElement() && name() == ML::TagTiles);
// QXmlStreamAttributes attribs = attributes(); // QXmlStreamAttributes attribs = attributes();
// attribs.value(ML::AttrVisible); // TODO // attribs.value(ML::AttrVisible); // TODO
@ -195,7 +195,7 @@ void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout) void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout)
{ {
Q_ASSERT(isStartElement() && name() == ML::TagLayers); SCASSERT(isStartElement() && name() == ML::TagLayers);
while (readNextStartElement()) while (readNextStartElement())
{ {
@ -219,7 +219,7 @@ void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer) void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer)
{ {
Q_ASSERT(isStartElement() && (name() == ML::TagLayer || name() == ML::TagUnplacedPiecesLayer)); SCASSERT(isStartElement() && (name() == ML::TagLayer || name() == ML::TagUnplacedPiecesLayer));
QXmlStreamAttributes attribs = attributes(); QXmlStreamAttributes attribs = attributes();
layer->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Layer"))); layer->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Layer")));
@ -245,7 +245,7 @@ void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer)
void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece) void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece)
{ {
Q_UNUSED(piece); Q_UNUSED(piece);
Q_ASSERT(isStartElement() && name() == ML::TagPiece); SCASSERT(isStartElement() && name() == ML::TagPiece);
QXmlStreamAttributes attribs = attributes(); QXmlStreamAttributes attribs = attributes();
piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece"))); piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece")));