wip: fix: minor

This commit is contained in:
2025-12-01 01:00:29 +01:00
parent 8475e28450
commit fc3306ea55
2 changed files with 25 additions and 34 deletions
+18 -30
View File
@@ -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 <QScrollArea>
#include <QScrollBar>
#include <QVector>
#include <algorithm>
#include <functional>
#include <iterator>
#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,
+7 -4
View File
@@ -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 <QMutex>
#include <QObject>
#include <QPixmap>
#include <QPointer>
#include <QPropertyAnimation>
#include <QQueue>
#include <QRunnable>
@@ -43,7 +44,7 @@ class ImageLoader : public QRunnable {
private:
QString m_path;
ImagesCarousel* m_carousel;
QPointer<ImagesCarousel> 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);