Skip to content

Commit c59efe4

Browse files
author
Simon Vetter
committed
Immediately change to next photo when slideshow is started manually
1 parent f1622c7 commit c59efe4

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

src/viewer/ascent_viewer.cpp

+46-34
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void AscentViewer::connectUI()
169169
connect(nextPhotoButton, &QToolButton::clicked, this, &AscentViewer::handle_nextPhoto);
170170
connect(lastPhotoButton, &QToolButton::clicked, this, &AscentViewer::handle_lastPhoto);
171171
// Slideshow
172-
connect(slideshowStartStopButton, &QToolButton::clicked, this, &AscentViewer::handle_startStopSlideshow);
172+
connect(slideshowStartStopButton, &QToolButton::clicked, this, &AscentViewer::handle_toggleSlideshow);
173173
connect(slideshowIntervalSpinner, &QSpinBox::valueChanged, this, &AscentViewer::handle_slideshowIntervalChanged);
174174
// Changing photos
175175
connect(movePhotoLeftButton, &QToolButton::clicked, this, &AscentViewer::handle_movePhotoLeft);
@@ -251,7 +251,7 @@ void AscentViewer::setupSlideshow()
251251
*/
252252
void AscentViewer::changeToAscent(ViewRowIndex viewRowIndex)
253253
{
254-
stopSlideshowIfRunning();
254+
stopSlideshow();
255255

256256
saveDescription();
257257
savePhotoDescription();
@@ -270,7 +270,7 @@ void AscentViewer::changeToAscent(ViewRowIndex viewRowIndex)
270270
updateAscentNavigationNumbers();
271271

272272
if (slideshowAutostartCheckbox->isChecked() && photos.size() > 1) {
273-
handle_startStopSlideshow();
273+
handle_startSlideshow(false);
274274
}
275275
}
276276

@@ -670,15 +670,6 @@ void AscentViewer::restartSlideshowTimerIfRunning()
670670
slideshowTimer.start(slideshowIntervalSpinner->value() * 1000);
671671
}
672672

673-
/**
674-
* Stops the slideshow if it is running, else does nothing.
675-
*/
676-
void AscentViewer::stopSlideshowIfRunning()
677-
{
678-
if (!slideshowRunning) return;
679-
handle_startStopSlideshow();
680-
}
681-
682673

683674

684675
// EDITING PHOTOS
@@ -952,33 +943,54 @@ void AscentViewer::handle_lastPhoto()
952943
// SLIDESHOW
953944

954945
/**
955-
* Starts or stops the slideshow.
946+
* Starts the slideshow unless it is already running.
947+
*
948+
* Disables editing of the photo description, changes the slideshow button icon and starts the timer.
956949
*
957-
* Disabled editing of the photo description, changes the slideshow button icon and starts or stops
958-
* the timer.
950+
* @param nextPhotoImmediately Whether to change to the next photo immediately, skipping the first waiting interval.
959951
*/
960-
void AscentViewer::handle_startStopSlideshow()
952+
void AscentViewer::handle_startSlideshow(bool nextPhotoImmediately)
961953
{
954+
if (slideshowRunning) return;
955+
962956
if (photoDescriptionEditable) {
963957
editPhotoDescriptionButton->setChecked(false);
964958
handle_photoDescriptionEditableChanged();
965959
}
966960

967-
QStyle::StandardPixmap newIcon;
961+
slideshowTimer.start(slideshowIntervalSpinner->value() * 1000);
962+
slideshowStartStopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
963+
slideshowRunning = true;
968964

969-
if (!slideshowRunning) {
970-
// Slideshow not running, START
971-
slideshowTimer.start(slideshowIntervalSpinner->value() * 1000);
972-
newIcon = QStyle::SP_MediaStop;
973-
}
974-
else {
975-
// Slideshow running, STOP
976-
slideshowTimer.stop();
977-
newIcon = QStyle::SP_MediaPlay;
978-
}
965+
if (nextPhotoImmediately) handle_slideshowTimerTrigger();
966+
}
967+
968+
/**
969+
* Stops the slideshow if it is running.
970+
*
971+
* Changes the slideshow button icon and stops the timer.
972+
*/
973+
void AscentViewer::handle_stopSlideshow()
974+
{
975+
if (!slideshowRunning) return;
979976

980-
slideshowStartStopButton->setIcon(style()->standardIcon(newIcon));
981-
slideshowRunning = !slideshowRunning;
977+
slideshowTimer.stop();
978+
slideshowStartStopButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
979+
slideshowRunning = false;
980+
}
981+
982+
/**
983+
* Starts the slideshow if it is not running and stops it otherwise.
984+
*
985+
* @param nextPhotoImmediately Whether to change to the next photo immediately when starting the slideshow.
986+
*/
987+
void AscentViewer::handle_toggleSlideshow(bool nextPhotoImmediately)
988+
{
989+
if (slideshowRunning) {
990+
stopSlideshow();
991+
} else {
992+
startSlideshow(nextPhotoImmediately);
993+
}
982994
}
983995

984996
/**
@@ -1005,7 +1017,7 @@ void AscentViewer::handle_slideshowIntervalChanged()
10051017
*/
10061018
void AscentViewer::handle_userInteractedWithImageLabel()
10071019
{
1008-
stopSlideshowIfRunning();
1020+
stopSlideshow();
10091021
}
10101022

10111023

@@ -1034,7 +1046,7 @@ void AscentViewer::handle_movePhotoRight()
10341046
*/
10351047
void AscentViewer::handle_addPhotos()
10361048
{
1037-
stopSlideshowIfRunning();
1049+
stopSlideshow();
10381050
addPhotosFromDialog();
10391051
}
10401052

@@ -1051,7 +1063,7 @@ void AscentViewer::handle_removePhoto()
10511063
*/
10521064
void AscentViewer::handle_replacePhoto()
10531065
{
1054-
stopSlideshowIfRunning();
1066+
stopSlideshow();
10551067
replaceCurrentPhoto();
10561068
}
10571069

@@ -1061,7 +1073,7 @@ void AscentViewer::handle_replacePhoto()
10611073
void AscentViewer::handle_relocatePhotos()
10621074
{
10631075
savePhotoDescription();
1064-
stopSlideshowIfRunning();
1076+
stopSlideshow();
10651077
RelocatePhotosDialog(this, db).exec();
10661078
loadPhotosList();
10671079
changeToPhoto(currentPhotoIndex, false);
@@ -1120,7 +1132,7 @@ void AscentViewer::handle_photoDescriptionEditableChanged()
11201132
} else {
11211133
photoDescriptionLineEdit->setText(photoDescriptionLabel->text());
11221134

1123-
stopSlideshowIfRunning();
1135+
stopSlideshow();
11241136
}
11251137

11261138
photoDescriptionEditable = editPhotoDescriptionButton->isChecked();

src/viewer/ascent_viewer.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ private slots:
171171
void handle_nextPhoto();
172172
void handle_lastPhoto();
173173
// Slideshow
174-
void handle_startStopSlideshow();
174+
void handle_startSlideshow(bool nextPhotoImmediately);
175+
void handle_stopSlideshow();
176+
void handle_toggleSlideshow(bool nextPhotoImmediately = true);
175177
void handle_slideshowTimerTrigger();
176178
void handle_slideshowIntervalChanged();
177179
void handle_userInteractedWithImageLabel();

0 commit comments

Comments
 (0)