From c792facb7322f2e5918c83913c534f6fdaf98908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Fri, 7 Jul 2017 20:26:10 +0200 Subject: [PATCH 1/3] Fix filtered horizontal thumbs Take two images, the first in portrait, the second in landscape orientation. Mark the second with a red dot and filter for red. Now open that image in SETM. The top tumb is too slim. --- rtgui/thumbbrowserbase.cc | 54 +++++++++++++++------------------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index 531ed8c25..e8363f774 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -523,63 +523,49 @@ void ThumbBrowserBase::arrangeFiles () // We could lock it one more time, there's no harm excepted (negligible) speed penalty //GThreadLock lock; - int N = fd.size (); - - // apply filter - for (int i = 0; i < N; i++) { - fd[i]->filtered = !checkFilter (fd[i]); - } + const int N = fd.size(); int rowHeight = 0; - // compute size of the items - for (int i = 0; i < N; i++) + for (int i = 0; i < N; i++) { + // apply filter + fd[i]->filtered = !checkFilter (fd[i]); + + // compute size of the items if (!fd[i]->filtered && fd[i]->getMinimalHeight() > rowHeight) { rowHeight = fd[i]->getMinimalHeight (); } + } if (arrangement == TB_Horizontal) { numOfCols = 1; - int numOfRows = 1; -// if (rowHeight>0) { -// numOfRows = (internal.get_height()+rowHeight/2)/rowHeight; -// if (numOfRows<1) -// numOfRows = 1; -// } int ct = 0; int currx = 0; while (ct < N) { - // find widest item in the column - int maxw = 0; - - for (int i = 0; ct + i < N && i < numOfRows; i++) - if (fd[ct + i]->getMinimalWidth() > maxw) { - maxw = fd[ct + i]->getMinimalWidth (); - } - // arrange items in the column int curry = 0; - for (int i = 0; ct < N && i < numOfRows; i++, ct++) { - while (ct < N && fd[ct]->filtered) { - fd[ct++]->drawable = false; - } - - if (ct < N) { - fd[ct]->setPosition (currx, curry, maxw, rowHeight); - fd[ct]->drawable = true; - curry += rowHeight; - } + while (ct < N && fd[ct]->filtered) { + fd[ct++]->drawable = false; } - currx += maxw; + if (ct < N) { + const int maxw = fd[ct]->getMinimalWidth(); + + fd[ct]->setPosition(currx, curry, maxw, rowHeight); + fd[ct]->drawable = true; + currx += maxw; + curry += rowHeight; + + ++ct; + } } MYREADERLOCK_RELEASE(l); // This will require a Writer access - resizeThumbnailArea (currx, numOfRows * rowHeight); + resizeThumbnailArea (currx, rowHeight); } else { int availWidth = internal.get_width(); // initial number of columns From 30ef9092c45763cdf5836fadbd5259a8e0bcbe53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Fri, 7 Jul 2017 20:51:07 +0200 Subject: [PATCH 2/3] Additional cleanups for `ThumbBrowserBase::arrangeFiles()` --- rtgui/thumbbrowserbase.cc | 71 +++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index e8363f774..5983f1c3a 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -14,13 +14,16 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ -#include -#include "../rtengine/rt_math.h" +#include + +#include -#include "thumbbrowserbase.h" #include "multilangmgr.h" #include "options.h" +#include "thumbbrowserbase.h" + #include "../rtengine/mytime.h" +#include "../rtengine/rt_math.h" using namespace std; @@ -515,7 +518,7 @@ void ThumbBrowserBase::configScrollBars () } } -void ThumbBrowserBase::arrangeFiles () +void ThumbBrowserBase::arrangeFiles() { MYREADERLOCK(l, entryRW); @@ -523,11 +526,9 @@ void ThumbBrowserBase::arrangeFiles () // We could lock it one more time, there's no harm excepted (negligible) speed penalty //GThreadLock lock; - const int N = fd.size(); - int rowHeight = 0; - for (int i = 0; i < N; i++) { + for (unsigned int i = 0; i < fd.size(); i++) { // apply filter fd[i]->filtered = !checkFilter (fd[i]); @@ -540,43 +541,42 @@ void ThumbBrowserBase::arrangeFiles () if (arrangement == TB_Horizontal) { numOfCols = 1; - int ct = 0; int currx = 0; - while (ct < N) { + for (unsigned int ct = 0; ct < fd.size(); ++ct) { // arrange items in the column int curry = 0; - while (ct < N && fd[ct]->filtered) { - fd[ct++]->drawable = false; + for (; ct < fd.size() && fd[ct]->filtered; ++ct) { + fd[ct]->drawable = false; } - if (ct < N) { + if (ct < fd.size()) { const int maxw = fd[ct]->getMinimalWidth(); fd[ct]->setPosition(currx, curry, maxw, rowHeight); fd[ct]->drawable = true; currx += maxw; curry += rowHeight; - - ++ct; } } MYREADERLOCK_RELEASE(l); // This will require a Writer access - resizeThumbnailArea (currx, rowHeight); + resizeThumbnailArea(currx, rowHeight); } else { - int availWidth = internal.get_width(); + const int availWidth = internal.get_width(); + // initial number of columns numOfCols = 0; int colsWidth = 0; - for (int i = 0; i < N; i++) + for (unsigned int i = 0; i < fd.size(); ++i) { if (!fd[i]->filtered && colsWidth + fd[i]->getMinimalWidth() <= availWidth) { - colsWidth += fd[numOfCols]->getMinimalWidth (); - numOfCols++; + colsWidth += fd[numOfCols]->getMinimalWidth(); + ++numOfCols; } + } if (numOfCols < 1) { numOfCols = 1; @@ -584,30 +584,22 @@ void ThumbBrowserBase::arrangeFiles () std::vector colWidths; - for (; numOfCols > 0; numOfCols--) { + for (; numOfCols > 0; --numOfCols) { // compute column widths - colWidths.resize (numOfCols); + colWidths.assign(numOfCols, 0); - for (int i = 0; i < numOfCols; i++) { - colWidths[i] = 0; - } - - for (int i = 0, j = 0; i < N; i++) { + for (unsigned int i = 0, j = 0; i < fd.size(); ++i) { if (!fd[i]->filtered && fd[i]->getMinimalWidth() > colWidths[j % numOfCols]) { - colWidths[j % numOfCols] = fd[i]->getMinimalWidth (); + colWidths[j % numOfCols] = fd[i]->getMinimalWidth(); } if (!fd[i]->filtered) { - j++; + ++j; } } // if not wider than the space available, arrange it and we are ready - colsWidth = 0; - - for (int i = 0; i < numOfCols; i++) { - colsWidth += colWidths[i]; - } + colsWidth = std::accumulate(colWidths.begin(), colWidths.end(), 0); if (numOfCols == 1 || colsWidth < availWidth) { break; @@ -615,20 +607,19 @@ void ThumbBrowserBase::arrangeFiles () } // arrange files - int ct = 0; int curry = 0; - while (ct < N) { + for (unsigned int ct = 0; ct < fd.size();) { // arrange items in the row int currx = 0; - for (int i = 0; ct < N && i < numOfCols; i++, ct++) { - while (ct < N && fd[ct]->filtered) { - fd[ct++]->drawable = false; + for (int i = 0; ct < fd.size() && i < numOfCols; ++i, ++ct) { + for (; ct < fd.size() && fd[ct]->filtered; ++ct) { + fd[ct]->drawable = false; } - if (ct < N) { - fd[ct]->setPosition (currx, curry, colWidths[i % numOfCols], rowHeight); + if (ct < fd.size()) { + fd[ct]->setPosition(currx, curry, colWidths[i % numOfCols], rowHeight); fd[ct]->drawable = true; currx += colWidths[i % numOfCols]; } From 57adea62cc2e7b81a3c6cc6e32c6b4f534a37c63 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Fri, 7 Jul 2017 21:31:05 +0200 Subject: [PATCH 3/3] Small optimization in ThumbBrowserBase::arrangeFiles() --- rtgui/thumbbrowserbase.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index 5983f1c3a..abb8ec68d 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -575,6 +575,9 @@ void ThumbBrowserBase::arrangeFiles() if (!fd[i]->filtered && colsWidth + fd[i]->getMinimalWidth() <= availWidth) { colsWidth += fd[numOfCols]->getMinimalWidth(); ++numOfCols; + if(colsWidth > availWidth) { + break; + } } }