rotated view + wheel inverter

This commit is contained in:
2026-08-26 17:10:34 +02:00
parent 78988700be
commit c33dbc147f
7 changed files with 341 additions and 135 deletions
+5 -4
View File
@@ -1,10 +1,11 @@
qml_module(ZShell-components
URI ZShell.Components
SOURCES
lazylistview.hpp lazylistview.cpp
SOURCES
lazylistview.hpp lazylistview.cpp
wavyline.hpp wavyline.cpp
buttonrow.hpp buttonrow.cpp
carouselview.hpp carouselview.cpp
LIBRARIES
Qt::Quick
wheelinverter.hpp
LIBRARIES
Qt::Quick
)
@@ -0,0 +1,90 @@
#pragma once
#include <QQuickItem>
#include <QQuickWindow>
#include <QWheelEvent>
#include <QCoreApplication>
#include <QPointer>
#include <QDebug>
namespace ZShell::components {
class WheelInverter : public QQuickItem {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(
QQuickItem* target READ target WRITE setTarget NOTIFY targetChanged)
public:
using QQuickItem::QQuickItem;
QQuickItem* target() const { return m_target; }
void setTarget(QQuickItem* target) {
if (m_target == target) return;
if (m_target) m_target->removeEventFilter(this);
m_target = target;
if (m_target) m_target->installEventFilter(this);
emit targetChanged();
}
protected:
class InvertedWheelEvent : public QWheelEvent {
public:
using QWheelEvent::QWheelEvent;
bool invertedByWheelInverter = true;
};
bool eventFilter(QObject* watched, QEvent* event) override {
if (watched != m_target || event->type() != QEvent::Wheel)
return QQuickItem::eventFilter(watched, event);
auto* wheel = static_cast<QWheelEvent*>(event);
const bool inverted = dynamic_cast<InvertedWheelEvent*>(wheel) !=
nullptr;
if (inverted) return false;
auto* window = m_target ? m_target->window() : nullptr;
if (!window) {
qInfo() << "[WheelInverter] no window";
return false;
}
const QPointF windowPos =
window->mapFromGlobal(wheel->globalPosition());
auto* invertedEvent = new InvertedWheelEvent(
windowPos,
wheel->globalPosition(),
-wheel->pixelDelta(),
-wheel->angleDelta(),
wheel->buttons(),
wheel->modifiers(),
wheel->phase(),
wheel->inverted(),
wheel->source(),
wheel->pointingDevice());
invertedEvent->setTimestamp(wheel->timestamp());
QCoreApplication::postEvent(window, invertedEvent);
return true;
}
signals:
void targetChanged();
private:
QPointer<QQuickItem> m_target;
};
} // namespace ZShell::components