From fc3306ea5569337db00bb559ae58a056efe3712e Mon Sep 17 00:00:00 2001 From: Uyanide Date: Mon, 1 Dec 2025 01:00:29 +0100 Subject: [PATCH] wip: fix: minor --- src/images_carousel.cpp | 48 ++++++++++++++++------------------------- src/images_carousel.h | 11 ++++++---- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/images_carousel.cpp b/src/images_carousel.cpp index 84a659a..5341179 100644 --- a/src/images_carousel.cpp +++ b/src/images_carousel.cpp @@ -1,7 +1,7 @@ /* * @Author: Uyanide pywang0608@foxmail.com * @Date: 2025-08-05 01:22:53 - * @LastEditTime: 2025-12-01 00:45:52 + * @LastEditTime: 2025-12-01 00:58:12 * @Description: Animated carousel widget for displaying and selecting images. */ #include "images_carousel.h" @@ -15,7 +15,9 @@ #include #include #include +#include #include +#include #include "logger.h" #include "ui_images_carousel.h" @@ -42,25 +44,11 @@ ImagesCarousel::ImagesCarousel(const Config::StyleConfigItems& styleConfig, // Remove border ui->scrollArea->setFrameShape(QFrame::NoFrame); - // Load initial images - connect(this, - &ImagesCarousel::loadingCompleted, - this, - &ImagesCarousel::_onInitImagesLoaded); - - // Also handle subsequent image loads connect(this, &ImagesCarousel::loadingCompleted, this, &ImagesCarousel::_onImagesLoaded); - // Load initial images - connect(this, - &ImagesCarousel::stopped, - this, - &ImagesCarousel::_onInitImagesLoaded); - - // Also handle subsequent image loads connect(this, &ImagesCarousel::stopped, this, @@ -88,21 +76,6 @@ ImagesCarousel::ImagesCarousel(const Config::StyleConfigItems& styleConfig, }); } -void ImagesCarousel::_onInitImagesLoaded() { - disconnect(this, &ImagesCarousel::loadingCompleted, this, &ImagesCarousel::_onInitImagesLoaded); - disconnect(this, &ImagesCarousel::stopped, this, &ImagesCarousel::_onInitImagesLoaded); - - // No images loaded - if (m_loadedImages.isEmpty()) { - return; - } - // Focus the first image - if (m_currentIndex < 0) { - m_currentIndex = 0; - } - focusCurrImage(); -} - void ImagesCarousel::_onImagesLoaded() { m_animationEnabled = true; if (!m_noLoadingScreen) { @@ -112,6 +85,17 @@ void ImagesCarousel::_onImagesLoaded() { m_imageInsertQueueTimer->deleteLater(); m_imageInsertQueueTimer = nullptr; } + if (m_initialImagesLoaded) { + // No images loaded + if (m_loadedImages.isEmpty()) { + return; + } + // Focus the first image + if (m_currentIndex < 0) { + m_currentIndex = 0; + focusCurrImage(); + } + } // exit(1); // for debug } @@ -282,6 +266,10 @@ void ImagesCarousel::_enableUIUpdates(bool enable) { void ImageLoader::run() { ImageData* data = nullptr; Defer defer([this, &data]() { + if (m_carousel.isNull()) { + delete data; + return; + } QMetaObject::invokeMethod(m_carousel, "_insertImageQueue", Qt::QueuedConnection, diff --git a/src/images_carousel.h b/src/images_carousel.h index 1b35dec..f87db89 100644 --- a/src/images_carousel.h +++ b/src/images_carousel.h @@ -1,7 +1,7 @@ /* * @Author: Uyanide pywang0608@foxmail.com * @Date: 2025-08-05 01:22:53 - * @LastEditTime: 2025-11-30 23:10:44 + * @LastEditTime: 2025-12-01 00:59:39 * @Description: Animated carousel widget for displaying and selecting images. */ #ifndef IMAGES_CAROUSEL_H @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ class ImageLoader : public QRunnable { private: QString m_path; - ImagesCarousel* m_carousel; + QPointer m_carousel; const int m_initWidth; const int m_initHeight; }; @@ -66,7 +67,7 @@ class ImagesCarousel : public QWidget { static constexpr int s_debounceInterval = 200; static constexpr int s_animationDuration = 300; static constexpr int s_processBatchTimeout = 50; // ms - static constexpr int s_processBatchSize = 10; // items + static constexpr int s_processBatchSize = 30; // items [[nodiscard]] QString getCurrentImagePath() const { if (m_currentIndex < 0 || m_currentIndex >= m_loadedImages.size()) { @@ -104,7 +105,6 @@ class ImagesCarousel : public QWidget { private slots: void _onScrollBarValueChanged(int value); void _onItemClicked(const QString& path); - void _onInitImagesLoaded(); void _onImagesLoaded(); void _processImageInsertQueue(); @@ -150,6 +150,9 @@ class ImagesCarousel : public QWidget { QMutex m_stopSignMutex; bool m_stopSign = false; + // Flags + bool m_initialImagesLoaded = true; + signals: void imageFocused(const QString& path, const int index, const int count);