QSet<int> GridCardViewerWidget::getRowSelectableIndices( int row ) { // Use QMutableSetIterator to operate on set in-place. QSet<int> indices = getRowIndices( row ); QMutableSetIterator<int> iter( indices ); while( iter.hasNext() ) { int i = iter.next(); if( !isIndexSelectable( i ) ) iter.remove(); } return indices; }
GridCardViewerWidget::GridCardViewerWidget( ImageLoaderFactory* imageLoaderFactory, const Logging::Config& loggingConfig, QWidget* parent ) : CardViewerWidget( imageLoaderFactory, loggingConfig, parent ), mGridCardsLayout( nullptr ), mWaitingForTurn( false ) { // Create column buttons. for( int col = 0; col < 3; ++col ) { for( bool top : { true, false } ) { GridToolButton* button = new GridToolButton(); button->setArrowType( top ? Qt::DownArrow : Qt::UpArrow ); button->setText( "Select Column" ); button->setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); button->setToolTip( tr("Select column %0").arg(col+1) ); // Keep the layout from jerking around when buttons are hidden. QSizePolicy sizePolicy = button->sizePolicy(); sizePolicy.setRetainSizeWhenHidden( true ); button->setSizePolicy( sizePolicy ); connect( button, &GridToolButton::mouseEntered, [this,col]() { for( auto i : getColSelectableIndices( col ) ) { if( i < mCardWidgetsList.size() ) mCardWidgetsList[i]->setHighlighted( true ); } } ); connect( button, &GridToolButton::mouseExited, [this,col]() { for( auto i : getColIndices( col ) ) { if( i < mCardWidgetsList.size() ) mCardWidgetsList[i]->setHighlighted( false ); } } ); connect( button, &QToolButton::clicked, [this,col]() { QList<int> indices = QList<int>::fromSet( getColSelectableIndices( col ) ); emit cardIndicesSelectRequested( indices ); } ); if( top ) { mTopColButtons[col] = button; } else { mBottomColButtons[col] = button; } } } // Create row buttons. for( int row = 0; row < 3; ++row ) { for( bool left : { true, false } ) { GridToolButton* button = new GridToolButton(); button->setArrowType( left ? Qt::RightArrow : Qt::LeftArrow ); button->setText( "Select\nRow" ); button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); button->setToolTip( tr("Select row %0").arg(row+1) ); connect( button, &GridToolButton::mouseEntered, [this,row]() { for( auto i : getRowSelectableIndices( row ) ) { if( i < mCardWidgetsList.size() ) mCardWidgetsList[i]->setHighlighted( true ); } } ); connect( button, &GridToolButton::mouseExited, [this,row]() { for( auto i : getRowIndices( row ) ) { if( i < mCardWidgetsList.size() ) mCardWidgetsList[i]->setHighlighted( false ); } } ); connect( button, &QToolButton::clicked, [this,row]() { QList<int> indices = QList<int>::fromSet( getRowSelectableIndices( row ) ); emit cardIndicesSelectRequested( indices ); } ); if( left ) { mLeftRowButtons[row] = button; } else { mRightRowButtons[row] = button; } } } }
int *getMutableRowIndices(int irow){ // using const_cast to stop warnings about cast-away constness return const_cast<int *>(getRowIndices(irow)); }