feat: click to focus

This commit is contained in:
2025-08-06 22:46:29 +02:00
parent 8535691d4d
commit 567baeeeab
3 changed files with 22 additions and 10 deletions
-6
View File
@@ -1,10 +1,4 @@
#!/bin/env bash #!/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")")" path="$(dirname "$(readlink -f "$0")")"
+10 -2
View File
@@ -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-08-06 02:12:46 * @LastEditTime: 2025-08-06 22:44:49
* @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"
@@ -152,8 +152,15 @@ void ImagesCarousel::_updateImages() {
for (auto it = m_loadedImages.rbegin(); for (auto it = m_loadedImages.rbegin();
it != m_loadedImages.rend() && it != m_loadedImages.rend() &&
cmpFuncs[static_cast<int>(m_sortType)](*it, item) == m_sortReverse; cmpFuncs[static_cast<int>(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_loadedImages.insert(inserPos, item);
m_imagesLayout->insertWidget(inserPos, item); m_imagesLayout->insertWidget(inserPos, item);
processCount++; processCount++;
@@ -263,6 +270,7 @@ void ImagesCarousel::_onScrollBarValueChanged(int value) {
int centerOffset = (value + m_itemFocusWidth / 2); int centerOffset = (value + m_itemFocusWidth / 2);
int itemOffset = m_itemWidth + ui->scrollAreaWidgetContents->layout()->spacing(); int itemOffset = m_itemWidth + ui->scrollAreaWidgetContents->layout()->spacing();
int index = centerOffset / itemOffset; int index = centerOffset / itemOffset;
if (index < 0 || index >= m_loadedImages.size()) { if (index < 0 || index >= m_loadedImages.size()) {
return; // Out of bounds return; // Out of bounds
} }
+12 -2
View File
@@ -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-08-06 02:10:43 * @LastEditTime: 2025-08-06 22:40:18
* @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
@@ -67,14 +67,24 @@ class ImageItem : public QLabel {
[[nodiscard]] qint64 getFileSize() const { return m_data->file.size(); } [[nodiscard]] qint64 getFileSize() const { return m_data->file.size(); }
public:
void setFocus(bool focus = true); void setFocus(bool focus = true);
int m_index = 0;
protected:
void mousePressEvent(QMouseEvent* event) override {
emit clicked(m_index);
QLabel::mousePressEvent(event);
}
private: private:
const ImageData* m_data; const ImageData* m_data;
QSize m_itemSize; QSize m_itemSize;
QSize m_itemFocusSize; QSize m_itemFocusSize;
QPropertyAnimation* m_scaleAnimation = nullptr; QPropertyAnimation* m_scaleAnimation = nullptr;
signals:
void clicked(int index);
}; };
class ImageLoader : public QRunnable { class ImageLoader : public QRunnable {