diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index bcc90cb9e..245149e7e 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -64,10 +64,6 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa m_layout->SetPiecesGapConverted(1.27); m_layout->SetUnit(Unit::Cm); m_layout->SetWarningSuperpositionOfPieces(true); - VPuzzleLayer *unplacedLayer = m_layout->GetUnplacedPiecesLayer(); - VPuzzlePiece *piece = new VPuzzlePiece(); - piece->SetName("Hello"); - unplacedLayer->AddPiece(piece); // -------------------------------------------------------- ui->setupUi(this); @@ -289,7 +285,7 @@ void PuzzleMainWindow::InitPropertyTabLayers() //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::InitPieceCarrousel() { - m_pieceCarrousel = new VPieceCarrousel(m_layout); + m_pieceCarrousel = new VPieceCarrousel(m_layout, ui->dockWidgetPieceCarrousel); ui->dockWidgetPieceCarrousel->setWidget(m_pieceCarrousel); connect(ui->dockWidgetPieceCarrousel, QOverload::of(&QDockWidget::dockLocationChanged), this, diff --git a/src/app/puzzle/puzzlemainwindow.ui b/src/app/puzzle/puzzlemainwindow.ui index d8516accc..d2731a6e5 100644 --- a/src/app/puzzle/puzzlemainwindow.ui +++ b/src/app/puzzle/puzzlemainwindow.ui @@ -94,8 +94,8 @@ - 160 - 208 + 24 + 37 @@ -126,7 +126,11 @@ 0 - + + + 0 + + @@ -228,8 +232,8 @@ 0 0 - 170 - 452 + 356 + 760 @@ -858,8 +862,8 @@ 0 0 - 98 - 41 + 356 + 760 @@ -938,8 +942,8 @@ 0 0 - 98 - 41 + 356 + 760 diff --git a/src/app/puzzle/vpiececarrousel.cpp b/src/app/puzzle/vpiececarrousel.cpp index 1bf2ee2de..327e53054 100644 --- a/src/app/puzzle/vpiececarrousel.cpp +++ b/src/app/puzzle/vpiececarrousel.cpp @@ -32,6 +32,7 @@ #include "../vmisc/backport/qoverload.h" #include +#include Q_LOGGING_CATEGORY(pCarrousel, "p.carrousel") @@ -40,6 +41,7 @@ VPieceCarrousel::VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent) : QWidget(parent), m_layout(layout), m_comboBoxLayer(new QComboBox(this)), + m_scrollArea(new QScrollArea(this)), m_layersContainer(new QWidget(this)), m_carrouselLayers(QList()) { @@ -65,6 +67,7 @@ void VPieceCarrousel::Init() // init the layers container and corresponding scroll area QWidget *layersContainerWrapper = new QWidget(); + QVBoxLayout *layersContainerWrapperLayout = new QVBoxLayout(); layersContainerWrapperLayout->setMargin(0); layersContainerWrapper->setLayout(layersContainerWrapperLayout); @@ -77,20 +80,21 @@ void VPieceCarrousel::Init() layersContainerWrapperLayout->addWidget(m_layersContainer); layersContainerWrapperLayout->addSpacerItem(spacer); - QScrollArea *scrollArea = new QScrollArea(); - scrollArea->setWidgetResizable( true ); - scrollArea->setWidget(layersContainerWrapper); + m_scrollArea->setWidgetResizable( true ); + m_scrollArea->setWidget(layersContainerWrapper); // init the layout of the piece carrousel QVBoxLayout *mainLayout = new QVBoxLayout(); setLayout(mainLayout); - setMinimumSize(140,140); mainLayout->addWidget(m_comboBoxLayer); - mainLayout->addWidget(scrollArea); + mainLayout->addWidget(m_scrollArea); // ------ then we fill the carrousel with the layout content Refresh(); + + // ------ and make sure the calculation for the qlayout is right + SetOrientation(Qt::Vertical); } //--------------------------------------------------------------------------------------------------------------------- @@ -111,8 +115,6 @@ void VPieceCarrousel::Refresh() // add layer name to combo m_comboBoxLayer->addItem(layer->GetName()); - qCDebug(pCarrousel, "layer name : %s", layer->GetName().toStdString().c_str()); - // add new carrousel layer VPieceCarrouselLayer *carrouselLayer = new VPieceCarrouselLayer(layer, this); m_carrouselLayers.append(carrouselLayer); @@ -142,7 +144,7 @@ void VPieceCarrousel::Clear() } } - // Removes and deletes the carrousel layer from the list + // Removes and deletes the carrousel layers from the list while (!m_carrouselLayers.isEmpty()) { VPieceCarrouselLayer *carrouselLayer = m_carrouselLayers.takeLast(); @@ -168,29 +170,51 @@ void VPieceCarrousel::on_ActiveLayerChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) { - QBoxLayout::Direction direction = QBoxLayout::LeftToRight; - if(orientation == Qt::Horizontal) - { - m_comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - } - else // Qt::Vertical - { - direction = QBoxLayout::TopToBottom; - m_comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); - } - - // TODO: it's not updated anymore: + QBoxLayout::Direction direction = (orientation == Qt::Horizontal)? + QBoxLayout::LeftToRight + : + QBoxLayout::TopToBottom; + // Update the various qlayouts QBoxLayout* mainScrollAreaLayout = qobject_cast(m_layersContainer->layout()); mainScrollAreaLayout->setDirection(direction); + QBoxLayout* layerContainerWrapper = qobject_cast(m_scrollArea->widget()->layout()); + layerContainerWrapper->setDirection(direction); + for (VPieceCarrouselLayer *widget: m_carrouselLayers) { QBoxLayout* layerLayout = qobject_cast(widget->layout()); layerLayout->setDirection(direction); } + + // then update the scrollarea min height / width and scrollbar behaviour + if(orientation == Qt::Horizontal) + { + m_comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + // scroll bar policy of scroll area + m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + 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->setMinimumWidth(0); + } + else // Qt::Vertical + { + m_comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + + + // scroll bar policy of scroll area + m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + + m_scrollArea->setMinimumHeight(0); + m_scrollArea->setMinimumWidth(120 + m_scrollArea->verticalScrollBar()->sizeHint().width()+2); + // FIXME: find a nicer way than putting directly the 120 width of the piece + } + } diff --git a/src/app/puzzle/vpiececarrousel.h b/src/app/puzzle/vpiececarrousel.h index 22a08cd79..e8dd9c9ed 100644 --- a/src/app/puzzle/vpiececarrousel.h +++ b/src/app/puzzle/vpiececarrousel.h @@ -69,6 +69,7 @@ private: VPuzzleLayout *m_layout; QComboBox *m_comboBoxLayer; + QScrollArea *m_scrollArea; QWidget *m_layersContainer; QList m_carrouselLayers; diff --git a/src/app/puzzle/vpiececarrousellayer.cpp b/src/app/puzzle/vpiececarrousellayer.cpp index 7a28c7fd0..5993ed71a 100644 --- a/src/app/puzzle/vpiececarrousellayer.cpp +++ b/src/app/puzzle/vpiececarrousellayer.cpp @@ -67,9 +67,14 @@ void VPieceCarrouselLayer::Refresh() // Updates the carrousel pieces from the pieces list QList pieces = m_layer->GetPieces(); + // sort the pieces in alphabetical order + std::sort(pieces.begin(), pieces.end(), + [](const VPuzzlePiece* a, const VPuzzlePiece* b) -> bool { return a->GetName() < b->GetName();}); + + // create the corresponding carrousel pieces for (auto piece : pieces) { - qCDebug(pCarrouselLayer, "piece name : %s", piece->GetName().toStdString().c_str()); +// qCDebug(pCarrouselLayer, "piece name : %s", piece->GetName().toStdString().c_str()); VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece); m_carrouselPieces.append(carrouselPiece); diff --git a/src/app/puzzle/vpiececarrouselpiece.cpp b/src/app/puzzle/vpiececarrouselpiece.cpp index 553ff8db0..7c1085f3e 100644 --- a/src/app/puzzle/vpiececarrouselpiece.cpp +++ b/src/app/puzzle/vpiececarrouselpiece.cpp @@ -64,6 +64,7 @@ void VPieceCarrouselPiece::Init() m_label->setStyleSheet("background-color:cornflowerblue"); pieceLayout->addWidget(m_label); + setMinimumSize(120,120); // then refresh the data Refresh();