File indexing completed on 2024-04-21 03:49:42

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2005-2007 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 // SPDX-FileCopyrightText: 2014 Adam Dabrowski <adamdbrw@gmail.com>
0006 //
0007 
0008 #ifndef MARBLE_MARBLEINPUTHANDLER_H
0009 #define MARBLE_MARBLEINPUTHANDLER_H
0010 
0011 #include <QObject>
0012 
0013 #include "marble_export.h"
0014 #include "GeoDataCoordinates.h"
0015 
0016 class QEvent;
0017 class QKeyEvent;
0018 class QMouseEvent;
0019 class QTouchEvent;
0020 class QWheelEvent;
0021 class QGestureEvent;
0022 class QCursor;
0023 class QTimer;
0024 class QString;
0025 class QRect;
0026 
0027 namespace Marble
0028 {
0029 
0030 class MarbleAbstractPresenter;
0031 class AbstractDataPluginItem;
0032 class RenderPlugin;
0033 
0034 class MARBLE_EXPORT MarbleInputHandler  : public QObject
0035 {
0036     Q_OBJECT
0037 
0038  public:
0039     explicit MarbleInputHandler( MarbleAbstractPresenter* );
0040     ~MarbleInputHandler() override;
0041 
0042     void setPositionSignalConnected( bool connected );
0043     bool isPositionSignalConnected() const;
0044 
0045     /**
0046 //
0047 // The MarbleInputHandler handles mouse and keyboard input.
0048 //
0049 
0050      * @brief  Set whether a popup menu appears on a click (not drag) with the left mouse button
0051      * @param  enabled True to enable the popup menu (default), false to disable it
0052      */
0053     void setMouseButtonPopupEnabled( Qt::MouseButton mouseButton, bool enabled );
0054 
0055     /**
0056      * @brief  Return whether the left mouse button popup menu is active
0057      * @return True iff a popup menu is shown on left mouse button clicks
0058      */
0059     bool isMouseButtonPopupEnabled( Qt::MouseButton mouseButton ) const;
0060 
0061     void setPanViaArrowsEnabled( bool enabled );
0062 
0063     bool panViaArrowsEnabled() const;
0064 
0065     void setInertialEarthRotationEnabled( bool enabled );
0066 
0067     /**
0068      * @brief Returns true iff dragging the map with the mouse keeps spinning
0069      * in the chosen direction for a slightly longer time than the mouse is
0070      * actually performing the drag operation
0071      */
0072     bool inertialEarthRotationEnabled() const;
0073 
0074     void setMouseViewRotationEnabled( bool enabled );
0075 
0076     bool mouseViewRotationEnabled() const;
0077 
0078     /// should the map do kinetic scrolling, this would stop the operation
0079     virtual void stopInertialEarthRotation();
0080 
0081  Q_SIGNALS:
0082     // Mouse button menus
0083     void lmbRequest( int, int );
0084     void rmbRequest( int, int );
0085 
0086     //Gps coordinates
0087     void mouseClickScreenPosition( int, int );
0088     void mouseMoveGeoPosition( const QString& );
0089 
0090     /*
0091      * To detect mouse click followed by mouse move
0092      * with no mouse move in between
0093      */
0094     void mouseClickGeoPosition( qreal, qreal, GeoDataCoordinates::Unit );
0095 
0096  protected Q_SLOTS:
0097     void restoreViewContext();
0098 
0099  protected:
0100     class Protected;
0101     Protected * const d;
0102 
0103  private Q_SLOTS:
0104     virtual void installPluginEventFilter( RenderPlugin *renderPlugin ) = 0;
0105 
0106  private:
0107     Q_DISABLE_COPY( MarbleInputHandler )
0108 };
0109 
0110 class AbstractSelectionRubber
0111 {
0112 public:
0113     virtual ~AbstractSelectionRubber() {}
0114     virtual void show() = 0;
0115     virtual void hide() = 0;
0116     virtual bool isVisible() const = 0;
0117     virtual const QRect &geometry() const = 0;
0118     virtual void setGeometry(const QRect &geometry) = 0;
0119 };
0120 
0121 class MARBLE_EXPORT MarbleDefaultInputHandler  : public MarbleInputHandler
0122 {
0123     Q_OBJECT
0124 
0125  public:
0126     explicit MarbleDefaultInputHandler( MarbleAbstractPresenter* marblePresenter);
0127     ~MarbleDefaultInputHandler() override;
0128 
0129     void stopInertialEarthRotation() override;
0130 
0131  protected:
0132     bool eventFilter( QObject *, QEvent * ) override;
0133     bool handleMouseEvent(QMouseEvent *e);
0134     bool handlePinch(const QPointF &center, qreal scaleFactor, Qt::GestureState state);
0135 
0136     //FIXME - refactor (abstraction & composition)
0137     const AbstractDataPluginItem *lastToolTipItem() const;
0138     QTimer* toolTipTimer();
0139     QPoint toolTipPosition() const;
0140 
0141     virtual bool handleKeyPress(QKeyEvent *e);
0142     virtual void handleMouseButtonPressAndHold(const QPoint &position);
0143 
0144  private Q_SLOTS:
0145     void installPluginEventFilter( RenderPlugin *renderPlugin ) override = 0;
0146     virtual void showLmbMenu( int, int ) = 0;
0147     virtual void showRmbMenu( int, int ) = 0;
0148     void handlePressAndHold();
0149 
0150     virtual void openItemToolTip() = 0;
0151     virtual void setCursor(const QCursor &) = 0;
0152 
0153     void lmbTimeout();
0154 
0155  private:
0156     virtual AbstractSelectionRubber *selectionRubber() = 0;
0157     virtual bool layersEventFilter(QObject *, QEvent *) = 0;
0158 
0159     virtual bool handleTouch(QTouchEvent *e);
0160     virtual bool handleDoubleClick(QMouseEvent *e);
0161     virtual bool handleWheel(QWheelEvent *e);
0162     virtual bool handleGesture(QGestureEvent *e);
0163 
0164     virtual void handleMouseButtonPress(QMouseEvent *e);
0165     virtual void handleLeftMouseButtonPress(QMouseEvent *e);
0166     virtual void handleRightMouseButtonPress(QMouseEvent *e);
0167     virtual void handleMiddleMouseButtonPress(QMouseEvent *e);
0168     virtual void handleMouseButtonRelease(QMouseEvent *e);
0169 
0170     virtual void hideSelectionIfCtrlReleased(QEvent *e);
0171     virtual void checkReleasedMove(QMouseEvent *e);
0172 
0173     //Returns whatever should be returned from mouse event handling loop
0174     virtual bool acceptMouse();
0175 
0176     void notifyPosition(bool isAboveMap, qreal mouseLon, qreal mouseLat);
0177     QPoint mouseMovedOutside(QMouseEvent *event);
0178     void adjustCursorShape(const QPoint& mousePosition, const QPoint& mouseDirection);
0179 
0180     Q_DISABLE_COPY(MarbleDefaultInputHandler)
0181     class Private;
0182     Private * const d;
0183 };
0184 
0185 }
0186 
0187 #endif  //MARBLE_MARBLEINPUTHANDLER_H