From d080bba351f3db0135fe7efa931af39a16aa0eec Mon Sep 17 00:00:00 2001 From: Morgan Hardwood Date: Mon, 18 Feb 2019 03:10:58 +0100 Subject: [PATCH] Center selected thumb in Filmstrip #5174 When opening an image, selecting the next/previous image or syncing the Filmstrip, the newly selected thumbnail is centered, unless it lies within the visible area more than 1 thumbnails-width away from either edge, in which case centering does not occur. --- rtgui/editorpanel.cc | 8 ++-- rtgui/filebrowser.cc | 105 ++++++++++++++++++++++--------------------- rtgui/filebrowser.h | 7 +-- 3 files changed, 61 insertions(+), 59 deletions(-) diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 684d362b0..6e390cf42 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -1057,14 +1057,14 @@ void EditorPanel::open (Thumbnail* tmb, rtengine::InitialImage* isrc) } else { Gtk::Allocation alloc; iareapanel->imageArea->on_resized (alloc); + + // When passing a photo as an argument to the RawTherapee executable, the user wants + // this auto-loaded photo's thumbnail to be selected and visible in the Filmstrip. + EditorPanel::syncFileBrowser(); } history->resetSnapShotNumber(); navigator->setInvalid(ipc->getFullWidth(),ipc->getFullHeight()); - - // When passing a photo as an argument to the RawTherapee executable, the user wants - // this auto-loaded photo's thumbnail to be selected and visible in the Filmstrip. - EditorPanel::syncFileBrowser(); } void EditorPanel::close () diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index d489bb1d3..9f267be4e 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -1727,62 +1727,62 @@ void FileBrowser::buttonPressed (LWButton* button, int actionCode, void* actionD } } -void FileBrowser::openNextImage () +void FileBrowser::openNextImage() { MYWRITERLOCK(l, entryRW); if (!fd.empty() && selected.size() > 0 && !options.tabbedUI) { - for (size_t i = 0; i < fd.size() - 1; i++) { if (selected[0]->thumbnail->getFileName() == fd[i]->filename) { // located 1-st image in current selection if (i < fd.size() && tbl) { // find the first not-filtered-out (next) image for (size_t k = i + 1; k < fd.size(); k++) { if (!fd[k]->filtered/*checkFilter (fd[k])*/) { + // clear current selection for (size_t j = 0; j < selected.size(); j++) { selected[j]->selected = false; } - selected.clear (); + selected.clear(); // set new selection fd[k]->selected = true; - selected.push_back (fd[k]); - //queue_draw (); + selected.push_back(fd[k]); + //queue_draw(); MYWRITERLOCK_RELEASE(l); // this will require a read access - notifySelectionListener (); + notifySelectionListener(); MYWRITERLOCK_ACQUIRE(l); - // scroll to the selected position - double h1, v1; - getScrollPosition(h1, v1); + // scroll to the selected position, centered horizontally in the container + double x1, y1; + getScrollPosition(x1, y1); - double h2 = selected[0]->getStartX(); - double v2 = selected[0]->getStartY(); + double x2 = selected[0]->getStartX(); + double y2 = selected[0]->getStartY(); Thumbnail* thumb = (static_cast(fd[k]))->thumbnail; - int minWidth = get_width() - fd[k]->getMinimalWidth(); + int tw = fd[k]->getMinimalWidth(); // thumb width + + int ww = get_width(); // window width MYWRITERLOCK_RELEASE(l); // scroll only when selected[0] is outside of the displayed bounds - if (h2 + minWidth - h1 > get_width()) { - setScrollPosition(h2 - minWidth, v2); - } - - if (h1 > h2) { - setScrollPosition(h2, v2); + // or less than a thumbnail's width from either edge. + if ((x2 > x1 + ww - 2 * tw) || (x2 - tw < x1)) { + setScrollPosition(x2 - (ww - tw) / 2, y2); } // open the selected image std::vector entries; - entries.push_back (thumb); - tbl->openRequested (entries); + entries.push_back(thumb); + tbl->openRequested(entries); + return; } } @@ -1792,62 +1792,62 @@ void FileBrowser::openNextImage () } } -void FileBrowser::openPrevImage () +void FileBrowser::openPrevImage() { MYWRITERLOCK(l, entryRW); if (!fd.empty() && selected.size() > 0 && !options.tabbedUI) { - for (size_t i = 1; i < fd.size(); i++) { if (selected[0]->thumbnail->getFileName() == fd[i]->filename) { // located 1-st image in current selection if (i > 0 && tbl) { // find the first not-filtered-out (previous) image for (ssize_t k = (ssize_t)i - 1; k >= 0; k--) { if (!fd[k]->filtered/*checkFilter (fd[k])*/) { + // clear current selection for (size_t j = 0; j < selected.size(); j++) { selected[j]->selected = false; } - selected.clear (); + selected.clear(); // set new selection fd[k]->selected = true; - selected.push_back (fd[k]); - //queue_draw (); + selected.push_back(fd[k]); + //queue_draw(); MYWRITERLOCK_RELEASE(l); // this will require a read access - notifySelectionListener (); + notifySelectionListener(); MYWRITERLOCK_ACQUIRE(l); - // scroll to the selected position - double h1, v1; - getScrollPosition(h1, v1); + // scroll to the selected position, centered horizontally in the container + double x1, y1; + getScrollPosition(x1, y1); - double h2 = selected[0]->getStartX(); - double v2 = selected[0]->getStartY(); + double x2 = selected[0]->getStartX(); + double y2 = selected[0]->getStartY(); Thumbnail* thumb = (static_cast(fd[k]))->thumbnail; - int minWidth = get_width() - fd[k]->getMinimalWidth(); + int tw = fd[k]->getMinimalWidth(); // thumb width + + int ww = get_width(); // window width MYWRITERLOCK_RELEASE(l); // scroll only when selected[0] is outside of the displayed bounds - if (h2 + minWidth - h1 > get_width()) { - setScrollPosition(h2 - minWidth, v2); - } - - if (h1 > h2) { - setScrollPosition(h2, v2); + // or less than a thumbnail's width from either edge. + if ((x2 > x1 + ww - 2 * tw) || (x2 - tw < x1)) { + setScrollPosition(x2 - (ww - tw) / 2, y2); } // open the selected image std::vector entries; - entries.push_back (thumb); - tbl->openRequested (entries); + entries.push_back(thumb); + tbl->openRequested(entries); + return; } } @@ -1857,11 +1857,8 @@ void FileBrowser::openPrevImage () } } - -void FileBrowser::selectImage (Glib::ustring fname) +void FileBrowser::selectImage(Glib::ustring fname) { - - // need to clear the filter in filecatalog MYWRITERLOCK(l, entryRW); if (!fd.empty() && !options.tabbedUI) { @@ -1874,27 +1871,31 @@ void FileBrowser::selectImage (Glib::ustring fname) selected[j]->selected = false; } - selected.clear (); + selected.clear(); // set new selection fd[i]->selected = true; - selected.push_back (fd[i]); - queue_draw (); + selected.push_back(fd[i]); + queue_draw(); MYWRITERLOCK_RELEASE(l); // this will require a read access - notifySelectionListener (); + notifySelectionListener(); MYWRITERLOCK_ACQUIRE(l); - // scroll to the selected position - double h = selected[0]->getStartX(); - double v = selected[0]->getStartY(); + // scroll to the selected position, centered horizontally in the container + double x = selected[0]->getStartX(); + double y = selected[0]->getStartY(); + + int tw = fd[i]->getMinimalWidth(); // thumb width + + int ww = get_width(); // window width MYWRITERLOCK_RELEASE(l); - setScrollPosition(h, v); + setScrollPosition(x - (ww - tw) / 2, y); return; } diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index f876872eb..44646ab17 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -181,12 +181,13 @@ public: return tbl ? tbl->isInTabMode() : false; } - void openNextImage (); - void openPrevImage (); + void openNextImage(); + void openPrevImage(); + void selectImage(Glib::ustring fname); + void copyProfile (); void pasteProfile (); void partPasteProfile (); - void selectImage (Glib::ustring fname); void openNextPreviousEditorImage (Glib::ustring fname, eRTNav eNextPrevious); #ifdef WIN32