mirror of https://github.com/Nheko-Reborn/nheko
That way we can autohide the scollbar if needed, it should fix some jumping issues, it makes it possible to flick on mobile, etc. Some related bugs: https://bugreports.qt.io/browse/QTBUG-75223 https://bugreports.qt.io/browse/QTBUG-44902pull/956/head
parent
2c9ef11254
commit
46fbb0e749
@ -0,0 +1,61 @@ |
||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "NhekoEventObserver.h" |
||||
|
||||
#include <QMouseEvent> |
||||
|
||||
#include "Logging.h" |
||||
|
||||
NhekoEventObserver::NhekoEventObserver(QQuickItem *parent) |
||||
: QQuickItem(parent) |
||||
{ |
||||
setFiltersChildMouseEvents(true); |
||||
} |
||||
|
||||
bool |
||||
NhekoEventObserver::childMouseEventFilter(QQuickItem * /*item*/, QEvent *event) |
||||
{ |
||||
// nhlog::ui()->debug("Touched {}", item->metaObject()->className());
|
||||
|
||||
auto setTouched = [this](bool touched) { |
||||
if (touched != this->wasTouched_) { |
||||
this->wasTouched_ = touched; |
||||
emit wasTouchedChanged(); |
||||
} |
||||
}; |
||||
|
||||
// see
|
||||
// https://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quicktemplates2/qquickscrollview.cpp?id=7f29e89c26ae2babc358b1c4e6f965af6ec759f4#n471
|
||||
switch (event->type()) { |
||||
case QEvent::TouchBegin: |
||||
case QEvent::TouchEnd: |
||||
setTouched(true); |
||||
break; |
||||
|
||||
case QEvent::MouseButtonPress: |
||||
if (static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized) { |
||||
setTouched(false); |
||||
} |
||||
break; |
||||
|
||||
case QEvent::MouseMove: |
||||
case QEvent::MouseButtonRelease: |
||||
if (static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized) |
||||
setTouched(false); |
||||
break; |
||||
|
||||
case QEvent::HoverEnter: |
||||
case QEvent::HoverMove: |
||||
case QEvent::Wheel: |
||||
setTouched(false); |
||||
break; |
||||
|
||||
default: |
||||
break; |
||||
} |
||||
|
||||
return false; |
||||
} |
@ -0,0 +1,27 @@ |
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once |
||||
|
||||
#include <QQuickItem> |
||||
|
||||
class NhekoEventObserver : public QQuickItem |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
Q_PROPERTY(bool wasTouched READ wasTouched NOTIFY wasTouchedChanged) |
||||
|
||||
public: |
||||
explicit NhekoEventObserver(QQuickItem *parent = 0); |
||||
|
||||
bool childMouseEventFilter(QQuickItem *item, QEvent *event) override; |
||||
|
||||
private: |
||||
bool wasTouched() { return wasTouched_; } |
||||
|
||||
bool wasTouched_ = false; |
||||
|
||||
signals: |
||||
void wasTouchedChanged(); |
||||
}; |
Loading…
Reference in new issue