wip: fix: minor
This commit is contained in:
+18
-30
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 01:22:53
|
* @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.
|
* @Description: Animated carousel widget for displaying and selecting images.
|
||||||
*/
|
*/
|
||||||
#include "images_carousel.h"
|
#include "images_carousel.h"
|
||||||
@@ -15,7 +15,9 @@
|
|||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "ui_images_carousel.h"
|
#include "ui_images_carousel.h"
|
||||||
@@ -42,25 +44,11 @@ ImagesCarousel::ImagesCarousel(const Config::StyleConfigItems& styleConfig,
|
|||||||
// Remove border
|
// Remove border
|
||||||
ui->scrollArea->setFrameShape(QFrame::NoFrame);
|
ui->scrollArea->setFrameShape(QFrame::NoFrame);
|
||||||
|
|
||||||
// Load initial images
|
|
||||||
connect(this,
|
|
||||||
&ImagesCarousel::loadingCompleted,
|
|
||||||
this,
|
|
||||||
&ImagesCarousel::_onInitImagesLoaded);
|
|
||||||
|
|
||||||
// Also handle subsequent image loads
|
|
||||||
connect(this,
|
connect(this,
|
||||||
&ImagesCarousel::loadingCompleted,
|
&ImagesCarousel::loadingCompleted,
|
||||||
this,
|
this,
|
||||||
&ImagesCarousel::_onImagesLoaded);
|
&ImagesCarousel::_onImagesLoaded);
|
||||||
|
|
||||||
// Load initial images
|
|
||||||
connect(this,
|
|
||||||
&ImagesCarousel::stopped,
|
|
||||||
this,
|
|
||||||
&ImagesCarousel::_onInitImagesLoaded);
|
|
||||||
|
|
||||||
// Also handle subsequent image loads
|
|
||||||
connect(this,
|
connect(this,
|
||||||
&ImagesCarousel::stopped,
|
&ImagesCarousel::stopped,
|
||||||
this,
|
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() {
|
void ImagesCarousel::_onImagesLoaded() {
|
||||||
m_animationEnabled = true;
|
m_animationEnabled = true;
|
||||||
if (!m_noLoadingScreen) {
|
if (!m_noLoadingScreen) {
|
||||||
@@ -112,6 +85,17 @@ void ImagesCarousel::_onImagesLoaded() {
|
|||||||
m_imageInsertQueueTimer->deleteLater();
|
m_imageInsertQueueTimer->deleteLater();
|
||||||
m_imageInsertQueueTimer = nullptr;
|
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
|
// exit(1); // for debug
|
||||||
}
|
}
|
||||||
@@ -282,6 +266,10 @@ void ImagesCarousel::_enableUIUpdates(bool enable) {
|
|||||||
void ImageLoader::run() {
|
void ImageLoader::run() {
|
||||||
ImageData* data = nullptr;
|
ImageData* data = nullptr;
|
||||||
Defer defer([this, &data]() {
|
Defer defer([this, &data]() {
|
||||||
|
if (m_carousel.isNull()) {
|
||||||
|
delete data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
QMetaObject::invokeMethod(m_carousel,
|
QMetaObject::invokeMethod(m_carousel,
|
||||||
"_insertImageQueue",
|
"_insertImageQueue",
|
||||||
Qt::QueuedConnection,
|
Qt::QueuedConnection,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 01:22:53
|
* @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.
|
* @Description: Animated carousel widget for displaying and selecting images.
|
||||||
*/
|
*/
|
||||||
#ifndef IMAGES_CAROUSEL_H
|
#ifndef IMAGES_CAROUSEL_H
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QPointer>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
@@ -43,7 +44,7 @@ class ImageLoader : public QRunnable {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_path;
|
QString m_path;
|
||||||
ImagesCarousel* m_carousel;
|
QPointer<ImagesCarousel> m_carousel;
|
||||||
const int m_initWidth;
|
const int m_initWidth;
|
||||||
const int m_initHeight;
|
const int m_initHeight;
|
||||||
};
|
};
|
||||||
@@ -66,7 +67,7 @@ class ImagesCarousel : public QWidget {
|
|||||||
static constexpr int s_debounceInterval = 200;
|
static constexpr int s_debounceInterval = 200;
|
||||||
static constexpr int s_animationDuration = 300;
|
static constexpr int s_animationDuration = 300;
|
||||||
static constexpr int s_processBatchTimeout = 50; // ms
|
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 {
|
[[nodiscard]] QString getCurrentImagePath() const {
|
||||||
if (m_currentIndex < 0 || m_currentIndex >= m_loadedImages.size()) {
|
if (m_currentIndex < 0 || m_currentIndex >= m_loadedImages.size()) {
|
||||||
@@ -104,7 +105,6 @@ class ImagesCarousel : public QWidget {
|
|||||||
private slots:
|
private slots:
|
||||||
void _onScrollBarValueChanged(int value);
|
void _onScrollBarValueChanged(int value);
|
||||||
void _onItemClicked(const QString& path);
|
void _onItemClicked(const QString& path);
|
||||||
void _onInitImagesLoaded();
|
|
||||||
void _onImagesLoaded();
|
void _onImagesLoaded();
|
||||||
|
|
||||||
void _processImageInsertQueue();
|
void _processImageInsertQueue();
|
||||||
@@ -150,6 +150,9 @@ class ImagesCarousel : public QWidget {
|
|||||||
QMutex m_stopSignMutex;
|
QMutex m_stopSignMutex;
|
||||||
bool m_stopSign = false;
|
bool m_stopSign = false;
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
bool m_initialImagesLoaded = true;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void imageFocused(const QString& path, const int index, const int count);
|
void imageFocused(const QString& path, const int index, const int count);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user