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
|
||||
* @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<ImagesCarouselScrollArea*>(ui->scrollArea);
|
||||
|
||||
m_imagesLayout = dynamic_cast<QHBoxLayout*>(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();
|
||||
}
|
||||
|
||||
|
||||
+27
-1
@@ -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
|
||||
@@ -150,6 +154,7 @@ class ImagesCarousel : public QWidget {
|
||||
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
|
||||
|
||||
+10
-1
@@ -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();
|
||||
|
||||
+2
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user