Skip to content

Commit 914be23

Browse files
committed
if multiple images are selected, limit only run the slidthe slideshow to those
closes #6
1 parent 84a11da commit 914be23

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

Phototonic.cpp

+45-18
Original file line numberDiff line numberDiff line change
@@ -2672,11 +2672,12 @@ void Phototonic::toggleSlideShow() {
26722672
}
26732673

26742674
if (Settings::layoutMode == ThumbViewWidget) {
2675-
QModelIndexList indexesList = thumbsViewer->selectionModel()->selectedIndexes();
2676-
if (indexesList.size() != 1) {
2675+
QModelIndexList selection = thumbsViewer->selectionModel()->selectedIndexes();
2676+
if (selection.size() < 2) {
26772677
loadImage(Phototonic::First);
26782678
} else {
2679-
thumbsViewer->setCurrentIndex(indexesList.first());
2679+
thumbsViewer->selectionModel()->setCurrentIndex(selection.first(), QItemSelectionModel::NoUpdate);
2680+
// thumbsViewer->setCurrentIndex(selection.first());
26802681
}
26812682

26822683
showViewer();
@@ -2715,29 +2716,55 @@ void Phototonic::slideShowHandler() {
27152716
return;
27162717
}
27172718

2718-
if (next > -1 && next < thumbsViewer->model()->rowCount() && last == thumbsViewer->currentIndex().row())
2719-
thumbsViewer->setCurrentIndex(next);
2719+
QModelIndexList selection = thumbsViewer->selectionModel()->selectedIndexes();
2720+
QStandardItemModel *thumbModel = static_cast<QStandardItemModel*>(thumbsViewer->model());
2721+
if (next > -1 && next < thumbModel->rowCount() && last == thumbsViewer->currentIndex().row()) {
2722+
if (selection.size() > 1) {
2723+
QModelIndex idx = thumbModel->indexFromItem(thumbModel->item(next));
2724+
if (idx.isValid())
2725+
thumbsViewer->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::NoUpdate);
2726+
} else {
2727+
thumbsViewer->setCurrentIndex(next);
2728+
}
2729+
}
27202730
last = thumbsViewer->currentIndex().row();
27212731

2722-
if (Settings::slideShowRandom) {
2723-
next = QRandomGenerator::global()->bounded(thumbsViewer->visibleThumbs());
2724-
if (thumbsViewer->visibleThumbs() != thumbsViewer->model()->rowCount()) {
2725-
// for the filtered case we've to figure the nth non-hidden thumb, naively picking some
2726-
// number and moving to the next visible will cause less than random results if a huge
2727-
// block is hidden because we'll often end at its adjacent indexes
2728-
int n = next;
2729-
for (next = 0; next < thumbsViewer->model()->rowCount(); ++next) {
2730-
if (!thumbsViewer->isRowHidden(next) && --n < 0)
2732+
if (selection.size() > 1) { // use only selected images
2733+
if (Settings::slideShowRandom) {
2734+
next = QRandomGenerator::global()->bounded(selection.size());
2735+
next = selection.at(next).row();
2736+
} else {
2737+
next = -1;
2738+
for (int i = 0; i < selection.size(); ++i) {
2739+
if (selection.at(i).row() == last) {
2740+
if (i < selection.size() - 1)
2741+
next = selection.at(i+1).row();
2742+
else if (Settings::wrapImageList)
2743+
next = selection.at(0).row();
27312744
break;
2745+
}
27322746
}
27332747
}
2734-
2735-
} else {
2736-
next = thumbsViewer->nextRow();
2748+
} else { // use all visible images
2749+
if (Settings::slideShowRandom) {
2750+
next = QRandomGenerator::global()->bounded(thumbsViewer->visibleThumbs());
2751+
if (thumbsViewer->visibleThumbs() != thumbsViewer->model()->rowCount()) {
2752+
// for the filtered case we've to figure the n-th non-hidden thumb, naively picking some
2753+
// number and moving to the next visible will cause less than random results if a huge
2754+
// block is hidden because we'll often end at its adjacent indexes
2755+
int n = next;
2756+
for (next = 0; next < thumbsViewer->model()->rowCount(); ++next) {
2757+
if (!thumbsViewer->isRowHidden(next) && --n < 0)
2758+
break;
2759+
}
2760+
}
2761+
} else {
2762+
next = thumbsViewer->nextRow();
2763+
}
27372764
}
27382765

27392766
if (next < 0)
2740-
next = Settings::wrapImageList ? 0 : -2;
2767+
next = Settings::wrapImageList ? -1 : -2;
27412768

27422769
if (next > -1 && next < thumbsViewer->model()->rowCount())
27432770
QTimer::singleShot(500, this, [=]() {imageViewer->preload(thumbsViewer->fullPathOf(next));});

0 commit comments

Comments
 (0)