diff --git a/ImageViewBase.cpp b/ImageViewBase.cpp index dc69bdaf6..2918e3612 100644 --- a/ImageViewBase.cpp +++ b/ImageViewBase.cpp @@ -21,20 +21,19 @@ #include "PixmapRenderer.h" #include "BackgroundExecutor.h" #include "Dpm.h" -#include "Dpi.h" #include "ScopedIncDec.h" #include "imageproc/PolygonUtils.h" #include "imageproc/Transform.h" #include "OpenGLSupport.h" #include "ColorSchemeManager.h" #include "UnitsProvider.h" -#include "StatusBarPanel.h" +#include "Utils.h" +#include #include #include #include #include #include -#include #include #include #include @@ -595,8 +594,8 @@ void ImageViewBase::showEvent(QShowEvent* event) { QWidget::showEvent(event); if (auto* mainWindow = dynamic_cast(window())) { - if (auto* statusBarPanel = mainWindow->statusBar()->findChild()) { - statusBarPanel->setInfoProvider(&infoProvider()); + if (auto* infoObserver = Utils::castOrFindChild(mainWindow->statusBar())) { + infoObserver->setInfoProvider(&infoProvider()); } } } diff --git a/ImageViewInfoObserver.h b/ImageViewInfoObserver.h index 48f1d5614..67cebb1c5 100644 --- a/ImageViewInfoObserver.h +++ b/ImageViewInfoObserver.h @@ -6,6 +6,7 @@ #include #include +class ImageViewInfoProvider; class Dpi; class ImageViewInfoObserver { @@ -19,6 +20,9 @@ class ImageViewInfoObserver { virtual void updateDpi(const Dpi& dpi) = 0; virtual void clearImageViewInfo() = 0; + + virtual void setInfoProvider(ImageViewInfoProvider* infoProvider) { + } }; diff --git a/StatusBarPanel.h b/StatusBarPanel.h index deffa021e..f64d9866b 100644 --- a/StatusBarPanel.h +++ b/StatusBarPanel.h @@ -42,7 +42,7 @@ Q_OBJECT void updateUnits(Units) override; - void setInfoProvider(ImageViewInfoProvider* infoProvider); + void setInfoProvider(ImageViewInfoProvider* infoProvider) override; private: void mousePosChanged(); diff --git a/Utils.h b/Utils.h index 1d3475faf..b7f4b9b9e 100644 --- a/Utils.h +++ b/Utils.h @@ -104,11 +104,21 @@ Utils::mapSetValue(std::unordered_map& map, const K& ke template T Utils::castOrFindChild(QObject* object) { + if (object == nullptr) { + return nullptr; + } + if (auto result = dynamic_cast(object)) { return result; } else { - return object->findChild(); + for (QObject* child : object->children()) { + if (result = castOrFindChild(child)) { + return result; + } + } } + + return nullptr; } #endif // ifndef UTILS_H_