@@ -378,25 +378,20 @@ void AscentViewer::setupPhotos()
378
378
379
379
380
380
381
- void AscentViewer::changeToPhoto (int photoIndex)
381
+ void AscentViewer::changeToPhoto (int photoIndex, bool saveDescriptionFirst )
382
382
{
383
- savePhotoDescription ();
383
+ if (saveDescriptionFirst) {
384
+ savePhotoDescription ();
385
+ }
384
386
385
387
currentPhotoIndex = photoIndex;
386
- updatePhoto ();
387
- updatePhotoButtonsEnabled ();
388
- }
389
-
390
- void AscentViewer::updatePhoto ()
391
- {
388
+
392
389
photoDescriptionLabel ->setText (QString ());
393
390
photoDescriptionLineEdit->setText (QString ());
394
391
photoDescriptionLabel ->setVisible (false );
395
392
photoDescriptionLineEdit->setVisible (false );
396
393
imageLabel ->setToolTip (QString ());
397
394
398
- updatePhotoIndexLabel ();
399
-
400
395
if (currentPhotoIndex < 0 || photos.isEmpty ()) {
401
396
imageLabel->clearImage ();
402
397
return ;
@@ -418,21 +413,23 @@ void AscentViewer::updatePhoto()
418
413
QMessageBox::StandardButton result = QMessageBox::warning (this , title, message, buttons);
419
414
420
415
if (result == QMessageBox::Yes) {
421
- removeCurrentPhoto ();
422
- updatePhoto ();
416
+ removeCurrentPhoto (); // calls changeToPhoto() back, recursing until valid image is found or all photos removed
423
417
}
424
- return ;
425
418
}
426
-
427
- image = newImage;
428
- if (image.colorSpace ().isValid ()) image.convertToColorSpace (QColorSpace::SRgb);
429
- imageLabel->setImage (image);
419
+ else {
420
+ image = newImage;
421
+ if (image.colorSpace ().isValid ()) image.convertToColorSpace (QColorSpace::SRgb);
422
+ imageLabel->setImage (image);
423
+ }
430
424
431
425
photoDescriptionLabel ->setText (photos.at (currentPhotoIndex).description );
432
426
photoDescriptionLineEdit->setText (photos.at (currentPhotoIndex).description );
433
427
photoDescriptionLabel ->setVisible (!photoDescriptionEditable);
434
428
photoDescriptionLineEdit->setVisible (photoDescriptionEditable);
435
429
imageLabel ->setToolTip (filepath);
430
+
431
+ updatePhotoIndexLabel ();
432
+ updatePhotoButtonsEnabled ();
436
433
}
437
434
438
435
void AscentViewer::updatePhotoIndexLabel ()
@@ -481,26 +478,25 @@ void AscentViewer::addPhotos()
481
478
QStringList filepaths = openFileDialogForPhotosSelection (this );
482
479
if (filepaths.isEmpty ()) return ;
483
480
481
+ savePhotoDescription ();
482
+
484
483
if (currentPhotoIndex < 0 ) currentPhotoIndex = -1 ;
485
484
currentPhotoIndex++; // Set to index of first inserted photo
486
485
for (int i = 0 ; i < filepaths.size (); i++) {
487
486
photos.insert (currentPhotoIndex + i, Photo (currentAscentID, ItemID (), -1 , filepaths.at (i), QString ()));
488
487
}
489
-
490
488
savePhotosList ();
491
489
492
- updatePhoto ();
493
- updatePhotoButtonsEnabled ();
490
+ changeToPhoto (currentPhotoIndex);
494
491
}
495
492
496
493
void AscentViewer::removeCurrentPhoto ()
497
494
{
498
495
photos.removeAt (currentPhotoIndex);
499
496
savePhotosList ();
500
497
501
- if (currentPhotoIndex >= photos.size ()) currentPhotoIndex = photos.size () - 1 ;
502
- updatePhotoButtonsEnabled ();
503
- updatePhoto ();
498
+ int newPhotoIndex = std::min (currentPhotoIndex, (int ) photos.size () - 1 );
499
+ changeToPhoto (newPhotoIndex);
504
500
}
505
501
506
502
void AscentViewer::savePhotoDescription ()
@@ -589,22 +585,22 @@ void AscentViewer::handle_lastAscentOfPeak()
589
585
590
586
void AscentViewer::handle_firstPhoto ()
591
587
{
592
- changeToPhoto (0 );
588
+ changeToPhoto (0 , true );
593
589
}
594
590
595
591
void AscentViewer::handle_previousPhoto ()
596
592
{
597
- changeToPhoto (currentPhotoIndex - 1 );
593
+ changeToPhoto (currentPhotoIndex - 1 , true );
598
594
}
599
595
600
596
void AscentViewer::handle_nextPhoto ()
601
597
{
602
- changeToPhoto (currentPhotoIndex + 1 );
598
+ changeToPhoto (currentPhotoIndex + 1 , true );
603
599
}
604
600
605
601
void AscentViewer::handle_lastPhoto ()
606
602
{
607
- changeToPhoto (photos.size () - 1 );
603
+ changeToPhoto (photos.size () - 1 , true );
608
604
}
609
605
610
606
0 commit comments