From d080bba351f3db0135fe7efa931af39a16aa0eec Mon Sep 17 00:00:00 2001 From: Morgan Hardwood Date: Mon, 18 Feb 2019 03:10:58 +0100 Subject: [PATCH 1/4] 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 From 2155cf76f0f6bf522a2544c45ffa430fe9a46f48 Mon Sep 17 00:00:00 2001 From: Morgan Hardwood Date: Sun, 10 Mar 2019 22:29:32 +0100 Subject: [PATCH 2/4] Refactored as suggested by Floessie #5183 --- rtgui/filebrowser.cc | 12 ++++-------- rtgui/filebrowser.h | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index 9f267be4e..53e6fa7f1 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -1779,9 +1779,7 @@ void FileBrowser::openNextImage() } // open the selected image - std::vector entries; - entries.push_back(thumb); - tbl->openRequested(entries); + tbl->openRequested({thumb}); return; } @@ -1844,9 +1842,7 @@ void FileBrowser::openPrevImage() } // open the selected image - std::vector entries; - entries.push_back(thumb); - tbl->openRequested(entries); + tbl->openRequested({thumb}); return; } @@ -1857,7 +1853,7 @@ void FileBrowser::openPrevImage() } } -void FileBrowser::selectImage(Glib::ustring fname) +void FileBrowser::selectImage(const Glib::ustring& fname) { MYWRITERLOCK(l, entryRW); @@ -1903,7 +1899,7 @@ void FileBrowser::selectImage(Glib::ustring fname) } } -void FileBrowser::openNextPreviousEditorImage (Glib::ustring fname, eRTNav nextPrevious) +void FileBrowser::openNextPreviousEditorImage (const Glib::ustring& fname, eRTNav nextPrevious) { // let FileBrowser acquire Editor's perspective diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index 44646ab17..484d414ae 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -183,12 +183,12 @@ public: void openNextImage(); void openPrevImage(); - void selectImage(Glib::ustring fname); + void selectImage(const Glib::ustring& fname); void copyProfile (); void pasteProfile (); void partPasteProfile (); - void openNextPreviousEditorImage (Glib::ustring fname, eRTNav eNextPrevious); + void openNextPreviousEditorImage(const Glib::ustring& fname, eRTNav eNextPrevious); #ifdef WIN32 void openDefaultViewer (int destination); From b29651c5f2afc95bb2a440d47be1ed2d96273962 Mon Sep 17 00:00:00 2001 From: Morgan Hardwood Date: Sun, 10 Mar 2019 23:26:17 +0100 Subject: [PATCH 3/4] Makes Next/Prev buttons work same as F3/F4 #5183 --- rtgui/filebrowser.cc | 9 ++++++--- rtgui/filebrowser.h | 2 +- rtgui/filecatalog.cc | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index 53e6fa7f1..c9dc638a1 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -1853,7 +1853,7 @@ void FileBrowser::openPrevImage() } } -void FileBrowser::selectImage(const Glib::ustring& fname) +void FileBrowser::selectImage(const Glib::ustring& fname, bool doScroll) { MYWRITERLOCK(l, entryRW); @@ -1891,7 +1891,10 @@ void FileBrowser::selectImage(const Glib::ustring& fname) MYWRITERLOCK_RELEASE(l); - setScrollPosition(x - (ww - tw) / 2, y); + if (doScroll) { + // Center thumb + setScrollPosition(x - (ww - tw) / 2, y); + } return; } @@ -1903,7 +1906,7 @@ void FileBrowser::openNextPreviousEditorImage (const Glib::ustring& fname, eRTNa { // let FileBrowser acquire Editor's perspective - selectImage (fname); + selectImage (fname, false); // now switch to the requested image if (nextPrevious == NAV_NEXT) { diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index 484d414ae..03c8b01e3 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -183,7 +183,7 @@ public: void openNextImage(); void openPrevImage(); - void selectImage(const Glib::ustring& fname); + void selectImage(const Glib::ustring& fname, bool doScroll); void copyProfile (); void pasteProfile (); diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 5ebac5e12..8605b53d1 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -829,7 +829,7 @@ void FileCatalog::previewsFinishedUI () filepanel->loadingThumbs(M("PROGRESSBAR_READY"), 0); if (!imageToSelect_fname.empty()) { - fileBrowser->selectImage(imageToSelect_fname); + fileBrowser->selectImage(imageToSelect_fname, true); imageToSelect_fname = ""; } @@ -2144,7 +2144,7 @@ void FileCatalog::selectImage (Glib::ustring fname, bool clearFilters) imageToSelect_fname = fname; } else { // FileCatalog::filterChanged ();//this will be replaced by queue_draw() in fileBrowser->selectImage - fileBrowser->selectImage(fname); + fileBrowser->selectImage(fname, true); imageToSelect_fname = ""; } } From df2c6b0bcbed41e4f3502532279629819fa9e370 Mon Sep 17 00:00:00 2001 From: Morgan Hardwood Date: Sun, 10 Mar 2019 23:49:28 +0100 Subject: [PATCH 4/4] Default to using defaults by default --- rtgui/filebrowser.h | 2 +- rtgui/filecatalog.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index 03c8b01e3..d579a48f4 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -183,7 +183,7 @@ public: void openNextImage(); void openPrevImage(); - void selectImage(const Glib::ustring& fname, bool doScroll); + void selectImage(const Glib::ustring& fname, bool doScroll = true); void copyProfile (); void pasteProfile (); diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 8605b53d1..5ebac5e12 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -829,7 +829,7 @@ void FileCatalog::previewsFinishedUI () filepanel->loadingThumbs(M("PROGRESSBAR_READY"), 0); if (!imageToSelect_fname.empty()) { - fileBrowser->selectImage(imageToSelect_fname, true); + fileBrowser->selectImage(imageToSelect_fname); imageToSelect_fname = ""; } @@ -2144,7 +2144,7 @@ void FileCatalog::selectImage (Glib::ustring fname, bool clearFilters) imageToSelect_fname = fname; } else { // FileCatalog::filterChanged ();//this will be replaced by queue_draw() in fileBrowser->selectImage - fileBrowser->selectImage(fname, true); + fileBrowser->selectImage(fname); imageToSelect_fname = ""; } }