Skip to content
Permalink
Browse files

Gallery: Add slideshow jump forward/back

Up/Down jumps forward/back 10 slides in slideshow view
  • Loading branch information...
dizygotheca committed Feb 3, 2016
1 parent 75a698e commit c41c6e715e481111fa05ff771bd4f5d8bfe1514d
@@ -147,9 +147,13 @@ bool GallerySlideView::keyPressEvent(QKeyEvent *event)
handled = true;

if (action == "LEFT")
ShowPrevSlide();
ShowPrevSlide(1);
else if (action == "RIGHT")
ShowNextSlide();
ShowNextSlide(1);
else if (action == "UP")
ShowPrevSlide(10);
else if (action == "DOWN")
ShowNextSlide(10);
else if (action == "INFO")
ShowInfo();
else if (action == "MENU")
@@ -421,7 +425,7 @@ void GallerySlideView::Stop()
void GallerySlideView::Play(bool useTransition)
{
// Start from next slide
ShowNextSlide(useTransition);
ShowNextSlide(1, useTransition);

m_playing = true;
if (!m_suspended)
@@ -620,7 +624,7 @@ void GallerySlideView::TransitionComplete()
return;

// Preload next slide, if any
m_slides.Preload(m_view->HasNext());
m_slides.Preload(m_view->HasNext(1));

// Populate display for new slide
ImagePtrK im = m_slides.GetCurrent().GetImageData();
@@ -657,14 +661,14 @@ void GallerySlideView::TransitionComplete()
/*!
\brief Display the previous slide in the sequence
*/
void GallerySlideView::ShowPrevSlide()
void GallerySlideView::ShowPrevSlide(int inc)
{
if (m_playing && m_view->HasPrev() == NULL)
if (m_playing && m_view->HasPrev(inc) == NULL)
// Prohibit back-wrapping during slideshow: it will cause premature end
//: Cannot go back beyond first slide of slideshow
SetStatus(tr("Start"));

else if (m_view->Prev())
else if (m_view->Prev(inc))
ShowSlide(-1);
}

@@ -673,17 +677,21 @@ void GallerySlideView::ShowPrevSlide()
\brief Display the next slide in the sequence
\param useTransition if false, slide will be updated instantly
*/
void GallerySlideView::ShowNextSlide(bool useTransition)
void GallerySlideView::ShowNextSlide(int inc, bool useTransition)
{
// Browsing always wraps; slideshows depend on repeat setting
if (m_playing && m_view->HasNext() == NULL
if (m_playing && m_view->HasNext(inc) == NULL
&& !gCoreContext->GetNumSetting("GalleryRepeat", false))
{
Stop();
//: Slideshow has reached last slide
SetStatus(tr("End"));
// Don't stop due to jumping past end
if (inc == 1)
{
Stop();
//: Slideshow has reached last slide
SetStatus(tr("End"));
}
}
else if (m_view->Next())
else if (m_view->Next(inc))
ShowSlide(useTransition ? 1 : 0);
else
{
@@ -50,8 +50,8 @@ public slots:
void ClearStatus(Slide &next);

private slots:
void ShowPrevSlide();
void ShowNextSlide(bool useTransition = true);
void ShowPrevSlide(int inc = 1);
void ShowNextSlide(int inc = 1, bool useTransition = true);
void SlideAvailable(int count);
void TransitionComplete();
void ShowSlide(int direction = 0);
@@ -59,28 +59,6 @@ QString FlatView::GetPosition() const
}


/*!
\brief Peeks at next image in view but does not advance iterator
\return ImageItem The next image or NULL
*/
ImagePtrK FlatView::HasNext() const
{
return m_sequence.isEmpty() || m_active >= m_sequence.size() - 1
? ImagePtrK() : m_images.value(m_sequence.at(m_active + 1));
}


/*!
\brief Peeks at previous image in view but does not decrement iterator
\return ImageItem The previous image or NULL
*/
ImagePtrK FlatView::HasPrev() const
{
return m_sequence.isEmpty() || m_active <= 0
? ImagePtrK() : m_images.value(m_sequence.at(m_active - 1));
}


/*!
\brief Updates view with images that have been updated.
\param idList List of image ids that have been updated
@@ -148,43 +126,65 @@ void FlatView::Clear(bool resetParent)


/*!
\brief Advance iterator and return next image. Wraps at end and regenerates
view order on wrap, if necessary
\brief Peeks at next image in view but does not advance iterator
\return ImageItem The next image or NULL
*/
ImagePtrK FlatView::HasNext(int inc) const
{
return m_sequence.isEmpty() || m_active + inc >= m_sequence.size()
? ImagePtrK() : m_images.value(m_sequence.at(m_active + inc));
}


/*!
\brief Advance iterator and return next image, wrapping if necessary.
Regenerates unordered views on wrap.
\return ImageItem Next image or NULL if empty
*/
ImagePtrK FlatView::Next()
ImagePtrK FlatView::Next(int inc)
{
if (m_sequence.isEmpty())
return ImagePtrK();

// wrap at end
if (m_active >= m_sequence.size() - 1)
{
if (m_order == kOrdered)
m_active = -1;
// Regenerate unordered views on every repeat
else if (!LoadFromDb(m_parentId))
// Images have disappeared
return ImagePtrK();
}
// Preserve index as it may be reset when wrapping
int next = m_active + inc;

// Regenerate unordered views when wrapping
if (next >= m_sequence.size() && m_order != kOrdered && !LoadFromDb(m_parentId))
// Images have disappeared
return ImagePtrK();

m_active = next % m_sequence.size();
return m_images.value(m_sequence.at(m_active));
}

return m_images.value(m_sequence.at(++m_active));

/*!
\brief Peeks at previous image in view but does not decrement iterator
\return ImageItem The previous image or NULL
*/
ImagePtrK FlatView::HasPrev(int inc) const
{
return m_sequence.isEmpty() || m_active < inc
? ImagePtrK() : m_images.value(m_sequence.at(m_active - inc));
}


/*!
\brief Decrements iterator and returns previous image. Wraps at start.
\return ImageItem Previous image or NULL if empty
*/
ImagePtrK FlatView::Prev()
ImagePtrK FlatView::Prev(int inc)
{
if (m_sequence.isEmpty())
return ImagePtrK();

if (m_active <= 0)
m_active = m_sequence.size();
// Wrap avoiding modulo of negative uncertainty
m_active -= inc % m_sequence.size();
if (m_active < 0)
m_active += m_sequence.size();

return m_images.value(m_sequence.at(--m_active));
return m_images.value(m_sequence.at(m_active));
}


@@ -110,10 +110,10 @@ class FlatView
int GetParentId() const { return m_parentId; }
ImageListK GetAllNodes() const;
ImagePtrK GetSelected() const;
ImagePtrK HasNext() const;
ImagePtrK HasPrev() const;
ImagePtrK Next();
ImagePtrK Prev();
ImagePtrK HasNext(int inc) const;
ImagePtrK HasPrev(int inc) const;
ImagePtrK Next(int inc);
ImagePtrK Prev(int inc);
QString GetPosition() const;
bool Select(int id, int fallback = 0);
virtual bool LoadFromDb(int parentId);

0 comments on commit c41c6e7

Please sign in to comment.
You can’t perform that action at this time.