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() {
|
[[nodiscard]] QString ManualMonospaceFont() {
|
||||||
const auto kTryFirst = std::initializer_list<QString>{
|
const auto kTryFirst = std::initializer_list<QString>{
|
||||||
"Cascadia Code",
|
"Cascadia Mono",
|
||||||
"Consolas",
|
"Consolas",
|
||||||
"Liberation Mono",
|
"Liberation Mono",
|
||||||
"Menlo",
|
"Menlo",
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QtGui/QScreen>
|
#include <QtGui/QScreen>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <private/qapplication_p.h>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
@ -203,6 +204,8 @@ void PopupMenu::init() {
|
||||||
hideMenu(true);
|
hideMenu(true);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
installEventFilter(this);
|
||||||
|
|
||||||
const auto paddingWrap = static_cast<PaddingWrap<Menu::Menu>*>(
|
const auto paddingWrap = static_cast<PaddingWrap<Menu::Menu>*>(
|
||||||
_menu->parentWidget());
|
_menu->parentWidget());
|
||||||
paddingWrap->paintRequest(
|
paddingWrap->paintRequest(
|
||||||
|
|
@ -620,6 +623,37 @@ void PopupMenu::mousePressEvent(QMouseEvent *e) {
|
||||||
forwardMousePress(e->globalPos());
|
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) {
|
void PopupMenu::hideMenu(bool fast) {
|
||||||
if (isHidden()) {
|
if (isHidden()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -901,6 +935,8 @@ bool PopupMenu::prepareGeometryFor(const QPoint &p, PopupMenu *parent) {
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
|
||||||
createWinId();
|
createWinId();
|
||||||
|
windowHandle()->removeEventFilter(this);
|
||||||
|
windowHandle()->installEventFilter(this);
|
||||||
if (_parent) {
|
if (_parent) {
|
||||||
windowHandle()->setScreen(_parent->screen());
|
windowHandle()->setScreen(_parent->screen());
|
||||||
} else if (screen) {
|
} else if (screen) {
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,8 @@ protected:
|
||||||
void mouseMoveEvent(QMouseEvent *e) override;
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
|
bool eventFilter(QObject *o, QEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintBg(QPainter &p);
|
void paintBg(QPainter &p);
|
||||||
void hideFast();
|
void hideFast();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue