summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-02-19 02:49:58 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2022-02-19 21:45:43 +0100
commit46fbb0e74990e1d5909fdef12d8e28da484db7e0 (patch)
treef0ca8ba06cc015a115b41e95bfa4169cfbea0297 /src
parentMerge pull request #947 from maltee1/search_button (diff)
downloadnheko-46fbb0e74990e1d5909fdef12d8e28da484db7e0.tar.xz
Use ListView without scrollview for messages
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-44902
Diffstat (limited to 'src')
-rw-r--r--src/MainWindow.cpp2
-rw-r--r--src/ui/NhekoEventObserver.cpp61
-rw-r--r--src/ui/NhekoEventObserver.h27
3 files changed, 90 insertions, 0 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp

index 872e61f8..f3893998 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp
@@ -49,6 +49,7 @@ #include "ui/MxcMediaProxy.h" #include "ui/NhekoCursorShape.h" #include "ui/NhekoDropArea.h" +#include "ui/NhekoEventObserver.h" #include "ui/NhekoGlobalObject.h" #include "ui/UIA.h" #include "voip/WebRTCSession.h" @@ -164,6 +165,7 @@ MainWindow::registerQmlTypes() qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser"); qmlRegisterType<NhekoDropArea>("im.nheko", 1, 0, "NhekoDropArea"); qmlRegisterType<NhekoCursorShape>("im.nheko", 1, 0, "CursorShape"); + qmlRegisterType<NhekoEventObserver>("im.nheko", 1, 0, "EventObserver"); qmlRegisterType<MxcAnimatedImage>("im.nheko", 1, 0, "MxcAnimatedImage"); qmlRegisterType<MxcMediaProxy>("im.nheko", 1, 0, "MxcMedia"); qmlRegisterType<RoomDirectoryModel>("im.nheko", 1, 0, "RoomDirectoryModel"); diff --git a/src/ui/NhekoEventObserver.cpp b/src/ui/NhekoEventObserver.cpp new file mode 100644
index 00000000..5e67cec4 --- /dev/null +++ b/src/ui/NhekoEventObserver.cpp
@@ -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; +} diff --git a/src/ui/NhekoEventObserver.h b/src/ui/NhekoEventObserver.h new file mode 100644
index 00000000..6d14f30f --- /dev/null +++ b/src/ui/NhekoEventObserver.h
@@ -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(); +};