feat: wheel events
This commit is contained in:
Executable
+17
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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 01:27:49
|
* @LastEditTime: 2025-08-06 02:12:46
|
||||||
* @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"
|
||||||
@@ -39,6 +39,7 @@ ImagesCarousel::ImagesCarousel(const double itemAspectRatio,
|
|||||||
m_sortType(sortType),
|
m_sortType(sortType),
|
||||||
m_sortReverse(sortReverse) {
|
m_sortReverse(sortReverse) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
m_scrollArea = dynamic_cast<ImagesCarouselScrollArea*>(ui->scrollArea);
|
||||||
|
|
||||||
m_imagesLayout = dynamic_cast<QHBoxLayout*>(ui->scrollAreaWidgetContents->layout());
|
m_imagesLayout = dynamic_cast<QHBoxLayout*>(ui->scrollAreaWidgetContents->layout());
|
||||||
|
|
||||||
@@ -245,8 +246,10 @@ void ImagesCarousel::_focusCurrImage() {
|
|||||||
this,
|
this,
|
||||||
[this]() {
|
[this]() {
|
||||||
m_suppressAutoFocus = false;
|
m_suppressAutoFocus = false;
|
||||||
|
m_scrollArea->setBlockInput(false);
|
||||||
});
|
});
|
||||||
m_suppressAutoFocus = true;
|
m_suppressAutoFocus = true;
|
||||||
|
m_scrollArea->setBlockInput(true);
|
||||||
m_scrollAnimation->start();
|
m_scrollAnimation->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+31
-5
@@ -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 01:32:56
|
* @LastEditTime: 2025-08-06 02:10:43
|
||||||
* @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
|
||||||
@@ -24,7 +24,11 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
class ImageData;
|
||||||
|
class ImageItem;
|
||||||
|
class ImageLoader;
|
||||||
class ImagesCarousel;
|
class ImagesCarousel;
|
||||||
|
class ImagesCarouselScrollArea;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Data structure to hold image information
|
* @brief Data structure to hold image information
|
||||||
@@ -146,10 +150,11 @@ class ImagesCarousel : public QWidget {
|
|||||||
QPropertyAnimation* m_scrollAnimation = nullptr;
|
QPropertyAnimation* m_scrollAnimation = nullptr;
|
||||||
QHBoxLayout* m_imagesLayout = nullptr;
|
QHBoxLayout* m_imagesLayout = nullptr;
|
||||||
QMutex m_imageCountMutex;
|
QMutex m_imageCountMutex;
|
||||||
int m_imageCount = 0;
|
int m_imageCount = 0;
|
||||||
bool m_suppressAutoFocus = false;
|
bool m_suppressAutoFocus = false;
|
||||||
int m_pendingScrollValue = 0;
|
int m_pendingScrollValue = 0;
|
||||||
QTimer* m_scrollDebounceTimer = nullptr;
|
QTimer* m_scrollDebounceTimer = nullptr;
|
||||||
|
ImagesCarouselScrollArea* m_scrollArea = nullptr;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void imageFocused(const QString& path, const int index, const int count);
|
void imageFocused(const QString& path, const int index, const int count);
|
||||||
@@ -166,14 +171,35 @@ class ImagesCarouselScrollArea : public QScrollArea {
|
|||||||
// setWidgetResizable(true);
|
// setWidgetResizable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setBlockInput(bool block) { m_blockInput = block; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent* event) override {
|
void keyPressEvent(QKeyEvent* event) override {
|
||||||
|
if (m_blockInput) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) {
|
if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
} else {
|
} else {
|
||||||
QScrollArea::keyPressEvent(event);
|
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
|
#endif // IMAGES_CAROUSEL_H
|
||||||
|
|||||||
+10
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 00:37:58
|
* @Date: 2025-08-05 00:37:58
|
||||||
* @LastEditTime: 2025-08-06 00:48:11
|
* @LastEditTime: 2025-08-06 02:13:59
|
||||||
* @Description: MainWindow implementation.
|
* @Description: MainWindow implementation.
|
||||||
*/
|
*/
|
||||||
#include "main_window.h"
|
#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() {
|
void MainWindow::onConfirm() {
|
||||||
close();
|
close();
|
||||||
const auto path = m_carousel->getCurrentImagePath();
|
const auto path = m_carousel->getCurrentImagePath();
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 00:37:58
|
* @Date: 2025-08-05 00:37:58
|
||||||
* @LastEditTime: 2025-08-06 00:47:04
|
* @LastEditTime: 2025-08-06 02:13:47
|
||||||
* @Description: MainWindow implementation.
|
* @Description: MainWindow implementation.
|
||||||
*/
|
*/
|
||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
@@ -33,6 +33,7 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _setupUI();
|
void _setupUI();
|
||||||
|
|||||||
Reference in New Issue
Block a user