Handle touch events in PopupMenu.
This commit is contained in:
parent
e72b521618
commit
18580e46a1
3 changed files with 39 additions and 1 deletions
|
|
@ -98,7 +98,7 @@ bool LoadCustomFont(const QString &filePath, const QString &familyName, int flag
|
|||
|
||||
[[nodiscard]] QString ManualMonospaceFont() {
|
||||
const auto kTryFirst = std::initializer_list<QString>{
|
||||
"Cascadia Code",
|
||||
"Cascadia Mono",
|
||||
"Consolas",
|
||||
"Liberation Mono",
|
||||
"Menlo",
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <QtGui/QScreen>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <private/qapplication_p.h>
|
||||
|
||||
namespace Ui {
|
||||
namespace {
|
||||
|
|
@ -203,6 +204,8 @@ void PopupMenu::init() {
|
|||
hideMenu(true);
|
||||
}, lifetime());
|
||||
|
||||
installEventFilter(this);
|
||||
|
||||
const auto paddingWrap = static_cast<PaddingWrap<Menu::Menu>*>(
|
||||
_menu->parentWidget());
|
||||
paddingWrap->paintRequest(
|
||||
|
|
@ -620,6 +623,37 @@ void PopupMenu::mousePressEvent(QMouseEvent *e) {
|
|||
forwardMousePress(e->globalPos());
|
||||
}
|
||||
|
||||
bool PopupMenu::eventFilter(QObject *o, QEvent *e) {
|
||||
const auto type = e->type();
|
||||
if (type == QEvent::TouchBegin
|
||||
|| type == QEvent::TouchUpdate
|
||||
|| type == QEvent::TouchEnd) {
|
||||
if (o == windowHandle() && isActiveWindow()) {
|
||||
const auto event = static_cast<QTouchEvent*>(e);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
e->setAccepted(
|
||||
QApplicationPrivate::translateRawTouchEvent(
|
||||
this,
|
||||
event->device(),
|
||||
event->touchPoints(),
|
||||
event->timestamp()));
|
||||
#elif QT_VERSION < QT_VERSION_CHECK(6, 3, 0) // Qt < 6.0.0
|
||||
e->setAccepted(
|
||||
QApplicationPrivate::translateRawTouchEvent(
|
||||
this,
|
||||
event->pointingDevice(),
|
||||
const_cast<QList<QEventPoint> &>(event->points()),
|
||||
event->timestamp()));
|
||||
#else // Qt < 6.3.0
|
||||
e->setAccepted(
|
||||
QApplicationPrivate::translateRawTouchEvent(this, event));
|
||||
#endif
|
||||
return e->isAccepted();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PopupMenu::hideMenu(bool fast) {
|
||||
if (isHidden()) {
|
||||
return;
|
||||
|
|
@ -901,6 +935,8 @@ bool PopupMenu::prepareGeometryFor(const QPoint &p, PopupMenu *parent) {
|
|||
_parent = parent;
|
||||
|
||||
createWinId();
|
||||
windowHandle()->removeEventFilter(this);
|
||||
windowHandle()->installEventFilter(this);
|
||||
if (_parent) {
|
||||
windowHandle()->setScreen(_parent->screen());
|
||||
} else if (screen) {
|
||||
|
|
|
|||
|
|
@ -109,6 +109,8 @@ protected:
|
|||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
|
||||
bool eventFilter(QObject *o, QEvent *e) override;
|
||||
|
||||
private:
|
||||
void paintBg(QPainter &p);
|
||||
void hideFast();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue