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; handled = true;


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


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


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


// Populate display for new slide // Populate display for new slide
ImagePtrK im = m_slides.GetCurrent().GetImageData(); ImagePtrK im = m_slides.GetCurrent().GetImageData();
@@ -657,14 +661,14 @@ void GallerySlideView::TransitionComplete()
/*! /*!
\brief Display the previous slide in the sequence \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 // Prohibit back-wrapping during slideshow: it will cause premature end
//: Cannot go back beyond first slide of slideshow //: Cannot go back beyond first slide of slideshow
SetStatus(tr("Start")); SetStatus(tr("Start"));


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


@@ -673,17 +677,21 @@ void GallerySlideView::ShowPrevSlide()
\brief Display the next slide in the sequence \brief Display the next slide in the sequence
\param useTransition if false, slide will be updated instantly \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 // 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)) && !gCoreContext->GetNumSetting("GalleryRepeat", false))
{ {
Stop(); // Don't stop due to jumping past end
//: Slideshow has reached last slide if (inc == 1)
SetStatus(tr("End")); {
Stop();
//: Slideshow has reached last slide
SetStatus(tr("End"));
}
} }
else if (m_view->Next()) else if (m_view->Next(inc))
ShowSlide(useTransition ? 1 : 0); ShowSlide(useTransition ? 1 : 0);
else else
{ {
@@ -50,8 +50,8 @@ public slots:
void ClearStatus(Slide &next); void ClearStatus(Slide &next);


private slots: private slots:
void ShowPrevSlide(); void ShowPrevSlide(int inc = 1);
void ShowNextSlide(bool useTransition = true); void ShowNextSlide(int inc = 1, bool useTransition = true);
void SlideAvailable(int count); void SlideAvailable(int count);
void TransitionComplete(); void TransitionComplete();
void ShowSlide(int direction = 0); 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. \brief Updates view with images that have been updated.
\param idList List of image ids 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 \brief Peeks at next image in view but does not advance iterator
view order on wrap, if necessary \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 \return ImageItem Next image or NULL if empty
*/ */
ImagePtrK FlatView::Next() ImagePtrK FlatView::Next(int inc)
{ {
if (m_sequence.isEmpty()) if (m_sequence.isEmpty())
return ImagePtrK(); return ImagePtrK();


// wrap at end // Preserve index as it may be reset when wrapping
if (m_active >= m_sequence.size() - 1) int next = m_active + inc;
{
if (m_order == kOrdered) // Regenerate unordered views when wrapping
m_active = -1; if (next >= m_sequence.size() && m_order != kOrdered && !LoadFromDb(m_parentId))
// Regenerate unordered views on every repeat // Images have disappeared
else if (!LoadFromDb(m_parentId)) return ImagePtrK();
// 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. \brief Decrements iterator and returns previous image. Wraps at start.
\return ImageItem Previous image or NULL if empty \return ImageItem Previous image or NULL if empty
*/ */
ImagePtrK FlatView::Prev() ImagePtrK FlatView::Prev(int inc)
{ {
if (m_sequence.isEmpty()) if (m_sequence.isEmpty())
return ImagePtrK(); return ImagePtrK();


if (m_active <= 0) // Wrap avoiding modulo of negative uncertainty
m_active = m_sequence.size(); 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; } int GetParentId() const { return m_parentId; }
ImageListK GetAllNodes() const; ImageListK GetAllNodes() const;
ImagePtrK GetSelected() const; ImagePtrK GetSelected() const;
ImagePtrK HasNext() const; ImagePtrK HasNext(int inc) const;
ImagePtrK HasPrev() const; ImagePtrK HasPrev(int inc) const;
ImagePtrK Next(); ImagePtrK Next(int inc);
ImagePtrK Prev(); ImagePtrK Prev(int inc);
QString GetPosition() const; QString GetPosition() const;
bool Select(int id, int fallback = 0); bool Select(int id, int fallback = 0);
virtual bool LoadFromDb(int parentId); virtual bool LoadFromDb(int parentId);

0 comments on commit c41c6e7

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