Commit 657badad authored by Dennis Nienhüser's avatar Dennis Nienhüser

Add a pressAndHold event similar to what QML MouseArea provides

parent 0a9795a2
......@@ -164,6 +164,7 @@ class Q_DECL_HIDDEN MarbleDefaultInputHandler::Private
int m_dragThreshold;
QTimer m_lmbTimer;
QTimer m_pressAndHoldTimer;
// Models to handle the kinetic spinning.
KineticModel m_kineticSpinning;
......@@ -222,6 +223,10 @@ MarbleDefaultInputHandler::MarbleDefaultInputHandler(MarbleAbstractPresenter *ma
// Left and right mouse button signals.
connect(this, SIGNAL(rmbRequest(int,int)), this, SLOT(showRmbMenu(int,int)));
connect(this, SIGNAL(lmbRequest(int,int)), this, SLOT(showLmbMenu(int,int)));
d->m_pressAndHoldTimer.setInterval(800);
d->m_pressAndHoldTimer.setSingleShot(true);
connect(&d->m_pressAndHoldTimer, SIGNAL(timeout()), this, SLOT(handlePressAndHold()));
}
MarbleDefaultInputHandler::~MarbleDefaultInputHandler()
......@@ -283,6 +288,7 @@ bool MarbleDefaultInputHandler::handleDoubleClick(QMouseEvent *event)
mouseLon, mouseLat, GeoDataCoordinates::Radian);
if(isMouseAboveMap)
{
d->m_pressAndHoldTimer.stop();
d->m_lmbTimer.stop();
MarbleInputHandler::d->m_marblePresenter->moveTo(event->pos(), 0.67);
}
......@@ -490,6 +496,7 @@ void MarbleDefaultInputHandler::handleLeftMouseButtonPress(QMouseEvent *event)
if (event->modifiers() & Qt::ControlModifier)
{
mDebug() << Q_FUNC_INFO << "Starting selection";
d->m_pressAndHoldTimer.stop();
d->m_lmbTimer.stop();
d->m_selectionOrigin = event->pos();
selectionRubber()->setGeometry(QRect(d->m_selectionOrigin, QSize()));
......@@ -691,6 +698,7 @@ QPoint MarbleDefaultInputHandler::mouseMovedOutside(QMouseEvent *event)
if (event->button() == Qt::LeftButton && event->type() == QEvent::MouseButtonPress
&& panViaArrowsEnabled() && !d->m_kineticSpinning.hasVelocity())
{
d->m_pressAndHoldTimer.stop();
d->m_lmbTimer.stop();
qreal moveStep = MarbleInputHandler::d->m_marblePresenter->moveStep();
if (polarity < 0)
......@@ -728,6 +736,7 @@ bool MarbleDefaultInputHandler::handleMouseEvent(QMouseEvent *event)
if ( floatItem->enabled() && floatItem->visible()
&& floatItem->contains( event->pos() ) )
{
d->m_pressAndHoldTimer.stop();
d->m_lmbTimer.stop();
return false;
}
......@@ -747,11 +756,13 @@ bool MarbleDefaultInputHandler::handleMouseEvent(QMouseEvent *event)
{
if (event->type() == QEvent::MouseButtonPress)
{
d->m_pressAndHoldTimer.start();
handleMouseButtonPress(event);
}
if (event->type() == QEvent::MouseButtonRelease)
{
d->m_pressAndHoldTimer.stop();
handleMouseButtonRelease(event);
}
......@@ -768,6 +779,7 @@ bool MarbleDefaultInputHandler::handleMouseEvent(QMouseEvent *event)
{
MarbleInputHandler::d->m_marblePresenter->setViewContext(Animation);
d->m_pressAndHoldTimer.stop();
d->m_lmbTimer.stop();
const qreal posLon = d->m_leftPressedLon - 90.0 * d->m_leftPressedDirection * deltax / radius;
......@@ -888,6 +900,16 @@ bool MarbleDefaultInputHandler::handleKeyPress(QKeyEvent* event)
return false;
}
void MarbleDefaultInputHandler::handleMouseButtonPressAndHold(const QPoint &)
{
// Default implementation does nothing
}
void MarbleDefaultInputHandler::handlePressAndHold()
{
handleMouseButtonPressAndHold(QPoint(d->m_leftPressedX, d->m_leftPressedY));
}
QPointer<AbstractDataPluginItem> MarbleDefaultInputHandler::lastToolTipItem()
{
return d->m_lastToolTipItem;
......
......@@ -138,11 +138,13 @@ class MARBLE_EXPORT MarbleDefaultInputHandler : public MarbleInputHandler
QPoint toolTipPosition();
virtual bool handleKeyPress(QKeyEvent *e);
virtual void handleMouseButtonPressAndHold(const QPoint &position);
private Q_SLOTS:
virtual void installPluginEventFilter( RenderPlugin *renderPlugin ) = 0;
virtual void showLmbMenu( int, int ) = 0;
virtual void showRmbMenu( int, int ) = 0;
void handlePressAndHold();
virtual void openItemToolTip() = 0;
virtual void setCursor(const QCursor &) = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment