rotated view + wheel inverter
This commit is contained in:
@@ -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
|
||||
@@ -23,6 +23,7 @@ class ChatSession : public QObject {
|
||||
Q_PROPERTY(QDateTime createdAt READ createdAt CONSTANT)
|
||||
Q_PROPERTY(QDateTime updatedAt READ updatedAt NOTIFY updatedAtChanged)
|
||||
Q_PROPERTY(bool pinned READ pinned NOTIFY pinnedChanged)
|
||||
Q_PROPERTY(bool loaded READ isLoaded NOTIFY loaded)
|
||||
Q_PROPERTY(int messageCount READ messageCount NOTIFY messageCountChanged)
|
||||
Q_PROPERTY(
|
||||
ZShell::llm::ChatMessageModel* messagesModel READ messagesModel CONSTANT)
|
||||
|
||||
Reference in New Issue
Block a user