fix: 修复了触摸滑动可以点击的问题
Description: 移植了editor的代码 Log: 修复了触摸滑动可以点击的问题 Change-Id: I97a94973f9f6921b7c74dfc3a8df044d5d273742
This commit is contained in:
parent
50597c89dd
commit
23bc192c04
21
src/main.cpp
21
src/main.cpp
|
@ -33,8 +33,23 @@
|
|||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
//判断是否是wayland
|
||||
bool CheckWayland()
|
||||
{
|
||||
auto e = QProcessEnvironment::systemEnvironment();
|
||||
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
|
||||
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
|
||||
|
||||
if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive))
|
||||
return true;
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
|
@ -42,7 +57,11 @@ int main(int argc, char *argv[])
|
|||
qDebug() << "Cant open a null file";
|
||||
return 0;
|
||||
}
|
||||
|
||||
//判断是否是wayland
|
||||
if (CheckWayland()) {
|
||||
//默认走xdgv6,该库没有维护了,因此需要添加该代码
|
||||
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "kwayland-shell");
|
||||
}
|
||||
|
||||
DGuiApplicationHelper::setUseInactiveColorGroup(false);
|
||||
#if(DTK_VERSION < DTK_VERSION_CHECK(5,4,0,0))
|
||||
|
|
|
@ -46,14 +46,15 @@ ResultTextView::ResultTextView(QWidget *parent)
|
|||
connect(m_actPaste, &QAction::triggered, this, [ = ]() {
|
||||
emit this->paste();
|
||||
});
|
||||
connect(this, &QPlainTextEdit::selectionChanged, this, &ResultTextView::onSelectionArea);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setMouseTracking(true);
|
||||
grabGesture(Qt::TapGesture);
|
||||
// grabGesture(Qt::TapAndHoldGesture);
|
||||
// grabGesture(Qt::SwipeGesture);
|
||||
// grabGesture(Qt::PanGesture);
|
||||
// grabGesture(Qt::PinchGesture);
|
||||
grabGesture(Qt::TapAndHoldGesture);
|
||||
grabGesture(Qt::SwipeGesture);
|
||||
grabGesture(Qt::PanGesture);
|
||||
grabGesture(Qt::PinchGesture);
|
||||
}
|
||||
|
||||
void ResultTextView::contextMenuEvent(QContextMenuEvent *e)
|
||||
|
@ -124,6 +125,7 @@ void ResultTextView::mouseMoveEvent(QMouseEvent *e)
|
|||
changeX = m_stepSpeedX * sqrt(abs(m_stepSpeedX)) * 100;
|
||||
|
||||
//return true;
|
||||
|
||||
}
|
||||
|
||||
if (m_gestureAction != GA_null) {
|
||||
|
@ -172,6 +174,15 @@ bool ResultTextView::gestureEvent(QGestureEvent *event)
|
|||
if (QGesture *tap = event->gesture(Qt::TapGesture)) {
|
||||
tapGestureTriggered(static_cast<QTapGesture *>(tap));
|
||||
}
|
||||
if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture))
|
||||
tapAndHoldGestureTriggered(static_cast<QTapAndHoldGesture *>(tapAndHold));
|
||||
if (QGesture *pan = event->gesture(Qt::PanGesture))
|
||||
panTriggered(static_cast<QPanGesture *>(pan));
|
||||
if (QGesture *pinch = event->gesture(Qt::PinchGesture))
|
||||
pinchTriggered(static_cast<QPinchGesture *>(pinch));
|
||||
// qDebug()<<event<<"this is for test";
|
||||
// if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
|
||||
// swipeTriggered(static_cast<QSwipeGesture *>(swipe));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -210,6 +221,91 @@ void ResultTextView::tapGestureTriggered(QTapGesture *tap)
|
|||
}
|
||||
}
|
||||
|
||||
void ResultTextView::tapAndHoldGestureTriggered(QTapAndHoldGesture *tapAndHold)
|
||||
{
|
||||
//单指长按
|
||||
switch (tapAndHold->state()) {
|
||||
case Qt::GestureStarted:
|
||||
m_gestureAction = GA_hold;
|
||||
break;
|
||||
case Qt::GestureUpdated:
|
||||
break;
|
||||
case Qt::GestureCanceled:
|
||||
break;
|
||||
case Qt::GestureFinished:
|
||||
m_gestureAction = GA_null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ResultTextView::panTriggered(QPanGesture *pan)
|
||||
{
|
||||
//两指平移
|
||||
switch (pan->state()) {
|
||||
case Qt::GestureStarted:
|
||||
m_gestureAction = GA_pan;
|
||||
break;
|
||||
case Qt::GestureUpdated:
|
||||
break;
|
||||
case Qt::GestureCanceled:
|
||||
break;
|
||||
case Qt::GestureFinished:
|
||||
m_gestureAction = GA_null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ResultTextView::pinchTriggered(QPinchGesture *pinch)
|
||||
{
|
||||
//两指拉伸 -----缩放or放大
|
||||
switch (pinch->state()) {
|
||||
case Qt::GestureStarted: {
|
||||
m_gestureAction = GA_pinch;
|
||||
if (static_cast<int>(m_scaleFactor) != m_fontSize) {
|
||||
m_scaleFactor = m_fontSize;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Qt::GestureUpdated: {
|
||||
QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags();
|
||||
if (changeFlags & QPinchGesture::ScaleFactorChanged) {
|
||||
m_currentStepScaleFactor = pinch->totalScaleFactor();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Qt::GestureCanceled: {
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
case Qt::GestureFinished: {
|
||||
m_gestureAction = GA_null;
|
||||
m_scaleFactor *= m_currentStepScaleFactor;
|
||||
m_currentStepScaleFactor = 1;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}//switch
|
||||
|
||||
//QFont font = getVTFont();
|
||||
int size = static_cast<int>(m_scaleFactor * m_currentStepScaleFactor);
|
||||
if (size < 8)
|
||||
size = 8;
|
||||
if (size > 50)
|
||||
size = 50;
|
||||
//根据移动距离设置字体大小
|
||||
// setFontSize(size);
|
||||
//同步设置界面字体栏数值
|
||||
// qobject_cast<Window *>(this->window())->changeSettingDialogComboxFontNumber(size);
|
||||
}
|
||||
|
||||
|
||||
void ResultTextView::slideGestureY(qreal diff)
|
||||
{
|
||||
static qreal delta = 0.0;
|
||||
|
@ -227,3 +323,14 @@ void ResultTextView::slideGestureX(qreal diff)
|
|||
|
||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + step * 10);
|
||||
}
|
||||
|
||||
void ResultTextView::onSelectionArea()
|
||||
{
|
||||
if (m_gestureAction != GA_null) {
|
||||
QTextCursor cursor = textCursor();
|
||||
if (cursor.selectedText() != "") {
|
||||
cursor.clearSelection();
|
||||
setTextCursor(cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,18 @@ protected:
|
|||
//触摸屏功能函数
|
||||
bool gestureEvent(QGestureEvent *event);
|
||||
void tapGestureTriggered(QTapGesture *tap);
|
||||
void tapAndHoldGestureTriggered(QTapAndHoldGesture *tapAndHold);
|
||||
void panTriggered(QPanGesture *pan);
|
||||
void pinchTriggered(QPinchGesture *pinch);
|
||||
// void swipeTriggered(QSwipeGesture *swipe);
|
||||
|
||||
//add for single refers to the sliding
|
||||
void slideGestureY(qreal diff);
|
||||
void slideGestureX(qreal diff);
|
||||
|
||||
|
||||
private slots:
|
||||
void onSelectionArea();
|
||||
signals:
|
||||
void sigChangeSize();
|
||||
private:
|
||||
|
@ -63,6 +71,10 @@ private:
|
|||
ulong m_lastMouseTimeX;
|
||||
ulong m_lastMouseTimeY;
|
||||
|
||||
qreal m_scaleFactor = 1;
|
||||
qreal m_currentStepScaleFactor = 1;
|
||||
Qt::GestureState m_tapStatus = Qt::NoGesture;
|
||||
int m_fontSize = 16;
|
||||
};
|
||||
|
||||
#endif // RESULTTEXTVIEW_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user