From a6dfa35fa77a153d13be1d8f3b9d58b83d985df5 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Wed, 6 Aug 2025 02:15:16 +0200 Subject: [PATCH] feat: wheel events --- app/install.sh | 17 +++++++++++++++++ app/wallpaper_chooser.desktop | 8 ++++++++ src/images_carousel.cpp | 5 ++++- src/images_carousel.h | 36 ++++++++++++++++++++++++++++++----- src/main_window.cpp | 11 ++++++++++- src/main_window.h | 3 ++- 6 files changed, 72 insertions(+), 8 deletions(-) create mode 100755 app/install.sh create mode 100644 app/wallpaper_chooser.desktop diff --git a/app/install.sh b/app/install.sh new file mode 100755 index 0000000..4a5eea9 --- /dev/null +++ b/app/install.sh @@ -0,0 +1,17 @@ +#!/bin/env bash + +path="$(dirname "$(readlink -f "$0")")" + +cmake -S "$path/.." -B "$path/../build" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$HOME"/.local || exit 1 + +cmake --build "$path/../build" --target install || exit 1 + +cp "$path/wallpaper_chooser.desktop" "$HOME"/.local/share/applications/wallpaper_chooser.desktop + +echo -e "\nExec=$HOME/.local/bin/wallpaper_chooser" >> "$HOME"/.local/share/applications/wallpaper_chooser.desktop + +if command -v update-desktop-database &> /dev/null; then + update-desktop-database "$HOME"/.local/share/applications/ +fi \ No newline at end of file diff --git a/app/wallpaper_chooser.desktop b/app/wallpaper_chooser.desktop new file mode 100644 index 0000000..5e18413 --- /dev/null +++ b/app/wallpaper_chooser.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Wallpaper Chooser +Comment=A small wallpaper utility made with Qt +Terminal=false +Categories=Application;Utility; +StartupNotify=true \ No newline at end of file diff --git a/src/images_carousel.cpp b/src/images_carousel.cpp index 5954125..3e03684 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 01:27:49 + * @LastEditTime: 2025-08-06 02:12:46 * @Description: Animated carousel widget for displaying and selecting images. */ #include "images_carousel.h" @@ -39,6 +39,7 @@ ImagesCarousel::ImagesCarousel(const double itemAspectRatio, m_sortType(sortType), m_sortReverse(sortReverse) { ui->setupUi(this); + m_scrollArea = dynamic_cast(ui->scrollArea); m_imagesLayout = dynamic_cast(ui->scrollAreaWidgetContents->layout()); @@ -245,8 +246,10 @@ void ImagesCarousel::_focusCurrImage() { this, [this]() { m_suppressAutoFocus = false; + m_scrollArea->setBlockInput(false); }); m_suppressAutoFocus = true; + m_scrollArea->setBlockInput(true); m_scrollAnimation->start(); } diff --git a/src/images_carousel.h b/src/images_carousel.h index 4c53f79..39757c8 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 01:32:56 + * @LastEditTime: 2025-08-06 02:10:43 * @Description: Animated carousel widget for displaying and selecting images. */ #ifndef IMAGES_CAROUSEL_H @@ -24,7 +24,11 @@ #include "config.h" +class ImageData; +class ImageItem; +class ImageLoader; class ImagesCarousel; +class ImagesCarouselScrollArea; /** * @brief Data structure to hold image information @@ -146,10 +150,11 @@ class ImagesCarousel : public QWidget { QPropertyAnimation* m_scrollAnimation = nullptr; QHBoxLayout* m_imagesLayout = nullptr; QMutex m_imageCountMutex; - int m_imageCount = 0; - bool m_suppressAutoFocus = false; - int m_pendingScrollValue = 0; - QTimer* m_scrollDebounceTimer = nullptr; + int m_imageCount = 0; + bool m_suppressAutoFocus = false; + int m_pendingScrollValue = 0; + QTimer* m_scrollDebounceTimer = nullptr; + ImagesCarouselScrollArea* m_scrollArea = nullptr; signals: void imageFocused(const QString& path, const int index, const int count); @@ -166,14 +171,35 @@ class ImagesCarouselScrollArea : public QScrollArea { // setWidgetResizable(true); } + void setBlockInput(bool block) { m_blockInput = block; } + protected: void keyPressEvent(QKeyEvent* event) override { + if (m_blockInput) { + event->ignore(); + return; + } if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) { event->ignore(); } else { QScrollArea::keyPressEvent(event); } } + + void wheelEvent(QWheelEvent* event) override { + if (m_blockInput) { + event->ignore(); + return; + } + if (event->angleDelta().y() != 0) { + event->ignore(); + } else { + QScrollArea::wheelEvent(event); + } + } + + private: + bool m_blockInput = false; }; #endif // IMAGES_CAROUSEL_H diff --git a/src/main_window.cpp b/src/main_window.cpp index 947440a..ababc65 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -1,7 +1,7 @@ /* * @Author: Uyanide pywang0608@foxmail.com * @Date: 2025-08-05 00:37:58 - * @LastEditTime: 2025-08-06 00:48:11 + * @LastEditTime: 2025-08-06 02:13:59 * @Description: MainWindow implementation. */ #include "main_window.h" @@ -70,6 +70,15 @@ void MainWindow::keyPressEvent(QKeyEvent *event) { } } +void MainWindow::wheelEvent(QWheelEvent *event) { + if (event->angleDelta().y() > 0) { + m_carousel->focusPrevImage(); + } else { + m_carousel->focusNextImage(); + } + event->accept(); +} + void MainWindow::onConfirm() { close(); const auto path = m_carousel->getCurrentImagePath(); diff --git a/src/main_window.h b/src/main_window.h index b28b9fc..ace1f4f 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -1,7 +1,7 @@ /* * @Author: Uyanide pywang0608@foxmail.com * @Date: 2025-08-05 00:37:58 - * @LastEditTime: 2025-08-06 00:47:04 + * @LastEditTime: 2025-08-06 02:13:47 * @Description: MainWindow implementation. */ #ifndef MAINWINDOW_H @@ -33,6 +33,7 @@ class MainWindow : public QMainWindow { protected: void keyPressEvent(QKeyEvent *event) override; + void wheelEvent(QWheelEvent *event) override; private: void _setupUI();