代码拉取完成,页面将自动刷新
同步操作将从 src-anolis-os/qt5-qtbase 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From d458d0957b54bfee185ce0833a220e9ab20a718f Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Mon, 4 Jul 2022 18:10:03 +0800
Subject: [PATCH]
QTBUG001-85978-85985-QLineEdit-Fix-the-problem-under-the-touch-screen
---
src/widgets/widgets/qlineedit.cpp | 52 ++++++++++++++++++++++++++++-
src/widgets/widgets/qlineedit.h | 1 +
src/widgets/widgets/qlineedit_p.cpp | 16 +++++++++
src/widgets/widgets/qlineedit_p.h | 9 +++++
4 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 0c725693..f5b1e495 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -1536,6 +1536,13 @@ bool QLineEdit::event(QEvent * e)
void QLineEdit::mousePressEvent(QMouseEvent* e)
{
Q_D(QLineEdit);
+ if (e->source() == Qt::MouseEventSynthesizedByQt) {
+ d->touchPress = true;
+ if (d->touchPopup)
+ d->touchPopup = false;
+ d->oldPosX = e->screenPos().x();
+ }
+
d->mousePressPos = e->pos();
@@ -1569,7 +1576,14 @@ void QLineEdit::mousePressEvent(QMouseEvent* e)
} else
#endif
{
- d->control->moveCursor(cursor, mark);
+ if (d->touchPress) {
+ d->CurrentCursor = cursor;
+ d->modStateMark = mark;
+ QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(_q_waitTouchPopup()));
+ } else {
+ d->control->moveCursor(cursor, mark);
+ }
+
}
}
@@ -1612,6 +1626,26 @@ void QLineEdit::mouseMoveEvent(QMouseEvent * e)
} else
#endif
{
+ if (d->oldPosX == 0) {
+ d->oldPosX = e->screenPos().x();
+ return;
+ }
+
+ if (d->doublePress)
+ return;
+
+ // 1.0: Touch jitter causes the range of coordinates to change
+ if ((d->touchPress && !d->touchPopup) && (qAbs(e->screenPos().x() - d->oldPosX) < 1.0)) {
+ d->oldPosX = e->screenPos().x();
+ return;
+ }
+
+ d->oldPosX = e->screenPos().x();
+
+ //A long press under the touch screen will trigger Qt::MouseEventSource(MouseEventNotSynthesized)
+ if (d->touchPress && (e->screenPos().x() - (qreal)e->screenPos().toPoint().rx() == 0))
+ return;
+
d->control->moveCursor(d->xToPos(e->pos().x()), select);
}
}
@@ -1625,6 +1659,15 @@ void QLineEdit::mouseMoveEvent(QMouseEvent * e)
void QLineEdit::mouseReleaseEvent(QMouseEvent* e)
{
Q_D(QLineEdit);
+ if (e->source() == Qt::MouseEventSynthesizedByQt && d->touchPress) {
+ d->touchPress = false;
+ d->touchPopup = true;
+ if (d->doublePress) {
+ d->touchPopup = false;
+ d->doublePress = false;
+ }
+ }
+
if (d->sendMouseEventToInputContext(e))
return;
#if QT_CONFIG(draganddrop)
@@ -1657,6 +1700,8 @@ void QLineEdit::mouseReleaseEvent(QMouseEvent* e)
void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e)
{
Q_D(QLineEdit);
+ if (e->source() == Qt::MouseEventSynthesizedByQt)
+ d->doublePress = true;
if (e->button() == Qt::LeftButton) {
int position = d->xToPos(e->pos().x());
@@ -2179,6 +2224,11 @@ void QLineEdit::dropEvent(QDropEvent* e)
*/
void QLineEdit::contextMenuEvent(QContextMenuEvent *event)
{
+ Q_D(QLineEdit);
+ d->touchPress = false;
+ d->touchPopup = false;
+ d->doublePress = false;
+
if (QMenu *menu = createStandardContextMenu()) {
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->popup(event->globalPos());
diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h
index 1cf1f244..4a575c13 100644
--- a/src/widgets/widgets/qlineedit.h
+++ b/src/widgets/widgets/qlineedit.h
@@ -255,6 +255,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate())
Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &))
Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int))
+ Q_PRIVATE_SLOT(d_func(), void _q_waitTouchPopup())
#if QT_CONFIG(completer)
Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(const QString &))
#endif
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 413f1a44..ff293d53 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -144,6 +144,15 @@ void QLineEditPrivate::_q_cursorPositionChanged(int from, int to)
emit q->cursorPositionChanged(from, to);
}
+void QLineEditPrivate::_q_waitTouchPopup()
+{
+ if (touchPopup) {
+ control->moveCursor(CurrentCursor, modStateMark);
+ touchPopup = false;
+ }
+}
+
+
#ifdef QT_KEYPAD_NAVIGATION
void QLineEditPrivate::_q_editFocusChange(bool e)
{
@@ -241,6 +250,13 @@ void QLineEditPrivate::init(const QString& txt)
q->setAttribute(Qt::WA_MacShowFocusRect);
+ touchPress = false;
+ touchPopup = false;
+ doublePress = false;
+ oldPosX = 0;
+ CurrentCursor = 0;
+ modStateMark = false;
+
initMouseYThreshold();
}
diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h
index 5ae402b9..fcb52b47 100644
--- a/src/widgets/widgets/qlineedit_p.h
+++ b/src/widgets/widgets/qlineedit_p.h
@@ -206,6 +206,14 @@ public:
uint clickCausedFocus : 1;
uint edited : 1;
int hscroll;
+
+ int CurrentCursor;
+ bool touchPress;
+ bool touchPopup;
+ bool doublePress;
+ bool modStateMark;
+ qreal oldPosX ;
+
int vscroll;
uint alignment;
static const int verticalMargin;
@@ -218,6 +226,7 @@ public:
void _q_handleWindowActivate();
void _q_textEdited(const QString &);
void _q_cursorPositionChanged(int, int);
+ void _q_waitTouchPopup();
#ifdef QT_KEYPAD_NAVIGATION
void _q_editFocusChange(bool);
#endif
--
2.31.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。