Commit 9d8b73d2 authored by Johannes Zarl-Zierl's avatar Johannes Zarl-Zierl Committed by Miika Turkia
Browse files

Allow inclusion of collapsed stacks for selection.

By default, ThumbnailFacade::selection now includes images of collapsed
stacks, not just the stack head. You can revert to the old behaviour by
using ThumbnailFacade::selection(ThumbnailView::NoExpandCollapsedStacks)

BUG: 185872
parent 53478f64
......@@ -38,7 +38,7 @@ bool ThumbnailView::KeyboardEventHandler::keyPressEvent( QKeyEvent* event )
bool mustRemoveToken = false;
bool hadHit = false;
const DB::IdList selection = widget()->selection();
const DB::IdList selection = widget()->selection( NoExpandCollapsedStacks );
for( DB::IdList::ConstIterator it = selection.begin(); it != selection.end(); ++it ) {
DB::ImageInfoPtr info = (*it).fetchInfo();
if ( ! hadHit ) {
......@@ -61,7 +61,7 @@ bool ThumbnailView::KeyboardEventHandler::keyPressEvent( QKeyEvent* event )
bool ok;
short rating = event->text().left(1).toShort(&ok, 10);
if (ok) {
const DB::IdList selection = widget()->selection();
const DB::IdList selection = widget()->selection( NoExpandCollapsedStacks );
for( DB::IdList::ConstIterator it = selection.begin(); it != selection.end(); ++it ) {
DB::ImageInfoPtr info = (*it).fetchInfo();
info->setRating(rating * 2);
......
......@@ -60,7 +60,7 @@ void ThumbnailView::SelectionInteraction::startDrag()
{
_dragInProgress = true;
KUrl::List urls;
Q_FOREACH(DB::ImageInfoPtr info, widget()->selection().fetchInfos()) {
Q_FOREACH(DB::ImageInfoPtr info, widget()->selection( NoExpandCollapsedStacks ).fetchInfos()) {
const QString fileName = info->fileName(DB::AbsolutePath);
urls.append( fileName );
}
......
......@@ -22,7 +22,7 @@ ThumbnailView::SelectionMaintainer::SelectionMaintainer(ThumbnailWidget *widget,
{
m_currentItem = widget->currentItem();
m_currentRow = widget->currentIndex().row();
m_selectedItems = widget->selection();
m_selectedItems = widget->selection( NoExpandCollapsedStacks );
if ( m_selectedItems.isEmpty())
m_firstRow = -1;
else
......
......@@ -101,7 +101,7 @@ void ThumbnailView::ThumbnailDND::realDropEvent()
// protect against self drop
if ( !widget()->isSelected( model()->leftDropItem() ) && ! widget()->isSelected( model()->rightDropItem() ) ) {
const DB::IdList selected = widget()->selection();
const DB::IdList selected = widget()->selection( ExpandCollapsedStacks );
if ( model()->rightDropItem().isNull() ) {
// We dropped onto the first image.
DB::ImageDB::instance()->reorder( model()->leftDropItem(), selected, false );
......
......@@ -74,9 +74,9 @@ void ThumbnailView::ThumbnailFacade::reload( SelectionUpdateMethod method )
_widget->reload( method );
}
DB::IdList ThumbnailView::ThumbnailFacade::selection() const
DB::IdList ThumbnailView::ThumbnailFacade::selection( ThumbnailView::SelectionMode mode ) const
{
return _widget->selection();
return _widget->selection(mode);
}
DB::IdList ThumbnailView::ThumbnailFacade::imageList(Order order) const
......@@ -166,7 +166,7 @@ ThumbnailView::ThumbnailFacade* ThumbnailView::ThumbnailFacade::instance()
void ThumbnailView::ThumbnailFacade::slotRecreateThumbnail()
{
Q_FOREACH( const DB::Id& id, widget()->selection() ) {
Q_FOREACH( const DB::Id& id, widget()->selection( NoExpandCollapsedStacks ) ) {
const DB::ImageInfoPtr info = id.fetchInfo();
const QString fileName = info->fileName(DB::AbsolutePath);
ImageManager::ThumbnailCache::instance()->removeThumbnail( fileName );
......
......@@ -36,7 +36,7 @@ public:
QWidget* gui();
void setCurrentItem( const DB::Id& id );
void reload( SelectionUpdateMethod method );
DB::IdList selection() const;
DB::IdList selection( ThumbnailView::SelectionMode mode = ExpandCollapsedStacks ) const;
DB::IdList imageList(Order) const;
DB::Id mediaIdUnderCursor() const;
DB::Id currentItem() const;
......
......@@ -263,7 +263,7 @@ void ThumbnailView::ThumbnailWidget::reload(SelectionUpdateMethod method )
cellGeometryInfo()->flushCache();
updatePalette();
const DB::IdList selectedItems = selection();
const DB::IdList selectedItems = selection( NoExpandCollapsedStacks );
ThumbnailComponent::model()->reset();
if ( method == ClearSelection )
......@@ -338,7 +338,7 @@ int ThumbnailView::ThumbnailWidget::cellWidth() const
void ThumbnailView::ThumbnailWidget::emitSelectionChangedSignal()
{
emit selectionCountChanged( selectionModel()->selectedIndexes().count() );
emit selectionCountChanged( selection( ExpandCollapsedStacks ).size() );
}
void ThumbnailView::ThumbnailWidget::scheduleDateChangeSignal()
......@@ -365,18 +365,40 @@ void ThumbnailView::ThumbnailWidget::showEvent( QShowEvent* event )
QListView::showEvent( event );
}
DB::IdList ThumbnailView::ThumbnailWidget::selection() const
DB::IdList ThumbnailView::ThumbnailWidget::selection( ThumbnailView::SelectionMode mode ) const
{
DB::IdList res;
Q_FOREACH(const QModelIndex& index, selectedIndexes()) {
res.append(model()->imageAt( index.row() ));
DB::Id currId = model()->imageAt( index.row() );
switch ( mode )
{
case ExpandCollapsedStacks:
{
// if the selected image belongs to a collapsed thread,
// imply that all images in the stack are selected:
DB::ImageInfoPtr imageInfo = currId.fetchInfo();
if ( imageInfo && imageInfo->isStacked()
&& ! model()->isItemInExpandedStack( imageInfo->stackId() ) )
{
// add all images in the same stack
DB::IdList stack = DB::ImageDB::instance()->getStackFor( currId );
Q_FOREACH( const DB::Id & id, stack )
res.append(id);
} else
res.append(currId);
}
break;
case NoExpandCollapsedStacks:
res.append(currId);
break;
}
}
return res;
}
bool ThumbnailView::ThumbnailWidget::isSelected( const DB::Id& id ) const
{
return selectedIndexes().contains( model()->idToIndex(id) );
return selection( NoExpandCollapsedStacks ).indexOf( id ) != -1;
}
/**
......@@ -386,7 +408,7 @@ bool ThumbnailView::ThumbnailWidget::isSelected( const DB::Id& id ) const
*/
void ThumbnailView::ThumbnailWidget::changeSingleSelection(const DB::Id& id)
{
if ( selection().size() == 1 ) {
if ( selection( NoExpandCollapsedStacks ).size() == 1 ) {
QItemSelectionModel* selection = selectionModel();
selection->select( model()->idToIndex(id), QItemSelectionModel::ClearAndSelect );
setCurrentItem( id );
......@@ -399,3 +421,4 @@ void ThumbnailView::ThumbnailWidget::select(const DB::IdList& items )
selectionModel()->select(model()->idToIndex(id), QItemSelectionModel::Select );
}
// vi:expandtab:tabstop=4 shiftwidth=4:
......@@ -59,7 +59,7 @@ public:
// Misc
int cellWidth() const;
OVERRIDE void showEvent( QShowEvent* );
DB::IdList selection() const;
DB::IdList selection( ThumbnailView::SelectionMode mode ) const;
bool isSelected( const DB::Id& id ) const;
void select( const DB::IdList& );
......
......@@ -30,6 +30,7 @@ enum VisibleState { FullyVisible, PartlyVisible };
typedef QSet<DB::Id> IdSet;
enum SelectionUpdateMethod { ClearSelection, MaintainSelection };
enum SelectionMode { NoExpandCollapsedStacks, ExpandCollapsedStacks };
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment