From 567baeeeabad77096aa1510ceee2875a77194e23 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Wed, 6 Aug 2025 22:46:29 +0200 Subject: [PATCH] feat: click to focus --- app/install.sh | 6 ------ src/images_carousel.cpp | 12 ++++++++++-- src/images_carousel.h | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/install.sh b/app/install.sh index d7ed293..8ab2aa4 100755 --- a/app/install.sh +++ b/app/install.sh @@ -1,10 +1,4 @@ #!/bin/env bash -### - # @Author: Uyanide pywang0608@foxmail.com - # @Date: 2025-08-06 01:43:32 - # @LastEditTime: 2025-08-06 02:28:12 - # @Description: -### path="$(dirname "$(readlink -f "$0")")" diff --git a/src/images_carousel.cpp b/src/images_carousel.cpp index 3e03684..9cb3e61 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-08-06 02:12:46 + * @LastEditTime: 2025-08-06 22:44:49 * @Description: Animated carousel widget for displaying and selecting images. */ #include "images_carousel.h" @@ -152,8 +152,15 @@ void ImagesCarousel::_updateImages() { for (auto it = m_loadedImages.rbegin(); it != m_loadedImages.rend() && cmpFuncs[static_cast(m_sortType)](*it, item) == m_sortReverse; - ++it, --inserPos); + (*it)->m_index++, ++it, --inserPos); } + item->m_index = inserPos; + connect(item, &ImageItem::clicked, this, [this](int index) { + // if (m_suppressAutoFocus) return; + _unfocusCurrImage(); + m_currentIndex = index; + _focusCurrImage(); + }); m_loadedImages.insert(inserPos, item); m_imagesLayout->insertWidget(inserPos, item); processCount++; @@ -263,6 +270,7 @@ void ImagesCarousel::_onScrollBarValueChanged(int value) { int centerOffset = (value + m_itemFocusWidth / 2); int itemOffset = m_itemWidth + ui->scrollAreaWidgetContents->layout()->spacing(); int index = centerOffset / itemOffset; + if (index < 0 || index >= m_loadedImages.size()) { return; // Out of bounds } diff --git a/src/images_carousel.h b/src/images_carousel.h index 39757c8..793388d 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-08-06 02:10:43 + * @LastEditTime: 2025-08-06 22:40:18 * @Description: Animated carousel widget for displaying and selecting images. */ #ifndef IMAGES_CAROUSEL_H @@ -67,14 +67,24 @@ class ImageItem : public QLabel { [[nodiscard]] qint64 getFileSize() const { return m_data->file.size(); } - public: void setFocus(bool focus = true); + int m_index = 0; + + protected: + void mousePressEvent(QMouseEvent* event) override { + emit clicked(m_index); + QLabel::mousePressEvent(event); + } + private: const ImageData* m_data; QSize m_itemSize; QSize m_itemFocusSize; QPropertyAnimation* m_scaleAnimation = nullptr; + + signals: + void clicked(int index); }; class ImageLoader : public QRunnable {