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,
&PuzzleMainWindow::on_PieceCarrouselLocationChanged);
connect(m_pieceCarrousel, QOverload<VPuzzlePiece*>::of(&VPieceCarrousel::pieceClicked), this,
&PuzzleMainWindow::on_PieceSelected);
}
@ -329,7 +332,10 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData()
}
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);
/**
* @brief on_PieceSelected When a been has been selected
* @param piece the piece that was selected
*/
void on_PieceSelected(VPuzzlePiece* piece);
};
#endif // PUZZLEMAINWINDOW_H

View File

@ -119,6 +119,10 @@ 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);
@ -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)
{
@ -198,7 +216,7 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// 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);
}
else // Qt::Vertical
@ -211,10 +229,16 @@ void VPieceCarrousel::SetOrientation(Qt::Orientation orientation)
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
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
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrousel::on_PieceClicked(VPieceCarrouselPiece* carrouselPiece)
{
emit pieceClicked(carrouselPiece->GetPiece());
}

View File

@ -33,6 +33,7 @@
#include <QComboBox>
#include <QScrollArea>
#include "vpuzzlelayout.h"
#include "vpuzzlepiece.h"
#include "vpiececarrousellayer.h"
class VPieceCarrousel : public QWidget
@ -59,9 +60,19 @@ public:
*/
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:
void pieceClicked(VPuzzlePiece* piece);
public slots:
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
private:
Q_DISABLE_COPY(VPieceCarrousel)

View File

@ -86,5 +86,21 @@ void VPieceCarrouselLayer::Refresh()
setVisible(true);
carrouselPiece->CleanPreview();
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 Refresh();
QList<VPieceCarrouselPiece*> GetCarrouselPieces();
signals:
void pieceClicked(VPieceCarrouselPiece* carrouselPiece);
public slots:
void on_PieceClicked(VPieceCarrouselPiece* carrouselPiece);
private:
Q_DISABLE_COPY(VPieceCarrouselLayer)

View File

@ -37,7 +37,7 @@
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();
}
@ -52,25 +52,31 @@ VPieceCarrouselPiece::~VPieceCarrouselPiece()
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselPiece::Init()
{
//m_label->setStyleSheet("background-color:cornflowerblue");
// Define the structure
setFixedSize(120,120);
setFixedSize(124,128);
QVBoxLayout *pieceLayout = new QVBoxLayout();
pieceLayout->setMargin(0);
pieceLayout->setSpacing(0);
setLayout(pieceLayout);
setStyleSheet("background-color:white; border: 2px solid transparent;");
// define the preview of the piece
m_graphicsView = new QGraphicsView(this);
// m_graphicsView = new VMainGraphicsView(this);
// --> undefined reference to 'VMainGraphicsView::VMainGraphicView(QWidget*)'
QGraphicsScene *graphicsScene = new QGraphicsScene(this);
m_graphicsView->setScene(graphicsScene);
m_graphicsView->setFixedSize(120,100);
m_graphicsView->setStyleSheet("border: 4px solid transparent;");
// define the label
m_label = new QLabel();
m_label->sizePolicy();
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_label);
@ -111,6 +117,46 @@ void VPieceCarrouselPiece::Refresh()
QString clippedText = metrix.elidedText(m_piece->GetName(), Qt::ElideRight, width);
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
#define VPIECECARROUSELPIECE_H
#include <QWidget>
#include <QFrame>
#include <QLabel>
#include <QGraphicsView>
#include <QMouseEvent>
#include "vpuzzlepiece.h"
class VPieceCarrouselPiece : public QWidget
class VPieceCarrouselPiece : public QFrame
{
Q_OBJECT
public:
@ -50,16 +51,40 @@ public:
*/
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:
void clicked(VPieceCarrouselPiece* m_piece);
public slots:
protected:
void mousePressEvent(QMouseEvent *event) override;
private:
Q_DISABLE_COPY(VPieceCarrouselPiece)
VPuzzlePiece *m_piece;
QLabel *m_label;
QGraphicsView *m_graphicsView;
QLabel *m_label{nullptr};
QGraphicsView *m_graphicsView{nullptr};
bool m_isSelected = false;
private slots:

View File

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

View File

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