8#include "MarbleWidgetInputHandler.h"
15#include "AbstractDataPluginItem.h"
16#include "MarbleAbstractPresenter.h"
17#include "MarbleDebug.h"
18#include "MarbleGlobal.h"
21#include "MarbleWidgetPopupMenu.h"
22#include "PopupLayer.h"
23#include "RenderPlugin.h"
24#include "RoutingLayer.h"
30class MarbleWidgetInputHandlerPrivate
32 class MarbleWidgetSelectionRubber :
public AbstractSelectionRubber
35 explicit MarbleWidgetSelectionRubber(MarbleWidget *widget)
49 bool isVisible()
const override
53 const QRect &geometry()
const override
57 void setGeometry(
const QRect &geometry)
override
67 MarbleWidgetInputHandlerPrivate(MarbleWidgetInputHandler *handler, MarbleWidget *widget, MarbleAbstractPresenter *presenter)
68 : m_inputHandler(handler)
69 , m_marbleWidget(widget)
70 , m_marblePresenter(presenter)
71 , m_selectionRubber(widget)
72 , m_debugModeEnabled(false)
74 for (RenderPlugin *renderPlugin : widget->renderPlugins()) {
75 if (renderPlugin->isInitialized()) {
76 installPluginEventFilter(renderPlugin);
82 void setCursor(
const QCursor &cursor)
84 m_marbleWidget->setCursor(cursor);
89 if (m_marbleWidget->popupLayer()->eventFilter(o, e)) {
93 if (m_marbleWidget->routingLayer()->eventFilter(o, e)) {
100 void installPluginEventFilter(RenderPlugin *renderPlugin)
102 m_marbleWidget->installEventFilter(renderPlugin);
105 MarbleWidgetInputHandler *m_inputHandler;
106 MarbleWidget *m_marbleWidget;
107 MarbleAbstractPresenter *m_marblePresenter;
108 MarbleWidgetSelectionRubber m_selectionRubber;
109 bool m_debugModeEnabled;
110 bool m_pinchDetected =
false;
111 bool m_panDetected =
false;
114void MarbleWidgetInputHandler::setCursor(
const QCursor &cursor)
116 d->setCursor(cursor);
119bool MarbleWidgetInputHandler::handleKeyPress(
QKeyEvent *event)
121 if (d->m_debugModeEnabled) {
123 switch (
event->key()) {
125 d->m_marbleWidget->setLevelToDebug(0);
128 d->m_marbleWidget->setLevelToDebug(1);
131 d->m_marbleWidget->setLevelToDebug(2);
134 d->m_marbleWidget->setLevelToDebug(3);
137 d->m_marbleWidget->setLevelToDebug(4);
140 d->m_marbleWidget->setLevelToDebug(5);
143 d->m_marbleWidget->setLevelToDebug(6);
146 d->m_marbleWidget->setLevelToDebug(7);
149 d->m_marbleWidget->setLevelToDebug(8);
152 d->m_marbleWidget->setLevelToDebug(9);
155 d->m_marbleWidget->setLevelToDebug(d->m_marbleWidget->levelToDebug() + 1);
158 d->m_marbleWidget->setLevelToDebug(d->m_marbleWidget->levelToDebug() - 1);
162 switch (
event->key()) {
164 MarbleDebug::setEnabled(!MarbleDebug::isEnabled());
167 d->m_marbleWidget->setShowRuntimeTrace(!d->m_marbleWidget->showRuntimeTrace());
170 d->m_marbleWidget->setShowDebugPlacemarks(!d->m_marbleWidget->showDebugPlacemarks());
173 d->m_marbleWidget->setShowDebugPolygons(!d->m_marbleWidget->showDebugPolygons());
176 d->m_marbleWidget->setShowDebugBatchRender(!d->m_marbleWidget->showDebugBatchRender());
179 d->m_marbleWidget->setDebugLevelTags(!d->m_marbleWidget->debugLevelTags());
184 return MarbleDefaultInputHandler::handleKeyPress(event);
187bool MarbleWidgetInputHandler::handleTouch(
QTouchEvent *event)
191 if (
event->touchPoints().count() == 1) {
192 QTouchEvent::TouchPoint p =
event->touchPoints().at(0);
194 d->m_pinchDetected =
false;
195 d->m_panDetected =
false;
197 handleMouseEvent(&press);
199 if (!d->m_pinchDetected) {
200 d->m_panDetected =
true;
202 handleMouseEvent(&move);
206 if (d->m_pinchDetected || d->m_panDetected)
210 handleMouseEvent(&release);
212 if (d->m_pinchDetected || d->m_panDetected) {
213 if (d->m_pinchDetected)
214 stopInertialEarthRotation();
223bool MarbleWidgetInputHandler::handleGesture(
QGestureEvent *e)
226 if (pinch && !d->m_panDetected) {
227 d->m_pinchDetected =
true;
228 handlePinchGesture(pinch);
235void MarbleWidgetInputHandler::handlePinchGesture(
QPinchGesture *pinch)
237 MarbleAbstractPresenter *marblePresenter = d->m_marblePresenter;
239 switch (pinch->
state()) {
243 marblePresenter->setViewContext(Animation);
249 if (scaleFactor > 1.0)
251 else if (scaleFactor < 1.0)
256 qreal
zoom = marblePresenter->zoom();
257 bool oldAnim = marblePresenter->animationsEnabled();
258 qreal newDistance = marblePresenter->distanceFromZoom(zoom + 20 * scaleFactor);
259 marblePresenter->setAnimationsEnabled(
false);
260 marblePresenter->zoomAt(center, newDistance);
261 marblePresenter->setAnimationsEnabled(oldAnim);
266 restoreViewContext();
271AbstractSelectionRubber *MarbleWidgetInputHandler::selectionRubber()
273 return &d->m_selectionRubber;
276bool MarbleWidgetInputHandler::layersEventFilter(
QObject *o,
QEvent *e)
278 return d->layersEventFilter(o, e);
281void MarbleWidgetInputHandler::installPluginEventFilter(RenderPlugin *renderPlugin)
283 d->installPluginEventFilter(renderPlugin);
286MarbleWidgetInputHandler::MarbleWidgetInputHandler(MarbleAbstractPresenter *marblePresenter, MarbleWidget *widget)
287 : MarbleDefaultInputHandler(marblePresenter)
288 , d(new MarbleWidgetInputHandlerPrivate(this, widget, marblePresenter))
292void MarbleWidgetInputHandler::setDebugModeEnabled(
bool enabled)
294 d->m_debugModeEnabled = enabled;
298void MarbleWidgetInputHandler::showLmbMenu(
int x,
int y)
300 if (isMouseButtonPopupEnabled(
Qt::LeftButton) && !d->m_pinchDetected && !d->m_panDetected) {
301 d->m_marbleWidget->popupMenu()->showLmbMenu(x, y);
302 toolTipTimer()->stop();
306void MarbleWidgetInputHandler::showRmbMenu(
int x,
int y)
309 d->m_marbleWidget->popupMenu()->showRmbMenu(x, y);
313void MarbleWidgetInputHandler::openItemToolTip()
315 if (lastToolTipItem()) {
317 lastToolTipItem()->toolTip(),
319 lastToolTipItem()->containsRect(toolTipPosition()).toRect());
325#include "moc_MarbleWidgetInputHandler.cpp"
This file contains the headers for MarbleMap.
This file contains the headers for ViewportParams.
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
KIOCORE_EXPORT CopyJob * move(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)
Binds a QML item to a specific geodetic location in screen coordinates.
QGesture * gesture(Qt::GestureType type) const const
void setGeometry(const QRect &rect)
QTextStream & center(QTextStream &stream)
void showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime)