From d9c93e77ae9a29aedaf4ccd145eae97059e22d0a Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Fri, 19 Jul 2019 23:45:02 +0200 Subject: [PATCH] filecatalog/filebrowser: further optimizations --- rtgui/batchqueueentry.cc | 6 +-- rtgui/batchqueueentry.h | 6 +-- rtgui/filebrowserentry.cc | 47 ++++++++---------- rtgui/filebrowserentry.h | 6 +-- rtgui/filecatalog.cc | 11 ++--- rtgui/inspector.h | 2 +- rtgui/rtimage.cc | 3 +- rtgui/thumbbrowserentrybase.cc | 34 +++++-------- rtgui/thumbbrowserentrybase.h | 90 ++++++++++++++++------------------ 9 files changed, 89 insertions(+), 116 deletions(-) diff --git a/rtgui/batchqueueentry.cc b/rtgui/batchqueueentry.cc index d52fe4305..a5dfb6dde 100644 --- a/rtgui/batchqueueentry.cc +++ b/rtgui/batchqueueentry.cc @@ -148,7 +148,7 @@ void BatchQueueEntry::removeButtonSet () buttonSet = nullptr; } -std::vector > BatchQueueEntry::getIconsOnImageArea () +std::vector> BatchQueueEntry::getIconsOnImageArea () { std::vector > ret; @@ -160,7 +160,7 @@ std::vector > BatchQueueEntry::getIconsOnImageArea () return ret; } -void BatchQueueEntry::getIconSize (int& w, int& h) +void BatchQueueEntry::getIconSize (int& w, int& h) const { w = savedAsIcon->get_width (); @@ -168,7 +168,7 @@ void BatchQueueEntry::getIconSize (int& w, int& h) } -Glib::ustring BatchQueueEntry::getToolTip (int x, int y) +Glib::ustring BatchQueueEntry::getToolTip (int x, int y) const { // get the parent class' tooltip first Glib::ustring tooltip = ThumbBrowserEntryBase::getToolTip(x, y); diff --git a/rtgui/batchqueueentry.h b/rtgui/batchqueueentry.h index f3e8c1336..d13dfe827 100644 --- a/rtgui/batchqueueentry.h +++ b/rtgui/batchqueueentry.h @@ -68,9 +68,9 @@ public: void removeButtonSet (); - std::vector > getIconsOnImageArea () override; - void getIconSize (int& w, int& h) override; - Glib::ustring getToolTip (int x, int y) override; + std::vector> getIconsOnImageArea () override; + void getIconSize (int& w, int& h) const override; + Glib::ustring getToolTip (int x, int y) const override; // bqentryupdatelistener interface void updateImage (guint8* img, int w, int h, int origw, int origh, guint8* newOPreview) override; diff --git a/rtgui/filebrowserentry.cc b/rtgui/filebrowserentry.cc index 0fa5694de..4b1764824 100644 --- a/rtgui/filebrowserentry.cc +++ b/rtgui/filebrowserentry.cc @@ -119,39 +119,37 @@ void FileBrowserEntry::calcThumbnailSize () } } -std::vector > FileBrowserEntry::getIconsOnImageArea () +std::vector> FileBrowserEntry::getIconsOnImageArea () { - - std::vector > ret; - if (!thumbnail) { - return ret; + return {}; } + std::vector> ret; + if (thumbnail->hasProcParams() && editedIcon) { - ret.push_back (editedIcon); + ret.push_back(editedIcon); } if (thumbnail->isRecentlySaved() && recentlySavedIcon) { - ret.push_back (recentlySavedIcon); + ret.push_back(recentlySavedIcon); } if (thumbnail->isEnqueued () && enqueuedIcon) { - ret.push_back (enqueuedIcon); + ret.push_back(enqueuedIcon); } return ret; } -std::vector > FileBrowserEntry::getSpecificityIconsOnImageArea () +std::vector> FileBrowserEntry::getSpecificityIconsOnImageArea () { - - std::vector > ret; - if (!thumbnail) { - return ret; + return {}; } + std::vector> ret; + if (thumbnail->isHDR() && hdr) { ret.push_back (hdr); } @@ -188,7 +186,7 @@ void FileBrowserEntry::customBackBufferUpdate (Cairo::RefPtr c) } } -void FileBrowserEntry::getIconSize (int& w, int& h) +void FileBrowserEntry::getIconSize (int& w, int& h) const { w = editedIcon->get_width (); @@ -286,34 +284,29 @@ void FileBrowserEntry::_updateImage(rtengine::IImage8* img, double s, const rten bool FileBrowserEntry::motionNotify (int x, int y) { - bool b = ThumbBrowserEntryBase::motionNotify (x, y); + const bool b = ThumbBrowserEntryBase::motionNotify(x, y); - int ix = x - startx - ofsX; - int iy = y - starty - ofsY; + const int ix = x - startx - ofsX; + const int iy = y - starty - ofsY; Inspector* inspector = parent->getInspector(); if (inspector && inspector->isActive() && !parent->isInTabMode()) { - rtengine::Coord2D coord(-1., -1.); - getPosInImgSpace(x, y, coord); + const rtengine::Coord2D coord(getPosInImgSpace(x, y)); if (coord.x != -1.) { if (!wasInside) { inspector->switchImage(filename); + wasInside = true; } - - wasInside = true; inspector->mouseMove(coord, 0); } else { - if (wasInside) { - wasInside = false; - rtengine::Coord2D coord(-1, -1); - } + wasInside = false; } } - if (inside (x, y)) { - updateCursor (ix, iy); + if (inside(x, y)) { + updateCursor(ix, iy); } if (state == SRotateSelecting) { diff --git a/rtgui/filebrowserentry.h b/rtgui/filebrowserentry.h index 3a3d32977..5122de55f 100644 --- a/rtgui/filebrowserentry.h +++ b/rtgui/filebrowserentry.h @@ -93,9 +93,9 @@ public: void refreshQuickThumbnailImage () override; void calcThumbnailSize () override; - std::vector > getIconsOnImageArea () override; - std::vector > getSpecificityIconsOnImageArea () override; - void getIconSize (int& w, int& h) override; + std::vector> getIconsOnImageArea () override; + std::vector> getSpecificityIconsOnImageArea () override; + void getIconSize (int& w, int& h) const override; // thumbnaillistener interface void procParamsChanged (Thumbnail* thm, int whoChangedIt) override; diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 57555fd76..dbe540cb4 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -37,9 +37,6 @@ #include "batchqueue.h" #include "placesbrowser.h" -#define BENCHMARK -#include "../rtengine/StopWatch.h" - using namespace std; #define CHECKTIME 2000 @@ -568,7 +565,7 @@ void FileCatalog::closeDir () std::vector FileCatalog::getFileList() { - BENCHFUN + std::vector names; const std::set& extensions = options.parsedExtensionsSet; @@ -626,9 +623,9 @@ std::vector FileCatalog::getFileList() void FileCatalog::dirSelected (const Glib::ustring& dirname, const Glib::ustring& openfile) { -BENCHFUN + try { - Glib::RefPtr dir = Gio::File::create_for_path (dirname); + const Glib::RefPtr dir = Gio::File::create_for_path(dirname); if (!dir) { return; @@ -1681,7 +1678,7 @@ void FileCatalog::filterChanged () void FileCatalog::reparseDirectory () { -BENCHFUN + if (selectedDirectory.empty()) { return; } diff --git a/rtgui/inspector.h b/rtgui/inspector.h index d5ed327b8..86ad9114e 100644 --- a/rtgui/inspector.h +++ b/rtgui/inspector.h @@ -87,7 +87,7 @@ public: /** @brief Get the on/off state */ - bool isActive() + bool isActive() const { return active; }; diff --git a/rtgui/rtimage.cc b/rtgui/rtimage.cc index 6a289ead6..cd687f252 100644 --- a/rtgui/rtimage.cc +++ b/rtgui/rtimage.cc @@ -197,8 +197,7 @@ void RTImage::updateImages() Glib::RefPtr RTImage::createPixbufFromFile (const Glib::ustring& fileName) { Cairo::RefPtr imgSurf = createImgSurfFromFile(fileName); - Glib::RefPtr pixbuf = Gdk::Pixbuf::create(imgSurf, 0, 0, imgSurf->get_width(), imgSurf->get_height()); - return pixbuf; + return Gdk::Pixbuf::create(imgSurf, 0, 0, imgSurf->get_width(), imgSurf->get_height()); } Cairo::RefPtr RTImage::createImgSurfFromFile (const Glib::ustring& fileName) diff --git a/rtgui/thumbbrowserentrybase.cc b/rtgui/thumbbrowserentrybase.cc index ed34c65c7..2960ccf70 100644 --- a/rtgui/thumbbrowserentrybase.cc +++ b/rtgui/thumbbrowserentrybase.cc @@ -157,9 +157,6 @@ ThumbBrowserEntryBase::ThumbBrowserEntryBase (const Glib::ustring& fname) : collate_name(getPaddedName(dispname).casefold_collate_key()), thumbnail(nullptr), filename(fname), - shortname(dispname), - exifline(""), - datetimeline(""), selected(false), drawable(false), filtered(false), @@ -439,7 +436,6 @@ void ThumbBrowserEntryBase::getTextSizes (int& infow, int& infoh) Gtk::Widget* w = parent->getDrawingArea (); // calculate dimensions of the text based fields - dispname = shortname; Glib::RefPtr context = w->get_pango_context () ; context->set_font_description (w->get_style_context()->get_font()); @@ -449,7 +445,7 @@ void ThumbBrowserEntryBase::getTextSizes (int& infow, int& infoh) Pango::FontDescription fontd = context->get_font_description (); fontd.set_weight (Pango::WEIGHT_BOLD); context->set_font_description (fontd); - Glib::RefPtr fn = w->create_pango_layout(shortname); + Glib::RefPtr fn = w->create_pango_layout(dispname); fn->get_pixel_size (fnlabw, fnlabh); // calculate cummulated height of all info fields @@ -672,16 +668,15 @@ void ThumbBrowserEntryBase::setOffset (int x, int y) } } -bool ThumbBrowserEntryBase::inside (int x, int y) +bool ThumbBrowserEntryBase::inside (int x, int y) const { return x > ofsX + startx && x < ofsX + startx + exp_width && y > ofsY + starty && y < ofsY + starty + exp_height; } -void ThumbBrowserEntryBase::getPosInImgSpace (int x, int y, rtengine::Coord2D &coord) +rtengine::Coord2D ThumbBrowserEntryBase::getPosInImgSpace (int x, int y) const { - - coord.x = coord.y = -1.; + rtengine::Coord2D coord(-1., -1.); if (preview) { x -= ofsX + startx; @@ -692,15 +687,16 @@ void ThumbBrowserEntryBase::getPosInImgSpace (int x, int y, rtengine::Coord2D &c coord.y = double(y - prey) / double(preh); } } + return coord; } -bool ThumbBrowserEntryBase::insideWindow (int x, int y, int w, int h) +bool ThumbBrowserEntryBase::insideWindow (int x, int y, int w, int h) const { return !(ofsX + startx > x + w || ofsX + startx + exp_width < x || ofsY + starty > y + h || ofsY + starty + exp_height < y); } -std::vector > ThumbBrowserEntryBase::getIconsOnImageArea() +std::vector> ThumbBrowserEntryBase::getIconsOnImageArea() { return std::vector >(); } @@ -710,12 +706,6 @@ std::vector > ThumbBrowserEntryBase::getSpecificityIco return std::vector >(); } -void ThumbBrowserEntryBase::getIconSize(int& w, int& h) -{ - w = 0; - h = 0; -} - bool ThumbBrowserEntryBase::motionNotify (int x, int y) { @@ -734,12 +724,12 @@ bool ThumbBrowserEntryBase::releaseNotify (int button, int type, int bstate, int return buttonSet ? buttonSet->releaseNotify (x, y) : false; } -Glib::ustring ThumbBrowserEntryBase::getToolTip (int x, int y) +Glib::ustring ThumbBrowserEntryBase::getToolTip (int x, int y) const { - Glib::ustring tooltip = ""; + Glib::ustring tooltip; if (buttonSet) { - tooltip = buttonSet->getToolTip (x, y); + tooltip = buttonSet->getToolTip(x, y); } // Always show the filename in the tooltip since the filename in the thumbnail could be truncated. @@ -748,11 +738,11 @@ Glib::ustring ThumbBrowserEntryBase::getToolTip (int x, int y) tooltip = dispname; if (withFilename < WFNAME_FULL) { - if (options.fbShowDateTime && datetimeline != "") { + if (options.fbShowDateTime && !datetimeline.empty()) { tooltip += Glib::ustring("\n") + datetimeline; } - if (options.fbShowBasicExif && exifline != "") { + if (options.fbShowBasicExif && !exifline.empty()) { tooltip += Glib::ustring("\n") + exifline; } } diff --git a/rtgui/thumbbrowserentrybase.h b/rtgui/thumbbrowserentrybase.h index 8237b7c6b..12e64c60d 100644 --- a/rtgui/thumbbrowserentrybase.h +++ b/rtgui/thumbbrowserentrybase.h @@ -16,8 +16,7 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ -#ifndef _THUMBNAILBROWSERENTRYBASE_ -#define _THUMBNAILBROWSERENTRYBASE_ +#pragma once #include @@ -82,8 +81,8 @@ protected: Glib::RefPtr backBuffer; bool bbSelected, bbFramed; guint8* bbPreview; - std::vector > bbIcons; - std::vector > bbSpecificityIcons; + std::vector> bbIcons; + std::vector> bbSpecificityIcons; CursorShape cursor_type; void drawFrame (Cairo::RefPtr cr, const Gdk::RGBA& bg, const Gdk::RGBA& fg); @@ -101,7 +100,6 @@ public: // thumbnail preview properties: Glib::ustring filename; - Glib::ustring shortname; Glib::ustring exifline; Glib::ustring datetimeline; @@ -117,61 +115,61 @@ public: bool updatepriority; eWithFilename withFilename; - explicit ThumbBrowserEntryBase (const Glib::ustring& fname); - virtual ~ThumbBrowserEntryBase (); + explicit ThumbBrowserEntryBase (const Glib::ustring& fname); + virtual ~ThumbBrowserEntryBase (); void setParent (ThumbBrowserBase* l) { parent = l; } - void updateBackBuffer (); - void resize (int h); - virtual void draw (Cairo::RefPtr cc); + void updateBackBuffer (); + void resize (int h); + virtual void draw (Cairo::RefPtr cc); - void addButtonSet (LWButtonSet* bs); - int getMinimalHeight () + void addButtonSet (LWButtonSet* bs); + int getMinimalHeight () const { return height; } - int getMinimalWidth () + int getMinimalWidth () const { return width; } - int getEffectiveWidth () const + int getEffectiveWidth () const { return exp_width; } - int getEffectiveHeight () const + int getEffectiveHeight () const { return exp_height; } - int getPreviewHeight () const + int getPreviewHeight () const { return preh; } - int getStartX () const + int getStartX () const { return startx; } - int getStartY () const + int getStartY () const { return starty; } - int getX () const + int getX () const { return ofsX + startx; } - int getY () const + int getY () const { return ofsY + starty; } - bool inside (int x, int y); - void getPosInImgSpace (int x, int y, rtengine::Coord2D &coord); - bool insideWindow (int x, int y, int w, int h); - void setPosition (int x, int y, int w, int h); + bool inside (int x, int y) const; + rtengine::Coord2D getPosInImgSpace (int x, int y) const; + bool insideWindow (int x, int y, int w, int h) const; + void setPosition (int x, int y, int w, int h); void setOffset (int x, int y); bool operator <(const ThumbBrowserEntryBase& other) const @@ -179,33 +177,29 @@ public: return collate_name < other.collate_name; } - ThumbBrowserEntryBase* getOriginal () const; - void setOriginal (ThumbBrowserEntryBase* original); - - virtual void refreshThumbnailImage () {} + virtual void refreshThumbnailImage () = 0; virtual void refreshQuickThumbnailImage () {} - virtual void calcThumbnailSize () {} + virtual void calcThumbnailSize () = 0; virtual void drawProgressBar (Glib::RefPtr win, const Gdk::RGBA& foregr, const Gdk::RGBA& backgr, int x, int w, int y, int h) {} - virtual std::vector > getIconsOnImageArea (); - virtual std::vector > getSpecificityIconsOnImageArea (); - virtual void getIconSize (int& w, int& h); + virtual std::vector> getIconsOnImageArea (); + virtual std::vector> getSpecificityIconsOnImageArea (); + virtual void getIconSize (int& w, int& h) const = 0; + + virtual bool motionNotify (int x, int y); + virtual bool pressNotify (int button, int type, int bstate, int x, int y); + virtual bool releaseNotify (int button, int type, int bstate, int x, int y); + virtual Glib::ustring getToolTip (int x, int y) const; + + inline ThumbBrowserEntryBase* getOriginal() const + { + return original; + } + + inline void setOriginal(ThumbBrowserEntryBase* original) + { + this->original = original; + } - virtual bool motionNotify (int x, int y); - virtual bool pressNotify (int button, int type, int bstate, int x, int y); - virtual bool releaseNotify (int button, int type, int bstate, int x, int y); - virtual Glib::ustring getToolTip (int x, int y); }; - -inline ThumbBrowserEntryBase* ThumbBrowserEntryBase::getOriginal() const -{ - return original; -} - -inline void ThumbBrowserEntryBase::setOriginal(ThumbBrowserEntryBase* original) -{ - this->original = original; -} - -#endif