Index: kstars/fitsviewer/fitsdata.h =================================================================== --- kstars/fitsviewer/fitsdata.h +++ kstars/fitsviewer/fitsdata.h @@ -33,6 +33,7 @@ #include #include +#include #ifndef KSTARS_LITE #include "fitshistogram.h" Index: kstars/skymap.h =================================================================== --- kstars/skymap.h +++ kstars/skymap.h @@ -25,6 +25,7 @@ #include "skyobjects/skyline.h" #include +#include #include class QPainter; @@ -509,6 +510,8 @@ void removeSkyObject(SkyObject *object); protected: + bool event(QEvent *event) override; + /** Process keystrokes: * @li arrow keys Slew the map * @li +/- keys Zoom in and out @@ -670,6 +673,10 @@ bool m_objPointingMode { false }; bool m_fovCaptureMode { false }; + bool m_touchMode { false }; + bool m_pinchMode { false }; + bool m_tapAndHoldMode { false }; + qreal m_pinchScale { 0.0 }; QWidget *m_SkyMapDraw { nullptr }; // Can be dynamic_cast<> to SkyMapDrawAbstract Index: kstars/skymap.cpp =================================================================== --- kstars/skymap.cpp +++ kstars/skymap.cpp @@ -125,6 +125,10 @@ : QGraphicsView(KStars::Instance()), computeSkymap(true), rulerMode(false), data(KStarsData::Instance()), pmenu(nullptr), ClickedObject(nullptr), FocusObject(nullptr), m_proj(nullptr), m_previewLegend(false), m_objPointingMode(false) { +#if !defined(KSTARS_LITE) + grabGesture(Qt::PinchGesture); + grabGesture(Qt::TapAndHoldGesture); +#endif m_Scale = 1.0; ZoomRect = QRect(); Index: kstars/skymapevents.cpp =================================================================== --- kstars/skymapevents.cpp +++ kstars/skymapevents.cpp @@ -32,6 +32,7 @@ #include "skycomponents/starcomponent.h" #include "widgets/infoboxwidget.h" +#include #include #include @@ -396,11 +397,76 @@ void SkyMap::stopTracking() { KStars *kstars = KStars::Instance(); + emit positionChanged(focus()); if (kstars && Options::isTracking()) kstars->slotTrack(); } +bool SkyMap::event(QEvent *event) +{ +#if !defined(KSTARS_LITE) + if (event->type() == QEvent::TouchBegin) + { + m_touchMode = true; + m_pinchScale = -1; + } + + if (event->type() == QEvent::Gesture) + { + QGestureEvent* gestureEvent = static_cast(event); + + if (QPinchGesture *pinch = static_cast(gestureEvent->gesture(Qt::PinchGesture))) + { + QPinchGesture::ChangeFlags changeFlags = pinch->changeFlags(); + + m_pinchMode = true; + if (changeFlags & QPinchGesture::ScaleFactorChanged) + { + if (m_pinchScale == -1) + { + m_pinchScale = pinch->totalScaleFactor(); + return true; + } + if (pinch->totalScaleFactor()-m_pinchScale > 0.1) + { + m_pinchScale = pinch->totalScaleFactor(); + zoomInOrMagStep(0); + return true; + } + if (pinch->totalScaleFactor()-m_pinchScale < -0.1) + { + m_pinchScale = pinch->totalScaleFactor(); + zoomOutOrMagStep(0); + return true; + } + } + } + if (QTapAndHoldGesture *tapAndHold = static_cast(gestureEvent->gesture(Qt::TapAndHoldGesture))) + { + m_tapAndHoldMode = true; + if (tapAndHold->state() == Qt::GestureFinished) + { + if (clickedObject()) + { + clickedObject()->showPopupMenu(pmenu, tapAndHold->position().toPoint()); + } + else + { + pmenu->createEmptyMenu(clickedPoint()); + pmenu->popup(tapAndHold->position().toPoint()); + } + m_touchMode = false; + m_pinchMode = false; + m_tapAndHoldMode = false; + } + } + return true; + } +#endif + return QGraphicsView::event(event); +} + void SkyMap::keyReleaseEvent(QKeyEvent *e) { switch (e->key()) @@ -429,6 +495,12 @@ void SkyMap::mouseMoveEvent(QMouseEvent *e) { +#if !defined(KSTARS_LITE) + // Skip touch points + if (m_pinchMode || m_tapAndHoldMode || (m_touchMode && e->globalX() == 0 && e->globalY() == 0)) + return; +#endif + if (Options::useHoverLabel()) { //Start a single-shot timer to monitor whether we are currently hovering. @@ -552,6 +624,15 @@ void SkyMap::mouseReleaseEvent(QMouseEvent *) { +#if !defined(KSTARS_LITE) + if (m_touchMode) + { + m_touchMode = false; + m_pinchMode = false; + m_tapAndHoldMode = false; + } +#endif + if (ZoomRect.isValid()) { stopTracking();