Changeset View
Changeset View
Standalone View
Standalone View
src/lib/marble/MarbleInputHandler.cpp
Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 132 | public: | |||
---|---|---|---|---|---|
141 | QPixmap m_curpmbl; | 141 | QPixmap m_curpmbl; | ||
142 | QPixmap m_curpmbc; | 142 | QPixmap m_curpmbc; | ||
143 | QPixmap m_curpmbr; | 143 | QPixmap m_curpmbr; | ||
144 | 144 | | |||
145 | QCursor m_arrowCur[3][3]; | 145 | QCursor m_arrowCur[3][3]; | ||
146 | 146 | | |||
147 | // Indicates if the left mouse button has been pressed already. | 147 | // Indicates if the left mouse button has been pressed already. | ||
148 | bool m_leftPressed; | 148 | bool m_leftPressed; | ||
149 | // Indicates whether the drag was started by a click above or below the visible pole. | | |||
150 | int m_leftPressedDirection; | | |||
151 | // Indicates if the middle mouse button has been pressed already. | 149 | // Indicates if the middle mouse button has been pressed already. | ||
152 | bool m_midPressed; | 150 | bool m_midPressed; | ||
153 | // The mouse pointer x position when the left mouse button has been pressed. | 151 | // The mouse pointer x position when the left mouse button has been pressed. | ||
154 | int m_leftPressedX; | 152 | int m_leftPressedX; | ||
155 | // The mouse pointer y position when the left mouse button has been pressed. | 153 | // The mouse pointer y position when the left mouse button has been pressed. | ||
156 | int m_leftPressedY; | 154 | int m_leftPressedY; | ||
157 | // The mouse pointer y position when the middle mouse button has been pressed. | 155 | // The mouse pointer y position when the middle mouse button has been pressed. | ||
158 | int m_midPressedY; | 156 | int m_midPressedY; | ||
159 | int m_startingRadius; | 157 | int m_startingRadius; | ||
160 | 158 | | |||
159 | // Indicates if the right mouse button has been pressed already. | ||||
160 | bool m_rightPressed; | ||||
161 | // Point where the right mouse button has been pressed on. | ||||
162 | QPoint m_rightOrigin; | ||||
163 | // Position to calculate the heading. | ||||
164 | // Indicates previous position since mouse has been moved. | ||||
165 | QPoint m_rightPosition; | ||||
166 | // Indicates the heading when the right mouse button has been pressed | ||||
167 | // and mouse is moving. | ||||
168 | qreal m_heading; | ||||
169 | | ||||
161 | // The center longitude in radian when the left mouse button has been pressed. | 170 | // The center longitude in radian when the left mouse button has been pressed. | ||
162 | qreal m_leftPressedLon; | 171 | qreal m_leftPressedLon; | ||
163 | // The center latitude in radian when the left mouse button has been pressed. | 172 | // The center latitude in radian when the left mouse button has been pressed. | ||
164 | qreal m_leftPressedLat; | 173 | qreal m_leftPressedLat; | ||
165 | 174 | | |||
166 | int m_dragThreshold; | 175 | int m_dragThreshold; | ||
167 | QTimer m_lmbTimer; | 176 | QTimer m_lmbTimer; | ||
168 | QTimer m_pressAndHoldTimer; | 177 | QTimer m_pressAndHoldTimer; | ||
169 | 178 | | |||
170 | // Models to handle the kinetic spinning. | 179 | // Models to handle the kinetic spinning. | ||
171 | KineticModel m_kineticSpinning; | 180 | KineticModel m_kineticSpinning; | ||
172 | 181 | | |||
173 | QPoint m_selectionOrigin; | 182 | QPoint m_selectionOrigin; | ||
174 | 183 | | |||
175 | QPointer<AbstractDataPluginItem> m_lastToolTipItem; | 184 | QPointer<AbstractDataPluginItem> m_lastToolTipItem; | ||
176 | QTimer m_toolTipTimer; | 185 | QTimer m_toolTipTimer; | ||
177 | QPoint m_toolTipPosition; | 186 | QPoint m_toolTipPosition; | ||
178 | }; | 187 | }; | ||
179 | 188 | | |||
180 | MarbleDefaultInputHandler::Private::Private() | 189 | MarbleDefaultInputHandler::Private::Private() | ||
181 | : m_leftPressed(false), | 190 | : m_leftPressed(false), | ||
182 | m_midPressed(false), | 191 | m_midPressed(false), | ||
192 | m_rightPressed(false), | ||||
nienhueser: m_heading should be initialized here as well | |||||
193 | m_heading(0), | ||||
183 | m_dragThreshold(MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ? 15 : 3) | 194 | m_dragThreshold(MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ? 15 : 3) | ||
184 | { | 195 | { | ||
185 | m_curpmtl.load(QStringLiteral(":/marble/cursor/tl.png")); | 196 | m_curpmtl.load(QStringLiteral(":/marble/cursor/tl.png")); | ||
186 | m_curpmtc.load(QStringLiteral(":/marble/cursor/tc.png")); | 197 | m_curpmtc.load(QStringLiteral(":/marble/cursor/tc.png")); | ||
187 | m_curpmtr.load(QStringLiteral(":/marble/cursor/tr.png")); | 198 | m_curpmtr.load(QStringLiteral(":/marble/cursor/tr.png")); | ||
188 | m_curpmcr.load(QStringLiteral(":/marble/cursor/cr.png")); | 199 | m_curpmcr.load(QStringLiteral(":/marble/cursor/cr.png")); | ||
189 | m_curpmcl.load(QStringLiteral(":/marble/cursor/cl.png")); | 200 | m_curpmcl.load(QStringLiteral(":/marble/cursor/cl.png")); | ||
190 | m_curpmbl.load(QStringLiteral(":/marble/cursor/bl.png")); | 201 | m_curpmbl.load(QStringLiteral(":/marble/cursor/bl.png")); | ||
Show All 23 Lines | 223 | { | |||
214 | d->m_toolTipTimer.setInterval(TOOLTIP_START_INTERVAL); | 225 | d->m_toolTipTimer.setInterval(TOOLTIP_START_INTERVAL); | ||
215 | connect(&d->m_toolTipTimer, SIGNAL(timeout()), this, SLOT(openItemToolTip())); | 226 | connect(&d->m_toolTipTimer, SIGNAL(timeout()), this, SLOT(openItemToolTip())); | ||
216 | d->m_lmbTimer.setSingleShot(true); | 227 | d->m_lmbTimer.setSingleShot(true); | ||
217 | connect(&d->m_lmbTimer, SIGNAL(timeout()), this, SLOT(lmbTimeout())); | 228 | connect(&d->m_lmbTimer, SIGNAL(timeout()), this, SLOT(lmbTimeout())); | ||
218 | 229 | | |||
219 | d->m_kineticSpinning.setUpdateInterval(35); | 230 | d->m_kineticSpinning.setUpdateInterval(35); | ||
220 | connect(&d->m_kineticSpinning, SIGNAL(positionChanged(qreal,qreal)), | 231 | connect(&d->m_kineticSpinning, SIGNAL(positionChanged(qreal,qreal)), | ||
221 | MarbleInputHandler::d->m_marblePresenter, SLOT(centerOn(qreal,qreal))); | 232 | MarbleInputHandler::d->m_marblePresenter, SLOT(centerOn(qreal,qreal))); | ||
233 | connect(&d->m_kineticSpinning, SIGNAL(headingChanged(qreal)), | ||||
234 | MarbleInputHandler::d->m_marblePresenter, SLOT(headingOn(qreal))); | ||||
222 | connect(&d->m_kineticSpinning, SIGNAL(finished()), SLOT(restoreViewContext())); | 235 | connect(&d->m_kineticSpinning, SIGNAL(finished()), SLOT(restoreViewContext())); | ||
223 | 236 | | |||
224 | // Left and right mouse button signals. | 237 | // Left and right mouse button signals. | ||
225 | connect(this, SIGNAL(rmbRequest(int,int)), this, SLOT(showRmbMenu(int,int))); | 238 | connect(this, SIGNAL(rmbRequest(int,int)), this, SLOT(showRmbMenu(int,int))); | ||
226 | connect(this, SIGNAL(lmbRequest(int,int)), this, SLOT(showLmbMenu(int,int))); | 239 | connect(this, SIGNAL(lmbRequest(int,int)), this, SLOT(showLmbMenu(int,int))); | ||
227 | 240 | | |||
228 | d->m_pressAndHoldTimer.setInterval(800); | 241 | d->m_pressAndHoldTimer.setInterval(800); | ||
229 | d->m_pressAndHoldTimer.setSingleShot(true); | 242 | d->m_pressAndHoldTimer.setSingleShot(true); | ||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Line(s) | 471 | { | |||
476 | // still down. | 489 | // still down. | ||
477 | d->m_leftPressedX = event->x(); | 490 | d->m_leftPressedX = event->x(); | ||
478 | d->m_leftPressedY = event->y(); | 491 | d->m_leftPressedY = event->y(); | ||
479 | 492 | | |||
480 | // Calculate translation of center point | 493 | // Calculate translation of center point | ||
481 | d->m_leftPressedLon = MarbleInputHandler::d->m_marblePresenter->centerLongitude(); | 494 | d->m_leftPressedLon = MarbleInputHandler::d->m_marblePresenter->centerLongitude(); | ||
482 | d->m_leftPressedLat = MarbleInputHandler::d->m_marblePresenter->centerLatitude(); | 495 | d->m_leftPressedLat = MarbleInputHandler::d->m_marblePresenter->centerLatitude(); | ||
483 | 496 | | |||
484 | d->m_leftPressedDirection = 1; | | |||
485 | | ||||
486 | if (MarbleInputHandler::d->m_inertialEarthRotation) | 497 | if (MarbleInputHandler::d->m_inertialEarthRotation) | ||
487 | { | 498 | { | ||
488 | d->m_kineticSpinning.stop(); | 499 | d->m_kineticSpinning.stop(); | ||
489 | d->m_kineticSpinning.setPosition(d->m_leftPressedLon, d->m_leftPressedLat); | 500 | d->m_kineticSpinning.setPosition(d->m_leftPressedLon, d->m_leftPressedLat); | ||
490 | } | 501 | } | ||
491 | 502 | | |||
492 | // Choose spin direction by taking into account whether we | | |||
493 | // drag above or below the visible pole. | | |||
494 | if (MarbleInputHandler::d->m_marblePresenter->map()->projection() == Spherical) | | |||
495 | { | | |||
496 | if (d->m_leftPressedLat >= 0) | | |||
497 | { // The visible pole is the north pole | | |||
498 | qreal northPoleX, northPoleY; | | |||
499 | MarbleInputHandler::d->m_marblePresenter->map()->screenCoordinates(0.0, 90.0, northPoleX, northPoleY); | | |||
500 | if (event->y() < northPoleY) | | |||
501 | { | | |||
502 | d->m_leftPressedDirection = -1; | | |||
503 | } | | |||
504 | } | | |||
505 | else | | |||
506 | { // The visible pole is the south pole | | |||
507 | qreal southPoleX, southPoleY; | | |||
508 | MarbleInputHandler::d->m_marblePresenter->map()->screenCoordinates(0.0, -90.0, southPoleX, southPoleY); | | |||
509 | if (event->y() > southPoleY) | | |||
510 | { | | |||
511 | d->m_leftPressedDirection = -1; | | |||
512 | } | | |||
513 | } | | |||
514 | } | | |||
515 | | ||||
516 | if (event->modifiers() & Qt::ControlModifier) | 503 | if (event->modifiers() & Qt::ControlModifier) | ||
517 | { | 504 | { | ||
518 | mDebug() << Q_FUNC_INFO << "Starting selection"; | 505 | mDebug() << Q_FUNC_INFO << "Starting selection"; | ||
519 | d->m_pressAndHoldTimer.stop(); | 506 | d->m_pressAndHoldTimer.stop(); | ||
520 | d->m_lmbTimer.stop(); | 507 | d->m_lmbTimer.stop(); | ||
521 | d->m_selectionOrigin = event->pos(); | 508 | d->m_selectionOrigin = event->pos(); | ||
522 | selectionRubber()->setGeometry(QRect(d->m_selectionOrigin, QSize())); | 509 | selectionRubber()->setGeometry(QRect(d->m_selectionOrigin, QSize())); | ||
523 | selectionRubber()->show(); | 510 | selectionRubber()->show(); | ||
Show All 13 Lines | 515 | { | |||
537 | } | 524 | } | ||
538 | 525 | | |||
539 | selectionRubber()->hide(); | 526 | selectionRubber()->hide(); | ||
540 | MarbleInputHandler::d->m_marblePresenter->setViewContext(Animation); | 527 | MarbleInputHandler::d->m_marblePresenter->setViewContext(Animation); | ||
541 | } | 528 | } | ||
542 | 529 | | |||
543 | void MarbleDefaultInputHandler::handleRightMouseButtonPress(QMouseEvent *event) | 530 | void MarbleDefaultInputHandler::handleRightMouseButtonPress(QMouseEvent *event) | ||
544 | { | 531 | { | ||
545 | emit rmbRequest(event->x(), event->y()); | 532 | d->m_rightPressed = true; | ||
533 | d->m_rightOrigin = event->pos(); | ||||
534 | d->m_rightPosition = event->pos(); | ||||
535 | d->m_heading = MarbleInputHandler::d->m_marblePresenter->map()->heading(); | ||||
536 | if (MarbleInputHandler::d->m_inertialEarthRotation) | ||||
537 | { | ||||
538 | d->m_kineticSpinning.stop(); | ||||
539 | d->m_kineticSpinning.setHeading(d->m_heading); | ||||
540 | } | ||||
546 | } | 541 | } | ||
547 | 542 | | |||
548 | void MarbleDefaultInputHandler::handleMouseButtonRelease(QMouseEvent *event) | 543 | void MarbleDefaultInputHandler::handleMouseButtonRelease(QMouseEvent *event) | ||
549 | { | 544 | { | ||
550 | if (event->button() == Qt::LeftButton) | 545 | if (event->button() == Qt::LeftButton) | ||
551 | { | 546 | { | ||
552 | //emit current coordinates to be interpreted | 547 | //emit current coordinates to be interpreted | ||
553 | //as requested | 548 | //as requested | ||
Show All 14 Lines | |||||
568 | { | 563 | { | ||
569 | d->m_midPressed = false; | 564 | d->m_midPressed = false; | ||
570 | 565 | | |||
571 | MarbleInputHandler::d->m_marblePresenter->setViewContext(Still); | 566 | MarbleInputHandler::d->m_marblePresenter->setViewContext(Still); | ||
572 | } | 567 | } | ||
573 | 568 | | |||
574 | if (event->type() == QEvent::MouseButtonRelease && event->button() == Qt::RightButton) | 569 | if (event->type() == QEvent::MouseButtonRelease && event->button() == Qt::RightButton) | ||
575 | { | 570 | { | ||
571 | if (d->m_rightOrigin == event->pos()) | ||||
572 | { | ||||
573 | emit rmbRequest(event->x(), event->y()); | ||||
574 | } | ||||
575 | d->m_rightPressed = false; | ||||
576 | | ||||
577 | if (MarbleInputHandler::d->m_inertialEarthRotation) | ||||
578 | { | ||||
579 | d->m_kineticSpinning.start(); | ||||
580 | } | ||||
581 | else | ||||
582 | { | ||||
583 | MarbleInputHandler::d->m_marblePresenter->setViewContext(Still); | ||||
584 | } | ||||
576 | } | 585 | } | ||
577 | 586 | | |||
578 | if (event->type() == QEvent::MouseButtonRelease && event->button() == Qt::LeftButton | 587 | if (event->type() == QEvent::MouseButtonRelease && event->button() == Qt::LeftButton | ||
579 | && selectionRubber()->isVisible()) | 588 | && selectionRubber()->isVisible()) | ||
580 | { | 589 | { | ||
581 | mDebug() << Q_FUNC_INFO << "Leaving selection"; | 590 | mDebug() << Q_FUNC_INFO << "Leaving selection"; | ||
582 | MarbleInputHandler::d->m_marblePresenter->setSelection(selectionRubber()->geometry()); | 591 | MarbleInputHandler::d->m_marblePresenter->setSelection(selectionRubber()->geometry()); | ||
583 | selectionRubber()->hide(); | 592 | selectionRubber()->hide(); | ||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Line(s) | 789 | { | |||
781 | d->m_pressAndHoldTimer.stop(); | 790 | d->m_pressAndHoldTimer.stop(); | ||
782 | handleMouseButtonRelease(event); | 791 | handleMouseButtonRelease(event); | ||
783 | } | 792 | } | ||
784 | 793 | | |||
785 | // Regarding all kinds of mouse moves: | 794 | // Regarding all kinds of mouse moves: | ||
786 | if (d->m_leftPressed && !selectionRubber()->isVisible()) | 795 | if (d->m_leftPressed && !selectionRubber()->isVisible()) | ||
787 | { | 796 | { | ||
788 | qreal radius = (qreal)(MarbleInputHandler::d->m_marblePresenter->radius()); | 797 | qreal radius = (qreal)(MarbleInputHandler::d->m_marblePresenter->radius()); | ||
789 | int deltax = event->x() - d->m_leftPressedX; | 798 | qreal deltax = event->x() - d->m_leftPressedX; | ||
790 | int deltay = event->y() - d->m_leftPressedY; | 799 | qreal deltay = event->y() - d->m_leftPressedY; | ||
791 | 800 | | |||
nienhueser: qAbs (does not compile with abs here, same for the other ones) | |||||
792 | if (abs(deltax) > d->m_dragThreshold | 801 | if (qAbs(deltax) > d->m_dragThreshold | ||
nienhueser: qAbs | |||||
793 | || abs(deltay) > d->m_dragThreshold | 802 | || qAbs(deltay) > d->m_dragThreshold | ||
794 | || !d->m_lmbTimer.isActive()) | 803 | || !d->m_lmbTimer.isActive()) | ||
795 | { | 804 | { | ||
796 | MarbleInputHandler::d->m_marblePresenter->setViewContext(Animation); | 805 | MarbleInputHandler::d->m_marblePresenter->setViewContext(Animation); | ||
797 | 806 | | |||
798 | d->m_pressAndHoldTimer.stop(); | 807 | d->m_pressAndHoldTimer.stop(); | ||
799 | d->m_lmbTimer.stop(); | 808 | d->m_lmbTimer.stop(); | ||
800 | 809 | const Quaternion rotation = Quaternion::fromEuler( 0, 0, MarbleInputHandler::d->m_marblePresenter->map()->heading() * DEG2RAD ); | |||
801 | const qreal posLon = d->m_leftPressedLon - 90.0 * d->m_leftPressedDirection * deltax / radius; | 810 | Quaternion quat = Quaternion::fromSpherical( - M_PI/2 * deltax / radius, + M_PI/2 * deltay / radius ); | ||
802 | const qreal posLat = d->m_leftPressedLat + 90.0 * deltay / radius; | 811 | quat.rotateAroundAxis( rotation ); | ||
812 | qreal lon, lat; | ||||
813 | quat.getSpherical( lon, lat ); | ||||
814 | const qreal posLon = d->m_leftPressedLon + RAD2DEG * lon; | ||||
815 | const qreal posLat = d->m_leftPressedLat + RAD2DEG * lat; | ||||
803 | MarbleInputHandler::d->m_marblePresenter->centerOn(posLon, posLat); | 816 | MarbleInputHandler::d->m_marblePresenter->centerOn(posLon, posLat); | ||
804 | if (MarbleInputHandler::d->m_inertialEarthRotation) | 817 | if (MarbleInputHandler::d->m_inertialEarthRotation) | ||
805 | { | 818 | { | ||
806 | d->m_kineticSpinning.setPosition(posLon, posLat); | 819 | d->m_kineticSpinning.setPosition(posLon, posLat); | ||
807 | } | 820 | } | ||
808 | } | 821 | } | ||
809 | } | 822 | } | ||
810 | 823 | | |||
811 | if (d->m_midPressed) | 824 | if (d->m_midPressed) | ||
812 | { | 825 | { | ||
813 | int eventy = event->y(); | 826 | int eventy = event->y(); | ||
814 | int dy = d->m_midPressedY - eventy; | 827 | int dy = d->m_midPressedY - eventy; | ||
815 | MarbleInputHandler::d->m_marblePresenter->setRadius(d->m_startingRadius * pow(1.005, dy)); | 828 | MarbleInputHandler::d->m_marblePresenter->setRadius(d->m_startingRadius * pow(1.005, dy)); | ||
816 | } | 829 | } | ||
817 | 830 | | |||
831 | if (d->m_rightPressed) | ||||
832 | { | ||||
833 | qreal centerX, centerY; | ||||
834 | MarbleInputHandler::d->m_marblePresenter->map()->screenCoordinates( | ||||
835 | MarbleInputHandler::d->m_marblePresenter->centerLongitude(), | ||||
836 | MarbleInputHandler::d->m_marblePresenter->centerLatitude(), centerX, centerY); | ||||
837 | | ||||
838 | // Deltas from previous position. | ||||
839 | int dx = event->x() - d->m_rightPosition.x(); | ||||
840 | int dy = event->y() - d->m_rightPosition.y(); | ||||
841 | | ||||
842 | d->m_rightPosition = event->pos(); | ||||
843 | | ||||
844 | // Moving on the bottom should be opposite direction. | ||||
845 | int sign = event->y() > centerY ? -1 : 1; | ||||
846 | // Left top and right bottom sides for y axis should be opposite direction. | ||||
847 | if ((event->x() < centerX && event->y() < centerY) || (event->x() > centerX && event->y() > centerY)) | ||||
848 | { | ||||
849 | dy *= -1; | ||||
850 | } | ||||
851 | | ||||
852 | const qreal speedFactor = 0.3; | ||||
853 | d->m_heading += (dx + dy) * sign * speedFactor; | ||||
854 | MarbleInputHandler::d->m_marblePresenter->map()->setHeading(d->m_heading); | ||||
855 | if (MarbleInputHandler::d->m_inertialEarthRotation) | ||||
856 | { | ||||
857 | d->m_kineticSpinning.setHeading(d->m_heading); | ||||
858 | } | ||||
859 | } | ||||
860 | | ||||
818 | if (selectionRubber()->isVisible()) | 861 | if (selectionRubber()->isVisible()) | ||
819 | { | 862 | { | ||
820 | // We change selection. | 863 | // We change selection. | ||
821 | selectionRubber()->setGeometry(QRect(d->m_selectionOrigin, event->pos()).normalized()); | 864 | selectionRubber()->setGeometry(QRect(d->m_selectionOrigin, event->pos()).normalized()); | ||
822 | } | 865 | } | ||
823 | } | 866 | } | ||
824 | else | 867 | else | ||
825 | { | 868 | { | ||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |
m_heading should be initialized here as well