Handle panning touch gestures (#5524)
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QEasingCurve>
|
||||
#include <QGestureEvent>
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QJsonDocument>
|
||||
#include <QMessageBox>
|
||||
@@ -369,6 +370,8 @@ ChannelView::ChannelView(InternalCtor /*tag*/, QWidget *parent, Split *split,
|
||||
this->scrollUpdateRequested();
|
||||
});
|
||||
|
||||
this->grabGesture(Qt::PanGesture);
|
||||
|
||||
// TODO: Figure out if we need this, and if so, why
|
||||
// StrongFocus means we can focus this event through clicking it
|
||||
// and tabbing to it from another widget. I don't currently know
|
||||
@@ -1786,8 +1789,71 @@ void ChannelView::leaveEvent(QEvent * /*event*/)
|
||||
this->unpause(PauseReason::Mouse);
|
||||
}
|
||||
|
||||
bool ChannelView::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::Gesture)
|
||||
{
|
||||
if (const auto *gestureEvent = dynamic_cast<QGestureEvent *>(event))
|
||||
{
|
||||
return this->gestureEvent(gestureEvent);
|
||||
}
|
||||
}
|
||||
|
||||
return BaseWidget::event(event);
|
||||
}
|
||||
|
||||
bool ChannelView::gestureEvent(const QGestureEvent *event)
|
||||
{
|
||||
if (QGesture *pan = event->gesture(Qt::PanGesture))
|
||||
{
|
||||
if (const auto *gesture = dynamic_cast<QPanGesture *>(pan))
|
||||
{
|
||||
switch (gesture->state())
|
||||
{
|
||||
case Qt::GestureStarted: {
|
||||
this->isPanning_ = true;
|
||||
// Remove any selections and hide tooltip while panning
|
||||
this->clearSelection();
|
||||
this->tooltipWidget_->hide();
|
||||
if (this->isScrolling_)
|
||||
{
|
||||
this->disableScrolling();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::GestureUpdated: {
|
||||
if (this->scrollBar_->isVisible())
|
||||
{
|
||||
this->scrollBar_->offset(-gesture->delta().y() * 0.1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::GestureFinished:
|
||||
case Qt::GestureCanceled:
|
||||
default: {
|
||||
this->clearSelection();
|
||||
this->isPanning_ = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->isPanning_)
|
||||
{
|
||||
// Don't do any text selection, hovering, etc while panning
|
||||
return;
|
||||
}
|
||||
|
||||
/// Pause on hover
|
||||
if (float pauseTime = getSettings()->pauseOnHoverDuration;
|
||||
pauseTime > 0.001F)
|
||||
|
||||
Reference in New Issue
Block a user